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