io.resys.hdes.client.api.programs.ImmutableFlowProgramStep 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 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 FlowProgram.FlowProgramStep}.
*
* Use the builder to create immutable instances:
* {@code ImmutableFlowProgramStep.builder()}.
*/
@Generated(from = "FlowProgram.FlowProgramStep", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableFlowProgramStep
implements FlowProgram.FlowProgramStep {
private final String id;
private final FlowProgram.FlowProgramStepPointer pointer;
private final @Nullable FlowProgram.FlowProgramStepBody body;
private ImmutableFlowProgramStep(
String id,
FlowProgram.FlowProgramStepPointer pointer,
@Nullable FlowProgram.FlowProgramStepBody body) {
this.id = id;
this.pointer = pointer;
this.body = body;
}
/**
* @return The value of the {@code id} attribute
*/
@Override
public String getId() {
return id;
}
/**
* @return The value of the {@code pointer} attribute
*/
@Override
public FlowProgram.FlowProgramStepPointer getPointer() {
return pointer;
}
/**
* @return The value of the {@code body} attribute
*/
@Override
public @Nullable FlowProgram.FlowProgramStepBody getBody() {
return body;
}
/**
* Copy the current immutable object by setting a value for the {@link FlowProgram.FlowProgramStep#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 ImmutableFlowProgramStep withId(String value) {
String newValue = Objects.requireNonNull(value, "id");
if (this.id.equals(newValue)) return this;
return new ImmutableFlowProgramStep(newValue, this.pointer, this.body);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowProgram.FlowProgramStep#getPointer() pointer} 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 pointer
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowProgramStep withPointer(FlowProgram.FlowProgramStepPointer value) {
if (this.pointer == value) return this;
FlowProgram.FlowProgramStepPointer newValue = Objects.requireNonNull(value, "pointer");
return new ImmutableFlowProgramStep(this.id, newValue, this.body);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowProgram.FlowProgramStep#getBody() body} 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 body (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowProgramStep withBody(@Nullable FlowProgram.FlowProgramStepBody value) {
if (this.body == value) return this;
return new ImmutableFlowProgramStep(this.id, this.pointer, value);
}
/**
* This instance is equal to all instances of {@code ImmutableFlowProgramStep} 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 ImmutableFlowProgramStep
&& equalTo((ImmutableFlowProgramStep) another);
}
private boolean equalTo(ImmutableFlowProgramStep another) {
return id.equals(another.id)
&& pointer.equals(another.pointer)
&& Objects.equals(body, another.body);
}
/**
* Computes a hash code from attributes: {@code id}, {@code pointer}, {@code body}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + id.hashCode();
h += (h << 5) + pointer.hashCode();
h += (h << 5) + Objects.hashCode(body);
return h;
}
/**
* Prints the immutable value {@code FlowProgramStep} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("FlowProgramStep")
.omitNullValues()
.add("id", id)
.add("pointer", pointer)
.add("body", body)
.toString();
}
/**
* Creates an immutable copy of a {@link FlowProgram.FlowProgramStep} 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 FlowProgramStep instance
*/
public static ImmutableFlowProgramStep copyOf(FlowProgram.FlowProgramStep instance) {
if (instance instanceof ImmutableFlowProgramStep) {
return (ImmutableFlowProgramStep) instance;
}
return ImmutableFlowProgramStep.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableFlowProgramStep ImmutableFlowProgramStep}.
*
* ImmutableFlowProgramStep.builder()
* .id(String) // required {@link FlowProgram.FlowProgramStep#getId() id}
* .pointer(io.resys.hdes.client.api.programs.FlowProgram.FlowProgramStepPointer) // required {@link FlowProgram.FlowProgramStep#getPointer() pointer}
* .body(io.resys.hdes.client.api.programs.FlowProgram.FlowProgramStepBody | null) // nullable {@link FlowProgram.FlowProgramStep#getBody() body}
* .build();
*
* @return A new ImmutableFlowProgramStep builder
*/
public static ImmutableFlowProgramStep.Builder builder() {
return new ImmutableFlowProgramStep.Builder();
}
/**
* Builds instances of type {@link ImmutableFlowProgramStep ImmutableFlowProgramStep}.
* 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 = "FlowProgram.FlowProgramStep", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_ID = 0x1L;
private static final long INIT_BIT_POINTER = 0x2L;
private long initBits = 0x3L;
private @Nullable String id;
private @Nullable FlowProgram.FlowProgramStepPointer pointer;
private @Nullable FlowProgram.FlowProgramStepBody body;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code FlowProgramStep} 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(FlowProgram.FlowProgramStep instance) {
Objects.requireNonNull(instance, "instance");
id(instance.getId());
pointer(instance.getPointer());
@Nullable FlowProgram.FlowProgramStepBody bodyValue = instance.getBody();
if (bodyValue != null) {
body(bodyValue);
}
return this;
}
/**
* Initializes the value for the {@link FlowProgram.FlowProgramStep#getId() id} attribute.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder id(String id) {
this.id = Objects.requireNonNull(id, "id");
initBits &= ~INIT_BIT_ID;
return this;
}
/**
* Initializes the value for the {@link FlowProgram.FlowProgramStep#getPointer() pointer} attribute.
* @param pointer The value for pointer
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder pointer(FlowProgram.FlowProgramStepPointer pointer) {
this.pointer = Objects.requireNonNull(pointer, "pointer");
initBits &= ~INIT_BIT_POINTER;
return this;
}
/**
* Initializes the value for the {@link FlowProgram.FlowProgramStep#getBody() body} attribute.
* @param body The value for body (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder body(@Nullable FlowProgram.FlowProgramStepBody body) {
this.body = body;
return this;
}
/**
* Builds a new {@link ImmutableFlowProgramStep ImmutableFlowProgramStep}.
* @return An immutable instance of FlowProgramStep
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableFlowProgramStep build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableFlowProgramStep(id, pointer, body);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_ID) != 0) attributes.add("id");
if ((initBits & INIT_BIT_POINTER) != 0) attributes.add("pointer");
return "Cannot build FlowProgramStep, some of required attributes are not set " + attributes;
}
}
}