All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.syndesis.integration.component.proxy.ImmutablePropertyRelation Maven / Gradle / Ivy

The newest version!
package io.syndesis.integration.component.proxy;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link ComponentDefinition.PropertyRelation}.
 * 

* Use the builder to create immutable instances: * {@code new ImmutablePropertyRelation.Builder()}. */ @Generated(from = "ComponentDefinition.PropertyRelation", generator = "Immutables") @SuppressWarnings({"all"}) @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") public final class ImmutablePropertyRelation implements ComponentDefinition.PropertyRelation { private final String action; private final List when; private ImmutablePropertyRelation( String action, List when) { this.action = action; this.when = when; } /** * @return The value of the {@code action} attribute */ @JsonProperty("action") @Override public String getAction() { return action; } /** * @return The value of the {@code when} attribute */ @JsonProperty("when") @Override public List getWhen() { return when; } /** * Copy the current immutable object by setting a value for the {@link ComponentDefinition.PropertyRelation#getAction() action} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for action * @return A modified copy of the {@code this} object */ public final ImmutablePropertyRelation withAction(String value) { String newValue = Objects.requireNonNull(value, "action"); if (this.action.equals(newValue)) return this; return new ImmutablePropertyRelation(newValue, this.when); } /** * Copy the current immutable object with elements that replace the content of {@link ComponentDefinition.PropertyRelation#getWhen() when}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutablePropertyRelation withWhen(ComponentDefinition.When... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return new ImmutablePropertyRelation(this.action, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link ComponentDefinition.PropertyRelation#getWhen() when}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of when elements to set * @return A modified copy of {@code this} object */ public final ImmutablePropertyRelation withWhen(Iterable elements) { if (this.when == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return new ImmutablePropertyRelation(this.action, newValue); } /** * This instance is equal to all instances of {@code ImmutablePropertyRelation} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof ImmutablePropertyRelation && equalTo((ImmutablePropertyRelation) another); } private boolean equalTo(ImmutablePropertyRelation another) { return action.equals(another.action) && when.equals(another.when); } /** * Computes a hash code from attributes: {@code action}, {@code when}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + action.hashCode(); h += (h << 5) + when.hashCode(); return h; } /** * Prints the immutable value {@code PropertyRelation} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "PropertyRelation{" + "action=" + action + ", when=" + when + "}"; } /** * Creates an immutable copy of a {@link ComponentDefinition.PropertyRelation} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable PropertyRelation instance */ public static ImmutablePropertyRelation copyOf(ComponentDefinition.PropertyRelation instance) { if (instance instanceof ImmutablePropertyRelation) { return (ImmutablePropertyRelation) instance; } return new ImmutablePropertyRelation.Builder() .from(instance) .build(); } /** * Builds instances of type {@link ImmutablePropertyRelation ImmutablePropertyRelation}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @Generated(from = "ComponentDefinition.PropertyRelation", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_ACTION = 0x1L; private long initBits = 0x1L; private String action; private List when = new ArrayList(); /** * Creates a builder for {@link ImmutablePropertyRelation ImmutablePropertyRelation} instances. *

     * new ImmutablePropertyRelation.Builder()
     *    .action(String) // required {@link ComponentDefinition.PropertyRelation#getAction() action}
     *    .addWhen|addAllWhen(io.syndesis.integration.component.proxy.ComponentDefinition.When) // {@link ComponentDefinition.PropertyRelation#getWhen() when} elements
     *    .build();
     * 
*/ public Builder() { } /** * Fill a builder with attribute values from the provided {@code PropertyRelation} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(ComponentDefinition.PropertyRelation instance) { Objects.requireNonNull(instance, "instance"); action(instance.getAction()); addAllWhen(instance.getWhen()); return this; } /** * Initializes the value for the {@link ComponentDefinition.PropertyRelation#getAction() action} attribute. * @param action The value for action * @return {@code this} builder for use in a chained invocation */ @JsonProperty("action") public final Builder action(String action) { this.action = Objects.requireNonNull(action, "action"); initBits &= ~INIT_BIT_ACTION; return this; } /** * Adds one element to {@link ComponentDefinition.PropertyRelation#getWhen() when} list. * @param element A when element * @return {@code this} builder for use in a chained invocation */ public final Builder addWhen(ComponentDefinition.When element) { this.when.add(Objects.requireNonNull(element, "when element")); return this; } /** * Adds elements to {@link ComponentDefinition.PropertyRelation#getWhen() when} list. * @param elements An array of when elements * @return {@code this} builder for use in a chained invocation */ public final Builder addWhen(ComponentDefinition.When... elements) { for (ComponentDefinition.When element : elements) { this.when.add(Objects.requireNonNull(element, "when element")); } return this; } /** * Sets or replaces all elements for {@link ComponentDefinition.PropertyRelation#getWhen() when} list. * @param elements An iterable of when elements * @return {@code this} builder for use in a chained invocation */ @JsonProperty("when") public final Builder when(Iterable elements) { this.when.clear(); return addAllWhen(elements); } /** * Adds elements to {@link ComponentDefinition.PropertyRelation#getWhen() when} list. * @param elements An iterable of when elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllWhen(Iterable elements) { for (ComponentDefinition.When element : elements) { this.when.add(Objects.requireNonNull(element, "when element")); } return this; } /** * Builds a new {@link ImmutablePropertyRelation ImmutablePropertyRelation}. * @return An immutable instance of PropertyRelation * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutablePropertyRelation build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutablePropertyRelation(action, createUnmodifiableList(true, when)); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_ACTION) != 0) attributes.add("action"); return "Cannot build PropertyRelation, some of required attributes are not set " + attributes; } } private static List createSafeList(Iterable iterable, boolean checkNulls, boolean skipNulls) { ArrayList list; if (iterable instanceof Collection) { int size = ((Collection) iterable).size(); if (size == 0) return Collections.emptyList(); list = new ArrayList<>(); } else { list = new ArrayList<>(); } for (T element : iterable) { if (skipNulls && element == null) continue; if (checkNulls) Objects.requireNonNull(element, "element"); list.add(element); } return list; } private static List createUnmodifiableList(boolean clone, List list) { switch(list.size()) { case 0: return Collections.emptyList(); case 1: return Collections.singletonList(list.get(0)); default: if (clone) { return Collections.unmodifiableList(new ArrayList<>(list)); } else { if (list instanceof ArrayList) { ((ArrayList) list).trimToSize(); } return Collections.unmodifiableList(list); } } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy