
io.syndesis.integration.component.proxy.ImmutableComponentDefinition Maven / Gradle / Ivy
package io.syndesis.integration.component.proxy;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link ComponentDefinition}.
*
* Use the builder to create immutable instances:
* {@code new ImmutableComponentDefinition.Builder()}.
*/
@Generated(from = "ComponentDefinition", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@JsonIgnoreProperties("connectorProperties")
public final class ImmutableComponentDefinition
implements ComponentDefinition {
private final ComponentDefinition.Component component;
private final Map componentProperties;
private final Map endpointProperties;
private ImmutableComponentDefinition(ImmutableComponentDefinition.Builder builder) {
this.component = builder.component;
if (builder.componentPropertiesIsSet()) {
initShim.componentProperties(createUnmodifiableMap(false, false, builder.componentProperties));
}
if (builder.endpointPropertiesIsSet()) {
initShim.endpointProperties(createUnmodifiableMap(false, false, builder.endpointProperties));
}
this.componentProperties = initShim.getComponentProperties();
this.endpointProperties = initShim.getEndpointProperties();
this.initShim = null;
}
private ImmutableComponentDefinition(
ComponentDefinition.Component component,
Map componentProperties,
Map endpointProperties) {
this.component = component;
this.componentProperties = componentProperties;
this.endpointProperties = endpointProperties;
this.initShim = null;
}
private static final byte STAGE_INITIALIZING = -1;
private static final byte STAGE_UNINITIALIZED = 0;
private static final byte STAGE_INITIALIZED = 1;
private transient volatile InitShim initShim = new InitShim();
@Generated(from = "ComponentDefinition", generator = "Immutables")
private final class InitShim {
private byte componentPropertiesBuildStage = STAGE_UNINITIALIZED;
private Map componentProperties;
Map getComponentProperties() {
if (componentPropertiesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (componentPropertiesBuildStage == STAGE_UNINITIALIZED) {
componentPropertiesBuildStage = STAGE_INITIALIZING;
this.componentProperties = createUnmodifiableMap(true, false, getComponentPropertiesInitialize());
componentPropertiesBuildStage = STAGE_INITIALIZED;
}
return this.componentProperties;
}
void componentProperties(Map componentProperties) {
this.componentProperties = componentProperties;
componentPropertiesBuildStage = STAGE_INITIALIZED;
}
private byte endpointPropertiesBuildStage = STAGE_UNINITIALIZED;
private Map endpointProperties;
Map getEndpointProperties() {
if (endpointPropertiesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (endpointPropertiesBuildStage == STAGE_UNINITIALIZED) {
endpointPropertiesBuildStage = STAGE_INITIALIZING;
this.endpointProperties = createUnmodifiableMap(true, false, getEndpointPropertiesInitialize());
endpointPropertiesBuildStage = STAGE_INITIALIZED;
}
return this.endpointProperties;
}
void endpointProperties(Map endpointProperties) {
this.endpointProperties = endpointProperties;
endpointPropertiesBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (componentPropertiesBuildStage == STAGE_INITIALIZING) attributes.add("componentProperties");
if (endpointPropertiesBuildStage == STAGE_INITIALIZING) attributes.add("endpointProperties");
return "Cannot build ComponentDefinition, attribute initializers form cycle " + attributes;
}
}
private Map getComponentPropertiesInitialize() {
return ComponentDefinition.super.getComponentProperties();
}
private Map getEndpointPropertiesInitialize() {
return ComponentDefinition.super.getEndpointProperties();
}
/**
* @return The value of the {@code component} attribute
*/
@JsonProperty("component")
@Override
public ComponentDefinition.Component getComponent() {
return component;
}
/**
* @return The value of the {@code componentProperties} attribute
*/
@JsonProperty("componentProperties")
@Override
public Map getComponentProperties() {
InitShim shim = this.initShim;
return shim != null
? shim.getComponentProperties()
: this.componentProperties;
}
/**
* @return The value of the {@code endpointProperties} attribute
*/
@JsonProperty("properties")
@Override
public Map getEndpointProperties() {
InitShim shim = this.initShim;
return shim != null
? shim.getEndpointProperties()
: this.endpointProperties;
}
/**
* Copy the current immutable object by setting a value for the {@link ComponentDefinition#getComponent() component} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for component
* @return A modified copy of the {@code this} object
*/
public final ImmutableComponentDefinition withComponent(ComponentDefinition.Component value) {
if (this.component == value) return this;
ComponentDefinition.Component newValue = Objects.requireNonNull(value, "component");
return new ImmutableComponentDefinition(newValue, this.componentProperties, this.endpointProperties);
}
/**
* Copy the current immutable object by replacing the {@link ComponentDefinition#getComponentProperties() componentProperties} map with the specified map.
* Nulls are not permitted as keys or values.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param entries The entries to be added to the componentProperties map
* @return A modified copy of {@code this} object
*/
public final ImmutableComponentDefinition withComponentProperties(Map entries) {
if (this.componentProperties == entries) return this;
Map newValue = createUnmodifiableMap(true, false, entries);
return new ImmutableComponentDefinition(this.component, newValue, this.endpointProperties);
}
/**
* Copy the current immutable object by replacing the {@link ComponentDefinition#getEndpointProperties() endpointProperties} map with the specified map.
* Nulls are not permitted as keys or values.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param entries The entries to be added to the endpointProperties map
* @return A modified copy of {@code this} object
*/
public final ImmutableComponentDefinition withEndpointProperties(Map entries) {
if (this.endpointProperties == entries) return this;
Map newValue = createUnmodifiableMap(true, false, entries);
return new ImmutableComponentDefinition(this.component, this.componentProperties, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableComponentDefinition} 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 ImmutableComponentDefinition
&& equalTo((ImmutableComponentDefinition) another);
}
private boolean equalTo(ImmutableComponentDefinition another) {
return component.equals(another.component)
&& componentProperties.equals(another.componentProperties)
&& endpointProperties.equals(another.endpointProperties);
}
/**
* Computes a hash code from attributes: {@code component}, {@code componentProperties}, {@code endpointProperties}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + component.hashCode();
h += (h << 5) + componentProperties.hashCode();
h += (h << 5) + endpointProperties.hashCode();
return h;
}
/**
* Prints the immutable value {@code ComponentDefinition} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "ComponentDefinition{"
+ "component=" + component
+ ", componentProperties=" + componentProperties
+ ", endpointProperties=" + endpointProperties
+ "}";
}
/**
* Creates an immutable copy of a {@link ComponentDefinition} 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 ComponentDefinition instance
*/
public static ImmutableComponentDefinition copyOf(ComponentDefinition instance) {
if (instance instanceof ImmutableComponentDefinition) {
return (ImmutableComponentDefinition) instance;
}
return new ImmutableComponentDefinition.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableComponentDefinition ImmutableComponentDefinition}.
* 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", generator = "Immutables")
@JsonIgnoreProperties("connectorProperties")
public static final class Builder {
private static final long INIT_BIT_COMPONENT = 0x1L;
private static final long OPT_BIT_COMPONENT_PROPERTIES = 0x1L;
private static final long OPT_BIT_ENDPOINT_PROPERTIES = 0x2L;
private long initBits = 0x1L;
private long optBits;
private ComponentDefinition.Component component;
private Map componentProperties = new LinkedHashMap();
private Map endpointProperties = new LinkedHashMap();
/**
* Creates a builder for {@link ImmutableComponentDefinition ImmutableComponentDefinition} instances.
*
* new ImmutableComponentDefinition.Builder()
* .component(io.syndesis.integration.component.proxy.ComponentDefinition.Component) // required {@link ComponentDefinition#getComponent() component}
* .putComponentProperties|putAllComponentProperties(String => io.syndesis.integration.component.proxy.ComponentDefinition.Property) // {@link ComponentDefinition#getComponentProperties() componentProperties} mappings
* .putEndpointProperties|putAllEndpointProperties(String => io.syndesis.integration.component.proxy.ComponentDefinition.Property) // {@link ComponentDefinition#getEndpointProperties() endpointProperties} mappings
* .build();
*
*/
public Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ComponentDefinition} 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 instance) {
Objects.requireNonNull(instance, "instance");
component(instance.getComponent());
putAllComponentProperties(instance.getComponentProperties());
putAllEndpointProperties(instance.getEndpointProperties());
return this;
}
/**
* Initializes the value for the {@link ComponentDefinition#getComponent() component} attribute.
* @param component The value for component
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("component")
public final Builder component(ComponentDefinition.Component component) {
this.component = Objects.requireNonNull(component, "component");
initBits &= ~INIT_BIT_COMPONENT;
return this;
}
/**
* Put one entry to the {@link ComponentDefinition#getComponentProperties() componentProperties} map.
* @param key The key in the componentProperties map
* @param value The associated value in the componentProperties map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putComponentProperties(String key, ComponentDefinition.Property value) {
this.componentProperties.put(
Objects.requireNonNull(key, "componentProperties key"),
Objects.requireNonNull(value, "componentProperties value"));
optBits |= OPT_BIT_COMPONENT_PROPERTIES;
return this;
}
/**
* Put one entry to the {@link ComponentDefinition#getComponentProperties() componentProperties} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putComponentProperties(Map.Entry entry) {
String k = entry.getKey();
ComponentDefinition.Property v = entry.getValue();
this.componentProperties.put(
Objects.requireNonNull(k, "componentProperties key"),
Objects.requireNonNull(v, "componentProperties value"));
optBits |= OPT_BIT_COMPONENT_PROPERTIES;
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link ComponentDefinition#getComponentProperties() componentProperties} map. Nulls are not permitted
* @param entries The entries that will be added to the componentProperties map
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("componentProperties")
public final Builder componentProperties(Map entries) {
this.componentProperties.clear();
optBits |= OPT_BIT_COMPONENT_PROPERTIES;
return putAllComponentProperties(entries);
}
/**
* Put all mappings from the specified map as entries to {@link ComponentDefinition#getComponentProperties() componentProperties} map. Nulls are not permitted
* @param entries The entries that will be added to the componentProperties map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putAllComponentProperties(Map entries) {
for (Map.Entry e : entries.entrySet()) {
String k = e.getKey();
ComponentDefinition.Property v = e.getValue();
this.componentProperties.put(
Objects.requireNonNull(k, "componentProperties key"),
Objects.requireNonNull(v, "componentProperties value"));
}
optBits |= OPT_BIT_COMPONENT_PROPERTIES;
return this;
}
/**
* Put one entry to the {@link ComponentDefinition#getEndpointProperties() endpointProperties} map.
* @param key The key in the endpointProperties map
* @param value The associated value in the endpointProperties map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putEndpointProperties(String key, ComponentDefinition.Property value) {
this.endpointProperties.put(
Objects.requireNonNull(key, "endpointProperties key"),
Objects.requireNonNull(value, "endpointProperties value"));
optBits |= OPT_BIT_ENDPOINT_PROPERTIES;
return this;
}
/**
* Put one entry to the {@link ComponentDefinition#getEndpointProperties() endpointProperties} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putEndpointProperties(Map.Entry entry) {
String k = entry.getKey();
ComponentDefinition.Property v = entry.getValue();
this.endpointProperties.put(
Objects.requireNonNull(k, "endpointProperties key"),
Objects.requireNonNull(v, "endpointProperties value"));
optBits |= OPT_BIT_ENDPOINT_PROPERTIES;
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link ComponentDefinition#getEndpointProperties() endpointProperties} map. Nulls are not permitted
* @param entries The entries that will be added to the endpointProperties map
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("properties")
public final Builder endpointProperties(Map entries) {
this.endpointProperties.clear();
optBits |= OPT_BIT_ENDPOINT_PROPERTIES;
return putAllEndpointProperties(entries);
}
/**
* Put all mappings from the specified map as entries to {@link ComponentDefinition#getEndpointProperties() endpointProperties} map. Nulls are not permitted
* @param entries The entries that will be added to the endpointProperties map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putAllEndpointProperties(Map entries) {
for (Map.Entry e : entries.entrySet()) {
String k = e.getKey();
ComponentDefinition.Property v = e.getValue();
this.endpointProperties.put(
Objects.requireNonNull(k, "endpointProperties key"),
Objects.requireNonNull(v, "endpointProperties value"));
}
optBits |= OPT_BIT_ENDPOINT_PROPERTIES;
return this;
}
/**
* Builds a new {@link ImmutableComponentDefinition ImmutableComponentDefinition}.
* @return An immutable instance of ComponentDefinition
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableComponentDefinition build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableComponentDefinition(this);
}
private boolean componentPropertiesIsSet() {
return (optBits & OPT_BIT_COMPONENT_PROPERTIES) != 0;
}
private boolean endpointPropertiesIsSet() {
return (optBits & OPT_BIT_ENDPOINT_PROPERTIES) != 0;
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_COMPONENT) != 0) attributes.add("component");
return "Cannot build ComponentDefinition, some of required attributes are not set " + attributes;
}
}
private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, Map extends K, ? extends V> map) {
switch (map.size()) {
case 0: return Collections.emptyMap();
case 1: {
Map.Entry extends K, ? extends V> e = map.entrySet().iterator().next();
K k = e.getKey();
V v = e.getValue();
if (checkNulls) {
Objects.requireNonNull(k, "key");
Objects.requireNonNull(v, "value");
}
if (skipNulls && (k == null || v == null)) {
return Collections.emptyMap();
}
return Collections.singletonMap(k, v);
}
default: {
Map linkedMap = new LinkedHashMap<>(map.size());
if (skipNulls || checkNulls) {
for (Map.Entry extends K, ? extends V> e : map.entrySet()) {
K k = e.getKey();
V v = e.getValue();
if (skipNulls) {
if (k == null || v == null) continue;
} else if (checkNulls) {
Objects.requireNonNull(k, "key");
Objects.requireNonNull(v, "value");
}
linkedMap.put(k, v);
}
} else {
linkedMap.putAll(map);
}
return Collections.unmodifiableMap(linkedMap);
}
}
}
}