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