io.syndesis.project.converter.visitor.ImmutableGeneratorContext 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.project.converter.visitor;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.syndesis.dao.extension.ExtensionDataManager;
import io.syndesis.dao.manager.DataManager;
import io.syndesis.integration.model.Flow;
import io.syndesis.model.integration.Integration;
import io.syndesis.project.converter.ProjectGeneratorProperties;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Generated;
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.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
/**
* Immutable implementation of {@link GeneratorContext}.
*
* Use the builder to create immutable instances:
* {@code new GeneratorContext.Builder()}.
* Use the static factory method to create immutable instances:
* {@code ImmutableGeneratorContext.of()}.
*/
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "GeneratorContext"})
@Immutable
final class ImmutableGeneratorContext implements GeneratorContext {
private final Integration integration;
private final Flow flow;
private final ProjectGeneratorProperties generatorProperties;
private final StepVisitorFactoryRegistry visitorFactoryRegistry;
private final TarArchiveOutputStream tarArchiveOutputStream;
private final DataManager dataManager;
private final @Nullable ExtensionDataManager extensionDataManager;
private ImmutableGeneratorContext(
Integration integration,
Flow flow,
ProjectGeneratorProperties generatorProperties,
StepVisitorFactoryRegistry visitorFactoryRegistry,
TarArchiveOutputStream tarArchiveOutputStream,
DataManager dataManager,
Optional extensionDataManager) {
this.integration = integration;
this.flow = flow;
this.generatorProperties = generatorProperties;
this.visitorFactoryRegistry = visitorFactoryRegistry;
this.tarArchiveOutputStream = tarArchiveOutputStream;
this.dataManager = dataManager;
this.extensionDataManager = extensionDataManager.orElse(null);
}
private ImmutableGeneratorContext(
ImmutableGeneratorContext original,
Integration integration,
Flow flow,
ProjectGeneratorProperties generatorProperties,
StepVisitorFactoryRegistry visitorFactoryRegistry,
TarArchiveOutputStream tarArchiveOutputStream,
DataManager dataManager,
@Nullable ExtensionDataManager extensionDataManager) {
this.integration = integration;
this.flow = flow;
this.generatorProperties = generatorProperties;
this.visitorFactoryRegistry = visitorFactoryRegistry;
this.tarArchiveOutputStream = tarArchiveOutputStream;
this.dataManager = dataManager;
this.extensionDataManager = extensionDataManager;
}
/**
* @return The value of the {@code integration} attribute
*/
@JsonProperty("integration")
@Override
public Integration getIntegration() {
return integration;
}
/**
* @return The value of the {@code flow} attribute
*/
@JsonProperty("flow")
@Override
public Flow getFlow() {
return flow;
}
/**
* @return The value of the {@code generatorProperties} attribute
*/
@JsonProperty("generatorProperties")
@Override
public ProjectGeneratorProperties getGeneratorProperties() {
return generatorProperties;
}
/**
* @return The value of the {@code visitorFactoryRegistry} attribute
*/
@JsonProperty("visitorFactoryRegistry")
@Override
public StepVisitorFactoryRegistry getVisitorFactoryRegistry() {
return visitorFactoryRegistry;
}
/**
* @return The value of the {@code tarArchiveOutputStream} attribute
*/
@JsonProperty("tarArchiveOutputStream")
@Override
public TarArchiveOutputStream getTarArchiveOutputStream() {
return tarArchiveOutputStream;
}
/**
* @return The value of the {@code dataManager} attribute
*/
@JsonProperty("dataManager")
@Override
public DataManager getDataManager() {
return dataManager;
}
/**
* @return The value of the {@code extensionDataManager} attribute
*/
@JsonProperty("extensionDataManager")
@Override
public Optional getExtensionDataManager() {
return Optional.ofNullable(extensionDataManager);
}
/**
* Copy the current immutable object by setting a value for the {@link GeneratorContext#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 ImmutableGeneratorContext withIntegration(Integration value) {
if (this.integration == value) return this;
return validate(new ImmutableGeneratorContext(
this,
value,
this.flow,
this.generatorProperties,
this.visitorFactoryRegistry,
this.tarArchiveOutputStream,
this.dataManager,
this.extensionDataManager));
}
/**
* Copy the current immutable object by setting a value for the {@link GeneratorContext#getFlow() flow} 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 flow (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableGeneratorContext withFlow(Flow value) {
if (this.flow == value) return this;
return validate(new ImmutableGeneratorContext(
this,
this.integration,
value,
this.generatorProperties,
this.visitorFactoryRegistry,
this.tarArchiveOutputStream,
this.dataManager,
this.extensionDataManager));
}
/**
* Copy the current immutable object by setting a value for the {@link GeneratorContext#getGeneratorProperties() generatorProperties} 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 generatorProperties (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableGeneratorContext withGeneratorProperties(ProjectGeneratorProperties value) {
if (this.generatorProperties == value) return this;
return validate(new ImmutableGeneratorContext(
this,
this.integration,
this.flow,
value,
this.visitorFactoryRegistry,
this.tarArchiveOutputStream,
this.dataManager,
this.extensionDataManager));
}
/**
* Copy the current immutable object by setting a value for the {@link GeneratorContext#getVisitorFactoryRegistry() visitorFactoryRegistry} 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 visitorFactoryRegistry (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableGeneratorContext withVisitorFactoryRegistry(StepVisitorFactoryRegistry value) {
if (this.visitorFactoryRegistry == value) return this;
return validate(new ImmutableGeneratorContext(
this,
this.integration,
this.flow,
this.generatorProperties,
value,
this.tarArchiveOutputStream,
this.dataManager,
this.extensionDataManager));
}
/**
* Copy the current immutable object by setting a value for the {@link GeneratorContext#getTarArchiveOutputStream() tarArchiveOutputStream} 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 tarArchiveOutputStream (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableGeneratorContext withTarArchiveOutputStream(TarArchiveOutputStream value) {
if (this.tarArchiveOutputStream == value) return this;
return validate(new ImmutableGeneratorContext(
this,
this.integration,
this.flow,
this.generatorProperties,
this.visitorFactoryRegistry,
value,
this.dataManager,
this.extensionDataManager));
}
/**
* Copy the current immutable object by setting a value for the {@link GeneratorContext#getDataManager() dataManager} 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 dataManager (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableGeneratorContext withDataManager(DataManager value) {
if (this.dataManager == value) return this;
return validate(new ImmutableGeneratorContext(
this,
this.integration,
this.flow,
this.generatorProperties,
this.visitorFactoryRegistry,
this.tarArchiveOutputStream,
value,
this.extensionDataManager));
}
/**
* Copy the current immutable object by setting a present value for the optional {@link GeneratorContext#getExtensionDataManager() extensionDataManager} attribute.
* @param value The value for extensionDataManager
* @return A modified copy of {@code this} object
*/
public final ImmutableGeneratorContext withExtensionDataManager(ExtensionDataManager value) {
@Nullable ExtensionDataManager newValue = Objects.requireNonNull(value, "extensionDataManager");
if (this.extensionDataManager == newValue) return this;
return validate(new ImmutableGeneratorContext(
this,
this.integration,
this.flow,
this.generatorProperties,
this.visitorFactoryRegistry,
this.tarArchiveOutputStream,
this.dataManager,
newValue));
}
/**
* Copy the current immutable object by setting an optional value for the {@link GeneratorContext#getExtensionDataManager() extensionDataManager} 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 extensionDataManager
* @return A modified copy of {@code this} object
*/
public final ImmutableGeneratorContext withExtensionDataManager(Optional extends ExtensionDataManager> optional) {
@Nullable ExtensionDataManager value = optional.orElse(null);
if (this.extensionDataManager == value) return this;
return validate(new ImmutableGeneratorContext(
this,
this.integration,
this.flow,
this.generatorProperties,
this.visitorFactoryRegistry,
this.tarArchiveOutputStream,
this.dataManager,
value));
}
/**
* This instance is equal to all instances of {@code ImmutableGeneratorContext} 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 ImmutableGeneratorContext
&& equalTo((ImmutableGeneratorContext) another);
}
private boolean equalTo(ImmutableGeneratorContext another) {
return Objects.equals(integration, another.integration)
&& Objects.equals(flow, another.flow)
&& Objects.equals(generatorProperties, another.generatorProperties)
&& Objects.equals(visitorFactoryRegistry, another.visitorFactoryRegistry)
&& Objects.equals(tarArchiveOutputStream, another.tarArchiveOutputStream)
&& Objects.equals(dataManager, another.dataManager)
&& Objects.equals(extensionDataManager, another.extensionDataManager);
}
/**
* Computes a hash code from attributes: {@code integration}, {@code flow}, {@code generatorProperties}, {@code visitorFactoryRegistry}, {@code tarArchiveOutputStream}, {@code dataManager}, {@code extensionDataManager}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(integration);
h += (h << 5) + Objects.hashCode(flow);
h += (h << 5) + Objects.hashCode(generatorProperties);
h += (h << 5) + Objects.hashCode(visitorFactoryRegistry);
h += (h << 5) + Objects.hashCode(tarArchiveOutputStream);
h += (h << 5) + Objects.hashCode(dataManager);
h += (h << 5) + Objects.hashCode(extensionDataManager);
return h;
}
/**
* Prints the immutable value {@code GeneratorContext} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("GeneratorContext{");
if (integration != null) {
builder.append("integration=").append(integration);
}
if (flow != null) {
if (builder.length() > 17) builder.append(", ");
builder.append("flow=").append(flow);
}
if (generatorProperties != null) {
if (builder.length() > 17) builder.append(", ");
builder.append("generatorProperties=").append(generatorProperties);
}
if (visitorFactoryRegistry != null) {
if (builder.length() > 17) builder.append(", ");
builder.append("visitorFactoryRegistry=").append(visitorFactoryRegistry);
}
if (tarArchiveOutputStream != null) {
if (builder.length() > 17) builder.append(", ");
builder.append("tarArchiveOutputStream=").append(tarArchiveOutputStream);
}
if (dataManager != null) {
if (builder.length() > 17) builder.append(", ");
builder.append("dataManager=").append(dataManager);
}
if (extensionDataManager != null) {
if (builder.length() > 17) builder.append(", ");
builder.append("extensionDataManager=").append(extensionDataManager);
}
return builder.append("}").toString();
}
/**
* Construct a new immutable {@code GeneratorContext} instance.
* @param integration The value for the {@code integration} attribute
* @param flow The value for the {@code flow} attribute
* @param generatorProperties The value for the {@code generatorProperties} attribute
* @param visitorFactoryRegistry The value for the {@code visitorFactoryRegistry} attribute
* @param tarArchiveOutputStream The value for the {@code tarArchiveOutputStream} attribute
* @param dataManager The value for the {@code dataManager} attribute
* @param extensionDataManager The value for the {@code extensionDataManager} attribute
* @return An immutable GeneratorContext instance
*/
public static GeneratorContext of(Integration integration, Flow flow, ProjectGeneratorProperties generatorProperties, StepVisitorFactoryRegistry visitorFactoryRegistry, TarArchiveOutputStream tarArchiveOutputStream, DataManager dataManager, Optional extensionDataManager) {
return validate(new ImmutableGeneratorContext(integration, flow, generatorProperties, visitorFactoryRegistry, tarArchiveOutputStream, dataManager, extensionDataManager));
}
private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
private static ImmutableGeneratorContext validate(ImmutableGeneratorContext instance) {
Set> constraintViolations = validator.validate(instance);
if (!constraintViolations.isEmpty()) {
throw new ConstraintViolationException(constraintViolations);
}
return instance;
}
/**
* Creates an immutable copy of a {@link GeneratorContext} 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 GeneratorContext instance
*/
public static GeneratorContext copyOf(GeneratorContext instance) {
if (instance instanceof ImmutableGeneratorContext) {
return (ImmutableGeneratorContext) instance;
}
return new GeneratorContext.Builder()
.createFrom(instance)
.build();
}
/**
* Builds instances of type {@link GeneratorContext GeneratorContext}.
* 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.
*/
@NotThreadSafe
public static class Builder {
private @Nullable Integration integration;
private @Nullable Flow flow;
private @Nullable ProjectGeneratorProperties generatorProperties;
private @Nullable StepVisitorFactoryRegistry visitorFactoryRegistry;
private @Nullable TarArchiveOutputStream tarArchiveOutputStream;
private @Nullable DataManager dataManager;
private @Nullable ExtensionDataManager extensionDataManager;
/**
* Creates a builder for {@link GeneratorContext GeneratorContext} instances.
*/
public Builder() {
if (!(this instanceof GeneratorContext.Builder)) {
throw new UnsupportedOperationException("Use: new GeneratorContext.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code GeneratorContext} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final GeneratorContext.Builder createFrom(GeneratorContext instance) {
Objects.requireNonNull(instance, "instance");
Integration integrationValue = instance.getIntegration();
if (integrationValue != null) {
integration(integrationValue);
}
Flow flowValue = instance.getFlow();
if (flowValue != null) {
flow(flowValue);
}
ProjectGeneratorProperties generatorPropertiesValue = instance.getGeneratorProperties();
if (generatorPropertiesValue != null) {
generatorProperties(generatorPropertiesValue);
}
StepVisitorFactoryRegistry visitorFactoryRegistryValue = instance.getVisitorFactoryRegistry();
if (visitorFactoryRegistryValue != null) {
visitorFactoryRegistry(visitorFactoryRegistryValue);
}
TarArchiveOutputStream tarArchiveOutputStreamValue = instance.getTarArchiveOutputStream();
if (tarArchiveOutputStreamValue != null) {
tarArchiveOutputStream(tarArchiveOutputStreamValue);
}
DataManager dataManagerValue = instance.getDataManager();
if (dataManagerValue != null) {
dataManager(dataManagerValue);
}
Optional extensionDataManagerOptional = instance.getExtensionDataManager();
if (extensionDataManagerOptional.isPresent()) {
extensionDataManager(extensionDataManagerOptional);
}
return (GeneratorContext.Builder) this;
}
/**
* Initializes the value for the {@link GeneratorContext#getIntegration() integration} attribute.
* @param integration The value for integration (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("integration")
public final GeneratorContext.Builder integration(Integration integration) {
this.integration = integration;
return (GeneratorContext.Builder) this;
}
/**
* Initializes the value for the {@link GeneratorContext#getFlow() flow} attribute.
* @param flow The value for flow (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("flow")
public final GeneratorContext.Builder flow(Flow flow) {
this.flow = flow;
return (GeneratorContext.Builder) this;
}
/**
* Initializes the value for the {@link GeneratorContext#getGeneratorProperties() generatorProperties} attribute.
* @param generatorProperties The value for generatorProperties (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("generatorProperties")
public final GeneratorContext.Builder generatorProperties(ProjectGeneratorProperties generatorProperties) {
this.generatorProperties = generatorProperties;
return (GeneratorContext.Builder) this;
}
/**
* Initializes the value for the {@link GeneratorContext#getVisitorFactoryRegistry() visitorFactoryRegistry} attribute.
* @param visitorFactoryRegistry The value for visitorFactoryRegistry (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("visitorFactoryRegistry")
public final GeneratorContext.Builder visitorFactoryRegistry(StepVisitorFactoryRegistry visitorFactoryRegistry) {
this.visitorFactoryRegistry = visitorFactoryRegistry;
return (GeneratorContext.Builder) this;
}
/**
* Initializes the value for the {@link GeneratorContext#getTarArchiveOutputStream() tarArchiveOutputStream} attribute.
* @param tarArchiveOutputStream The value for tarArchiveOutputStream (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("tarArchiveOutputStream")
public final GeneratorContext.Builder tarArchiveOutputStream(TarArchiveOutputStream tarArchiveOutputStream) {
this.tarArchiveOutputStream = tarArchiveOutputStream;
return (GeneratorContext.Builder) this;
}
/**
* Initializes the value for the {@link GeneratorContext#getDataManager() dataManager} attribute.
* @param dataManager The value for dataManager (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("dataManager")
public final GeneratorContext.Builder dataManager(DataManager dataManager) {
this.dataManager = dataManager;
return (GeneratorContext.Builder) this;
}
/**
* Initializes the optional value {@link GeneratorContext#getExtensionDataManager() extensionDataManager} to extensionDataManager.
* @param extensionDataManager The value for extensionDataManager
* @return {@code this} builder for chained invocation
*/
public final GeneratorContext.Builder extensionDataManager(ExtensionDataManager extensionDataManager) {
this.extensionDataManager = Objects.requireNonNull(extensionDataManager, "extensionDataManager");
return (GeneratorContext.Builder) this;
}
/**
* Initializes the optional value {@link GeneratorContext#getExtensionDataManager() extensionDataManager} to extensionDataManager.
* @param extensionDataManager The value for extensionDataManager
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("extensionDataManager")
public final GeneratorContext.Builder extensionDataManager(Optional extends ExtensionDataManager> extensionDataManager) {
this.extensionDataManager = extensionDataManager.orElse(null);
return (GeneratorContext.Builder) this;
}
/**
* Builds a new {@link GeneratorContext GeneratorContext}.
* @return An immutable instance of GeneratorContext
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public GeneratorContext build() {
return ImmutableGeneratorContext.validate(new ImmutableGeneratorContext(
null,
integration,
flow,
generatorProperties,
visitorFactoryRegistry,
tarArchiveOutputStream,
dataManager,
extensionDataManager));
}
}
}