io.resys.hdes.client.api.ast.ImmutableAstBranch Maven / Gradle / Ivy
package io.resys.hdes.client.api.ast;
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 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 AstBranch}.
*
* Use the builder to create immutable instances:
* {@code ImmutableAstBranch.builder()}.
*/
@Generated(from = "AstBranch", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableAstBranch implements AstBranch {
private final @Nullable String description;
private final AstBody.Headers headers;
private final AstBody.AstBodyType bodyType;
private final ImmutableList messages;
private final String name;
private final LocalDateTime created;
private final String tagId;
private ImmutableAstBranch(
@Nullable String description,
AstBody.Headers headers,
AstBody.AstBodyType bodyType,
ImmutableList messages,
String name,
LocalDateTime created,
String tagId) {
this.description = description;
this.headers = headers;
this.bodyType = bodyType;
this.messages = messages;
this.name = name;
this.created = created;
this.tagId = tagId;
}
/**
* @return The value of the {@code description} attribute
*/
@JsonProperty("description")
@Override
public @Nullable String getDescription() {
return description;
}
/**
* @return The value of the {@code headers} attribute
*/
@JsonProperty("headers")
@Override
public AstBody.Headers getHeaders() {
return headers;
}
/**
* @return The value of the {@code bodyType} attribute
*/
@JsonProperty("bodyType")
@Override
public AstBody.AstBodyType getBodyType() {
return bodyType;
}
/**
* @return The value of the {@code messages} attribute
*/
@JsonProperty("messages")
@Override
public ImmutableList getMessages() {
return messages;
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code created} attribute
*/
@JsonProperty("created")
@Override
public LocalDateTime getCreated() {
return created;
}
/**
* @return The value of the {@code tagId} attribute
*/
@JsonProperty("tagId")
@Override
public String getTagId() {
return tagId;
}
/**
* Copy the current immutable object by setting a value for the {@link AstBranch#getDescription() description} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for description (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableAstBranch withDescription(@Nullable String value) {
if (Objects.equals(this.description, value)) return this;
return new ImmutableAstBranch(value, this.headers, this.bodyType, this.messages, this.name, this.created, this.tagId);
}
/**
* Copy the current immutable object by setting a value for the {@link AstBranch#getHeaders() headers} 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 headers
* @return A modified copy of the {@code this} object
*/
public final ImmutableAstBranch withHeaders(AstBody.Headers value) {
if (this.headers == value) return this;
AstBody.Headers newValue = Objects.requireNonNull(value, "headers");
return new ImmutableAstBranch(this.description, newValue, this.bodyType, this.messages, this.name, this.created, this.tagId);
}
/**
* Copy the current immutable object by setting a value for the {@link AstBranch#getBodyType() bodyType} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for bodyType
* @return A modified copy of the {@code this} object
*/
public final ImmutableAstBranch withBodyType(AstBody.AstBodyType value) {
if (this.bodyType == value) return this;
AstBody.AstBodyType newValue = Objects.requireNonNull(value, "bodyType");
if (this.bodyType.equals(newValue)) return this;
return new ImmutableAstBranch(this.description, this.headers, newValue, this.messages, this.name, this.created, this.tagId);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AstBranch#getMessages() messages}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableAstBranch withMessages(AstBody.AstCommandMessage... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAstBranch(this.description, this.headers, this.bodyType, newValue, this.name, this.created, this.tagId);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AstBranch#getMessages() messages}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of messages elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableAstBranch withMessages(Iterable extends AstBody.AstCommandMessage> elements) {
if (this.messages == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAstBranch(this.description, this.headers, this.bodyType, newValue, this.name, this.created, this.tagId);
}
/**
* Copy the current immutable object by setting a value for the {@link AstBranch#getName() name} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for name
* @return A modified copy of the {@code this} object
*/
public final ImmutableAstBranch withName(String value) {
String newValue = Objects.requireNonNull(value, "name");
if (this.name.equals(newValue)) return this;
return new ImmutableAstBranch(
this.description,
this.headers,
this.bodyType,
this.messages,
newValue,
this.created,
this.tagId);
}
/**
* Copy the current immutable object by setting a value for the {@link AstBranch#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 ImmutableAstBranch withCreated(LocalDateTime value) {
if (this.created == value) return this;
LocalDateTime newValue = Objects.requireNonNull(value, "created");
return new ImmutableAstBranch(this.description, this.headers, this.bodyType, this.messages, this.name, newValue, this.tagId);
}
/**
* Copy the current immutable object by setting a value for the {@link AstBranch#getTagId() tagId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for tagId
* @return A modified copy of the {@code this} object
*/
public final ImmutableAstBranch withTagId(String value) {
String newValue = Objects.requireNonNull(value, "tagId");
if (this.tagId.equals(newValue)) return this;
return new ImmutableAstBranch(this.description, this.headers, this.bodyType, this.messages, this.name, this.created, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableAstBranch} 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 ImmutableAstBranch
&& equalTo((ImmutableAstBranch) another);
}
private boolean equalTo(ImmutableAstBranch another) {
return Objects.equals(description, another.description)
&& headers.equals(another.headers)
&& bodyType.equals(another.bodyType)
&& messages.equals(another.messages)
&& name.equals(another.name)
&& created.equals(another.created)
&& tagId.equals(another.tagId);
}
/**
* Computes a hash code from attributes: {@code description}, {@code headers}, {@code bodyType}, {@code messages}, {@code name}, {@code created}, {@code tagId}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(description);
h += (h << 5) + headers.hashCode();
h += (h << 5) + bodyType.hashCode();
h += (h << 5) + messages.hashCode();
h += (h << 5) + name.hashCode();
h += (h << 5) + created.hashCode();
h += (h << 5) + tagId.hashCode();
return h;
}
/**
* Prints the immutable value {@code AstBranch} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("AstBranch")
.omitNullValues()
.add("description", description)
.add("headers", headers)
.add("bodyType", bodyType)
.add("messages", messages)
.add("name", name)
.add("created", created)
.add("tagId", tagId)
.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 = "AstBranch", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements AstBranch {
@Nullable String description;
@Nullable AstBody.Headers headers;
@Nullable AstBody.AstBodyType bodyType;
@Nullable List messages = ImmutableList.of();
@Nullable String name;
@Nullable LocalDateTime created;
@Nullable String tagId;
@JsonProperty("description")
public void setDescription(@Nullable String description) {
this.description = description;
}
@JsonProperty("headers")
public void setHeaders(AstBody.Headers headers) {
this.headers = headers;
}
@JsonProperty("bodyType")
public void setBodyType(AstBody.AstBodyType bodyType) {
this.bodyType = bodyType;
}
@JsonProperty("messages")
public void setMessages(List messages) {
this.messages = messages;
}
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("created")
public void setCreated(LocalDateTime created) {
this.created = created;
}
@JsonProperty("tagId")
public void setTagId(String tagId) {
this.tagId = tagId;
}
@Override
public String getDescription() { throw new UnsupportedOperationException(); }
@Override
public AstBody.Headers getHeaders() { throw new UnsupportedOperationException(); }
@Override
public AstBody.AstBodyType getBodyType() { throw new UnsupportedOperationException(); }
@Override
public List getMessages() { throw new UnsupportedOperationException(); }
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public LocalDateTime getCreated() { throw new UnsupportedOperationException(); }
@Override
public String getTagId() { 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 ImmutableAstBranch fromJson(Json json) {
ImmutableAstBranch.Builder builder = ImmutableAstBranch.builder();
if (json.description != null) {
builder.description(json.description);
}
if (json.headers != null) {
builder.headers(json.headers);
}
if (json.bodyType != null) {
builder.bodyType(json.bodyType);
}
if (json.messages != null) {
builder.addAllMessages(json.messages);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.created != null) {
builder.created(json.created);
}
if (json.tagId != null) {
builder.tagId(json.tagId);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link AstBranch} 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 AstBranch instance
*/
public static ImmutableAstBranch copyOf(AstBranch instance) {
if (instance instanceof ImmutableAstBranch) {
return (ImmutableAstBranch) instance;
}
return ImmutableAstBranch.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableAstBranch ImmutableAstBranch}.
*
* ImmutableAstBranch.builder()
* .description(String | null) // nullable {@link AstBranch#getDescription() description}
* .headers(io.resys.hdes.client.api.ast.AstBody.Headers) // required {@link AstBranch#getHeaders() headers}
* .bodyType(io.resys.hdes.client.api.ast.AstBody.AstBodyType) // required {@link AstBranch#getBodyType() bodyType}
* .addMessages|addAllMessages(io.resys.hdes.client.api.ast.AstBody.AstCommandMessage) // {@link AstBranch#getMessages() messages} elements
* .name(String) // required {@link AstBranch#getName() name}
* .created(java.time.LocalDateTime) // required {@link AstBranch#getCreated() created}
* .tagId(String) // required {@link AstBranch#getTagId() tagId}
* .build();
*
* @return A new ImmutableAstBranch builder
*/
public static ImmutableAstBranch.Builder builder() {
return new ImmutableAstBranch.Builder();
}
/**
* Builds instances of type {@link ImmutableAstBranch ImmutableAstBranch}.
* 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 = "AstBranch", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_HEADERS = 0x1L;
private static final long INIT_BIT_BODY_TYPE = 0x2L;
private static final long INIT_BIT_NAME = 0x4L;
private static final long INIT_BIT_CREATED = 0x8L;
private static final long INIT_BIT_TAG_ID = 0x10L;
private long initBits = 0x1fL;
private @Nullable String description;
private @Nullable AstBody.Headers headers;
private @Nullable AstBody.AstBodyType bodyType;
private ImmutableList.Builder messages = ImmutableList.builder();
private @Nullable String name;
private @Nullable LocalDateTime created;
private @Nullable String tagId;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code io.resys.hdes.client.api.ast.AstBranch} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(AstBranch instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code io.resys.hdes.client.api.ast.AstBody} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(AstBody instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
@Var long bits = 0;
if (object instanceof AstBranch) {
AstBranch instance = (AstBranch) object;
if ((bits & 0x1L) == 0) {
name(instance.getName());
bits |= 0x1L;
}
tagId(instance.getTagId());
created(instance.getCreated());
}
if (object instanceof AstBody) {
AstBody instance = (AstBody) object;
bodyType(instance.getBodyType());
if ((bits & 0x1L) == 0) {
name(instance.getName());
bits |= 0x1L;
}
headers(instance.getHeaders());
@Nullable String descriptionValue = instance.getDescription();
if (descriptionValue != null) {
description(descriptionValue);
}
addAllMessages(instance.getMessages());
}
}
/**
* Initializes the value for the {@link AstBranch#getDescription() description} attribute.
* @param description The value for description (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("description")
public final Builder description(@Nullable String description) {
this.description = description;
return this;
}
/**
* Initializes the value for the {@link AstBranch#getHeaders() headers} attribute.
* @param headers The value for headers
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("headers")
public final Builder headers(AstBody.Headers headers) {
this.headers = Objects.requireNonNull(headers, "headers");
initBits &= ~INIT_BIT_HEADERS;
return this;
}
/**
* Initializes the value for the {@link AstBranch#getBodyType() bodyType} attribute.
* @param bodyType The value for bodyType
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("bodyType")
public final Builder bodyType(AstBody.AstBodyType bodyType) {
this.bodyType = Objects.requireNonNull(bodyType, "bodyType");
initBits &= ~INIT_BIT_BODY_TYPE;
return this;
}
/**
* Adds one element to {@link AstBranch#getMessages() messages} list.
* @param element A messages element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addMessages(AstBody.AstCommandMessage element) {
this.messages.add(element);
return this;
}
/**
* Adds elements to {@link AstBranch#getMessages() messages} list.
* @param elements An array of messages elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addMessages(AstBody.AstCommandMessage... elements) {
this.messages.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link AstBranch#getMessages() messages} list.
* @param elements An iterable of messages elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("messages")
public final Builder messages(Iterable extends AstBody.AstCommandMessage> elements) {
this.messages = ImmutableList.builder();
return addAllMessages(elements);
}
/**
* Adds elements to {@link AstBranch#getMessages() messages} list.
* @param elements An iterable of messages elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllMessages(Iterable extends AstBody.AstCommandMessage> elements) {
this.messages.addAll(elements);
return this;
}
/**
* Initializes the value for the {@link AstBranch#getName() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("name")
public final Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes the value for the {@link AstBranch#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;
}
/**
* Initializes the value for the {@link AstBranch#getTagId() tagId} attribute.
* @param tagId The value for tagId
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("tagId")
public final Builder tagId(String tagId) {
this.tagId = Objects.requireNonNull(tagId, "tagId");
initBits &= ~INIT_BIT_TAG_ID;
return this;
}
/**
* Builds a new {@link ImmutableAstBranch ImmutableAstBranch}.
* @return An immutable instance of AstBranch
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableAstBranch build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableAstBranch(description, headers, bodyType, messages.build(), name, created, tagId);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_HEADERS) != 0) attributes.add("headers");
if ((initBits & INIT_BIT_BODY_TYPE) != 0) attributes.add("bodyType");
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
if ((initBits & INIT_BIT_CREATED) != 0) attributes.add("created");
if ((initBits & INIT_BIT_TAG_ID) != 0) attributes.add("tagId");
return "Cannot build AstBranch, some of required attributes are not set " + attributes;
}
}
}