io.resys.hdes.client.api.ImmutableComposerEntity Maven / Gradle / Ivy
package io.resys.hdes.client.api;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import io.resys.hdes.client.api.ast.AstBody;
import io.resys.hdes.client.api.programs.ProgramEnvir;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link HdesComposer.ComposerEntity}.
*
* Use the builder to create immutable instances:
* {@code ImmutableComposerEntity.builder()}.
*/
@Generated(from = "HdesComposer.ComposerEntity", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableComposerEntity
implements HdesComposer.ComposerEntity {
private final String id;
private final @Nullable A ast;
private final AstBody.AstSource source;
private final ImmutableList warnings;
private final ImmutableList errors;
private final ImmutableList associations;
private final ProgramEnvir.ProgramStatus status;
private ImmutableComposerEntity(
String id,
@Nullable A ast,
AstBody.AstSource source,
ImmutableList warnings,
ImmutableList errors,
ImmutableList associations,
ProgramEnvir.ProgramStatus status) {
this.id = id;
this.ast = ast;
this.source = source;
this.warnings = warnings;
this.errors = errors;
this.associations = associations;
this.status = status;
}
/**
* @return The value of the {@code id} attribute
*/
@JsonProperty("id")
@Override
public String getId() {
return id;
}
/**
* @return The value of the {@code ast} attribute
*/
@JsonProperty("ast")
@Override
public @Nullable A getAst() {
return ast;
}
/**
* @return The value of the {@code source} attribute
*/
@JsonProperty("source")
@Override
public AstBody.AstSource getSource() {
return source;
}
/**
* @return The value of the {@code warnings} attribute
*/
@JsonProperty("warnings")
@Override
public ImmutableList getWarnings() {
return warnings;
}
/**
* @return The value of the {@code errors} attribute
*/
@JsonProperty("errors")
@Override
public ImmutableList getErrors() {
return errors;
}
/**
* @return The value of the {@code associations} attribute
*/
@JsonProperty("associations")
@Override
public ImmutableList getAssociations() {
return associations;
}
/**
* @return The value of the {@code status} attribute
*/
@JsonProperty("status")
@Override
public ProgramEnvir.ProgramStatus getStatus() {
return status;
}
/**
* Copy the current immutable object by setting a value for the {@link HdesComposer.ComposerEntity#getId() id} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for id
* @return A modified copy of the {@code this} object
*/
public final ImmutableComposerEntity withId(String value) {
String newValue = Objects.requireNonNull(value, "id");
if (this.id.equals(newValue)) return this;
return new ImmutableComposerEntity<>(newValue, this.ast, this.source, this.warnings, this.errors, this.associations, this.status);
}
/**
* Copy the current immutable object by setting a value for the {@link HdesComposer.ComposerEntity#getAst() ast} 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 ast (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableComposerEntity withAst(@Nullable A value) {
if (this.ast == value) return this;
return new ImmutableComposerEntity<>(this.id, value, this.source, this.warnings, this.errors, this.associations, this.status);
}
/**
* Copy the current immutable object by setting a value for the {@link HdesComposer.ComposerEntity#getSource() source} 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 source
* @return A modified copy of the {@code this} object
*/
public final ImmutableComposerEntity withSource(AstBody.AstSource value) {
if (this.source == value) return this;
AstBody.AstSource newValue = Objects.requireNonNull(value, "source");
return new ImmutableComposerEntity<>(this.id, this.ast, newValue, this.warnings, this.errors, this.associations, this.status);
}
/**
* Copy the current immutable object with elements that replace the content of {@link HdesComposer.ComposerEntity#getWarnings() warnings}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableComposerEntity withWarnings(ProgramEnvir.ProgramMessage... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableComposerEntity<>(this.id, this.ast, this.source, newValue, this.errors, this.associations, this.status);
}
/**
* Copy the current immutable object with elements that replace the content of {@link HdesComposer.ComposerEntity#getWarnings() warnings}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of warnings elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableComposerEntity withWarnings(Iterable extends ProgramEnvir.ProgramMessage> elements) {
if (this.warnings == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableComposerEntity<>(this.id, this.ast, this.source, newValue, this.errors, this.associations, this.status);
}
/**
* Copy the current immutable object with elements that replace the content of {@link HdesComposer.ComposerEntity#getErrors() errors}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableComposerEntity withErrors(ProgramEnvir.ProgramMessage... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableComposerEntity<>(this.id, this.ast, this.source, this.warnings, newValue, this.associations, this.status);
}
/**
* Copy the current immutable object with elements that replace the content of {@link HdesComposer.ComposerEntity#getErrors() errors}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of errors elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableComposerEntity withErrors(Iterable extends ProgramEnvir.ProgramMessage> elements) {
if (this.errors == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableComposerEntity<>(this.id, this.ast, this.source, this.warnings, newValue, this.associations, this.status);
}
/**
* Copy the current immutable object with elements that replace the content of {@link HdesComposer.ComposerEntity#getAssociations() associations}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableComposerEntity withAssociations(ProgramEnvir.ProgramAssociation... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableComposerEntity<>(this.id, this.ast, this.source, this.warnings, this.errors, newValue, this.status);
}
/**
* Copy the current immutable object with elements that replace the content of {@link HdesComposer.ComposerEntity#getAssociations() associations}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of associations elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableComposerEntity withAssociations(Iterable extends ProgramEnvir.ProgramAssociation> elements) {
if (this.associations == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableComposerEntity<>(this.id, this.ast, this.source, this.warnings, this.errors, newValue, this.status);
}
/**
* Copy the current immutable object by setting a value for the {@link HdesComposer.ComposerEntity#getStatus() status} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for status
* @return A modified copy of the {@code this} object
*/
public final ImmutableComposerEntity withStatus(ProgramEnvir.ProgramStatus value) {
if (this.status == value) return this;
ProgramEnvir.ProgramStatus newValue = Objects.requireNonNull(value, "status");
if (this.status.equals(newValue)) return this;
return new ImmutableComposerEntity<>(this.id, this.ast, this.source, this.warnings, this.errors, this.associations, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableComposerEntity} 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 ImmutableComposerEntity>
&& equalTo((ImmutableComposerEntity>) another);
}
private boolean equalTo(ImmutableComposerEntity> another) {
return id.equals(another.id)
&& Objects.equals(ast, another.ast)
&& source.equals(another.source)
&& warnings.equals(another.warnings)
&& errors.equals(another.errors)
&& associations.equals(another.associations)
&& status.equals(another.status);
}
/**
* Computes a hash code from attributes: {@code id}, {@code ast}, {@code source}, {@code warnings}, {@code errors}, {@code associations}, {@code status}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + id.hashCode();
h += (h << 5) + Objects.hashCode(ast);
h += (h << 5) + source.hashCode();
h += (h << 5) + warnings.hashCode();
h += (h << 5) + errors.hashCode();
h += (h << 5) + associations.hashCode();
h += (h << 5) + status.hashCode();
return h;
}
/**
* Prints the immutable value {@code ComposerEntity} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ComposerEntity")
.omitNullValues()
.add("id", id)
.add("ast", ast)
.add("source", source)
.add("warnings", warnings)
.add("errors", errors)
.add("associations", associations)
.add("status", status)
.toString();
}
/**
* Utility type used to correctly read immutable object from JSON representation.
* @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure
*/
@Generated(from = "HdesComposer.ComposerEntity", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json
implements HdesComposer.ComposerEntity {
@Nullable String id;
@Nullable A ast;
@Nullable AstBody.AstSource source;
@Nullable List warnings = ImmutableList.of();
@Nullable List errors = ImmutableList.of();
@Nullable List associations = ImmutableList.of();
@Nullable ProgramEnvir.ProgramStatus status;
@JsonProperty("id")
public void setId(String id) {
this.id = id;
}
@JsonProperty("ast")
public void setAst(@Nullable A ast) {
this.ast = ast;
}
@JsonProperty("source")
public void setSource(AstBody.AstSource source) {
this.source = source;
}
@JsonProperty("warnings")
public void setWarnings(List warnings) {
this.warnings = warnings;
}
@JsonProperty("errors")
public void setErrors(List errors) {
this.errors = errors;
}
@JsonProperty("associations")
public void setAssociations(List associations) {
this.associations = associations;
}
@JsonProperty("status")
public void setStatus(ProgramEnvir.ProgramStatus status) {
this.status = status;
}
@Override
public String getId() { throw new UnsupportedOperationException(); }
@Override
public A getAst() { throw new UnsupportedOperationException(); }
@Override
public AstBody.AstSource getSource() { throw new UnsupportedOperationException(); }
@Override
public List getWarnings() { throw new UnsupportedOperationException(); }
@Override
public List getErrors() { throw new UnsupportedOperationException(); }
@Override
public List getAssociations() { throw new UnsupportedOperationException(); }
@Override
public ProgramEnvir.ProgramStatus getStatus() { throw new UnsupportedOperationException(); }
}
/**
* @param generic parameter A
* @param json A JSON-bindable data structure
* @return An immutable value type
* @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure
*/
@Deprecated
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
static ImmutableComposerEntity fromJson(Json json) {
ImmutableComposerEntity.Builder builder = ImmutableComposerEntity.builder();
if (json.id != null) {
builder.id(json.id);
}
if (json.ast != null) {
builder.ast(json.ast);
}
if (json.source != null) {
builder.source(json.source);
}
if (json.warnings != null) {
builder.addAllWarnings(json.warnings);
}
if (json.errors != null) {
builder.addAllErrors(json.errors);
}
if (json.associations != null) {
builder.addAllAssociations(json.associations);
}
if (json.status != null) {
builder.status(json.status);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link HdesComposer.ComposerEntity} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param generic parameter A
* @param instance The instance to copy
* @return A copied immutable ComposerEntity instance
*/
public static ImmutableComposerEntity copyOf(HdesComposer.ComposerEntity instance) {
if (instance instanceof ImmutableComposerEntity>) {
return (ImmutableComposerEntity) instance;
}
return ImmutableComposerEntity.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableComposerEntity ImmutableComposerEntity}.
*
* ImmutableComposerEntity.<A>builder()
* .id(String) // required {@link HdesComposer.ComposerEntity#getId() id}
* .ast(A | null) // nullable {@link HdesComposer.ComposerEntity#getAst() ast}
* .source(io.resys.hdes.client.api.ast.AstBody.AstSource) // required {@link HdesComposer.ComposerEntity#getSource() source}
* .addWarnings|addAllWarnings(io.resys.hdes.client.api.programs.ProgramEnvir.ProgramMessage) // {@link HdesComposer.ComposerEntity#getWarnings() warnings} elements
* .addErrors|addAllErrors(io.resys.hdes.client.api.programs.ProgramEnvir.ProgramMessage) // {@link HdesComposer.ComposerEntity#getErrors() errors} elements
* .addAssociations|addAllAssociations(io.resys.hdes.client.api.programs.ProgramEnvir.ProgramAssociation) // {@link HdesComposer.ComposerEntity#getAssociations() associations} elements
* .status(io.resys.hdes.client.api.programs.ProgramEnvir.ProgramStatus) // required {@link HdesComposer.ComposerEntity#getStatus() status}
* .build();
*
* @param generic parameter A
* @return A new ImmutableComposerEntity builder
*/
public static ImmutableComposerEntity.Builder builder() {
return new ImmutableComposerEntity.Builder<>();
}
/**
* Builds instances of type {@link ImmutableComposerEntity ImmutableComposerEntity}.
* 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 = "HdesComposer.ComposerEntity", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_ID = 0x1L;
private static final long INIT_BIT_SOURCE = 0x2L;
private static final long INIT_BIT_STATUS = 0x4L;
private long initBits = 0x7L;
private @Nullable String id;
private @Nullable A ast;
private @Nullable AstBody.AstSource source;
private ImmutableList.Builder warnings = ImmutableList.builder();
private ImmutableList.Builder errors = ImmutableList.builder();
private ImmutableList.Builder associations = ImmutableList.builder();
private @Nullable ProgramEnvir.ProgramStatus status;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ComposerEntity} 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 Builder from(HdesComposer.ComposerEntity instance) {
Objects.requireNonNull(instance, "instance");
id(instance.getId());
@Nullable A astValue = instance.getAst();
if (astValue != null) {
ast(astValue);
}
source(instance.getSource());
addAllWarnings(instance.getWarnings());
addAllErrors(instance.getErrors());
addAllAssociations(instance.getAssociations());
status(instance.getStatus());
return this;
}
/**
* Initializes the value for the {@link HdesComposer.ComposerEntity#getId() id} attribute.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("id")
public final Builder id(String id) {
this.id = Objects.requireNonNull(id, "id");
initBits &= ~INIT_BIT_ID;
return this;
}
/**
* Initializes the value for the {@link HdesComposer.ComposerEntity#getAst() ast} attribute.
* @param ast The value for ast (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("ast")
public final Builder ast(@Nullable A ast) {
this.ast = ast;
return this;
}
/**
* Initializes the value for the {@link HdesComposer.ComposerEntity#getSource() source} attribute.
* @param source The value for source
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("source")
public final Builder source(AstBody.AstSource source) {
this.source = Objects.requireNonNull(source, "source");
initBits &= ~INIT_BIT_SOURCE;
return this;
}
/**
* Adds one element to {@link HdesComposer.ComposerEntity#getWarnings() warnings} list.
* @param element A warnings element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addWarnings(ProgramEnvir.ProgramMessage element) {
this.warnings.add(element);
return this;
}
/**
* Adds elements to {@link HdesComposer.ComposerEntity#getWarnings() warnings} list.
* @param elements An array of warnings elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addWarnings(ProgramEnvir.ProgramMessage... elements) {
this.warnings.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link HdesComposer.ComposerEntity#getWarnings() warnings} list.
* @param elements An iterable of warnings elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("warnings")
public final Builder warnings(Iterable extends ProgramEnvir.ProgramMessage> elements) {
this.warnings = ImmutableList.builder();
return addAllWarnings(elements);
}
/**
* Adds elements to {@link HdesComposer.ComposerEntity#getWarnings() warnings} list.
* @param elements An iterable of warnings elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllWarnings(Iterable extends ProgramEnvir.ProgramMessage> elements) {
this.warnings.addAll(elements);
return this;
}
/**
* Adds one element to {@link HdesComposer.ComposerEntity#getErrors() errors} list.
* @param element A errors element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addErrors(ProgramEnvir.ProgramMessage element) {
this.errors.add(element);
return this;
}
/**
* Adds elements to {@link HdesComposer.ComposerEntity#getErrors() errors} list.
* @param elements An array of errors elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addErrors(ProgramEnvir.ProgramMessage... elements) {
this.errors.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link HdesComposer.ComposerEntity#getErrors() errors} list.
* @param elements An iterable of errors elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("errors")
public final Builder errors(Iterable extends ProgramEnvir.ProgramMessage> elements) {
this.errors = ImmutableList.builder();
return addAllErrors(elements);
}
/**
* Adds elements to {@link HdesComposer.ComposerEntity#getErrors() errors} list.
* @param elements An iterable of errors elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllErrors(Iterable extends ProgramEnvir.ProgramMessage> elements) {
this.errors.addAll(elements);
return this;
}
/**
* Adds one element to {@link HdesComposer.ComposerEntity#getAssociations() associations} list.
* @param element A associations element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAssociations(ProgramEnvir.ProgramAssociation element) {
this.associations.add(element);
return this;
}
/**
* Adds elements to {@link HdesComposer.ComposerEntity#getAssociations() associations} list.
* @param elements An array of associations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAssociations(ProgramEnvir.ProgramAssociation... elements) {
this.associations.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link HdesComposer.ComposerEntity#getAssociations() associations} list.
* @param elements An iterable of associations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("associations")
public final Builder associations(Iterable extends ProgramEnvir.ProgramAssociation> elements) {
this.associations = ImmutableList.builder();
return addAllAssociations(elements);
}
/**
* Adds elements to {@link HdesComposer.ComposerEntity#getAssociations() associations} list.
* @param elements An iterable of associations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllAssociations(Iterable extends ProgramEnvir.ProgramAssociation> elements) {
this.associations.addAll(elements);
return this;
}
/**
* Initializes the value for the {@link HdesComposer.ComposerEntity#getStatus() status} attribute.
* @param status The value for status
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("status")
public final Builder status(ProgramEnvir.ProgramStatus status) {
this.status = Objects.requireNonNull(status, "status");
initBits &= ~INIT_BIT_STATUS;
return this;
}
/**
* Builds a new {@link ImmutableComposerEntity ImmutableComposerEntity}.
* @return An immutable instance of ComposerEntity
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableComposerEntity build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableComposerEntity<>(id, ast, source, warnings.build(), errors.build(), associations.build(), status);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_ID) != 0) attributes.add("id");
if ((initBits & INIT_BIT_SOURCE) != 0) attributes.add("source");
if ((initBits & INIT_BIT_STATUS) != 0) attributes.add("status");
return "Cannot build ComposerEntity, some of required attributes are not set " + attributes;
}
}
}