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

io.syndesis.common.model.connection.ImmutableDynamicActionMetadata 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.connection;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.syndesis.common.model.DataShape;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.Validator;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link DynamicActionMetadata}.
 * 

* Use the builder to create immutable instances: * {@code new DynamicActionMetadata.Builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableDynamicActionMetadata.of()}. */ @Generated(from = "DynamicActionMetadata", generator = "Immutables") @SuppressWarnings({"all"}) @SuppressFBWarnings @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue final class ImmutableDynamicActionMetadata implements DynamicActionMetadata { private final Map> properties; private final DataShape inputShape; private final DataShape outputShape; private ImmutableDynamicActionMetadata( Map> properties, DataShape inputShape, DataShape outputShape) { this.properties = createUnmodifiableMap(true, false, properties); this.inputShape = inputShape; this.outputShape = outputShape; } private ImmutableDynamicActionMetadata( ImmutableDynamicActionMetadata original, Map> properties, DataShape inputShape, DataShape outputShape) { this.properties = properties; this.inputShape = inputShape; this.outputShape = outputShape; } /** * @return The value of the {@code properties} attribute */ @JsonProperty("properties") @Override public Map> properties() { return properties; } /** * @return The value of the {@code inputShape} attribute */ @JsonProperty("inputShape") @Override public DataShape inputShape() { return inputShape; } /** * @return The value of the {@code outputShape} attribute */ @JsonProperty("outputShape") @Override public DataShape outputShape() { return outputShape; } /** * Copy the current immutable object by replacing the {@link DynamicActionMetadata#properties() 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 ImmutableDynamicActionMetadata withProperties(Map> entries) { if (this.properties == entries) return this; Map> newValue = createUnmodifiableMap(true, false, entries); return validate(new ImmutableDynamicActionMetadata(this, newValue, this.inputShape, this.outputShape)); } /** * Copy the current immutable object by setting a value for the {@link DynamicActionMetadata#inputShape() inputShape} 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 inputShape (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableDynamicActionMetadata withInputShape(DataShape value) { if (this.inputShape == value) return this; return validate(new ImmutableDynamicActionMetadata(this, this.properties, value, this.outputShape)); } /** * Copy the current immutable object by setting a value for the {@link DynamicActionMetadata#outputShape() outputShape} 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 outputShape (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableDynamicActionMetadata withOutputShape(DataShape value) { if (this.outputShape == value) return this; return validate(new ImmutableDynamicActionMetadata(this, this.properties, this.inputShape, value)); } /** * This instance is equal to all instances of {@code ImmutableDynamicActionMetadata} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableDynamicActionMetadata && equalTo((ImmutableDynamicActionMetadata) another); } private boolean equalTo(ImmutableDynamicActionMetadata another) { return properties.equals(another.properties) && Objects.equals(inputShape, another.inputShape) && Objects.equals(outputShape, another.outputShape); } /** * Computes a hash code from attributes: {@code properties}, {@code inputShape}, {@code outputShape}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + properties.hashCode(); h += (h << 5) + Objects.hashCode(inputShape); h += (h << 5) + Objects.hashCode(outputShape); return h; } /** * Prints the immutable value {@code DynamicActionMetadata} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "DynamicActionMetadata{" + "properties=" + properties + ", inputShape=" + inputShape + ", outputShape=" + outputShape + "}"; } /** * Construct a new immutable {@code DynamicActionMetadata} instance. * @param properties The value for the {@code properties} attribute * @param inputShape The value for the {@code inputShape} attribute * @param outputShape The value for the {@code outputShape} attribute * @return An immutable DynamicActionMetadata instance */ public static DynamicActionMetadata of(Map> properties, DataShape inputShape, DataShape outputShape) { return validate(new ImmutableDynamicActionMetadata(properties, inputShape, outputShape)); } private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); private static ImmutableDynamicActionMetadata validate(ImmutableDynamicActionMetadata instance) { Set> constraintViolations = validator.validate(instance); if (!constraintViolations.isEmpty()) { throw new ConstraintViolationException(constraintViolations); } return instance; } /** * Creates an immutable copy of a {@link DynamicActionMetadata} 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 DynamicActionMetadata instance */ public static DynamicActionMetadata copyOf(DynamicActionMetadata instance) { if (instance instanceof ImmutableDynamicActionMetadata) { return (ImmutableDynamicActionMetadata) instance; } return new DynamicActionMetadata.Builder() .createFrom(instance) .build(); } /** * Builds instances of type {@link DynamicActionMetadata DynamicActionMetadata}. * 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 = "DynamicActionMetadata", generator = "Immutables") @NotThreadSafe public static class Builder { private Map> properties = new LinkedHashMap>(); private @Nullable DataShape inputShape; private @Nullable DataShape outputShape; /** * Creates a builder for {@link DynamicActionMetadata DynamicActionMetadata} instances. *

     * new DynamicActionMetadata.Builder()
     *    .putProperty|putAllProperties(String => List&lt;io.syndesis.common.model.connection.DynamicActionMetadata.ActionPropertySuggestion&gt;) // {@link DynamicActionMetadata#properties() properties} mappings
     *    .inputShape(io.syndesis.common.model.DataShape | null) // nullable {@link DynamicActionMetadata#inputShape() inputShape}
     *    .outputShape(io.syndesis.common.model.DataShape | null) // nullable {@link DynamicActionMetadata#outputShape() outputShape}
     *    .build();
     * 
*/ public Builder() { if (!(this instanceof DynamicActionMetadata.Builder)) { throw new UnsupportedOperationException("Use: new DynamicActionMetadata.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code DynamicActionMetadata} 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 */ @CanIgnoreReturnValue public final DynamicActionMetadata.Builder createFrom(DynamicActionMetadata instance) { Objects.requireNonNull(instance, "instance"); putAllProperties(instance.properties()); DataShape inputShapeValue = instance.inputShape(); if (inputShapeValue != null) { inputShape(inputShapeValue); } DataShape outputShapeValue = instance.outputShape(); if (outputShapeValue != null) { outputShape(outputShapeValue); } return (DynamicActionMetadata.Builder) this; } /** * Put one entry to the {@link DynamicActionMetadata#properties() 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 */ @CanIgnoreReturnValue public final DynamicActionMetadata.Builder putProperty(String key, List value) { this.properties.put( Objects.requireNonNull(key, "properties key"), Objects.requireNonNull(value, "properties value")); return (DynamicActionMetadata.Builder) this; } /** * Put one entry to the {@link DynamicActionMetadata#properties() properties} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final DynamicActionMetadata.Builder putProperty(Map.Entry> entry) { String k = entry.getKey(); List v = entry.getValue(); this.properties.put( Objects.requireNonNull(k, "properties key"), Objects.requireNonNull(v, "properties value")); return (DynamicActionMetadata.Builder) this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link DynamicActionMetadata#properties() properties} map. Nulls are not permitted * @param entries The entries that will be added to the properties map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("properties") public final DynamicActionMetadata.Builder properties(Map> entries) { this.properties.clear(); return putAllProperties(entries); } /** * Put all mappings from the specified map as entries to {@link DynamicActionMetadata#properties() properties} map. Nulls are not permitted * @param entries The entries that will be added to the properties map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final DynamicActionMetadata.Builder putAllProperties(Map> entries) { for (Map.Entry> e : entries.entrySet()) { String k = e.getKey(); List v = e.getValue(); this.properties.put( Objects.requireNonNull(k, "properties key"), Objects.requireNonNull(v, "properties value")); } return (DynamicActionMetadata.Builder) this; } /** * Initializes the value for the {@link DynamicActionMetadata#inputShape() inputShape} attribute. * @param inputShape The value for inputShape (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("inputShape") public final DynamicActionMetadata.Builder inputShape(DataShape inputShape) { this.inputShape = inputShape; return (DynamicActionMetadata.Builder) this; } /** * Initializes the value for the {@link DynamicActionMetadata#outputShape() outputShape} attribute. * @param outputShape The value for outputShape (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("outputShape") public final DynamicActionMetadata.Builder outputShape(DataShape outputShape) { this.outputShape = outputShape; return (DynamicActionMetadata.Builder) this; } /** * Builds a new {@link DynamicActionMetadata DynamicActionMetadata}. * @return An immutable instance of DynamicActionMetadata * @throws java.lang.IllegalStateException if any required attributes are missing */ public DynamicActionMetadata build() { return ImmutableDynamicActionMetadata.validate(new ImmutableDynamicActionMetadata(null, createUnmodifiableMap(false, false, properties), inputShape, outputShape)); } } 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); } } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy