io.resys.hdes.client.api.ast.ImmutableAstCommandRange 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.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
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 AstBody.AstCommandRange}.
*
* Use the builder to create immutable instances:
* {@code ImmutableAstCommandRange.builder()}.
*/
@Generated(from = "AstBody.AstCommandRange", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableAstCommandRange implements AstBody.AstCommandRange {
private final int start;
private final int end;
private final @Nullable Integer column;
private final @Nullable Boolean insert;
private ImmutableAstCommandRange(
int start,
int end,
@Nullable Integer column,
@Nullable Boolean insert) {
this.start = start;
this.end = end;
this.column = column;
this.insert = insert;
}
/**
* @return The value of the {@code start} attribute
*/
@JsonProperty("start")
@Override
public int getStart() {
return start;
}
/**
* @return The value of the {@code end} attribute
*/
@JsonProperty("end")
@Override
public int getEnd() {
return end;
}
/**
* @return The value of the {@code column} attribute
*/
@JsonProperty("column")
@Override
public @Nullable Integer getColumn() {
return column;
}
/**
* @return The value of the {@code insert} attribute
*/
@JsonProperty("insert")
@Override
public @Nullable Boolean getInsert() {
return insert;
}
/**
* Copy the current immutable object by setting a value for the {@link AstBody.AstCommandRange#getStart() start} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for start
* @return A modified copy of the {@code this} object
*/
public final ImmutableAstCommandRange withStart(int value) {
if (this.start == value) return this;
return new ImmutableAstCommandRange(value, this.end, this.column, this.insert);
}
/**
* Copy the current immutable object by setting a value for the {@link AstBody.AstCommandRange#getEnd() end} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for end
* @return A modified copy of the {@code this} object
*/
public final ImmutableAstCommandRange withEnd(int value) {
if (this.end == value) return this;
return new ImmutableAstCommandRange(this.start, value, this.column, this.insert);
}
/**
* Copy the current immutable object by setting a value for the {@link AstBody.AstCommandRange#getColumn() column} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for column (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableAstCommandRange withColumn(@Nullable Integer value) {
if (Objects.equals(this.column, value)) return this;
return new ImmutableAstCommandRange(this.start, this.end, value, this.insert);
}
/**
* Copy the current immutable object by setting a value for the {@link AstBody.AstCommandRange#getInsert() insert} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for insert (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableAstCommandRange withInsert(@Nullable Boolean value) {
if (Objects.equals(this.insert, value)) return this;
return new ImmutableAstCommandRange(this.start, this.end, this.column, value);
}
/**
* This instance is equal to all instances of {@code ImmutableAstCommandRange} 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 ImmutableAstCommandRange
&& equalTo((ImmutableAstCommandRange) another);
}
private boolean equalTo(ImmutableAstCommandRange another) {
return start == another.start
&& end == another.end
&& Objects.equals(column, another.column)
&& Objects.equals(insert, another.insert);
}
/**
* Computes a hash code from attributes: {@code start}, {@code end}, {@code column}, {@code insert}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + start;
h += (h << 5) + end;
h += (h << 5) + Objects.hashCode(column);
h += (h << 5) + Objects.hashCode(insert);
return h;
}
/**
* Prints the immutable value {@code AstCommandRange} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("AstCommandRange")
.omitNullValues()
.add("start", start)
.add("end", end)
.add("column", column)
.add("insert", insert)
.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.AstCommandRange", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements AstBody.AstCommandRange {
int start;
boolean startIsSet;
int end;
boolean endIsSet;
@Nullable Integer column;
@Nullable Boolean insert;
@JsonProperty("start")
public void setStart(int start) {
this.start = start;
this.startIsSet = true;
}
@JsonProperty("end")
public void setEnd(int end) {
this.end = end;
this.endIsSet = true;
}
@JsonProperty("column")
public void setColumn(@Nullable Integer column) {
this.column = column;
}
@JsonProperty("insert")
public void setInsert(@Nullable Boolean insert) {
this.insert = insert;
}
@Override
public int getStart() { throw new UnsupportedOperationException(); }
@Override
public int getEnd() { throw new UnsupportedOperationException(); }
@Override
public Integer getColumn() { throw new UnsupportedOperationException(); }
@Override
public Boolean getInsert() { 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 ImmutableAstCommandRange fromJson(Json json) {
ImmutableAstCommandRange.Builder builder = ImmutableAstCommandRange.builder();
if (json.startIsSet) {
builder.start(json.start);
}
if (json.endIsSet) {
builder.end(json.end);
}
if (json.column != null) {
builder.column(json.column);
}
if (json.insert != null) {
builder.insert(json.insert);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link AstBody.AstCommandRange} 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 AstCommandRange instance
*/
public static ImmutableAstCommandRange copyOf(AstBody.AstCommandRange instance) {
if (instance instanceof ImmutableAstCommandRange) {
return (ImmutableAstCommandRange) instance;
}
return ImmutableAstCommandRange.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableAstCommandRange ImmutableAstCommandRange}.
*
* ImmutableAstCommandRange.builder()
* .start(int) // required {@link AstBody.AstCommandRange#getStart() start}
* .end(int) // required {@link AstBody.AstCommandRange#getEnd() end}
* .column(Integer | null) // nullable {@link AstBody.AstCommandRange#getColumn() column}
* .insert(Boolean | null) // nullable {@link AstBody.AstCommandRange#getInsert() insert}
* .build();
*
* @return A new ImmutableAstCommandRange builder
*/
public static ImmutableAstCommandRange.Builder builder() {
return new ImmutableAstCommandRange.Builder();
}
/**
* Builds instances of type {@link ImmutableAstCommandRange ImmutableAstCommandRange}.
* 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.AstCommandRange", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_START = 0x1L;
private static final long INIT_BIT_END = 0x2L;
private long initBits = 0x3L;
private int start;
private int end;
private @Nullable Integer column;
private @Nullable Boolean insert;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code AstCommandRange} 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
*/
@CanIgnoreReturnValue
public final Builder from(AstBody.AstCommandRange instance) {
Objects.requireNonNull(instance, "instance");
start(instance.getStart());
end(instance.getEnd());
@Nullable Integer columnValue = instance.getColumn();
if (columnValue != null) {
column(columnValue);
}
@Nullable Boolean insertValue = instance.getInsert();
if (insertValue != null) {
insert(insertValue);
}
return this;
}
/**
* Initializes the value for the {@link AstBody.AstCommandRange#getStart() start} attribute.
* @param start The value for start
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("start")
public final Builder start(int start) {
this.start = start;
initBits &= ~INIT_BIT_START;
return this;
}
/**
* Initializes the value for the {@link AstBody.AstCommandRange#getEnd() end} attribute.
* @param end The value for end
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("end")
public final Builder end(int end) {
this.end = end;
initBits &= ~INIT_BIT_END;
return this;
}
/**
* Initializes the value for the {@link AstBody.AstCommandRange#getColumn() column} attribute.
* @param column The value for column (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("column")
public final Builder column(@Nullable Integer column) {
this.column = column;
return this;
}
/**
* Initializes the value for the {@link AstBody.AstCommandRange#getInsert() insert} attribute.
* @param insert The value for insert (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("insert")
public final Builder insert(@Nullable Boolean insert) {
this.insert = insert;
return this;
}
/**
* Builds a new {@link ImmutableAstCommandRange ImmutableAstCommandRange}.
* @return An immutable instance of AstCommandRange
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableAstCommandRange build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableAstCommandRange(start, end, column, insert);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_START) != 0) attributes.add("start");
if ((initBits & INIT_BIT_END) != 0) attributes.add("end");
return "Cannot build AstCommandRange, some of required attributes are not set " + attributes;
}
}
}