org.cloudfoundry.client.lib.adapters.ImmutableRawInstancesInfo Maven / Gradle / Ivy
Show all versions of cloudfoundry-client-lib Show documentation
package org.cloudfoundry.client.lib.adapters;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.cloudfoundry.client.v2.applications.ApplicationInstancesResponse;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link RawInstancesInfo}.
*
* Use the builder to create immutable instances:
* {@code ImmutableRawInstancesInfo.builder()}.
* Use the static factory method to create immutable instances:
* {@code ImmutableRawInstancesInfo.of()}.
*/
@Generated(from = "RawInstancesInfo", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutableRawInstancesInfo extends RawInstancesInfo {
private final ApplicationInstancesResponse instancesResponse;
private ImmutableRawInstancesInfo(ApplicationInstancesResponse instancesResponse) {
this.instancesResponse = Objects.requireNonNull(instancesResponse, "instancesResponse");
}
private ImmutableRawInstancesInfo(
ImmutableRawInstancesInfo original,
ApplicationInstancesResponse instancesResponse) {
this.instancesResponse = instancesResponse;
}
/**
* @return The value of the {@code instancesResponse} attribute
*/
@Override
public ApplicationInstancesResponse getInstancesResponse() {
return instancesResponse;
}
/**
* Copy the current immutable object by setting a value for the {@link RawInstancesInfo#getInstancesResponse() instancesResponse} 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 instancesResponse
* @return A modified copy of the {@code this} object
*/
public final ImmutableRawInstancesInfo withInstancesResponse(ApplicationInstancesResponse value) {
if (this.instancesResponse == value) return this;
ApplicationInstancesResponse newValue = Objects.requireNonNull(value, "instancesResponse");
return new ImmutableRawInstancesInfo(this, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableRawInstancesInfo} 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 ImmutableRawInstancesInfo
&& equalTo((ImmutableRawInstancesInfo) another);
}
private boolean equalTo(ImmutableRawInstancesInfo another) {
return instancesResponse.equals(another.instancesResponse);
}
/**
* Computes a hash code from attributes: {@code instancesResponse}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + instancesResponse.hashCode();
return h;
}
/**
* Prints the immutable value {@code RawInstancesInfo} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "RawInstancesInfo{"
+ "instancesResponse=" + instancesResponse
+ "}";
}
/**
* Construct a new immutable {@code RawInstancesInfo} instance.
* @param instancesResponse The value for the {@code instancesResponse} attribute
* @return An immutable RawInstancesInfo instance
*/
public static ImmutableRawInstancesInfo of(ApplicationInstancesResponse instancesResponse) {
return new ImmutableRawInstancesInfo(instancesResponse);
}
/**
* Creates an immutable copy of a {@link RawInstancesInfo} 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 RawInstancesInfo instance
*/
public static ImmutableRawInstancesInfo copyOf(RawInstancesInfo instance) {
if (instance instanceof ImmutableRawInstancesInfo) {
return (ImmutableRawInstancesInfo) instance;
}
return ImmutableRawInstancesInfo.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableRawInstancesInfo ImmutableRawInstancesInfo}.
*
* ImmutableRawInstancesInfo.builder()
* .instancesResponse(org.cloudfoundry.client.v2.applications.ApplicationInstancesResponse) // required {@link RawInstancesInfo#getInstancesResponse() instancesResponse}
* .build();
*
* @return A new ImmutableRawInstancesInfo builder
*/
public static ImmutableRawInstancesInfo.Builder builder() {
return new ImmutableRawInstancesInfo.Builder();
}
/**
* Builds instances of type {@link ImmutableRawInstancesInfo ImmutableRawInstancesInfo}.
* 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 = "RawInstancesInfo", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_INSTANCES_RESPONSE = 0x1L;
private long initBits = 0x1L;
private ApplicationInstancesResponse instancesResponse;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code RawInstancesInfo} 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 Builder from(RawInstancesInfo instance) {
Objects.requireNonNull(instance, "instance");
instancesResponse(instance.getInstancesResponse());
return this;
}
/**
* Initializes the value for the {@link RawInstancesInfo#getInstancesResponse() instancesResponse} attribute.
* @param instancesResponse The value for instancesResponse
* @return {@code this} builder for use in a chained invocation
*/
public final Builder instancesResponse(ApplicationInstancesResponse instancesResponse) {
this.instancesResponse = Objects.requireNonNull(instancesResponse, "instancesResponse");
initBits &= ~INIT_BIT_INSTANCES_RESPONSE;
return this;
}
/**
* Builds a new {@link ImmutableRawInstancesInfo ImmutableRawInstancesInfo}.
* @return An immutable instance of RawInstancesInfo
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableRawInstancesInfo build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableRawInstancesInfo(null, instancesResponse);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_INSTANCES_RESPONSE) != 0) attributes.add("instancesResponse");
return "Cannot build RawInstancesInfo, some of required attributes are not set " + attributes;
}
}
}