![JAR search and dependency download from the Maven repository](/logo.png)
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.connector.catalog.ConnectorCatalog;
import io.syndesis.integration.model.Flow;
import io.syndesis.project.converter.GenerateProjectRequest;
import io.syndesis.project.converter.ProjectGeneratorProperties;
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;
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
@Generated({"Immutables.generator", "GeneratorContext"})
final class ImmutableGeneratorContext implements GeneratorContext {
private final GenerateProjectRequest request;
private final Flow flow;
private final ConnectorCatalog connectorCatalog;
private final ProjectGeneratorProperties generatorProperties;
private final StepVisitorFactoryRegistry visitorFactoryRegistry;
private final TarArchiveOutputStream tarArchiveOutputStream;
private ImmutableGeneratorContext(
GenerateProjectRequest request,
Flow flow,
ConnectorCatalog connectorCatalog,
ProjectGeneratorProperties generatorProperties,
StepVisitorFactoryRegistry visitorFactoryRegistry,
TarArchiveOutputStream tarArchiveOutputStream) {
this.request = request;
this.flow = flow;
this.connectorCatalog = connectorCatalog;
this.generatorProperties = generatorProperties;
this.visitorFactoryRegistry = visitorFactoryRegistry;
this.tarArchiveOutputStream = tarArchiveOutputStream;
}
/**
* @return The value of the {@code request} attribute
*/
@JsonProperty("request")
@Override
public GenerateProjectRequest getRequest() {
return request;
}
/**
* @return The value of the {@code flow} attribute
*/
@JsonProperty("flow")
@Override
public Flow getFlow() {
return flow;
}
/**
* @return The value of the {@code connectorCatalog} attribute
*/
@JsonProperty("connectorCatalog")
@Override
public ConnectorCatalog getConnectorCatalog() {
return connectorCatalog;
}
/**
* @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;
}
/**
* Copy the current immutable object by setting a value for the {@link GeneratorContext#getRequest() request} 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 request (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableGeneratorContext withRequest(GenerateProjectRequest value) {
if (this.request == value) return this;
return validate(new ImmutableGeneratorContext(
value,
this.flow,
this.connectorCatalog,
this.generatorProperties,
this.visitorFactoryRegistry,
this.tarArchiveOutputStream));
}
/**
* 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.request,
value,
this.connectorCatalog,
this.generatorProperties,
this.visitorFactoryRegistry,
this.tarArchiveOutputStream));
}
/**
* Copy the current immutable object by setting a value for the {@link GeneratorContext#getConnectorCatalog() connectorCatalog} 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 connectorCatalog (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableGeneratorContext withConnectorCatalog(ConnectorCatalog value) {
if (this.connectorCatalog == value) return this;
return validate(new ImmutableGeneratorContext(
this.request,
this.flow,
value,
this.generatorProperties,
this.visitorFactoryRegistry,
this.tarArchiveOutputStream));
}
/**
* 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.request,
this.flow,
this.connectorCatalog,
value,
this.visitorFactoryRegistry,
this.tarArchiveOutputStream));
}
/**
* 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.request,
this.flow,
this.connectorCatalog,
this.generatorProperties,
value,
this.tarArchiveOutputStream));
}
/**
* 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.request,
this.flow,
this.connectorCatalog,
this.generatorProperties,
this.visitorFactoryRegistry,
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(Object another) {
if (this == another) return true;
return another instanceof ImmutableGeneratorContext
&& equalTo((ImmutableGeneratorContext) another);
}
private boolean equalTo(ImmutableGeneratorContext another) {
return Objects.equals(request, another.request)
&& Objects.equals(flow, another.flow)
&& Objects.equals(connectorCatalog, another.connectorCatalog)
&& Objects.equals(generatorProperties, another.generatorProperties)
&& Objects.equals(visitorFactoryRegistry, another.visitorFactoryRegistry)
&& Objects.equals(tarArchiveOutputStream, another.tarArchiveOutputStream);
}
/**
* Computes a hash code from attributes: {@code request}, {@code flow}, {@code connectorCatalog}, {@code generatorProperties}, {@code visitorFactoryRegistry}, {@code tarArchiveOutputStream}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(request);
h += (h << 5) + Objects.hashCode(flow);
h += (h << 5) + Objects.hashCode(connectorCatalog);
h += (h << 5) + Objects.hashCode(generatorProperties);
h += (h << 5) + Objects.hashCode(visitorFactoryRegistry);
h += (h << 5) + Objects.hashCode(tarArchiveOutputStream);
return h;
}
/**
* Prints the immutable value {@code GeneratorContext} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "GeneratorContext{"
+ "request=" + request
+ ", flow=" + flow
+ ", connectorCatalog=" + connectorCatalog
+ ", generatorProperties=" + generatorProperties
+ ", visitorFactoryRegistry=" + visitorFactoryRegistry
+ ", tarArchiveOutputStream=" + tarArchiveOutputStream
+ "}";
}
/**
* Construct a new immutable {@code GeneratorContext} instance.
* @param request The value for the {@code request} attribute
* @param flow The value for the {@code flow} attribute
* @param connectorCatalog The value for the {@code connectorCatalog} 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
* @return An immutable GeneratorContext instance
*/
public static ImmutableGeneratorContext of(GenerateProjectRequest request, Flow flow, ConnectorCatalog connectorCatalog, ProjectGeneratorProperties generatorProperties, StepVisitorFactoryRegistry visitorFactoryRegistry, TarArchiveOutputStream tarArchiveOutputStream) {
return validate(new ImmutableGeneratorContext(request, flow, connectorCatalog, generatorProperties, visitorFactoryRegistry, tarArchiveOutputStream));
}
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 ImmutableGeneratorContext copyOf(GeneratorContext instance) {
if (instance instanceof ImmutableGeneratorContext) {
return (ImmutableGeneratorContext) instance;
}
return new GeneratorContext.Builder()
.createFrom(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableGeneratorContext ImmutableGeneratorContext}.
* 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 GenerateProjectRequest request;
private Flow flow;
private ConnectorCatalog connectorCatalog;
private ProjectGeneratorProperties generatorProperties;
private StepVisitorFactoryRegistry visitorFactoryRegistry;
private TarArchiveOutputStream tarArchiveOutputStream;
/**
* Creates a builder for {@link ImmutableGeneratorContext ImmutableGeneratorContext} instances.
*/
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");
GenerateProjectRequest requestValue = instance.getRequest();
if (requestValue != null) {
request(requestValue);
}
Flow flowValue = instance.getFlow();
if (flowValue != null) {
flow(flowValue);
}
ConnectorCatalog connectorCatalogValue = instance.getConnectorCatalog();
if (connectorCatalogValue != null) {
connectorCatalog(connectorCatalogValue);
}
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);
}
return (GeneratorContext.Builder) this;
}
/**
* Initializes the value for the {@link GeneratorContext#getRequest() request} attribute.
* @param request The value for request (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("request")
public final GeneratorContext.Builder request(GenerateProjectRequest request) {
this.request = request;
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#getConnectorCatalog() connectorCatalog} attribute.
* @param connectorCatalog The value for connectorCatalog (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("connectorCatalog")
public final GeneratorContext.Builder connectorCatalog(ConnectorCatalog connectorCatalog) {
this.connectorCatalog = connectorCatalog;
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;
}
/**
* Builds a new {@link ImmutableGeneratorContext ImmutableGeneratorContext}.
* @return An immutable instance of GeneratorContext
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableGeneratorContext build() {
return ImmutableGeneratorContext.validate(new ImmutableGeneratorContext(
request,
flow,
connectorCatalog,
generatorProperties,
visitorFactoryRegistry,
tarArchiveOutputStream));
}
}
}