io.resys.hdes.client.api.ast.ImmutableHeaders 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.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 AstBody.Headers}.
*
* Use the builder to create immutable instances:
* {@code ImmutableHeaders.builder()}.
*/
@Generated(from = "AstBody.Headers", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableHeaders implements AstBody.Headers {
private final ImmutableList acceptDefs;
private final ImmutableList returnDefs;
private ImmutableHeaders(
ImmutableList acceptDefs,
ImmutableList returnDefs) {
this.acceptDefs = acceptDefs;
this.returnDefs = returnDefs;
}
/**
* @return The value of the {@code acceptDefs} attribute
*/
@JsonProperty("acceptDefs")
@Override
public ImmutableList getAcceptDefs() {
return acceptDefs;
}
/**
* @return The value of the {@code returnDefs} attribute
*/
@JsonProperty("returnDefs")
@Override
public ImmutableList getReturnDefs() {
return returnDefs;
}
/**
* Copy the current immutable object with elements that replace the content of {@link AstBody.Headers#getAcceptDefs() acceptDefs}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableHeaders withAcceptDefs(TypeDef... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableHeaders(newValue, this.returnDefs);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AstBody.Headers#getAcceptDefs() acceptDefs}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of acceptDefs elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableHeaders withAcceptDefs(Iterable extends TypeDef> elements) {
if (this.acceptDefs == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableHeaders(newValue, this.returnDefs);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AstBody.Headers#getReturnDefs() returnDefs}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableHeaders withReturnDefs(TypeDef... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableHeaders(this.acceptDefs, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AstBody.Headers#getReturnDefs() returnDefs}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of returnDefs elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableHeaders withReturnDefs(Iterable extends TypeDef> elements) {
if (this.returnDefs == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableHeaders(this.acceptDefs, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableHeaders} 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 ImmutableHeaders
&& equalTo((ImmutableHeaders) another);
}
private boolean equalTo(ImmutableHeaders another) {
return acceptDefs.equals(another.acceptDefs)
&& returnDefs.equals(another.returnDefs);
}
/**
* Computes a hash code from attributes: {@code acceptDefs}, {@code returnDefs}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + acceptDefs.hashCode();
h += (h << 5) + returnDefs.hashCode();
return h;
}
/**
* Prints the immutable value {@code Headers} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Headers")
.omitNullValues()
.add("acceptDefs", acceptDefs)
.add("returnDefs", returnDefs)
.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 = "AstBody.Headers", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements AstBody.Headers {
@Nullable List acceptDefs = ImmutableList.of();
@Nullable List returnDefs = ImmutableList.of();
@JsonProperty("acceptDefs")
public void setAcceptDefs(List acceptDefs) {
this.acceptDefs = acceptDefs;
}
@JsonProperty("returnDefs")
public void setReturnDefs(List returnDefs) {
this.returnDefs = returnDefs;
}
@Override
public List getAcceptDefs() { throw new UnsupportedOperationException(); }
@Override
public List getReturnDefs() { 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 ImmutableHeaders fromJson(Json json) {
ImmutableHeaders.Builder builder = ImmutableHeaders.builder();
if (json.acceptDefs != null) {
builder.addAllAcceptDefs(json.acceptDefs);
}
if (json.returnDefs != null) {
builder.addAllReturnDefs(json.returnDefs);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link AstBody.Headers} 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 Headers instance
*/
public static ImmutableHeaders copyOf(AstBody.Headers instance) {
if (instance instanceof ImmutableHeaders) {
return (ImmutableHeaders) instance;
}
return ImmutableHeaders.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableHeaders ImmutableHeaders}.
*
* ImmutableHeaders.builder()
* .addAcceptDefs|addAllAcceptDefs(io.resys.hdes.client.api.ast.TypeDef) // {@link AstBody.Headers#getAcceptDefs() acceptDefs} elements
* .addReturnDefs|addAllReturnDefs(io.resys.hdes.client.api.ast.TypeDef) // {@link AstBody.Headers#getReturnDefs() returnDefs} elements
* .build();
*
* @return A new ImmutableHeaders builder
*/
public static ImmutableHeaders.Builder builder() {
return new ImmutableHeaders.Builder();
}
/**
* Builds instances of type {@link ImmutableHeaders ImmutableHeaders}.
* 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 = "AstBody.Headers", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private ImmutableList.Builder acceptDefs = ImmutableList.builder();
private ImmutableList.Builder returnDefs = ImmutableList.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Headers} 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(AstBody.Headers instance) {
Objects.requireNonNull(instance, "instance");
addAllAcceptDefs(instance.getAcceptDefs());
addAllReturnDefs(instance.getReturnDefs());
return this;
}
/**
* Adds one element to {@link AstBody.Headers#getAcceptDefs() acceptDefs} list.
* @param element A acceptDefs element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAcceptDefs(TypeDef element) {
this.acceptDefs.add(element);
return this;
}
/**
* Adds elements to {@link AstBody.Headers#getAcceptDefs() acceptDefs} list.
* @param elements An array of acceptDefs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAcceptDefs(TypeDef... elements) {
this.acceptDefs.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link AstBody.Headers#getAcceptDefs() acceptDefs} list.
* @param elements An iterable of acceptDefs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("acceptDefs")
public final Builder acceptDefs(Iterable extends TypeDef> elements) {
this.acceptDefs = ImmutableList.builder();
return addAllAcceptDefs(elements);
}
/**
* Adds elements to {@link AstBody.Headers#getAcceptDefs() acceptDefs} list.
* @param elements An iterable of acceptDefs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllAcceptDefs(Iterable extends TypeDef> elements) {
this.acceptDefs.addAll(elements);
return this;
}
/**
* Adds one element to {@link AstBody.Headers#getReturnDefs() returnDefs} list.
* @param element A returnDefs element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addReturnDefs(TypeDef element) {
this.returnDefs.add(element);
return this;
}
/**
* Adds elements to {@link AstBody.Headers#getReturnDefs() returnDefs} list.
* @param elements An array of returnDefs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addReturnDefs(TypeDef... elements) {
this.returnDefs.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link AstBody.Headers#getReturnDefs() returnDefs} list.
* @param elements An iterable of returnDefs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("returnDefs")
public final Builder returnDefs(Iterable extends TypeDef> elements) {
this.returnDefs = ImmutableList.builder();
return addAllReturnDefs(elements);
}
/**
* Adds elements to {@link AstBody.Headers#getReturnDefs() returnDefs} list.
* @param elements An iterable of returnDefs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllReturnDefs(Iterable extends TypeDef> elements) {
this.returnDefs.addAll(elements);
return this;
}
/**
* Builds a new {@link ImmutableHeaders ImmutableHeaders}.
* @return An immutable instance of Headers
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableHeaders build() {
return new ImmutableHeaders(acceptDefs.build(), returnDefs.build());
}
}
}