
io.protostuff.generator.html.json.message.ImmutableMessageField Maven / Gradle / Ivy
package io.protostuff.generator.html.json.message;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.Booleans;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link MessageField}.
*
* Use builder to create immutable instances:
* {@code ImmutableMessageField.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "MessageField"})
@Immutable
public final class ImmutableMessageField implements MessageField {
private final String name;
private final String typeId;
private final MessageFieldModifier modifier;
private final int tag;
private final @Nullable String description;
private final boolean isMap;
private final @Nullable String mapKeyTypeId;
private final @Nullable String mapValueTypeId;
private final @Nullable String oneof;
private ImmutableMessageField(ImmutableMessageField.Builder builder) {
this.name = builder.name;
this.typeId = builder.typeId;
this.modifier = builder.modifier;
this.tag = builder.tag;
this.description = builder.description;
this.mapKeyTypeId = builder.mapKeyTypeId;
this.mapValueTypeId = builder.mapValueTypeId;
this.oneof = builder.oneof;
this.isMap = builder.isMapIsSet()
? builder.isMap
: MessageField.super.isMap();
}
private ImmutableMessageField(
String name,
String typeId,
MessageFieldModifier modifier,
int tag,
@Nullable String description,
boolean isMap,
@Nullable String mapKeyTypeId,
@Nullable String mapValueTypeId,
@Nullable String oneof) {
this.name = name;
this.typeId = typeId;
this.modifier = modifier;
this.tag = tag;
this.description = description;
this.isMap = isMap;
this.mapKeyTypeId = mapKeyTypeId;
this.mapValueTypeId = mapValueTypeId;
this.oneof = oneof;
}
/**
* @return value of {@code name} attribute
*/
@JsonProperty
@Override
public String name() {
return name;
}
/**
* @return value of {@code typeId} attribute
*/
@JsonProperty
@Override
public String typeId() {
return typeId;
}
/**
* @return value of {@code modifier} attribute
*/
@JsonProperty
@Override
public MessageFieldModifier modifier() {
return modifier;
}
/**
* @return value of {@code tag} attribute
*/
@JsonProperty
@Override
public int tag() {
return tag;
}
/**
* @return value of {@code description} attribute
*/
@JsonProperty
@Override
public @Nullable String description() {
return description;
}
/**
* @return value of {@code isMap} attribute
*/
@JsonProperty
@Override
public boolean isMap() {
return isMap;
}
/**
* @return value of {@code mapKeyTypeId} attribute
*/
@JsonProperty
@Override
public @Nullable String mapKeyTypeId() {
return mapKeyTypeId;
}
/**
* @return value of {@code mapValueTypeId} attribute
*/
@JsonProperty
@Override
public @Nullable String mapValueTypeId() {
return mapValueTypeId;
}
/**
* @return value of {@code oneof} attribute
*/
@JsonProperty
@Override
public @Nullable String oneof() {
return oneof;
}
/**
* Copy current immutable object by setting value for {@link MessageField#name() name}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for name
* @return modified copy of the {@code this} object
*/
public final ImmutableMessageField withName(String value) {
if (this.name == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableMessageField(
newValue,
this.typeId,
this.modifier,
this.tag,
this.description,
this.isMap,
this.mapKeyTypeId,
this.mapValueTypeId,
this.oneof);
}
/**
* Copy current immutable object by setting value for {@link MessageField#typeId() typeId}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for typeId
* @return modified copy of the {@code this} object
*/
public final ImmutableMessageField withTypeId(String value) {
if (this.typeId == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableMessageField(
this.name,
newValue,
this.modifier,
this.tag,
this.description,
this.isMap,
this.mapKeyTypeId,
this.mapValueTypeId,
this.oneof);
}
/**
* Copy current immutable object by setting value for {@link MessageField#modifier() modifier}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for modifier
* @return modified copy of the {@code this} object
*/
public final ImmutableMessageField withModifier(MessageFieldModifier value) {
if (this.modifier == value) return this;
MessageFieldModifier newValue = Preconditions.checkNotNull(value);
return new ImmutableMessageField(
this.name,
this.typeId,
newValue,
this.tag,
this.description,
this.isMap,
this.mapKeyTypeId,
this.mapValueTypeId,
this.oneof);
}
/**
* Copy current immutable object by setting value for {@link MessageField#tag() tag}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for tag
* @return modified copy of the {@code this} object
*/
public final ImmutableMessageField withTag(int value) {
if (this.tag == value) return this;
int newValue = value;
return new ImmutableMessageField(
this.name,
this.typeId,
this.modifier,
newValue,
this.description,
this.isMap,
this.mapKeyTypeId,
this.mapValueTypeId,
this.oneof);
}
/**
* Copy current immutable object by setting value for {@link MessageField#description() description}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for description, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableMessageField withDescription(@Nullable String value) {
if (this.description == value) return this;
@Nullable String newValue = value;
return new ImmutableMessageField(
this.name,
this.typeId,
this.modifier,
this.tag,
newValue,
this.isMap,
this.mapKeyTypeId,
this.mapValueTypeId,
this.oneof);
}
/**
* Copy current immutable object by setting value for {@link MessageField#isMap() isMap}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for isMap
* @return modified copy of the {@code this} object
*/
public final ImmutableMessageField withIsMap(boolean value) {
if (this.isMap == value) return this;
boolean newValue = value;
return new ImmutableMessageField(
this.name,
this.typeId,
this.modifier,
this.tag,
this.description,
newValue,
this.mapKeyTypeId,
this.mapValueTypeId,
this.oneof);
}
/**
* Copy current immutable object by setting value for {@link MessageField#mapKeyTypeId() mapKeyTypeId}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for mapKeyTypeId, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableMessageField withMapKeyTypeId(@Nullable String value) {
if (this.mapKeyTypeId == value) return this;
@Nullable String newValue = value;
return new ImmutableMessageField(
this.name,
this.typeId,
this.modifier,
this.tag,
this.description,
this.isMap,
newValue,
this.mapValueTypeId,
this.oneof);
}
/**
* Copy current immutable object by setting value for {@link MessageField#mapValueTypeId() mapValueTypeId}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for mapValueTypeId, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableMessageField withMapValueTypeId(@Nullable String value) {
if (this.mapValueTypeId == value) return this;
@Nullable String newValue = value;
return new ImmutableMessageField(
this.name,
this.typeId,
this.modifier,
this.tag,
this.description,
this.isMap,
this.mapKeyTypeId,
newValue,
this.oneof);
}
/**
* Copy current immutable object by setting value for {@link MessageField#oneof() oneof}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for oneof, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableMessageField withOneof(@Nullable String value) {
if (this.oneof == value) return this;
@Nullable String newValue = value;
return new ImmutableMessageField(
this.name,
this.typeId,
this.modifier,
this.tag,
this.description,
this.isMap,
this.mapKeyTypeId,
this.mapValueTypeId,
newValue);
}
/**
* This instance is equal to instances of {@code ImmutableMessageField} with 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 ImmutableMessageField
&& equalTo((ImmutableMessageField) another);
}
private boolean equalTo(ImmutableMessageField another) {
return name.equals(another.name)
&& typeId.equals(another.typeId)
&& modifier.equals(another.modifier)
&& tag == another.tag
&& Objects.equal(description, another.description)
&& isMap == another.isMap
&& Objects.equal(mapKeyTypeId, another.mapKeyTypeId)
&& Objects.equal(mapValueTypeId, another.mapValueTypeId)
&& Objects.equal(oneof, another.oneof);
}
/**
* Computes hash code from attributes: {@code name}, {@code typeId}, {@code modifier}, {@code tag}, {@code description}, {@code isMap}, {@code mapKeyTypeId}, {@code mapValueTypeId}, {@code oneof}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + name.hashCode();
h = h * 17 + typeId.hashCode();
h = h * 17 + modifier.hashCode();
h = h * 17 + tag;
h = h * 17 + Objects.hashCode(description);
h = h * 17 + Booleans.hashCode(isMap);
h = h * 17 + Objects.hashCode(mapKeyTypeId);
h = h * 17 + Objects.hashCode(mapValueTypeId);
h = h * 17 + Objects.hashCode(oneof);
return h;
}
/**
* Prints immutable value {@code MessageField...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("MessageField")
.add("name", name)
.add("typeId", typeId)
.add("modifier", modifier)
.add("tag", tag)
.add("description", description)
.add("isMap", isMap)
.add("mapKeyTypeId", mapKeyTypeId)
.add("mapValueTypeId", mapValueTypeId)
.add("oneof", oneof)
.toString();
}
/**
* Simple representation of this value type suitable Jackson binding
* @deprecated Do not use this type directly, it exists only for Jackson-binding infrastructure
*/
@Deprecated
static final class Json {
@JsonProperty
@Nullable String name;
@JsonProperty
@Nullable String typeId;
@JsonProperty
@Nullable MessageFieldModifier modifier;
@JsonProperty
@Nullable Integer tag;
@JsonProperty
@Nullable String description;
@JsonProperty
@Nullable Boolean isMap;
@JsonProperty
@Nullable String mapKeyTypeId;
@JsonProperty
@Nullable String mapValueTypeId;
@JsonProperty
@Nullable String oneof;
}
/**
* @param json JSON-bindable data structure
* @return immutable value type
* @deprecated Do not use this method directly, it exists only for Jackson-binding infrastructure
*/
@Deprecated
@JsonCreator
static ImmutableMessageField fromJson(Json json) {
ImmutableMessageField.Builder builder = ImmutableMessageField.builder();
if (json.name != null) {
builder.name(json.name);
}
if (json.typeId != null) {
builder.typeId(json.typeId);
}
if (json.modifier != null) {
builder.modifier(json.modifier);
}
if (json.tag != null) {
builder.tag(json.tag);
}
if (json.description != null) {
builder.description(json.description);
}
if (json.isMap != null) {
builder.isMap(json.isMap);
}
if (json.mapKeyTypeId != null) {
builder.mapKeyTypeId(json.mapKeyTypeId);
}
if (json.mapValueTypeId != null) {
builder.mapValueTypeId(json.mapValueTypeId);
}
if (json.oneof != null) {
builder.oneof(json.oneof);
}
return builder.build();
}
/**
* Creates immutable copy of {@link MessageField}.
* Uses accessors to get values to initialize immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance instance to copy
* @return copied immutable MessageField instance
*/
public static ImmutableMessageField copyOf(MessageField instance) {
if (instance instanceof ImmutableMessageField) {
return (ImmutableMessageField) instance;
}
return ImmutableMessageField.builder()
.from(instance)
.build();
}
/**
* Creates builder for {@link io.protostuff.generator.html.json.message.ImmutableMessageField ImmutableMessageField}.
* @return new ImmutableMessageField builder
*/
public static ImmutableMessageField.Builder builder() {
return new ImmutableMessageField.Builder();
}
/**
* Builds instances of {@link io.protostuff.generator.html.json.message.ImmutableMessageField ImmutableMessageField}.
* Initialize attributes and then invoke {@link #build()} method to create
* immutable instance.
*
{@code Builder} is not thread safe and generally should not be stored in field or collection,
* but used immediately to create instances.
*/
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private static final long INIT_BIT_TYPE_ID = 0x2L;
private static final long INIT_BIT_MODIFIER = 0x4L;
private static final long INIT_BIT_TAG = 0x8L;
private static final long OPT_BIT_IS_MAP = 0x1L;
private long initBits = 0xf;
private long optBits;
private @Nullable String name;
private @Nullable String typeId;
private @Nullable MessageFieldModifier modifier;
private int tag;
private @Nullable String description;
private boolean isMap;
private @Nullable String mapKeyTypeId;
private @Nullable String mapValueTypeId;
private @Nullable String oneof;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link MessageField} instance.
* Regular attribute values will be replaced with ones of an instance.
* Instance's absent optional values will not replace present values.
* @param instance instance to copy values from
* @return {@code this} builder for chained invocation
*/
public final Builder from(MessageField instance) {
Preconditions.checkNotNull(instance);
name(instance.name());
typeId(instance.typeId());
modifier(instance.modifier());
tag(instance.tag());
@Nullable String descriptionValue = instance.description();
if (descriptionValue != null) {
description(descriptionValue);
}
isMap(instance.isMap());
@Nullable String mapKeyTypeIdValue = instance.mapKeyTypeId();
if (mapKeyTypeIdValue != null) {
mapKeyTypeId(mapKeyTypeIdValue);
}
@Nullable String mapValueTypeIdValue = instance.mapValueTypeId();
if (mapValueTypeIdValue != null) {
mapValueTypeId(mapValueTypeIdValue);
}
@Nullable String oneofValue = instance.oneof();
if (oneofValue != null) {
oneof(oneofValue);
}
return this;
}
/**
* Initializes value for {@link MessageField#name() name}.
* @param name value for name
* @return {@code this} builder for chained invocation
*/
public final Builder name(String name) {
this.name = Preconditions.checkNotNull(name);
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes value for {@link MessageField#typeId() typeId}.
* @param typeId value for typeId
* @return {@code this} builder for chained invocation
*/
public final Builder typeId(String typeId) {
this.typeId = Preconditions.checkNotNull(typeId);
initBits &= ~INIT_BIT_TYPE_ID;
return this;
}
/**
* Initializes value for {@link MessageField#modifier() modifier}.
* @param modifier value for modifier
* @return {@code this} builder for chained invocation
*/
public final Builder modifier(MessageFieldModifier modifier) {
this.modifier = Preconditions.checkNotNull(modifier);
initBits &= ~INIT_BIT_MODIFIER;
return this;
}
/**
* Initializes value for {@link MessageField#tag() tag}.
* @param tag value for tag
* @return {@code this} builder for chained invocation
*/
public final Builder tag(int tag) {
this.tag = tag;
initBits &= ~INIT_BIT_TAG;
return this;
}
/**
* Initializes value for {@link MessageField#description() description}.
* @param description value for description, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder description(@Nullable String description) {
this.description = description;
return this;
}
/**
* Initializes value for {@link MessageField#isMap() isMap}.
*
If not set, this attribute will have default value returned by initializer of {@link MessageField#isMap() isMap}.
* @param isMap value for isMap
* @return {@code this} builder for chained invocation
*/
public final Builder isMap(boolean isMap) {
this.isMap = isMap;
optBits |= OPT_BIT_IS_MAP;
return this;
}
/**
* Initializes value for {@link MessageField#mapKeyTypeId() mapKeyTypeId}.
* @param mapKeyTypeId value for mapKeyTypeId, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder mapKeyTypeId(@Nullable String mapKeyTypeId) {
this.mapKeyTypeId = mapKeyTypeId;
return this;
}
/**
* Initializes value for {@link MessageField#mapValueTypeId() mapValueTypeId}.
* @param mapValueTypeId value for mapValueTypeId, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder mapValueTypeId(@Nullable String mapValueTypeId) {
this.mapValueTypeId = mapValueTypeId;
return this;
}
/**
* Initializes value for {@link MessageField#oneof() oneof}.
* @param oneof value for oneof, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder oneof(@Nullable String oneof) {
this.oneof = oneof;
return this;
}
/**
* Builds new {@link io.protostuff.generator.html.json.message.ImmutableMessageField ImmutableMessageField}.
* @return immutable instance of MessageField
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableMessageField build()
throws IllegalStateException {
checkRequiredAttributes(); return new ImmutableMessageField(this);
}
private boolean isMapIsSet() {
return (optBits & OPT_BIT_IS_MAP) != 0;
}
private boolean nameIsSet() {
return (initBits & INIT_BIT_NAME) == 0;
}
private boolean typeIdIsSet() {
return (initBits & INIT_BIT_TYPE_ID) == 0;
}
private boolean modifierIsSet() {
return (initBits & INIT_BIT_MODIFIER) == 0;
}
private boolean tagIsSet() {
return (initBits & INIT_BIT_TAG) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!nameIsSet()) attributes.add("name");
if (!typeIdIsSet()) attributes.add("typeId");
if (!modifierIsSet()) attributes.add("modifier");
if (!tagIsSet()) attributes.add("tag");
return "Cannot build MessageField, some of required attributes are not set " + attributes;
}
}
}