io.resys.hdes.client.api.ImmutableDetachedEntity Maven / Gradle / Ivy
package io.resys.hdes.client.api;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import io.resys.hdes.client.api.ast.AstCommand;
import java.time.LocalDateTime;
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 HdesStore.DetachedEntity}.
*
* Use the builder to create immutable instances:
* {@code ImmutableDetachedEntity.builder()}.
*/
@Generated(from = "HdesStore.DetachedEntity", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableDetachedEntity implements HdesStore.DetachedEntity {
private final String hash;
private final LocalDateTime created;
private final ImmutableList body;
private ImmutableDetachedEntity(
String hash,
LocalDateTime created,
ImmutableList body) {
this.hash = hash;
this.created = created;
this.body = body;
}
/**
* @return The value of the {@code hash} attribute
*/
@JsonProperty("hash")
@Override
public String getHash() {
return hash;
}
/**
* @return The value of the {@code created} attribute
*/
@JsonProperty("created")
@Override
public LocalDateTime getCreated() {
return created;
}
/**
* @return The value of the {@code body} attribute
*/
@JsonProperty("body")
@Override
public ImmutableList getBody() {
return body;
}
/**
* Copy the current immutable object by setting a value for the {@link HdesStore.DetachedEntity#getHash() hash} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for hash
* @return A modified copy of the {@code this} object
*/
public final ImmutableDetachedEntity withHash(String value) {
String newValue = Objects.requireNonNull(value, "hash");
if (this.hash.equals(newValue)) return this;
return new ImmutableDetachedEntity(newValue, this.created, this.body);
}
/**
* Copy the current immutable object by setting a value for the {@link HdesStore.DetachedEntity#getCreated() created} 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 created
* @return A modified copy of the {@code this} object
*/
public final ImmutableDetachedEntity withCreated(LocalDateTime value) {
if (this.created == value) return this;
LocalDateTime newValue = Objects.requireNonNull(value, "created");
return new ImmutableDetachedEntity(this.hash, newValue, this.body);
}
/**
* Copy the current immutable object with elements that replace the content of {@link HdesStore.DetachedEntity#getBody() body}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableDetachedEntity withBody(AstCommand... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableDetachedEntity(this.hash, this.created, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link HdesStore.DetachedEntity#getBody() body}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of body elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableDetachedEntity withBody(Iterable extends AstCommand> elements) {
if (this.body == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableDetachedEntity(this.hash, this.created, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableDetachedEntity} 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 ImmutableDetachedEntity
&& equalTo((ImmutableDetachedEntity) another);
}
private boolean equalTo(ImmutableDetachedEntity another) {
return hash.equals(another.hash)
&& created.equals(another.created)
&& body.equals(another.body);
}
/**
* Computes a hash code from attributes: {@code hash}, {@code created}, {@code body}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + hash.hashCode();
h += (h << 5) + created.hashCode();
h += (h << 5) + body.hashCode();
return h;
}
/**
* Prints the immutable value {@code DetachedEntity} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("DetachedEntity")
.omitNullValues()
.add("hash", hash)
.add("created", created)
.add("body", body)
.toString();
}
/**
* Utility type used to correctly read immutable object from JSON representation.
* @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure
*/
@Generated(from = "HdesStore.DetachedEntity", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements HdesStore.DetachedEntity {
@Nullable String hash;
@Nullable LocalDateTime created;
@Nullable List body = ImmutableList.of();
@JsonProperty("hash")
public void setHash(String hash) {
this.hash = hash;
}
@JsonProperty("created")
public void setCreated(LocalDateTime created) {
this.created = created;
}
@JsonProperty("body")
public void setBody(List body) {
this.body = body;
}
@Override
public String getHash() { throw new UnsupportedOperationException(); }
@Override
public LocalDateTime getCreated() { throw new UnsupportedOperationException(); }
@Override
public List getBody() { throw new UnsupportedOperationException(); }
}
/**
* @param json A JSON-bindable data structure
* @return An immutable value type
* @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure
*/
@Deprecated
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
static ImmutableDetachedEntity fromJson(Json json) {
ImmutableDetachedEntity.Builder builder = ImmutableDetachedEntity.builder();
if (json.hash != null) {
builder.hash(json.hash);
}
if (json.created != null) {
builder.created(json.created);
}
if (json.body != null) {
builder.addAllBody(json.body);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link HdesStore.DetachedEntity} 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 DetachedEntity instance
*/
public static ImmutableDetachedEntity copyOf(HdesStore.DetachedEntity instance) {
if (instance instanceof ImmutableDetachedEntity) {
return (ImmutableDetachedEntity) instance;
}
return ImmutableDetachedEntity.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableDetachedEntity ImmutableDetachedEntity}.
*
* ImmutableDetachedEntity.builder()
* .hash(String) // required {@link HdesStore.DetachedEntity#getHash() hash}
* .created(java.time.LocalDateTime) // required {@link HdesStore.DetachedEntity#getCreated() created}
* .addBody|addAllBody(io.resys.hdes.client.api.ast.AstCommand) // {@link HdesStore.DetachedEntity#getBody() body} elements
* .build();
*
* @return A new ImmutableDetachedEntity builder
*/
public static ImmutableDetachedEntity.Builder builder() {
return new ImmutableDetachedEntity.Builder();
}
/**
* Builds instances of type {@link ImmutableDetachedEntity ImmutableDetachedEntity}.
* 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 = "HdesStore.DetachedEntity", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_HASH = 0x1L;
private static final long INIT_BIT_CREATED = 0x2L;
private long initBits = 0x3L;
private @Nullable String hash;
private @Nullable LocalDateTime created;
private ImmutableList.Builder body = ImmutableList.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code DetachedEntity} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(HdesStore.DetachedEntity instance) {
Objects.requireNonNull(instance, "instance");
hash(instance.getHash());
created(instance.getCreated());
addAllBody(instance.getBody());
return this;
}
/**
* Initializes the value for the {@link HdesStore.DetachedEntity#getHash() hash} attribute.
* @param hash The value for hash
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("hash")
public final Builder hash(String hash) {
this.hash = Objects.requireNonNull(hash, "hash");
initBits &= ~INIT_BIT_HASH;
return this;
}
/**
* Initializes the value for the {@link HdesStore.DetachedEntity#getCreated() created} attribute.
* @param created The value for created
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("created")
public final Builder created(LocalDateTime created) {
this.created = Objects.requireNonNull(created, "created");
initBits &= ~INIT_BIT_CREATED;
return this;
}
/**
* Adds one element to {@link HdesStore.DetachedEntity#getBody() body} list.
* @param element A body element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addBody(AstCommand element) {
this.body.add(element);
return this;
}
/**
* Adds elements to {@link HdesStore.DetachedEntity#getBody() body} list.
* @param elements An array of body elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addBody(AstCommand... elements) {
this.body.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link HdesStore.DetachedEntity#getBody() body} list.
* @param elements An iterable of body elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("body")
public final Builder body(Iterable extends AstCommand> elements) {
this.body = ImmutableList.builder();
return addAllBody(elements);
}
/**
* Adds elements to {@link HdesStore.DetachedEntity#getBody() body} list.
* @param elements An iterable of body elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllBody(Iterable extends AstCommand> elements) {
this.body.addAll(elements);
return this;
}
/**
* Builds a new {@link ImmutableDetachedEntity ImmutableDetachedEntity}.
* @return An immutable instance of DetachedEntity
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableDetachedEntity build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableDetachedEntity(hash, created, body.build());
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_HASH) != 0) attributes.add("hash");
if ((initBits & INIT_BIT_CREATED) != 0) attributes.add("created");
return "Cannot build DetachedEntity, some of required attributes are not set " + attributes;
}
}
}