com.arakelian.elastic.model.ImmutableNodeInfo Maven / Gradle / Ivy
package com.arakelian.elastic.model;
import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.Views;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import javax.annotation.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link Nodes.NodeInfo}.
*
* Use the builder to create immutable instances:
* {@code ImmutableNodeInfo.builder()}.
*/
@Generated(from = "Nodes.NodeInfo", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
@JsonIgnoreProperties(value = {"master", "data"}, allowGetters = true)
public final class ImmutableNodeInfo implements Nodes.NodeInfo {
private final ImmutableMap attributes;
private final @Nullable String buildFlavor;
private final @Nullable String buildHash;
private final @Nullable String buildType;
private final String host;
private final Nodes.NodeInfo.Http http;
private final @Nullable String httpAddress;
private final String ip;
private final String name;
private final @Nullable ImmutableSet roles;
private final String transportAddress;
private final String version;
private final boolean data;
private final boolean master;
private ImmutableNodeInfo(ImmutableNodeInfo.Builder builder) {
this.attributes = builder.attributes.build();
this.buildFlavor = builder.buildFlavor;
this.buildHash = builder.buildHash;
this.buildType = builder.buildType;
this.host = builder.host;
this.http = builder.http;
this.httpAddress = builder.httpAddress;
this.ip = builder.ip;
this.name = builder.name;
this.transportAddress = builder.transportAddress;
this.version = builder.version;
if (builder.rolesIsSet()) {
initShim.roles(builder.roles == null ? null : builder.roles.build());
}
this.roles = initShim.getRoles();
this.data = initShim.isData();
this.master = initShim.isMaster();
this.initShim = null;
}
private static final byte STAGE_INITIALIZING = -1;
private static final byte STAGE_UNINITIALIZED = 0;
private static final byte STAGE_INITIALIZED = 1;
@SuppressWarnings("Immutable")
private transient volatile InitShim initShim = new InitShim();
@Generated(from = "Nodes.NodeInfo", generator = "Immutables")
private final class InitShim {
private byte rolesBuildStage = STAGE_UNINITIALIZED;
private ImmutableSet roles;
ImmutableSet getRoles() {
if (rolesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (rolesBuildStage == STAGE_UNINITIALIZED) {
rolesBuildStage = STAGE_INITIALIZING;
this.roles = getRolesInitialize() == null ? null : ImmutableSet.copyOf(getRolesInitialize());
rolesBuildStage = STAGE_INITIALIZED;
}
return this.roles;
}
void roles(ImmutableSet roles) {
this.roles = roles;
rolesBuildStage = STAGE_INITIALIZED;
}
private byte dataBuildStage = STAGE_UNINITIALIZED;
private boolean data;
boolean isData() {
if (dataBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (dataBuildStage == STAGE_UNINITIALIZED) {
dataBuildStage = STAGE_INITIALIZING;
this.data = isDataInitialize();
dataBuildStage = STAGE_INITIALIZED;
}
return this.data;
}
private byte masterBuildStage = STAGE_UNINITIALIZED;
private boolean master;
boolean isMaster() {
if (masterBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (masterBuildStage == STAGE_UNINITIALIZED) {
masterBuildStage = STAGE_INITIALIZING;
this.master = isMasterInitialize();
masterBuildStage = STAGE_INITIALIZED;
}
return this.master;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (rolesBuildStage == STAGE_INITIALIZING) attributes.add("roles");
if (dataBuildStage == STAGE_INITIALIZING) attributes.add("data");
if (masterBuildStage == STAGE_INITIALIZING) attributes.add("master");
return "Cannot build NodeInfo, attribute initializers form cycle " + attributes;
}
}
private @Nullable Set getRolesInitialize() {
return Nodes.NodeInfo.super.getRoles();
}
private boolean isDataInitialize() {
return Nodes.NodeInfo.super.isData();
}
private boolean isMasterInitialize() {
return Nodes.NodeInfo.super.isMaster();
}
/**
* @return The value of the {@code attributes} attribute
*/
@JsonProperty("attributes")
@Override
public ImmutableMap getAttributes() {
return attributes;
}
/**
* @return The value of the {@code buildFlavor} attribute
*/
@JsonProperty("build_flavor")
@JsonView(Views.Elastic.Version6.Version63.class)
@Override
public @Nullable String getBuildFlavor() {
return buildFlavor;
}
/**
* @return The value of the {@code buildHash} attribute
*/
@JsonProperty("build_hash")
@Override
public @Nullable String getBuildHash() {
return buildHash;
}
/**
* @return The value of the {@code buildType} attribute
*/
@JsonProperty("build_type")
@JsonView(Views.Elastic.Version6.Version63.class)
@Override
public @Nullable String getBuildType() {
return buildType;
}
/**
* @return The value of the {@code host} attribute
*/
@JsonProperty("host")
@Override
public String getHost() {
return host;
}
/**
* @return The value of the {@code http} attribute
*/
@JsonProperty("http")
@Override
public Nodes.NodeInfo.Http getHttp() {
return http;
}
/**
* @return The value of the {@code httpAddress} attribute
*/
@JsonProperty("http_address")
@Override
public @Nullable String getHttpAddress() {
return httpAddress;
}
/**
* @return The value of the {@code ip} attribute
*/
@JsonProperty("ip")
@Override
public String getIp() {
return ip;
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code roles} attribute
*/
@JsonProperty("roles")
@Override
public @Nullable ImmutableSet getRoles() {
InitShim shim = this.initShim;
return shim != null
? shim.getRoles()
: this.roles;
}
/**
* @return The value of the {@code transportAddress} attribute
*/
@JsonProperty("transport_address")
@Override
public String getTransportAddress() {
return transportAddress;
}
/**
* @return The value of the {@code version} attribute
*/
@JsonProperty("version")
@Override
public String getVersion() {
return version;
}
/**
* @return The computed-at-construction value of the {@code data} attribute
*/
@JsonProperty("data")
@Override
public boolean isData() {
InitShim shim = this.initShim;
return shim != null
? shim.isData()
: this.data;
}
/**
* @return The computed-at-construction value of the {@code master} attribute
*/
@JsonProperty("master")
@Override
public boolean isMaster() {
InitShim shim = this.initShim;
return shim != null
? shim.isMaster()
: this.master;
}
/**
* This instance is equal to all instances of {@code ImmutableNodeInfo} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@javax.annotation.Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableNodeInfo
&& equalTo((ImmutableNodeInfo) another);
}
private boolean equalTo(ImmutableNodeInfo another) {
return attributes.equals(another.attributes)
&& Objects.equals(buildFlavor, another.buildFlavor)
&& Objects.equals(buildHash, another.buildHash)
&& Objects.equals(buildType, another.buildType)
&& host.equals(another.host)
&& http.equals(another.http)
&& Objects.equals(httpAddress, another.httpAddress)
&& ip.equals(another.ip)
&& name.equals(another.name)
&& Objects.equals(roles, another.roles)
&& transportAddress.equals(another.transportAddress)
&& version.equals(another.version)
&& data == another.data
&& master == another.master;
}
/**
* Computes a hash code from attributes: {@code attributes}, {@code buildFlavor}, {@code buildHash}, {@code buildType}, {@code host}, {@code http}, {@code httpAddress}, {@code ip}, {@code name}, {@code roles}, {@code transportAddress}, {@code version}, {@code data}, {@code master}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + attributes.hashCode();
h += (h << 5) + Objects.hashCode(buildFlavor);
h += (h << 5) + Objects.hashCode(buildHash);
h += (h << 5) + Objects.hashCode(buildType);
h += (h << 5) + host.hashCode();
h += (h << 5) + http.hashCode();
h += (h << 5) + Objects.hashCode(httpAddress);
h += (h << 5) + ip.hashCode();
h += (h << 5) + name.hashCode();
h += (h << 5) + Objects.hashCode(roles);
h += (h << 5) + transportAddress.hashCode();
h += (h << 5) + version.hashCode();
h += (h << 5) + Booleans.hashCode(data);
h += (h << 5) + Booleans.hashCode(master);
return h;
}
/**
* Prints the immutable value {@code NodeInfo} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("NodeInfo")
.omitNullValues()
.add("attributes", attributes)
.add("buildFlavor", buildFlavor)
.add("buildHash", buildHash)
.add("buildType", buildType)
.add("host", host)
.add("http", http)
.add("httpAddress", httpAddress)
.add("ip", ip)
.add("name", name)
.add("roles", roles)
.add("transportAddress", transportAddress)
.add("version", version)
.add("data", data)
.add("master", master)
.toString();
}
/**
* Creates a builder for {@link ImmutableNodeInfo ImmutableNodeInfo}.
*
* ImmutableNodeInfo.builder()
* .putAttribute|putAllAttributes(String => Object) // {@link Nodes.NodeInfo#getAttributes() attributes} mappings
* .buildFlavor(String | null) // nullable {@link Nodes.NodeInfo#getBuildFlavor() buildFlavor}
* .buildHash(String | null) // nullable {@link Nodes.NodeInfo#getBuildHash() buildHash}
* .buildType(String | null) // nullable {@link Nodes.NodeInfo#getBuildType() buildType}
* .host(String) // required {@link Nodes.NodeInfo#getHost() host}
* .http(com.arakelian.elastic.model.Nodes.NodeInfo.Http) // required {@link Nodes.NodeInfo#getHttp() http}
* .httpAddress(String | null) // nullable {@link Nodes.NodeInfo#getHttpAddress() httpAddress}
* .ip(String) // required {@link Nodes.NodeInfo#getIp() ip}
* .name(String) // required {@link Nodes.NodeInfo#getName() name}
* .roles(Set<String> | null) // nullable {@link Nodes.NodeInfo#getRoles() roles}
* .transportAddress(String) // required {@link Nodes.NodeInfo#getTransportAddress() transportAddress}
* .version(String) // required {@link Nodes.NodeInfo#getVersion() version}
* .build();
*
* @return A new ImmutableNodeInfo builder
*/
public static ImmutableNodeInfo.Builder builder() {
return new ImmutableNodeInfo.Builder();
}
/**
* Builds instances of type {@link ImmutableNodeInfo ImmutableNodeInfo}.
* 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 = "Nodes.NodeInfo", generator = "Immutables")
@NotThreadSafe
@JsonIgnoreProperties(value = {"master", "data"}, allowGetters = true)
public static final class Builder {
private static final long INIT_BIT_HOST = 0x1L;
private static final long INIT_BIT_HTTP = 0x2L;
private static final long INIT_BIT_IP = 0x4L;
private static final long INIT_BIT_NAME = 0x8L;
private static final long INIT_BIT_TRANSPORT_ADDRESS = 0x10L;
private static final long INIT_BIT_VERSION = 0x20L;
private static final long OPT_BIT_ROLES = 0x1L;
private long initBits = 0x3fL;
private long optBits;
private ImmutableMap.Builder attributes = ImmutableMap.builder();
private @javax.annotation.Nullable String buildFlavor;
private @javax.annotation.Nullable String buildHash;
private @javax.annotation.Nullable String buildType;
private @javax.annotation.Nullable String host;
private @javax.annotation.Nullable Nodes.NodeInfo.Http http;
private @javax.annotation.Nullable String httpAddress;
private @javax.annotation.Nullable String ip;
private @javax.annotation.Nullable String name;
private ImmutableSet.Builder roles = null;
private @javax.annotation.Nullable String transportAddress;
private @javax.annotation.Nullable String version;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code NodeInfo} 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(Nodes.NodeInfo instance) {
Objects.requireNonNull(instance, "instance");
putAllAttributes(instance.getAttributes());
String buildFlavorValue = instance.getBuildFlavor();
if (buildFlavorValue != null) {
buildFlavor(buildFlavorValue);
}
String buildHashValue = instance.getBuildHash();
if (buildHashValue != null) {
buildHash(buildHashValue);
}
String buildTypeValue = instance.getBuildType();
if (buildTypeValue != null) {
buildType(buildTypeValue);
}
host(instance.getHost());
http(instance.getHttp());
String httpAddressValue = instance.getHttpAddress();
if (httpAddressValue != null) {
httpAddress(httpAddressValue);
}
ip(instance.getIp());
name(instance.getName());
Set rolesValue = instance.getRoles();
if (rolesValue != null) {
addAllRoles(rolesValue);
}
transportAddress(instance.getTransportAddress());
version(instance.getVersion());
return this;
}
/**
* Put one entry to the {@link Nodes.NodeInfo#getAttributes() attributes} map.
* @param key The key in the attributes map
* @param value The associated value in the attributes map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAttribute(String key, Object value) {
this.attributes.put(key, value);
return this;
}
/**
* Put one entry to the {@link Nodes.NodeInfo#getAttributes() attributes} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAttribute(Map.Entry entry) {
this.attributes.put(entry);
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link Nodes.NodeInfo#getAttributes() attributes} map. Nulls are not permitted
* @param entries The entries that will be added to the attributes map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("attributes")
public final Builder attributes(Map entries) {
this.attributes = ImmutableMap.builder();
return putAllAttributes(entries);
}
/**
* Put all mappings from the specified map as entries to {@link Nodes.NodeInfo#getAttributes() attributes} map. Nulls are not permitted
* @param entries The entries that will be added to the attributes map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllAttributes(Map entries) {
this.attributes.putAll(entries);
return this;
}
/**
* Initializes the value for the {@link Nodes.NodeInfo#getBuildFlavor() buildFlavor} attribute.
* @param buildFlavor The value for buildFlavor (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("build_flavor")
@JsonView(Views.Elastic.Version6.Version63.class)
public final Builder buildFlavor(@Nullable String buildFlavor) {
this.buildFlavor = buildFlavor;
return this;
}
/**
* Initializes the value for the {@link Nodes.NodeInfo#getBuildHash() buildHash} attribute.
* @param buildHash The value for buildHash (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("build_hash")
public final Builder buildHash(@Nullable String buildHash) {
this.buildHash = buildHash;
return this;
}
/**
* Initializes the value for the {@link Nodes.NodeInfo#getBuildType() buildType} attribute.
* @param buildType The value for buildType (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("build_type")
@JsonView(Views.Elastic.Version6.Version63.class)
public final Builder buildType(@Nullable String buildType) {
this.buildType = buildType;
return this;
}
/**
* Initializes the value for the {@link Nodes.NodeInfo#getHost() host} attribute.
* @param host The value for host
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("host")
public final Builder host(String host) {
this.host = Objects.requireNonNull(host, "host");
initBits &= ~INIT_BIT_HOST;
return this;
}
/**
* Initializes the value for the {@link Nodes.NodeInfo#getHttp() http} attribute.
* @param http The value for http
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("http")
public final Builder http(Nodes.NodeInfo.Http http) {
this.http = Objects.requireNonNull(http, "http");
initBits &= ~INIT_BIT_HTTP;
return this;
}
/**
* Initializes the value for the {@link Nodes.NodeInfo#getHttpAddress() httpAddress} attribute.
* @param httpAddress The value for httpAddress (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("http_address")
public final Builder httpAddress(@Nullable String httpAddress) {
this.httpAddress = httpAddress;
return this;
}
/**
* Initializes the value for the {@link Nodes.NodeInfo#getIp() ip} attribute.
* @param ip The value for ip
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("ip")
public final Builder ip(String ip) {
this.ip = Objects.requireNonNull(ip, "ip");
initBits &= ~INIT_BIT_IP;
return this;
}
/**
* Initializes the value for the {@link Nodes.NodeInfo#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;
}
/**
* Adds one element to {@link Nodes.NodeInfo#getRoles() roles} set.
* @param element A roles element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRole(String element) {
if (this.roles == null) {
this.roles = ImmutableSet.builder();
}
this.roles.add(element);
optBits |= OPT_BIT_ROLES;
return this;
}
/**
* Adds elements to {@link Nodes.NodeInfo#getRoles() roles} set.
* @param elements An array of roles elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRoles(String... elements) {
if (this.roles == null) {
this.roles = ImmutableSet.builder();
}
this.roles.add(elements);
optBits |= OPT_BIT_ROLES;
return this;
}
/**
* Sets or replaces all elements for {@link Nodes.NodeInfo#getRoles() roles} set.
* @param elements An iterable of roles elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("roles")
public final Builder roles(@Nullable Iterable elements) {
if (elements == null) {
this.roles = null;
optBits |= OPT_BIT_ROLES;
return this;
}
this.roles = ImmutableSet.builder();
return addAllRoles(elements);
}
/**
* Adds elements to {@link Nodes.NodeInfo#getRoles() roles} set.
* @param elements An iterable of roles elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllRoles(Iterable elements) {
Objects.requireNonNull(elements, "roles element");
if (this.roles == null) {
this.roles = ImmutableSet.builder();
}
this.roles.addAll(elements);
optBits |= OPT_BIT_ROLES;
return this;
}
/**
* Initializes the value for the {@link Nodes.NodeInfo#getTransportAddress() transportAddress} attribute.
* @param transportAddress The value for transportAddress
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("transport_address")
public final Builder transportAddress(String transportAddress) {
this.transportAddress = Objects.requireNonNull(transportAddress, "transportAddress");
initBits &= ~INIT_BIT_TRANSPORT_ADDRESS;
return this;
}
/**
* Initializes the value for the {@link Nodes.NodeInfo#getVersion() version} attribute.
* @param version The value for version
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("version")
public final Builder version(String version) {
this.version = Objects.requireNonNull(version, "version");
initBits &= ~INIT_BIT_VERSION;
return this;
}
/**
* Builds a new {@link ImmutableNodeInfo ImmutableNodeInfo}.
* @return An immutable instance of NodeInfo
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableNodeInfo build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableNodeInfo(this);
}
private boolean rolesIsSet() {
return (optBits & OPT_BIT_ROLES) != 0;
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_HOST) != 0) attributes.add("host");
if ((initBits & INIT_BIT_HTTP) != 0) attributes.add("http");
if ((initBits & INIT_BIT_IP) != 0) attributes.add("ip");
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
if ((initBits & INIT_BIT_TRANSPORT_ADDRESS) != 0) attributes.add("transportAddress");
if ((initBits & INIT_BIT_VERSION) != 0) attributes.add("version");
return "Cannot build NodeInfo, some of required attributes are not set " + attributes;
}
}
}