io.syndesis.common.model.connection.ImmutableConnectorTemplate Maven / Gradle / Ivy
/*
* Copyright (C) 2016 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.syndesis.common.model.connection;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.syndesis.common.model.Kind;
import io.syndesis.common.model.WithConfigurationProperties;
import io.syndesis.common.model.WithConfiguredProperties;
import io.syndesis.common.model.WithKind;
import io.syndesis.common.model.WithName;
import io.syndesis.common.model.WithResourceId;
import io.syndesis.common.util.json.StringTrimmingConverter;
import java.io.ObjectStreamException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Generated;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.Validator;
/**
* Immutable implementation of {@link ConnectorTemplate}.
*
* Use the builder to create immutable instances:
* {@code new ConnectorTemplate.Builder()}.
* Use the static factory method to create immutable instances:
* {@code ImmutableConnectorTemplate.of()}.
*/
@SuppressWarnings({"all"})
@SuppressFBWarnings
@Generated({"Immutables.generator", "ConnectorTemplate"})
final class ImmutableConnectorTemplate implements ConnectorTemplate {
private final String camelConnectorGAV;
private final String camelConnectorPrefix;
private final ConnectorGroup connectorGroup;
private final Map connectorProperties;
private final String description;
private final String icon;
private final Kind kind;
private final String id;
private final String name;
private final Map properties;
private final Map configuredProperties;
private ImmutableConnectorTemplate(
String camelConnectorGAV,
String camelConnectorPrefix,
Optional connectorGroup,
Map connectorProperties,
String description,
String icon,
Kind kind,
Optional id,
String name,
Map properties,
Map configuredProperties) {
this.camelConnectorGAV = camelConnectorGAV;
this.camelConnectorPrefix = camelConnectorPrefix;
this.connectorGroup = connectorGroup.orElse(null);
this.connectorProperties = createUnmodifiableMap(true, false, connectorProperties);
this.description = description;
this.icon = icon;
this.kind = Objects.requireNonNull(kind, "kind");
this.id = id.orElse(null);
this.name = name;
this.properties = createUnmodifiableMap(true, false, properties);
this.configuredProperties = createUnmodifiableMap(true, false, configuredProperties);
initShim.kind(this.kind);
initShim.configuredProperties(this.configuredProperties);
this.initShim = null;
}
private ImmutableConnectorTemplate(ImmutableConnectorTemplate.Builder builder) {
this.camelConnectorGAV = builder.camelConnectorGAV;
this.camelConnectorPrefix = builder.camelConnectorPrefix;
this.connectorGroup = builder.connectorGroup;
this.connectorProperties = createUnmodifiableMap(false, false, builder.connectorProperties);
this.description = builder.description;
this.icon = builder.icon;
this.id = builder.id;
this.name = builder.name;
this.properties = createUnmodifiableMap(false, false, builder.properties);
if (builder.kind != null) {
initShim.kind(builder.kind);
}
if (builder.configuredPropertiesIsSet()) {
initShim.configuredProperties(createUnmodifiableMap(false, false, builder.configuredProperties));
}
this.kind = initShim.getKind();
this.configuredProperties = initShim.getConfiguredProperties();
this.initShim = null;
}
private ImmutableConnectorTemplate(
ImmutableConnectorTemplate original,
String camelConnectorGAV,
String camelConnectorPrefix,
ConnectorGroup connectorGroup,
Map connectorProperties,
String description,
String icon,
Kind kind,
String id,
String name,
Map properties,
Map configuredProperties) {
this.camelConnectorGAV = camelConnectorGAV;
this.camelConnectorPrefix = camelConnectorPrefix;
this.connectorGroup = connectorGroup;
this.connectorProperties = connectorProperties;
this.description = description;
this.icon = icon;
this.kind = kind;
this.id = id;
this.name = name;
this.properties = properties;
this.configuredProperties = configuredProperties;
this.initShim = null;
}
private static final int STAGE_INITIALIZING = -1;
private static final int STAGE_UNINITIALIZED = 0;
private static final int STAGE_INITIALIZED = 1;
private transient volatile InitShim initShim = new InitShim();
private final class InitShim {
private Kind kind;
private int kindBuildStage;
Kind getKind() {
if (kindBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (kindBuildStage == STAGE_UNINITIALIZED) {
kindBuildStage = STAGE_INITIALIZING;
this.kind = Objects.requireNonNull(getKindInitialize(), "kind");
kindBuildStage = STAGE_INITIALIZED;
}
return this.kind;
}
void kind(Kind kind) {
this.kind = kind;
kindBuildStage = STAGE_INITIALIZED;
}
private Map configuredProperties;
private int configuredPropertiesBuildStage;
Map getConfiguredProperties() {
if (configuredPropertiesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (configuredPropertiesBuildStage == STAGE_UNINITIALIZED) {
configuredPropertiesBuildStage = STAGE_INITIALIZING;
this.configuredProperties = createUnmodifiableMap(true, false, getConfiguredPropertiesInitialize());
configuredPropertiesBuildStage = STAGE_INITIALIZED;
}
return this.configuredProperties;
}
void configuredProperties(Map configuredProperties) {
this.configuredProperties = configuredProperties;
configuredPropertiesBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
ArrayList attributes = new ArrayList();
if (kindBuildStage == STAGE_INITIALIZING) attributes.add("kind");
if (configuredPropertiesBuildStage == STAGE_INITIALIZING) attributes.add("configuredProperties");
return "Cannot build ConnectorTemplate, attribute initializers form cycle" + attributes;
}
}
private Kind getKindInitialize() {
return ConnectorTemplate.super.getKind();
}
private Map getConfiguredPropertiesInitialize() {
return ConnectorTemplate.super.getConfiguredProperties();
}
/**
* @return The value of the {@code camelConnectorGAV} attribute
*/
@JsonProperty("camelConnectorGAV")
@Override
public String getCamelConnectorGAV() {
return camelConnectorGAV;
}
/**
* @return The value of the {@code camelConnectorPrefix} attribute
*/
@JsonProperty("camelConnectorPrefix")
@Override
public String getCamelConnectorPrefix() {
return camelConnectorPrefix;
}
/**
* @return The value of the {@code connectorGroup} attribute
*/
@JsonProperty("connectorGroup")
@Override
public Optional getConnectorGroup() {
return Optional.ofNullable(connectorGroup);
}
/**
* @return The value of the {@code connectorProperties} attribute
*/
@JsonProperty("connectorProperties")
@Override
public Map getConnectorProperties() {
return connectorProperties;
}
/**
* @return The value of the {@code description} attribute
*/
@JsonProperty("description")
@Override
public String getDescription() {
return description;
}
/**
* @return The value of the {@code icon} attribute
*/
@JsonProperty("icon")
@Override
public String getIcon() {
return icon;
}
/**
* @return The value of the {@code kind} attribute
*/
@JsonProperty("kind")
@Override
public Kind getKind() {
InitShim shim = this.initShim;
return shim != null
? shim.getKind()
: this.kind;
}
/**
* @return The value of the {@code id} attribute
*/
@JsonProperty("id")
@Override
public Optional getId() {
return Optional.ofNullable(id);
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@JsonDeserialize(converter = StringTrimmingConverter.class)
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code properties} attribute
*/
@JsonProperty("properties")
@Override
public Map getProperties() {
return properties;
}
/**
* @return The value of the {@code configuredProperties} attribute
*/
@JsonProperty("configuredProperties")
@Override
public Map getConfiguredProperties() {
InitShim shim = this.initShim;
return shim != null
? shim.getConfiguredProperties()
: this.configuredProperties;
}
/**
* Copy the current immutable object by setting a value for the {@link ConnectorTemplate#getCamelConnectorGAV() camelConnectorGAV} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for camelConnectorGAV (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableConnectorTemplate withCamelConnectorGAV(String value) {
if (Objects.equals(this.camelConnectorGAV, value)) return this;
return validate(new ImmutableConnectorTemplate(
this,
value,
this.camelConnectorPrefix,
this.connectorGroup,
this.connectorProperties,
this.description,
this.icon,
this.kind,
this.id,
this.name,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by setting a value for the {@link ConnectorTemplate#getCamelConnectorPrefix() camelConnectorPrefix} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for camelConnectorPrefix (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableConnectorTemplate withCamelConnectorPrefix(String value) {
if (Objects.equals(this.camelConnectorPrefix, value)) return this;
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
value,
this.connectorGroup,
this.connectorProperties,
this.description,
this.icon,
this.kind,
this.id,
this.name,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ConnectorTemplate#getConnectorGroup() connectorGroup} attribute.
* @param value The value for connectorGroup
* @return A modified copy of {@code this} object
*/
public final ImmutableConnectorTemplate withConnectorGroup(ConnectorGroup value) {
ConnectorGroup newValue = Objects.requireNonNull(value, "connectorGroup");
if (this.connectorGroup == newValue) return this;
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
newValue,
this.connectorProperties,
this.description,
this.icon,
this.kind,
this.id,
this.name,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by setting an optional value for the {@link ConnectorTemplate#getConnectorGroup() connectorGroup} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for connectorGroup
* @return A modified copy of {@code this} object
*/
public final ImmutableConnectorTemplate withConnectorGroup(Optional optional) {
ConnectorGroup value = optional.orElse(null);
if (this.connectorGroup == value) return this;
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
value,
this.connectorProperties,
this.description,
this.icon,
this.kind,
this.id,
this.name,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by replacing the {@link ConnectorTemplate#getConnectorProperties() connectorProperties} 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 connectorProperties map
* @return A modified copy of {@code this} object
*/
public final ImmutableConnectorTemplate withConnectorProperties(Map entries) {
if (this.connectorProperties == entries) return this;
Map newValue = createUnmodifiableMap(true, false, entries);
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
this.connectorGroup,
newValue,
this.description,
this.icon,
this.kind,
this.id,
this.name,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by setting a value for the {@link ConnectorTemplate#getDescription() description} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for description (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableConnectorTemplate withDescription(String value) {
if (Objects.equals(this.description, value)) return this;
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
this.connectorGroup,
this.connectorProperties,
value,
this.icon,
this.kind,
this.id,
this.name,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by setting a value for the {@link ConnectorTemplate#getIcon() icon} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for icon (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableConnectorTemplate withIcon(String value) {
if (Objects.equals(this.icon, value)) return this;
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
this.connectorGroup,
this.connectorProperties,
this.description,
value,
this.kind,
this.id,
this.name,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by setting a value for the {@link ConnectorTemplate#getKind() kind} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for kind
* @return A modified copy of the {@code this} object
*/
public final ImmutableConnectorTemplate withKind(Kind value) {
if (this.kind == value) return this;
Kind newValue = Objects.requireNonNull(value, "kind");
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
this.connectorGroup,
this.connectorProperties,
this.description,
this.icon,
newValue,
this.id,
this.name,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ConnectorTemplate#getId() id} attribute.
* @param value The value for id
* @return A modified copy of {@code this} object
*/
public final ImmutableConnectorTemplate withId(String value) {
String newValue = Objects.requireNonNull(value, "id");
if (Objects.equals(this.id, newValue)) return this;
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
this.connectorGroup,
this.connectorProperties,
this.description,
this.icon,
this.kind,
newValue,
this.name,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by setting an optional value for the {@link ConnectorTemplate#getId() id} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for id
* @return A modified copy of {@code this} object
*/
public final ImmutableConnectorTemplate withId(Optional optional) {
String value = optional.orElse(null);
if (Objects.equals(this.id, value)) return this;
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
this.connectorGroup,
this.connectorProperties,
this.description,
this.icon,
this.kind,
value,
this.name,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by setting a value for the {@link ConnectorTemplate#getName() name} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for name (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableConnectorTemplate withName(String value) {
if (Objects.equals(this.name, value)) return this;
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
this.connectorGroup,
this.connectorProperties,
this.description,
this.icon,
this.kind,
this.id,
value,
this.properties,
this.configuredProperties));
}
/**
* Copy the current immutable object by replacing the {@link ConnectorTemplate#getProperties() properties} 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 properties map
* @return A modified copy of {@code this} object
*/
public final ImmutableConnectorTemplate withProperties(Map entries) {
if (this.properties == entries) return this;
Map newValue = createUnmodifiableMap(true, false, entries);
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
this.connectorGroup,
this.connectorProperties,
this.description,
this.icon,
this.kind,
this.id,
this.name,
newValue,
this.configuredProperties));
}
/**
* Copy the current immutable object by replacing the {@link ConnectorTemplate#getConfiguredProperties() configuredProperties} 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 configuredProperties map
* @return A modified copy of {@code this} object
*/
public final ImmutableConnectorTemplate withConfiguredProperties(Map entries) {
if (this.configuredProperties == entries) return this;
Map newValue = createUnmodifiableMap(true, false, entries);
return validate(new ImmutableConnectorTemplate(
this,
this.camelConnectorGAV,
this.camelConnectorPrefix,
this.connectorGroup,
this.connectorProperties,
this.description,
this.icon,
this.kind,
this.id,
this.name,
this.properties,
newValue));
}
/**
* This instance is equal to all instances of {@code ImmutableConnectorTemplate} 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 ImmutableConnectorTemplate
&& equalTo((ImmutableConnectorTemplate) another);
}
private boolean equalTo(ImmutableConnectorTemplate another) {
return Objects.equals(camelConnectorGAV, another.camelConnectorGAV)
&& Objects.equals(camelConnectorPrefix, another.camelConnectorPrefix)
&& Objects.equals(connectorGroup, another.connectorGroup)
&& connectorProperties.equals(another.connectorProperties)
&& Objects.equals(description, another.description)
&& Objects.equals(icon, another.icon)
&& kind.equals(another.kind)
&& Objects.equals(id, another.id)
&& Objects.equals(name, another.name)
&& properties.equals(another.properties)
&& configuredProperties.equals(another.configuredProperties);
}
/**
* Computes a hash code from attributes: {@code camelConnectorGAV}, {@code camelConnectorPrefix}, {@code connectorGroup}, {@code connectorProperties}, {@code description}, {@code icon}, {@code kind}, {@code id}, {@code name}, {@code properties}, {@code configuredProperties}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(camelConnectorGAV);
h += (h << 5) + Objects.hashCode(camelConnectorPrefix);
h += (h << 5) + Objects.hashCode(connectorGroup);
h += (h << 5) + connectorProperties.hashCode();
h += (h << 5) + Objects.hashCode(description);
h += (h << 5) + Objects.hashCode(icon);
h += (h << 5) + kind.hashCode();
h += (h << 5) + Objects.hashCode(id);
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + properties.hashCode();
h += (h << 5) + configuredProperties.hashCode();
return h;
}
/**
* Prints the immutable value {@code ConnectorTemplate} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("ConnectorTemplate{");
if (camelConnectorGAV != null) {
builder.append("camelConnectorGAV=").append(camelConnectorGAV);
}
if (camelConnectorPrefix != null) {
if (builder.length() > 18) builder.append(", ");
builder.append("camelConnectorPrefix=").append(camelConnectorPrefix);
}
if (connectorGroup != null) {
if (builder.length() > 18) builder.append(", ");
builder.append("connectorGroup=").append(connectorGroup);
}
if (builder.length() > 18) builder.append(", ");
builder.append("connectorProperties=").append(connectorProperties);
if (description != null) {
builder.append(", ");
builder.append("description=").append(description);
}
if (icon != null) {
builder.append(", ");
builder.append("icon=").append(icon);
}
builder.append(", ");
builder.append("kind=").append(kind);
if (id != null) {
builder.append(", ");
builder.append("id=").append(id);
}
if (name != null) {
builder.append(", ");
builder.append("name=").append(name);
}
builder.append(", ");
builder.append("properties=").append(properties);
builder.append(", ");
builder.append("configuredProperties=").append(configuredProperties);
return builder.append("}").toString();
}
/**
* Construct a new immutable {@code ConnectorTemplate} instance.
* @param camelConnectorGAV The value for the {@code camelConnectorGAV} attribute
* @param camelConnectorPrefix The value for the {@code camelConnectorPrefix} attribute
* @param connectorGroup The value for the {@code connectorGroup} attribute
* @param connectorProperties The value for the {@code connectorProperties} attribute
* @param description The value for the {@code description} attribute
* @param icon The value for the {@code icon} attribute
* @param kind The value for the {@code kind} attribute
* @param id The value for the {@code id} attribute
* @param name The value for the {@code name} attribute
* @param properties The value for the {@code properties} attribute
* @param configuredProperties The value for the {@code configuredProperties} attribute
* @return An immutable ConnectorTemplate instance
*/
public static ConnectorTemplate of(String camelConnectorGAV, String camelConnectorPrefix, Optional connectorGroup, Map connectorProperties, String description, String icon, Kind kind, Optional id, String name, Map properties, Map configuredProperties) {
return validate(new ImmutableConnectorTemplate(camelConnectorGAV, camelConnectorPrefix, connectorGroup, connectorProperties, description, icon, kind, id, name, properties, configuredProperties));
}
private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
private static ImmutableConnectorTemplate validate(ImmutableConnectorTemplate instance) {
Set> constraintViolations = validator.validate(instance);
if (!constraintViolations.isEmpty()) {
throw new ConstraintViolationException(constraintViolations);
}
return instance;
}
/**
* Creates an immutable copy of a {@link ConnectorTemplate} 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 ConnectorTemplate instance
*/
public static ConnectorTemplate copyOf(ConnectorTemplate instance) {
if (instance instanceof ImmutableConnectorTemplate) {
return (ImmutableConnectorTemplate) instance;
}
return new ConnectorTemplate.Builder()
.createFrom(instance)
.build();
}
private Object readResolve() throws ObjectStreamException {
return validate(this);
}
/**
* Builds instances of type {@link ConnectorTemplate ConnectorTemplate}.
* 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.
*/
public static class Builder {
private static final long OPT_BIT_CONFIGURED_PROPERTIES = 0x1L;
private long optBits;
private String camelConnectorGAV;
private String camelConnectorPrefix;
private ConnectorGroup connectorGroup;
private Map connectorProperties = new LinkedHashMap();
private String description;
private String icon;
private Kind kind;
private String id;
private String name;
private Map properties = new LinkedHashMap();
private Map configuredProperties = new LinkedHashMap();
/**
* Creates a builder for {@link ConnectorTemplate ConnectorTemplate} instances.
*/
public Builder() {
if (!(this instanceof ConnectorTemplate.Builder)) {
throw new UnsupportedOperationException("Use: new ConnectorTemplate.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code io.syndesis.common.model.WithName} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder createFrom(WithName instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (ConnectorTemplate.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code io.syndesis.common.model.WithConfiguredProperties} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder createFrom(WithConfiguredProperties instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (ConnectorTemplate.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code io.syndesis.common.model.WithKind} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder createFrom(WithKind instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (ConnectorTemplate.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code io.syndesis.common.model.connection.ConnectorTemplate} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder createFrom(ConnectorTemplate instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (ConnectorTemplate.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code io.syndesis.common.model.WithResourceId} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder createFrom(WithResourceId instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (ConnectorTemplate.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code io.syndesis.common.model.WithConfigurationProperties} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder createFrom(WithConfigurationProperties instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (ConnectorTemplate.Builder) this;
}
private void from(Object object) {
long bits = 0;
if (object instanceof WithName) {
WithName instance = (WithName) object;
String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
}
if (object instanceof WithConfiguredProperties) {
WithConfiguredProperties instance = (WithConfiguredProperties) object;
putAllConfiguredProperties(instance.getConfiguredProperties());
}
if (object instanceof WithKind) {
WithKind instance = (WithKind) object;
if ((bits & 0x1L) == 0) {
kind(instance.getKind());
bits |= 0x1L;
}
}
if (object instanceof ConnectorTemplate) {
ConnectorTemplate instance = (ConnectorTemplate) object;
putAllConnectorProperties(instance.getConnectorProperties());
Optional connectorGroupOptional = instance.getConnectorGroup();
if (connectorGroupOptional.isPresent()) {
connectorGroup(connectorGroupOptional);
}
String camelConnectorPrefixValue = instance.getCamelConnectorPrefix();
if (camelConnectorPrefixValue != null) {
camelConnectorPrefix(camelConnectorPrefixValue);
}
if ((bits & 0x1L) == 0) {
kind(instance.getKind());
bits |= 0x1L;
}
String iconValue = instance.getIcon();
if (iconValue != null) {
icon(iconValue);
}
String descriptionValue = instance.getDescription();
if (descriptionValue != null) {
description(descriptionValue);
}
String camelConnectorGAVValue = instance.getCamelConnectorGAV();
if (camelConnectorGAVValue != null) {
camelConnectorGAV(camelConnectorGAVValue);
}
}
if (object instanceof WithResourceId) {
WithResourceId instance = (WithResourceId) object;
Optional idOptional = instance.getId();
if (idOptional.isPresent()) {
id(idOptional);
}
}
if (object instanceof WithConfigurationProperties) {
WithConfigurationProperties instance = (WithConfigurationProperties) object;
putAllProperties(instance.getProperties());
}
}
/**
* Initializes the value for the {@link ConnectorTemplate#getCamelConnectorGAV() camelConnectorGAV} attribute.
* @param camelConnectorGAV The value for camelConnectorGAV (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("camelConnectorGAV")
public final ConnectorTemplate.Builder camelConnectorGAV(String camelConnectorGAV) {
this.camelConnectorGAV = camelConnectorGAV;
return (ConnectorTemplate.Builder) this;
}
/**
* Initializes the value for the {@link ConnectorTemplate#getCamelConnectorPrefix() camelConnectorPrefix} attribute.
* @param camelConnectorPrefix The value for camelConnectorPrefix (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("camelConnectorPrefix")
public final ConnectorTemplate.Builder camelConnectorPrefix(String camelConnectorPrefix) {
this.camelConnectorPrefix = camelConnectorPrefix;
return (ConnectorTemplate.Builder) this;
}
/**
* Initializes the optional value {@link ConnectorTemplate#getConnectorGroup() connectorGroup} to connectorGroup.
* @param connectorGroup The value for connectorGroup
* @return {@code this} builder for chained invocation
*/
public final ConnectorTemplate.Builder connectorGroup(ConnectorGroup connectorGroup) {
this.connectorGroup = Objects.requireNonNull(connectorGroup, "connectorGroup");
return (ConnectorTemplate.Builder) this;
}
/**
* Initializes the optional value {@link ConnectorTemplate#getConnectorGroup() connectorGroup} to connectorGroup.
* @param connectorGroup The value for connectorGroup
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("connectorGroup")
public final ConnectorTemplate.Builder connectorGroup(Optional connectorGroup) {
this.connectorGroup = connectorGroup.orElse(null);
return (ConnectorTemplate.Builder) this;
}
/**
* Put one entry to the {@link ConnectorTemplate#getConnectorProperties() connectorProperties} map.
* @param key The key in the connectorProperties map
* @param value The associated value in the connectorProperties map
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder putConnectorProperty(String key, ConfigurationProperty value) {
this.connectorProperties.put(
Objects.requireNonNull(key, "connectorProperties key"),
Objects.requireNonNull(value, "connectorProperties value"));
return (ConnectorTemplate.Builder) this;
}
/**
* Put one entry to the {@link ConnectorTemplate#getConnectorProperties() connectorProperties} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder putConnectorProperty(Map.Entry entry) {
String k = entry.getKey();
ConfigurationProperty v = entry.getValue();
this.connectorProperties.put(
Objects.requireNonNull(k, "connectorProperties key"),
Objects.requireNonNull(v, "connectorProperties value"));
return (ConnectorTemplate.Builder) this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link ConnectorTemplate#getConnectorProperties() connectorProperties} map. Nulls are not permitted
* @param connectorProperties The entries that will be added to the connectorProperties map
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("connectorProperties")
public final ConnectorTemplate.Builder connectorProperties(Map connectorProperties) {
this.connectorProperties.clear();
return putAllConnectorProperties(connectorProperties);
}
/**
* Put all mappings from the specified map as entries to {@link ConnectorTemplate#getConnectorProperties() connectorProperties} map. Nulls are not permitted
* @param connectorProperties The entries that will be added to the connectorProperties map
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder putAllConnectorProperties(Map connectorProperties) {
for (Map.Entry entry : connectorProperties.entrySet()) {
String k = entry.getKey();
ConfigurationProperty v = entry.getValue();
this.connectorProperties.put(
Objects.requireNonNull(k, "connectorProperties key"),
Objects.requireNonNull(v, "connectorProperties value"));
}
return (ConnectorTemplate.Builder) this;
}
/**
* Initializes the value for the {@link ConnectorTemplate#getDescription() description} attribute.
* @param description The value for description (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("description")
public final ConnectorTemplate.Builder description(String description) {
this.description = description;
return (ConnectorTemplate.Builder) this;
}
/**
* Initializes the value for the {@link ConnectorTemplate#getIcon() icon} attribute.
* @param icon The value for icon (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("icon")
public final ConnectorTemplate.Builder icon(String icon) {
this.icon = icon;
return (ConnectorTemplate.Builder) this;
}
/**
* Initializes the value for the {@link ConnectorTemplate#getKind() kind} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link ConnectorTemplate#getKind() kind}.
* @param kind The value for kind
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("kind")
public final ConnectorTemplate.Builder kind(Kind kind) {
this.kind = Objects.requireNonNull(kind, "kind");
return (ConnectorTemplate.Builder) this;
}
/**
* Initializes the optional value {@link ConnectorTemplate#getId() id} to id.
* @param id The value for id
* @return {@code this} builder for chained invocation
*/
public final ConnectorTemplate.Builder id(String id) {
this.id = Objects.requireNonNull(id, "id");
return (ConnectorTemplate.Builder) this;
}
/**
* Initializes the optional value {@link ConnectorTemplate#getId() id} to id.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("id")
public final ConnectorTemplate.Builder id(Optional id) {
this.id = id.orElse(null);
return (ConnectorTemplate.Builder) this;
}
/**
* Initializes the value for the {@link ConnectorTemplate#getName() name} attribute.
* @param name The value for name (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("name")
@JsonDeserialize(converter = StringTrimmingConverter.class)
public final ConnectorTemplate.Builder name(String name) {
this.name = name;
return (ConnectorTemplate.Builder) this;
}
/**
* Put one entry to the {@link ConnectorTemplate#getProperties() properties} map.
* @param key The key in the properties map
* @param value The associated value in the properties map
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder putProperty(String key, ConfigurationProperty value) {
this.properties.put(
Objects.requireNonNull(key, "properties key"),
Objects.requireNonNull(value, "properties value"));
return (ConnectorTemplate.Builder) this;
}
/**
* Put one entry to the {@link ConnectorTemplate#getProperties() properties} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder putProperty(Map.Entry entry) {
String k = entry.getKey();
ConfigurationProperty v = entry.getValue();
this.properties.put(
Objects.requireNonNull(k, "properties key"),
Objects.requireNonNull(v, "properties value"));
return (ConnectorTemplate.Builder) this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link ConnectorTemplate#getProperties() properties} map. Nulls are not permitted
* @param properties The entries that will be added to the properties map
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("properties")
public final ConnectorTemplate.Builder properties(Map properties) {
this.properties.clear();
return putAllProperties(properties);
}
/**
* Put all mappings from the specified map as entries to {@link ConnectorTemplate#getProperties() properties} map. Nulls are not permitted
* @param properties The entries that will be added to the properties map
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder putAllProperties(Map properties) {
for (Map.Entry entry : properties.entrySet()) {
String k = entry.getKey();
ConfigurationProperty v = entry.getValue();
this.properties.put(
Objects.requireNonNull(k, "properties key"),
Objects.requireNonNull(v, "properties value"));
}
return (ConnectorTemplate.Builder) this;
}
/**
* Put one entry to the {@link ConnectorTemplate#getConfiguredProperties() configuredProperties} map.
* @param key The key in the configuredProperties map
* @param value The associated value in the configuredProperties map
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder putConfiguredProperty(String key, String value) {
this.configuredProperties.put(
Objects.requireNonNull(key, "configuredProperties key"),
Objects.requireNonNull(value, "configuredProperties value"));
optBits |= OPT_BIT_CONFIGURED_PROPERTIES;
return (ConnectorTemplate.Builder) this;
}
/**
* Put one entry to the {@link ConnectorTemplate#getConfiguredProperties() configuredProperties} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder putConfiguredProperty(Map.Entry entry) {
String k = entry.getKey();
String v = entry.getValue();
this.configuredProperties.put(
Objects.requireNonNull(k, "configuredProperties key"),
Objects.requireNonNull(v, "configuredProperties value"));
optBits |= OPT_BIT_CONFIGURED_PROPERTIES;
return (ConnectorTemplate.Builder) this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link ConnectorTemplate#getConfiguredProperties() configuredProperties} map. Nulls are not permitted
* @param configuredProperties The entries that will be added to the configuredProperties map
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("configuredProperties")
public final ConnectorTemplate.Builder configuredProperties(Map configuredProperties) {
this.configuredProperties.clear();
optBits |= OPT_BIT_CONFIGURED_PROPERTIES;
return putAllConfiguredProperties(configuredProperties);
}
/**
* Put all mappings from the specified map as entries to {@link ConnectorTemplate#getConfiguredProperties() configuredProperties} map. Nulls are not permitted
* @param configuredProperties The entries that will be added to the configuredProperties map
* @return {@code this} builder for use in a chained invocation
*/
public final ConnectorTemplate.Builder putAllConfiguredProperties(Map configuredProperties) {
for (Map.Entry entry : configuredProperties.entrySet()) {
String k = entry.getKey();
String v = entry.getValue();
this.configuredProperties.put(
Objects.requireNonNull(k, "configuredProperties key"),
Objects.requireNonNull(v, "configuredProperties value"));
}
optBits |= OPT_BIT_CONFIGURED_PROPERTIES;
return (ConnectorTemplate.Builder) this;
}
/**
* Builds a new {@link ConnectorTemplate ConnectorTemplate}.
* @return An immutable instance of ConnectorTemplate
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ConnectorTemplate build() {
return ImmutableConnectorTemplate.validate(new ImmutableConnectorTemplate(this));
}
private boolean configuredPropertiesIsSet() {
return (optBits & OPT_BIT_CONFIGURED_PROPERTIES) != 0;
}
}
private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, Map map) {
switch (map.size()) {
case 0: return Collections.emptyMap();
case 1: {
Map.Entry 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 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);
}
}
}
}