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

io.syndesis.common.model.action.ImmutableStepDescriptor Maven / Gradle / Ivy

There is a newer version: 1.13.2
Show newest version
/*
 * 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.action;

import com.fasterxml.jackson.annotation.JsonProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.syndesis.common.model.DataShape;
import java.io.ObjectStreamException;
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 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 StepDescriptor}.
 * 

* Use the builder to create immutable instances: * {@code new StepDescriptor.Builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableStepDescriptor.of()}. */ @SuppressWarnings({"all"}) @SuppressFBWarnings @Generated({"Immutables.generator", "StepDescriptor"}) final class ImmutableStepDescriptor implements StepDescriptor { private final StepAction.Kind kind; private final String entrypoint; private final String resource; private final DataShape inputDataShape; private final DataShape outputDataShape; private final List propertyDefinitionSteps; private ImmutableStepDescriptor( StepAction.Kind kind, String entrypoint, String resource, Optional inputDataShape, Optional outputDataShape, Iterable propertyDefinitionSteps) { this.kind = kind; this.entrypoint = entrypoint; this.resource = resource; this.inputDataShape = inputDataShape.orElse(null); this.outputDataShape = outputDataShape.orElse(null); this.propertyDefinitionSteps = createUnmodifiableList(false, createSafeList(propertyDefinitionSteps, true, false)); } private ImmutableStepDescriptor(ImmutableStepDescriptor.Builder builder) { this.kind = builder.kind; this.entrypoint = builder.entrypoint; this.resource = builder.resource; this.inputDataShape = builder.inputDataShape; this.outputDataShape = builder.outputDataShape; this.propertyDefinitionSteps = builder.propertyDefinitionStepsIsSet() ? createUnmodifiableList(true, builder.propertyDefinitionSteps) : createUnmodifiableList(false, createSafeList(StepDescriptor.super.getPropertyDefinitionSteps(), true, false)); } private ImmutableStepDescriptor( ImmutableStepDescriptor original, StepAction.Kind kind, String entrypoint, String resource, DataShape inputDataShape, DataShape outputDataShape, List propertyDefinitionSteps) { this.kind = kind; this.entrypoint = entrypoint; this.resource = resource; this.inputDataShape = inputDataShape; this.outputDataShape = outputDataShape; this.propertyDefinitionSteps = propertyDefinitionSteps; } /** * @return The value of the {@code kind} attribute */ @JsonProperty("kind") @Override public StepAction.Kind getKind() { return kind; } /** * @return The value of the {@code entrypoint} attribute */ @JsonProperty("entrypoint") @Override public String getEntrypoint() { return entrypoint; } /** * @return The value of the {@code resource} attribute */ @JsonProperty("resource") @Override public String getResource() { return resource; } /** * @return The value of the {@code inputDataShape} attribute */ @JsonProperty("inputDataShape") @Override public Optional getInputDataShape() { return Optional.ofNullable(inputDataShape); } /** * @return The value of the {@code outputDataShape} attribute */ @JsonProperty("outputDataShape") @Override public Optional getOutputDataShape() { return Optional.ofNullable(outputDataShape); } /** * @return The value of the {@code propertyDefinitionSteps} attribute */ @JsonProperty("propertyDefinitionSteps") @Override public List getPropertyDefinitionSteps() { return propertyDefinitionSteps; } /** * Copy the current immutable object by setting a value for the {@link StepDescriptor#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 (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableStepDescriptor withKind(StepAction.Kind value) { if (this.kind == value) return this; return validate(new ImmutableStepDescriptor( this, value, this.entrypoint, this.resource, this.inputDataShape, this.outputDataShape, this.propertyDefinitionSteps)); } /** * Copy the current immutable object by setting a value for the {@link StepDescriptor#getEntrypoint() entrypoint} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for entrypoint (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableStepDescriptor withEntrypoint(String value) { if (Objects.equals(this.entrypoint, value)) return this; return validate(new ImmutableStepDescriptor( this, this.kind, value, this.resource, this.inputDataShape, this.outputDataShape, this.propertyDefinitionSteps)); } /** * Copy the current immutable object by setting a value for the {@link StepDescriptor#getResource() resource} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for resource (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableStepDescriptor withResource(String value) { if (Objects.equals(this.resource, value)) return this; return validate(new ImmutableStepDescriptor( this, this.kind, this.entrypoint, value, this.inputDataShape, this.outputDataShape, this.propertyDefinitionSteps)); } /** * Copy the current immutable object by setting a present value for the optional {@link StepDescriptor#getInputDataShape() inputDataShape} attribute. * @param value The value for inputDataShape * @return A modified copy of {@code this} object */ public final ImmutableStepDescriptor withInputDataShape(DataShape value) { DataShape newValue = Objects.requireNonNull(value, "inputDataShape"); if (this.inputDataShape == newValue) return this; return validate(new ImmutableStepDescriptor( this, this.kind, this.entrypoint, this.resource, newValue, this.outputDataShape, this.propertyDefinitionSteps)); } /** * Copy the current immutable object by setting an optional value for the {@link StepDescriptor#getInputDataShape() inputDataShape} 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 inputDataShape * @return A modified copy of {@code this} object */ public final ImmutableStepDescriptor withInputDataShape(Optional optional) { DataShape value = optional.orElse(null); if (this.inputDataShape == value) return this; return validate(new ImmutableStepDescriptor( this, this.kind, this.entrypoint, this.resource, value, this.outputDataShape, this.propertyDefinitionSteps)); } /** * Copy the current immutable object by setting a present value for the optional {@link StepDescriptor#getOutputDataShape() outputDataShape} attribute. * @param value The value for outputDataShape * @return A modified copy of {@code this} object */ public final ImmutableStepDescriptor withOutputDataShape(DataShape value) { DataShape newValue = Objects.requireNonNull(value, "outputDataShape"); if (this.outputDataShape == newValue) return this; return validate(new ImmutableStepDescriptor( this, this.kind, this.entrypoint, this.resource, this.inputDataShape, newValue, this.propertyDefinitionSteps)); } /** * Copy the current immutable object by setting an optional value for the {@link StepDescriptor#getOutputDataShape() outputDataShape} 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 outputDataShape * @return A modified copy of {@code this} object */ public final ImmutableStepDescriptor withOutputDataShape(Optional optional) { DataShape value = optional.orElse(null); if (this.outputDataShape == value) return this; return validate(new ImmutableStepDescriptor( this, this.kind, this.entrypoint, this.resource, this.inputDataShape, value, this.propertyDefinitionSteps)); } /** * Copy the current immutable object with elements that replace the content of {@link StepDescriptor#getPropertyDefinitionSteps() propertyDefinitionSteps}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableStepDescriptor withPropertyDefinitionSteps(ActionDescriptor.ActionDescriptorStep... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return validate(new ImmutableStepDescriptor( this, this.kind, this.entrypoint, this.resource, this.inputDataShape, this.outputDataShape, newValue)); } /** * Copy the current immutable object with elements that replace the content of {@link StepDescriptor#getPropertyDefinitionSteps() propertyDefinitionSteps}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of propertyDefinitionSteps elements to set * @return A modified copy of {@code this} object */ public final ImmutableStepDescriptor withPropertyDefinitionSteps(Iterable elements) { if (this.propertyDefinitionSteps == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return validate(new ImmutableStepDescriptor( this, this.kind, this.entrypoint, this.resource, this.inputDataShape, this.outputDataShape, newValue)); } /** * This instance is equal to all instances of {@code ImmutableStepDescriptor} 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 ImmutableStepDescriptor && equalTo((ImmutableStepDescriptor) another); } private boolean equalTo(ImmutableStepDescriptor another) { return Objects.equals(kind, another.kind) && Objects.equals(entrypoint, another.entrypoint) && Objects.equals(resource, another.resource) && Objects.equals(inputDataShape, another.inputDataShape) && Objects.equals(outputDataShape, another.outputDataShape) && propertyDefinitionSteps.equals(another.propertyDefinitionSteps); } /** * Computes a hash code from attributes: {@code kind}, {@code entrypoint}, {@code resource}, {@code inputDataShape}, {@code outputDataShape}, {@code propertyDefinitionSteps}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Objects.hashCode(kind); h += (h << 5) + Objects.hashCode(entrypoint); h += (h << 5) + Objects.hashCode(resource); h += (h << 5) + Objects.hashCode(inputDataShape); h += (h << 5) + Objects.hashCode(outputDataShape); h += (h << 5) + propertyDefinitionSteps.hashCode(); return h; } /** * Prints the immutable value {@code StepDescriptor} with attribute values. * @return A string representation of the value */ @Override public String toString() { StringBuilder builder = new StringBuilder("StepDescriptor{"); if (kind != null) { builder.append("kind=").append(kind); } if (entrypoint != null) { if (builder.length() > 15) builder.append(", "); builder.append("entrypoint=").append(entrypoint); } if (resource != null) { if (builder.length() > 15) builder.append(", "); builder.append("resource=").append(resource); } if (inputDataShape != null) { if (builder.length() > 15) builder.append(", "); builder.append("inputDataShape=").append(inputDataShape); } if (outputDataShape != null) { if (builder.length() > 15) builder.append(", "); builder.append("outputDataShape=").append(outputDataShape); } if (builder.length() > 15) builder.append(", "); builder.append("propertyDefinitionSteps=").append(propertyDefinitionSteps); return builder.append("}").toString(); } /** * Construct a new immutable {@code StepDescriptor} instance. * @param kind The value for the {@code kind} attribute * @param entrypoint The value for the {@code entrypoint} attribute * @param resource The value for the {@code resource} attribute * @param inputDataShape The value for the {@code inputDataShape} attribute * @param outputDataShape The value for the {@code outputDataShape} attribute * @param propertyDefinitionSteps The value for the {@code propertyDefinitionSteps} attribute * @return An immutable StepDescriptor instance */ public static StepDescriptor of(StepAction.Kind kind, String entrypoint, String resource, Optional inputDataShape, Optional outputDataShape, List propertyDefinitionSteps) { return of(kind, entrypoint, resource, inputDataShape, outputDataShape, (Iterable) propertyDefinitionSteps); } /** * Construct a new immutable {@code StepDescriptor} instance. * @param kind The value for the {@code kind} attribute * @param entrypoint The value for the {@code entrypoint} attribute * @param resource The value for the {@code resource} attribute * @param inputDataShape The value for the {@code inputDataShape} attribute * @param outputDataShape The value for the {@code outputDataShape} attribute * @param propertyDefinitionSteps The value for the {@code propertyDefinitionSteps} attribute * @return An immutable StepDescriptor instance */ public static StepDescriptor of(StepAction.Kind kind, String entrypoint, String resource, Optional inputDataShape, Optional outputDataShape, Iterable propertyDefinitionSteps) { return validate(new ImmutableStepDescriptor(kind, entrypoint, resource, inputDataShape, outputDataShape, propertyDefinitionSteps)); } private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); private static ImmutableStepDescriptor validate(ImmutableStepDescriptor instance) { Set> constraintViolations = validator.validate(instance); if (!constraintViolations.isEmpty()) { throw new ConstraintViolationException(constraintViolations); } return instance; } /** * Creates an immutable copy of a {@link StepDescriptor} 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 StepDescriptor instance */ public static StepDescriptor copyOf(StepDescriptor instance) { if (instance instanceof ImmutableStepDescriptor) { return (ImmutableStepDescriptor) instance; } return new StepDescriptor.Builder() .createFrom(instance) .build(); } private Object readResolve() throws ObjectStreamException { return validate(this); } /** * Builds instances of type {@link StepDescriptor StepDescriptor}. * 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_PROPERTY_DEFINITION_STEPS = 0x1L; private long optBits; private StepAction.Kind kind; private String entrypoint; private String resource; private DataShape inputDataShape; private DataShape outputDataShape; private List propertyDefinitionSteps = new ArrayList(); /** * Creates a builder for {@link StepDescriptor StepDescriptor} instances. */ public Builder() { if (!(this instanceof StepDescriptor.Builder)) { throw new UnsupportedOperationException("Use: new StepDescriptor.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code io.syndesis.common.model.action.StepDescriptor} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final StepDescriptor.Builder createFrom(StepDescriptor instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (StepDescriptor.Builder) this; } /** * Fill a builder with attribute values from the provided {@code io.syndesis.common.model.action.ActionDescriptor} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final StepDescriptor.Builder createFrom(ActionDescriptor instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (StepDescriptor.Builder) this; } private void from(Object object) { if (object instanceof StepDescriptor) { StepDescriptor instance = (StepDescriptor) object; String resourceValue = instance.getResource(); if (resourceValue != null) { resource(resourceValue); } StepAction.Kind kindValue = instance.getKind(); if (kindValue != null) { kind(kindValue); } String entrypointValue = instance.getEntrypoint(); if (entrypointValue != null) { entrypoint(entrypointValue); } } if (object instanceof ActionDescriptor) { ActionDescriptor instance = (ActionDescriptor) object; Optional inputDataShapeOptional = instance.getInputDataShape(); if (inputDataShapeOptional.isPresent()) { inputDataShape(inputDataShapeOptional); } Optional outputDataShapeOptional = instance.getOutputDataShape(); if (outputDataShapeOptional.isPresent()) { outputDataShape(outputDataShapeOptional); } addAllPropertyDefinitionSteps(instance.getPropertyDefinitionSteps()); } } /** * Initializes the value for the {@link StepDescriptor#getKind() kind} attribute. * @param kind The value for kind (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @JsonProperty("kind") public final StepDescriptor.Builder kind(StepAction.Kind kind) { this.kind = kind; return (StepDescriptor.Builder) this; } /** * Initializes the value for the {@link StepDescriptor#getEntrypoint() entrypoint} attribute. * @param entrypoint The value for entrypoint (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @JsonProperty("entrypoint") public final StepDescriptor.Builder entrypoint(String entrypoint) { this.entrypoint = entrypoint; return (StepDescriptor.Builder) this; } /** * Initializes the value for the {@link StepDescriptor#getResource() resource} attribute. * @param resource The value for resource (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @JsonProperty("resource") public final StepDescriptor.Builder resource(String resource) { this.resource = resource; return (StepDescriptor.Builder) this; } /** * Initializes the optional value {@link StepDescriptor#getInputDataShape() inputDataShape} to inputDataShape. * @param inputDataShape The value for inputDataShape * @return {@code this} builder for chained invocation */ public final StepDescriptor.Builder inputDataShape(DataShape inputDataShape) { this.inputDataShape = Objects.requireNonNull(inputDataShape, "inputDataShape"); return (StepDescriptor.Builder) this; } /** * Initializes the optional value {@link StepDescriptor#getInputDataShape() inputDataShape} to inputDataShape. * @param inputDataShape The value for inputDataShape * @return {@code this} builder for use in a chained invocation */ @JsonProperty("inputDataShape") public final StepDescriptor.Builder inputDataShape(Optional inputDataShape) { this.inputDataShape = inputDataShape.orElse(null); return (StepDescriptor.Builder) this; } /** * Initializes the optional value {@link StepDescriptor#getOutputDataShape() outputDataShape} to outputDataShape. * @param outputDataShape The value for outputDataShape * @return {@code this} builder for chained invocation */ public final StepDescriptor.Builder outputDataShape(DataShape outputDataShape) { this.outputDataShape = Objects.requireNonNull(outputDataShape, "outputDataShape"); return (StepDescriptor.Builder) this; } /** * Initializes the optional value {@link StepDescriptor#getOutputDataShape() outputDataShape} to outputDataShape. * @param outputDataShape The value for outputDataShape * @return {@code this} builder for use in a chained invocation */ @JsonProperty("outputDataShape") public final StepDescriptor.Builder outputDataShape(Optional outputDataShape) { this.outputDataShape = outputDataShape.orElse(null); return (StepDescriptor.Builder) this; } /** * Adds one element to {@link StepDescriptor#getPropertyDefinitionSteps() propertyDefinitionSteps} list. * @param element A propertyDefinitionSteps element * @return {@code this} builder for use in a chained invocation */ public final StepDescriptor.Builder addPropertyDefinitionStep(ActionDescriptor.ActionDescriptorStep element) { this.propertyDefinitionSteps.add(Objects.requireNonNull(element, "propertyDefinitionSteps element")); optBits |= OPT_BIT_PROPERTY_DEFINITION_STEPS; return (StepDescriptor.Builder) this; } /** * Adds elements to {@link StepDescriptor#getPropertyDefinitionSteps() propertyDefinitionSteps} list. * @param elements An array of propertyDefinitionSteps elements * @return {@code this} builder for use in a chained invocation */ public final StepDescriptor.Builder addPropertyDefinitionStep(ActionDescriptor.ActionDescriptorStep... elements) { for (ActionDescriptor.ActionDescriptorStep element : elements) { this.propertyDefinitionSteps.add(Objects.requireNonNull(element, "propertyDefinitionSteps element")); } optBits |= OPT_BIT_PROPERTY_DEFINITION_STEPS; return (StepDescriptor.Builder) this; } /** * Sets or replaces all elements for {@link StepDescriptor#getPropertyDefinitionSteps() propertyDefinitionSteps} list. * @param elements An iterable of propertyDefinitionSteps elements * @return {@code this} builder for use in a chained invocation */ @JsonProperty("propertyDefinitionSteps") public final StepDescriptor.Builder propertyDefinitionSteps(Iterable elements) { this.propertyDefinitionSteps.clear(); return addAllPropertyDefinitionSteps(elements); } /** * Adds elements to {@link StepDescriptor#getPropertyDefinitionSteps() propertyDefinitionSteps} list. * @param elements An iterable of propertyDefinitionSteps elements * @return {@code this} builder for use in a chained invocation */ public final StepDescriptor.Builder addAllPropertyDefinitionSteps(Iterable elements) { for (ActionDescriptor.ActionDescriptorStep element : elements) { this.propertyDefinitionSteps.add(Objects.requireNonNull(element, "propertyDefinitionSteps element")); } optBits |= OPT_BIT_PROPERTY_DEFINITION_STEPS; return (StepDescriptor.Builder) this; } /** * Builds a new {@link StepDescriptor StepDescriptor}. * @return An immutable instance of StepDescriptor * @throws java.lang.IllegalStateException if any required attributes are missing */ public StepDescriptor build() { return ImmutableStepDescriptor.validate(new ImmutableStepDescriptor(this)); } private boolean propertyDefinitionStepsIsSet() { return (optBits & OPT_BIT_PROPERTY_DEFINITION_STEPS) != 0; } } 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 - 2024 Weber Informatics LLC | Privacy Policy