All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arakelian.elastic.model.ImmutableNodes Maven / Gradle / Ivy

package com.arakelian.elastic.model;

import com.arakelian.core.feature.Nullable;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
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 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}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableNodes.builder()}. */ @Generated(from = "Nodes", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableNodes implements Nodes { private final String clusterName; private final ImmutableMap nodes; private final @Nullable Shards shards; private ImmutableNodes(ImmutableNodes.Builder builder) { this.clusterName = builder.clusterName; this.nodes = builder.nodes.build(); this.shards = builder.shards; } /** * @return The value of the {@code clusterName} attribute */ @JsonProperty("cluster_name") @Override public String getClusterName() { return clusterName; } /** * @return The value of the {@code nodes} attribute */ @JsonProperty("nodes") @Override public ImmutableMap getNodes() { return nodes; } /** * @return The value of the {@code shards} attribute */ @JsonProperty("_nodes") @Override public @Nullable Shards getShards() { return shards; } /** * This instance is equal to all instances of {@code ImmutableNodes} 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 ImmutableNodes && equalTo((ImmutableNodes) another); } private boolean equalTo(ImmutableNodes another) { return clusterName.equals(another.clusterName) && nodes.equals(another.nodes) && Objects.equals(shards, another.shards); } /** * Computes a hash code from attributes: {@code clusterName}, {@code nodes}, {@code shards}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + clusterName.hashCode(); h += (h << 5) + nodes.hashCode(); h += (h << 5) + Objects.hashCode(shards); return h; } /** * Prints the immutable value {@code Nodes} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Nodes") .omitNullValues() .add("clusterName", clusterName) .add("nodes", nodes) .add("shards", shards) .toString(); } /** * Creates a builder for {@link ImmutableNodes ImmutableNodes}. *

   * ImmutableNodes.builder()
   *    .clusterName(String) // required {@link Nodes#getClusterName() clusterName}
   *    .putNode|putAllNodes(String => com.arakelian.elastic.model.Nodes.NodeInfo) // {@link Nodes#getNodes() nodes} mappings
   *    .shards(com.arakelian.elastic.model.Shards | null) // nullable {@link Nodes#getShards() shards}
   *    .build();
   * 
* @return A new ImmutableNodes builder */ public static ImmutableNodes.Builder builder() { return new ImmutableNodes.Builder(); } /** * Builds instances of type {@link ImmutableNodes ImmutableNodes}. * 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", generator = "Immutables") @NotThreadSafe @JsonPropertyOrder({"_nodes", "cluster_name", "nodes"}) public static final class Builder { private static final long INIT_BIT_CLUSTER_NAME = 0x1L; private long initBits = 0x1L; private @javax.annotation.Nullable String clusterName; private ImmutableMap.Builder nodes = ImmutableMap.builder(); private @javax.annotation.Nullable Shards shards; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Nodes} 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 instance) { Objects.requireNonNull(instance, "instance"); clusterName(instance.getClusterName()); putAllNodes(instance.getNodes()); Shards shardsValue = instance.getShards(); if (shardsValue != null) { shards(shardsValue); } return this; } /** * Initializes the value for the {@link Nodes#getClusterName() clusterName} attribute. * @param clusterName The value for clusterName * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("cluster_name") public final Builder clusterName(String clusterName) { this.clusterName = Objects.requireNonNull(clusterName, "clusterName"); initBits &= ~INIT_BIT_CLUSTER_NAME; return this; } /** * Put one entry to the {@link Nodes#getNodes() nodes} map. * @param key The key in the nodes map * @param value The associated value in the nodes map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putNode(String key, Nodes.NodeInfo value) { this.nodes.put(key, value); return this; } /** * Put one entry to the {@link Nodes#getNodes() nodes} 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 putNode(Map.Entry entry) { this.nodes.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link Nodes#getNodes() nodes} map. Nulls are not permitted * @param entries The entries that will be added to the nodes map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("nodes") public final Builder nodes(Map entries) { this.nodes = ImmutableMap.builder(); return putAllNodes(entries); } /** * Put all mappings from the specified map as entries to {@link Nodes#getNodes() nodes} map. Nulls are not permitted * @param entries The entries that will be added to the nodes map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putAllNodes(Map entries) { this.nodes.putAll(entries); return this; } /** * Initializes the value for the {@link Nodes#getShards() shards} attribute. * @param shards The value for shards (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("_nodes") public final Builder shards(@Nullable Shards shards) { this.shards = shards; return this; } /** * Builds a new {@link ImmutableNodes ImmutableNodes}. * @return An immutable instance of Nodes * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableNodes build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableNodes(this); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_CLUSTER_NAME) != 0) attributes.add("clusterName"); return "Cannot build Nodes, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy