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

io.syndesis.project.converter.ImmutableGenerateProjectRequest Maven / Gradle / Ivy

There is a newer version: 1.2.9
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.project.converter;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.syndesis.model.connection.Connector;
import io.syndesis.model.integration.Integration;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
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 GenerateProjectRequest}.
 * 

* Use the builder to create immutable instances: * {@code new GenerateProjectRequest.Builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableGenerateProjectRequest.of()}. */ @SuppressWarnings({"all"}) @SuppressFBWarnings @Generated({"Immutables.generator", "GenerateProjectRequest"}) final class ImmutableGenerateProjectRequest implements GenerateProjectRequest { private final Integration integration; private final Map connectors; private ImmutableGenerateProjectRequest( Integration integration, Map connectors) { this.integration = integration; this.connectors = createUnmodifiableMap(true, false, connectors); } private ImmutableGenerateProjectRequest( ImmutableGenerateProjectRequest original, Integration integration, Map connectors) { this.integration = integration; this.connectors = connectors; } /** * @return The value of the {@code integration} attribute */ @Override public Integration getIntegration() { return integration; } /** * @return The value of the {@code connectors} attribute */ @Override public Map getConnectors() { return connectors; } /** * Copy the current immutable object by setting a value for the {@link GenerateProjectRequest#getIntegration() integration} 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 integration (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableGenerateProjectRequest withIntegration(Integration value) { if (this.integration == value) return this; return validate(new ImmutableGenerateProjectRequest(this, value, this.connectors)); } /** * Copy the current immutable object by replacing the {@link GenerateProjectRequest#getConnectors() connectors} 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 connectors map * @return A modified copy of {@code this} object */ public final ImmutableGenerateProjectRequest withConnectors(Map entries) { if (this.connectors == entries) return this; Map newValue = createUnmodifiableMap(true, false, entries); return validate(new ImmutableGenerateProjectRequest(this, this.integration, newValue)); } /** * This instance is equal to all instances of {@code ImmutableGenerateProjectRequest} 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 ImmutableGenerateProjectRequest && equalTo((ImmutableGenerateProjectRequest) another); } private boolean equalTo(ImmutableGenerateProjectRequest another) { return Objects.equals(integration, another.integration) && connectors.equals(another.connectors); } /** * Computes a hash code from attributes: {@code integration}, {@code connectors}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Objects.hashCode(integration); h += (h << 5) + connectors.hashCode(); return h; } /** * Prints the immutable value {@code GenerateProjectRequest} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "GenerateProjectRequest{" + "integration=" + integration + ", connectors=" + connectors + "}"; } /** * Construct a new immutable {@code GenerateProjectRequest} instance. * @param integration The value for the {@code integration} attribute * @param connectors The value for the {@code connectors} attribute * @return An immutable GenerateProjectRequest instance */ public static ImmutableGenerateProjectRequest of(Integration integration, Map connectors) { return validate(new ImmutableGenerateProjectRequest(integration, connectors)); } private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); private static ImmutableGenerateProjectRequest validate(ImmutableGenerateProjectRequest instance) { Set> constraintViolations = validator.validate(instance); if (!constraintViolations.isEmpty()) { throw new ConstraintViolationException(constraintViolations); } return instance; } /** * Creates an immutable copy of a {@link GenerateProjectRequest} 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 GenerateProjectRequest instance */ public static ImmutableGenerateProjectRequest copyOf(GenerateProjectRequest instance) { if (instance instanceof ImmutableGenerateProjectRequest) { return (ImmutableGenerateProjectRequest) instance; } return new GenerateProjectRequest.Builder() .createFrom(instance) .build(); } /** * Builds instances of type {@link ImmutableGenerateProjectRequest ImmutableGenerateProjectRequest}. * 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. */ static class Builder { private Integration integration; private Map connectors = new LinkedHashMap(); /** * Creates a builder for {@link ImmutableGenerateProjectRequest ImmutableGenerateProjectRequest} instances. */ Builder() { if (!(this instanceof GenerateProjectRequest.Builder)) { throw new UnsupportedOperationException("Use: new GenerateProjectRequest.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code GenerateProjectRequest} 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 GenerateProjectRequest.Builder createFrom(GenerateProjectRequest instance) { Objects.requireNonNull(instance, "instance"); Integration integrationValue = instance.getIntegration(); if (integrationValue != null) { integration(integrationValue); } putAllConnectors(instance.getConnectors()); return (GenerateProjectRequest.Builder) this; } /** * Initializes the value for the {@link GenerateProjectRequest#getIntegration() integration} attribute. * @param integration The value for integration (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ public final GenerateProjectRequest.Builder integration(Integration integration) { this.integration = integration; return (GenerateProjectRequest.Builder) this; } /** * Put one entry to the {@link GenerateProjectRequest#getConnectors() connectors} map. * @param key The key in the connectors map * @param value The associated value in the connectors map * @return {@code this} builder for use in a chained invocation */ public final GenerateProjectRequest.Builder putConnector(String key, Connector value) { this.connectors.put( Objects.requireNonNull(key, "connectors key"), Objects.requireNonNull(value, "connectors value")); return (GenerateProjectRequest.Builder) this; } /** * Put one entry to the {@link GenerateProjectRequest#getConnectors() connectors} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ public final GenerateProjectRequest.Builder putConnector(Map.Entry entry) { String k = entry.getKey(); Connector v = entry.getValue(); this.connectors.put( Objects.requireNonNull(k, "connectors key"), Objects.requireNonNull(v, "connectors value")); return (GenerateProjectRequest.Builder) this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link GenerateProjectRequest#getConnectors() connectors} map. Nulls are not permitted * @param connectors The entries that will be added to the connectors map * @return {@code this} builder for use in a chained invocation */ public final GenerateProjectRequest.Builder connectors(Map connectors) { this.connectors.clear(); return putAllConnectors(connectors); } /** * Put all mappings from the specified map as entries to {@link GenerateProjectRequest#getConnectors() connectors} map. Nulls are not permitted * @param connectors The entries that will be added to the connectors map * @return {@code this} builder for use in a chained invocation */ public final GenerateProjectRequest.Builder putAllConnectors(Map connectors) { for (Map.Entry entry : connectors.entrySet()) { String k = entry.getKey(); Connector v = entry.getValue(); this.connectors.put( Objects.requireNonNull(k, "connectors key"), Objects.requireNonNull(v, "connectors value")); } return (GenerateProjectRequest.Builder) this; } /** * Builds a new {@link ImmutableGenerateProjectRequest ImmutableGenerateProjectRequest}. * @return An immutable instance of GenerateProjectRequest * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableGenerateProjectRequest build() { return ImmutableGenerateProjectRequest.validate(new ImmutableGenerateProjectRequest(null, integration, createUnmodifiableMap(false, false, connectors))); } } 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