io.resys.hdes.client.api.programs.ImmutableProgramAssociation Maven / Gradle / Ivy
package io.resys.hdes.client.api.programs;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import io.resys.hdes.client.api.ast.AstBody;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
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 ProgramEnvir.ProgramAssociation}.
*
* Use the builder to create immutable instances:
* {@code ImmutableProgramAssociation.builder()}.
*/
@Generated(from = "ProgramEnvir.ProgramAssociation", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableProgramAssociation
implements ProgramEnvir.ProgramAssociation {
private final @Nullable String id;
private final String ref;
private final AstBody.AstBodyType refType;
private final ProgramEnvir.ProgramStatus refStatus;
private final Boolean owner;
private ImmutableProgramAssociation(
@Nullable String id,
String ref,
AstBody.AstBodyType refType,
ProgramEnvir.ProgramStatus refStatus,
Boolean owner) {
this.id = id;
this.ref = ref;
this.refType = refType;
this.refStatus = refStatus;
this.owner = owner;
}
/**
* @return The value of the {@code id} attribute
*/
@Override
public Optional getId() {
return Optional.ofNullable(id);
}
/**
* @return The value of the {@code ref} attribute
*/
@Override
public String getRef() {
return ref;
}
/**
* @return The value of the {@code refType} attribute
*/
@Override
public AstBody.AstBodyType getRefType() {
return refType;
}
/**
* @return The value of the {@code refStatus} attribute
*/
@Override
public ProgramEnvir.ProgramStatus getRefStatus() {
return refStatus;
}
/**
* @return The value of the {@code owner} attribute
*/
@Override
public Boolean getOwner() {
return owner;
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ProgramEnvir.ProgramAssociation#getId() id} attribute.
* @param value The value for id
* @return A modified copy of {@code this} object
*/
public final ImmutableProgramAssociation withId(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "id");
if (Objects.equals(this.id, newValue)) return this;
return new ImmutableProgramAssociation(newValue, this.ref, this.refType, this.refStatus, this.owner);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ProgramEnvir.ProgramAssociation#getId() id} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for id
* @return A modified copy of {@code this} object
*/
public final ImmutableProgramAssociation withId(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.id, value)) return this;
return new ImmutableProgramAssociation(value, this.ref, this.refType, this.refStatus, this.owner);
}
/**
* Copy the current immutable object by setting a value for the {@link ProgramEnvir.ProgramAssociation#getRef() ref} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for ref
* @return A modified copy of the {@code this} object
*/
public final ImmutableProgramAssociation withRef(String value) {
String newValue = Objects.requireNonNull(value, "ref");
if (this.ref.equals(newValue)) return this;
return new ImmutableProgramAssociation(this.id, newValue, this.refType, this.refStatus, this.owner);
}
/**
* Copy the current immutable object by setting a value for the {@link ProgramEnvir.ProgramAssociation#getRefType() refType} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for refType
* @return A modified copy of the {@code this} object
*/
public final ImmutableProgramAssociation withRefType(AstBody.AstBodyType value) {
if (this.refType == value) return this;
AstBody.AstBodyType newValue = Objects.requireNonNull(value, "refType");
if (this.refType.equals(newValue)) return this;
return new ImmutableProgramAssociation(this.id, this.ref, newValue, this.refStatus, this.owner);
}
/**
* Copy the current immutable object by setting a value for the {@link ProgramEnvir.ProgramAssociation#getRefStatus() refStatus} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for refStatus
* @return A modified copy of the {@code this} object
*/
public final ImmutableProgramAssociation withRefStatus(ProgramEnvir.ProgramStatus value) {
if (this.refStatus == value) return this;
ProgramEnvir.ProgramStatus newValue = Objects.requireNonNull(value, "refStatus");
if (this.refStatus.equals(newValue)) return this;
return new ImmutableProgramAssociation(this.id, this.ref, this.refType, newValue, this.owner);
}
/**
* Copy the current immutable object by setting a value for the {@link ProgramEnvir.ProgramAssociation#getOwner() owner} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for owner
* @return A modified copy of the {@code this} object
*/
public final ImmutableProgramAssociation withOwner(Boolean value) {
Boolean newValue = Objects.requireNonNull(value, "owner");
if (this.owner.equals(newValue)) return this;
return new ImmutableProgramAssociation(this.id, this.ref, this.refType, this.refStatus, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableProgramAssociation} 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 ImmutableProgramAssociation
&& equalTo((ImmutableProgramAssociation) another);
}
private boolean equalTo(ImmutableProgramAssociation another) {
return Objects.equals(id, another.id)
&& ref.equals(another.ref)
&& refType.equals(another.refType)
&& refStatus.equals(another.refStatus)
&& owner.equals(another.owner);
}
/**
* Computes a hash code from attributes: {@code id}, {@code ref}, {@code refType}, {@code refStatus}, {@code owner}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(id);
h += (h << 5) + ref.hashCode();
h += (h << 5) + refType.hashCode();
h += (h << 5) + refStatus.hashCode();
h += (h << 5) + owner.hashCode();
return h;
}
/**
* Prints the immutable value {@code ProgramAssociation} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ProgramAssociation")
.omitNullValues()
.add("id", id)
.add("ref", ref)
.add("refType", refType)
.add("refStatus", refStatus)
.add("owner", owner)
.toString();
}
/**
* Creates an immutable copy of a {@link ProgramEnvir.ProgramAssociation} 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 ProgramAssociation instance
*/
public static ImmutableProgramAssociation copyOf(ProgramEnvir.ProgramAssociation instance) {
if (instance instanceof ImmutableProgramAssociation) {
return (ImmutableProgramAssociation) instance;
}
return ImmutableProgramAssociation.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableProgramAssociation ImmutableProgramAssociation}.
*
* ImmutableProgramAssociation.builder()
* .id(String) // optional {@link ProgramEnvir.ProgramAssociation#getId() id}
* .ref(String) // required {@link ProgramEnvir.ProgramAssociation#getRef() ref}
* .refType(io.resys.hdes.client.api.ast.AstBody.AstBodyType) // required {@link ProgramEnvir.ProgramAssociation#getRefType() refType}
* .refStatus(io.resys.hdes.client.api.programs.ProgramEnvir.ProgramStatus) // required {@link ProgramEnvir.ProgramAssociation#getRefStatus() refStatus}
* .owner(Boolean) // required {@link ProgramEnvir.ProgramAssociation#getOwner() owner}
* .build();
*
* @return A new ImmutableProgramAssociation builder
*/
public static ImmutableProgramAssociation.Builder builder() {
return new ImmutableProgramAssociation.Builder();
}
/**
* Builds instances of type {@link ImmutableProgramAssociation ImmutableProgramAssociation}.
* 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 = "ProgramEnvir.ProgramAssociation", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_REF = 0x1L;
private static final long INIT_BIT_REF_TYPE = 0x2L;
private static final long INIT_BIT_REF_STATUS = 0x4L;
private static final long INIT_BIT_OWNER = 0x8L;
private long initBits = 0xfL;
private @Nullable String id;
private @Nullable String ref;
private @Nullable AstBody.AstBodyType refType;
private @Nullable ProgramEnvir.ProgramStatus refStatus;
private @Nullable Boolean owner;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ProgramAssociation} 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
*/
@CanIgnoreReturnValue
public final Builder from(ProgramEnvir.ProgramAssociation instance) {
Objects.requireNonNull(instance, "instance");
Optional idOptional = instance.getId();
if (idOptional.isPresent()) {
id(idOptional);
}
ref(instance.getRef());
refType(instance.getRefType());
refStatus(instance.getRefStatus());
owner(instance.getOwner());
return this;
}
/**
* Initializes the optional value {@link ProgramEnvir.ProgramAssociation#getId() id} to id.
* @param id The value for id
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder id(String id) {
this.id = Objects.requireNonNull(id, "id");
return this;
}
/**
* Initializes the optional value {@link ProgramEnvir.ProgramAssociation#getId() id} to id.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder id(Optional id) {
this.id = id.orElse(null);
return this;
}
/**
* Initializes the value for the {@link ProgramEnvir.ProgramAssociation#getRef() ref} attribute.
* @param ref The value for ref
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder ref(String ref) {
this.ref = Objects.requireNonNull(ref, "ref");
initBits &= ~INIT_BIT_REF;
return this;
}
/**
* Initializes the value for the {@link ProgramEnvir.ProgramAssociation#getRefType() refType} attribute.
* @param refType The value for refType
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder refType(AstBody.AstBodyType refType) {
this.refType = Objects.requireNonNull(refType, "refType");
initBits &= ~INIT_BIT_REF_TYPE;
return this;
}
/**
* Initializes the value for the {@link ProgramEnvir.ProgramAssociation#getRefStatus() refStatus} attribute.
* @param refStatus The value for refStatus
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder refStatus(ProgramEnvir.ProgramStatus refStatus) {
this.refStatus = Objects.requireNonNull(refStatus, "refStatus");
initBits &= ~INIT_BIT_REF_STATUS;
return this;
}
/**
* Initializes the value for the {@link ProgramEnvir.ProgramAssociation#getOwner() owner} attribute.
* @param owner The value for owner
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder owner(Boolean owner) {
this.owner = Objects.requireNonNull(owner, "owner");
initBits &= ~INIT_BIT_OWNER;
return this;
}
/**
* Builds a new {@link ImmutableProgramAssociation ImmutableProgramAssociation}.
* @return An immutable instance of ProgramAssociation
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableProgramAssociation build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableProgramAssociation(id, ref, refType, refStatus, owner);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_REF) != 0) attributes.add("ref");
if ((initBits & INIT_BIT_REF_TYPE) != 0) attributes.add("refType");
if ((initBits & INIT_BIT_REF_STATUS) != 0) attributes.add("refStatus");
if ((initBits & INIT_BIT_OWNER) != 0) attributes.add("owner");
return "Cannot build ProgramAssociation, some of required attributes are not set " + attributes;
}
}
}