io.resys.hdes.client.api.programs.ImmutableServiceProgram 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.AstService;
import io.resys.hdes.client.api.ast.TypeDef;
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 ServiceProgram}.
*
* Use the builder to create immutable instances:
* {@code ImmutableServiceProgram.builder()}.
*/
@Generated(from = "ServiceProgram", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableServiceProgram implements ServiceProgram {
private final AstService.AstServiceType executorType;
private final AstService.ServiceExecutorType bean;
private final @Nullable TypeDef typeDef0;
private final @Nullable TypeDef typeDef1;
private ImmutableServiceProgram(
AstService.AstServiceType executorType,
AstService.ServiceExecutorType bean,
@Nullable TypeDef typeDef0,
@Nullable TypeDef typeDef1) {
this.executorType = executorType;
this.bean = bean;
this.typeDef0 = typeDef0;
this.typeDef1 = typeDef1;
}
/**
* @return The value of the {@code executorType} attribute
*/
@Override
public AstService.AstServiceType getExecutorType() {
return executorType;
}
/**
* @return The value of the {@code bean} attribute
*/
@Override
public AstService.ServiceExecutorType getBean() {
return bean;
}
/**
* @return The value of the {@code typeDef0} attribute
*/
@Override
public @Nullable TypeDef getTypeDef0() {
return typeDef0;
}
/**
* @return The value of the {@code typeDef1} attribute
*/
@Override
public @Nullable TypeDef getTypeDef1() {
return typeDef1;
}
/**
* Copy the current immutable object by setting a value for the {@link ServiceProgram#getExecutorType() executorType} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for executorType
* @return A modified copy of the {@code this} object
*/
public final ImmutableServiceProgram withExecutorType(AstService.AstServiceType value) {
if (this.executorType == value) return this;
AstService.AstServiceType newValue = Objects.requireNonNull(value, "executorType");
if (this.executorType.equals(newValue)) return this;
return new ImmutableServiceProgram(newValue, this.bean, this.typeDef0, this.typeDef1);
}
/**
* Copy the current immutable object by setting a value for the {@link ServiceProgram#getBean() bean} 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 bean
* @return A modified copy of the {@code this} object
*/
public final ImmutableServiceProgram withBean(AstService.ServiceExecutorType value) {
if (this.bean == value) return this;
AstService.ServiceExecutorType newValue = Objects.requireNonNull(value, "bean");
return new ImmutableServiceProgram(this.executorType, newValue, this.typeDef0, this.typeDef1);
}
/**
* Copy the current immutable object by setting a value for the {@link ServiceProgram#getTypeDef0() typeDef0} 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 typeDef0 (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableServiceProgram withTypeDef0(@Nullable TypeDef value) {
if (this.typeDef0 == value) return this;
return new ImmutableServiceProgram(this.executorType, this.bean, value, this.typeDef1);
}
/**
* Copy the current immutable object by setting a value for the {@link ServiceProgram#getTypeDef1() typeDef1} 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 typeDef1 (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableServiceProgram withTypeDef1(@Nullable TypeDef value) {
if (this.typeDef1 == value) return this;
return new ImmutableServiceProgram(this.executorType, this.bean, this.typeDef0, value);
}
/**
* This instance is equal to all instances of {@code ImmutableServiceProgram} 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 ImmutableServiceProgram
&& equalTo((ImmutableServiceProgram) another);
}
private boolean equalTo(ImmutableServiceProgram another) {
return executorType.equals(another.executorType)
&& bean.equals(another.bean)
&& Objects.equals(typeDef0, another.typeDef0)
&& Objects.equals(typeDef1, another.typeDef1);
}
/**
* Computes a hash code from attributes: {@code executorType}, {@code bean}, {@code typeDef0}, {@code typeDef1}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + executorType.hashCode();
h += (h << 5) + bean.hashCode();
h += (h << 5) + Objects.hashCode(typeDef0);
h += (h << 5) + Objects.hashCode(typeDef1);
return h;
}
/**
* Prints the immutable value {@code ServiceProgram} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ServiceProgram")
.omitNullValues()
.add("executorType", executorType)
.add("bean", bean)
.add("typeDef0", typeDef0)
.add("typeDef1", typeDef1)
.toString();
}
/**
* Creates an immutable copy of a {@link ServiceProgram} 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 ServiceProgram instance
*/
public static ImmutableServiceProgram copyOf(ServiceProgram instance) {
if (instance instanceof ImmutableServiceProgram) {
return (ImmutableServiceProgram) instance;
}
return ImmutableServiceProgram.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableServiceProgram ImmutableServiceProgram}.
*
* ImmutableServiceProgram.builder()
* .executorType(io.resys.hdes.client.api.ast.AstService.AstServiceType) // required {@link ServiceProgram#getExecutorType() executorType}
* .bean(io.resys.hdes.client.api.ast.AstService.ServiceExecutorType) // required {@link ServiceProgram#getBean() bean}
* .typeDef0(io.resys.hdes.client.api.ast.TypeDef | null) // nullable {@link ServiceProgram#getTypeDef0() typeDef0}
* .typeDef1(io.resys.hdes.client.api.ast.TypeDef | null) // nullable {@link ServiceProgram#getTypeDef1() typeDef1}
* .build();
*
* @return A new ImmutableServiceProgram builder
*/
public static ImmutableServiceProgram.Builder builder() {
return new ImmutableServiceProgram.Builder();
}
/**
* Builds instances of type {@link ImmutableServiceProgram ImmutableServiceProgram}.
* 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 = "ServiceProgram", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_EXECUTOR_TYPE = 0x1L;
private static final long INIT_BIT_BEAN = 0x2L;
private long initBits = 0x3L;
private @Nullable AstService.AstServiceType executorType;
private @Nullable AstService.ServiceExecutorType bean;
private @Nullable TypeDef typeDef0;
private @Nullable TypeDef typeDef1;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ServiceProgram} 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(ServiceProgram instance) {
Objects.requireNonNull(instance, "instance");
executorType(instance.getExecutorType());
bean(instance.getBean());
@Nullable TypeDef typeDef0Value = instance.getTypeDef0();
if (typeDef0Value != null) {
typeDef0(typeDef0Value);
}
@Nullable TypeDef typeDef1Value = instance.getTypeDef1();
if (typeDef1Value != null) {
typeDef1(typeDef1Value);
}
return this;
}
/**
* Initializes the value for the {@link ServiceProgram#getExecutorType() executorType} attribute.
* @param executorType The value for executorType
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder executorType(AstService.AstServiceType executorType) {
this.executorType = Objects.requireNonNull(executorType, "executorType");
initBits &= ~INIT_BIT_EXECUTOR_TYPE;
return this;
}
/**
* Initializes the value for the {@link ServiceProgram#getBean() bean} attribute.
* @param bean The value for bean
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder bean(AstService.ServiceExecutorType bean) {
this.bean = Objects.requireNonNull(bean, "bean");
initBits &= ~INIT_BIT_BEAN;
return this;
}
/**
* Initializes the value for the {@link ServiceProgram#getTypeDef0() typeDef0} attribute.
* @param typeDef0 The value for typeDef0 (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder typeDef0(@Nullable TypeDef typeDef0) {
this.typeDef0 = typeDef0;
return this;
}
/**
* Initializes the value for the {@link ServiceProgram#getTypeDef1() typeDef1} attribute.
* @param typeDef1 The value for typeDef1 (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder typeDef1(@Nullable TypeDef typeDef1) {
this.typeDef1 = typeDef1;
return this;
}
/**
* Builds a new {@link ImmutableServiceProgram ImmutableServiceProgram}.
* @return An immutable instance of ServiceProgram
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableServiceProgram build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableServiceProgram(executorType, bean, typeDef0, typeDef1);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_EXECUTOR_TYPE) != 0) attributes.add("executorType");
if ((initBits & INIT_BIT_BEAN) != 0) attributes.add("bean");
return "Cannot build ServiceProgram, some of required attributes are not set " + attributes;
}
}
}