com.github.jcustenborder.netty.wits.model.ImmutableField Maven / Gradle / Ivy
package com.github.jcustenborder.netty.wits.model;
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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
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 Record.Field}.
*
* Use the builder to create immutable instances:
* {@code ImmutableField.builder()}.
*/
@Generated(from = "Record.Field", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class ImmutableField implements Record.Field {
private final int fieldId;
private final Record.FieldType type;
private final String name;
private final @Nullable String documentation;
private final @Nullable String longMnemonic;
private final @Nullable String shortMnemonic;
private ImmutableField(
int fieldId,
Record.FieldType type,
String name,
@Nullable String documentation,
@Nullable String longMnemonic,
@Nullable String shortMnemonic) {
this.fieldId = fieldId;
this.type = type;
this.name = name;
this.documentation = documentation;
this.longMnemonic = longMnemonic;
this.shortMnemonic = shortMnemonic;
}
/**
* @return The value of the {@code fieldId} attribute
*/
@JsonProperty("fieldId")
@Override
public int fieldId() {
return fieldId;
}
/**
* @return The value of the {@code type} attribute
*/
@JsonProperty("type")
@Override
public Record.FieldType type() {
return type;
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public String name() {
return name;
}
/**
* @return The value of the {@code documentation} attribute
*/
@JsonProperty("documentation")
@Override
public @Nullable String documentation() {
return documentation;
}
/**
* @return The value of the {@code longMnemonic} attribute
*/
@JsonProperty("longMnemonic")
@Override
public @Nullable String longMnemonic() {
return longMnemonic;
}
/**
* @return The value of the {@code shortMnemonic} attribute
*/
@JsonProperty("shortMnemonic")
@Override
public @Nullable String shortMnemonic() {
return shortMnemonic;
}
/**
* Copy the current immutable object by setting a value for the {@link Record.Field#fieldId() fieldId} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for fieldId
* @return A modified copy of the {@code this} object
*/
public final ImmutableField withFieldId(int value) {
if (this.fieldId == value) return this;
return new ImmutableField(value, this.type, this.name, this.documentation, this.longMnemonic, this.shortMnemonic);
}
/**
* Copy the current immutable object by setting a value for the {@link Record.Field#type() type} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for type
* @return A modified copy of the {@code this} object
*/
public final ImmutableField withType(Record.FieldType value) {
if (this.type == value) return this;
Record.FieldType newValue = Objects.requireNonNull(value, "type");
if (this.type.equals(newValue)) return this;
return new ImmutableField(this.fieldId, newValue, this.name, this.documentation, this.longMnemonic, this.shortMnemonic);
}
/**
* Copy the current immutable object by setting a value for the {@link Record.Field#name() 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 ImmutableField withName(String value) {
String newValue = Objects.requireNonNull(value, "name");
if (this.name.equals(newValue)) return this;
return new ImmutableField(this.fieldId, this.type, newValue, this.documentation, this.longMnemonic, this.shortMnemonic);
}
/**
* Copy the current immutable object by setting a value for the {@link Record.Field#documentation() documentation} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for documentation (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableField withDocumentation(@Nullable String value) {
if (Objects.equals(this.documentation, value)) return this;
return new ImmutableField(this.fieldId, this.type, this.name, value, this.longMnemonic, this.shortMnemonic);
}
/**
* Copy the current immutable object by setting a value for the {@link Record.Field#longMnemonic() longMnemonic} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for longMnemonic (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableField withLongMnemonic(@Nullable String value) {
if (Objects.equals(this.longMnemonic, value)) return this;
return new ImmutableField(this.fieldId, this.type, this.name, this.documentation, value, this.shortMnemonic);
}
/**
* Copy the current immutable object by setting a value for the {@link Record.Field#shortMnemonic() shortMnemonic} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for shortMnemonic (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableField withShortMnemonic(@Nullable String value) {
if (Objects.equals(this.shortMnemonic, value)) return this;
return new ImmutableField(this.fieldId, this.type, this.name, this.documentation, this.longMnemonic, value);
}
/**
* This instance is equal to all instances of {@code ImmutableField} 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 ImmutableField
&& equalTo((ImmutableField) another);
}
private boolean equalTo(ImmutableField another) {
return fieldId == another.fieldId
&& type.equals(another.type)
&& name.equals(another.name)
&& Objects.equals(documentation, another.documentation)
&& Objects.equals(longMnemonic, another.longMnemonic)
&& Objects.equals(shortMnemonic, another.shortMnemonic);
}
/**
* Computes a hash code from attributes: {@code fieldId}, {@code type}, {@code name}, {@code documentation}, {@code longMnemonic}, {@code shortMnemonic}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + fieldId;
h += (h << 5) + type.hashCode();
h += (h << 5) + name.hashCode();
h += (h << 5) + Objects.hashCode(documentation);
h += (h << 5) + Objects.hashCode(longMnemonic);
h += (h << 5) + Objects.hashCode(shortMnemonic);
return h;
}
/**
* Prints the immutable value {@code Field} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "Field{"
+ "fieldId=" + fieldId
+ ", type=" + type
+ ", name=" + name
+ ", documentation=" + documentation
+ ", longMnemonic=" + longMnemonic
+ ", shortMnemonic=" + shortMnemonic
+ "}";
}
/**
* 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 = "Record.Field", generator = "Immutables")
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements Record.Field {
int fieldId;
boolean fieldIdIsSet;
@Nullable Record.FieldType type;
@Nullable String name;
@Nullable String documentation;
@Nullable String longMnemonic;
@Nullable String shortMnemonic;
@JsonProperty("fieldId")
public void setFieldId(int fieldId) {
this.fieldId = fieldId;
this.fieldIdIsSet = true;
}
@JsonProperty("type")
public void setType(Record.FieldType type) {
this.type = type;
}
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("documentation")
public void setDocumentation(@Nullable String documentation) {
this.documentation = documentation;
}
@JsonProperty("longMnemonic")
public void setLongMnemonic(@Nullable String longMnemonic) {
this.longMnemonic = longMnemonic;
}
@JsonProperty("shortMnemonic")
public void setShortMnemonic(@Nullable String shortMnemonic) {
this.shortMnemonic = shortMnemonic;
}
@Override
public int fieldId() { throw new UnsupportedOperationException(); }
@Override
public Record.FieldType type() { throw new UnsupportedOperationException(); }
@Override
public String name() { throw new UnsupportedOperationException(); }
@Override
public String documentation() { throw new UnsupportedOperationException(); }
@Override
public String longMnemonic() { throw new UnsupportedOperationException(); }
@Override
public String shortMnemonic() { 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 ImmutableField fromJson(Json json) {
ImmutableField.Builder builder = ImmutableField.builder();
if (json.fieldIdIsSet) {
builder.fieldId(json.fieldId);
}
if (json.type != null) {
builder.type(json.type);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.documentation != null) {
builder.documentation(json.documentation);
}
if (json.longMnemonic != null) {
builder.longMnemonic(json.longMnemonic);
}
if (json.shortMnemonic != null) {
builder.shortMnemonic(json.shortMnemonic);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link Record.Field} 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 Field instance
*/
public static ImmutableField copyOf(Record.Field instance) {
if (instance instanceof ImmutableField) {
return (ImmutableField) instance;
}
return ImmutableField.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableField ImmutableField}.
*
* ImmutableField.builder()
* .fieldId(int) // required {@link Record.Field#fieldId() fieldId}
* .type(com.github.jcustenborder.netty.wits.model.Record.FieldType) // required {@link Record.Field#type() type}
* .name(String) // required {@link Record.Field#name() name}
* .documentation(String | null) // nullable {@link Record.Field#documentation() documentation}
* .longMnemonic(String | null) // nullable {@link Record.Field#longMnemonic() longMnemonic}
* .shortMnemonic(String | null) // nullable {@link Record.Field#shortMnemonic() shortMnemonic}
* .build();
*
* @return A new ImmutableField builder
*/
public static ImmutableField.Builder builder() {
return new ImmutableField.Builder();
}
/**
* Builds instances of type {@link ImmutableField ImmutableField}.
* 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 = "Record.Field", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_FIELD_ID = 0x1L;
private static final long INIT_BIT_TYPE = 0x2L;
private static final long INIT_BIT_NAME = 0x4L;
private long initBits = 0x7L;
private int fieldId;
private @Nullable Record.FieldType type;
private @Nullable String name;
private @Nullable String documentation;
private @Nullable String longMnemonic;
private @Nullable String shortMnemonic;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Field} 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(Record.Field instance) {
Objects.requireNonNull(instance, "instance");
fieldId(instance.fieldId());
type(instance.type());
name(instance.name());
@Nullable String documentationValue = instance.documentation();
if (documentationValue != null) {
documentation(documentationValue);
}
@Nullable String longMnemonicValue = instance.longMnemonic();
if (longMnemonicValue != null) {
longMnemonic(longMnemonicValue);
}
@Nullable String shortMnemonicValue = instance.shortMnemonic();
if (shortMnemonicValue != null) {
shortMnemonic(shortMnemonicValue);
}
return this;
}
/**
* Initializes the value for the {@link Record.Field#fieldId() fieldId} attribute.
* @param fieldId The value for fieldId
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("fieldId")
public final Builder fieldId(int fieldId) {
this.fieldId = fieldId;
initBits &= ~INIT_BIT_FIELD_ID;
return this;
}
/**
* Initializes the value for the {@link Record.Field#type() type} attribute.
* @param type The value for type
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("type")
public final Builder type(Record.FieldType type) {
this.type = Objects.requireNonNull(type, "type");
initBits &= ~INIT_BIT_TYPE;
return this;
}
/**
* Initializes the value for the {@link Record.Field#name() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@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 Record.Field#documentation() documentation} attribute.
* @param documentation The value for documentation (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("documentation")
public final Builder documentation(@Nullable String documentation) {
this.documentation = documentation;
return this;
}
/**
* Initializes the value for the {@link Record.Field#longMnemonic() longMnemonic} attribute.
* @param longMnemonic The value for longMnemonic (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("longMnemonic")
public final Builder longMnemonic(@Nullable String longMnemonic) {
this.longMnemonic = longMnemonic;
return this;
}
/**
* Initializes the value for the {@link Record.Field#shortMnemonic() shortMnemonic} attribute.
* @param shortMnemonic The value for shortMnemonic (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("shortMnemonic")
public final Builder shortMnemonic(@Nullable String shortMnemonic) {
this.shortMnemonic = shortMnemonic;
return this;
}
/**
* Builds a new {@link ImmutableField ImmutableField}.
* @return An immutable instance of Field
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableField build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableField(fieldId, type, name, documentation, longMnemonic, shortMnemonic);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_FIELD_ID) != 0) attributes.add("fieldId");
if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type");
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
return "Cannot build Field, some of required attributes are not set " + attributes;
}
}
}