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

com.arakelian.elastic.model.search.ImmutableTotal Maven / Gradle / Ivy

package com.arakelian.elastic.model.search;

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.primitives.Longs;
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.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link SearchHits.Total}.
 * 

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

   * ImmutableTotal.builder()
   *    .relation(com.arakelian.elastic.model.search.SearchHits.Relation | null) // nullable {@link SearchHits.Total#getRelation() relation}
   *    .value(long) // required {@link SearchHits.Total#getValue() value}
   *    .build();
   * 
* @return A new ImmutableTotal builder */ public static ImmutableTotal.Builder builder() { return new ImmutableTotal.Builder(); } /** * Builds instances of type {@link ImmutableTotal ImmutableTotal}. * 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 = "SearchHits.Total", generator = "Immutables") @NotThreadSafe @JsonPropertyOrder({"total", "relation"}) public static final class Builder { private static final long INIT_BIT_VALUE = 0x1L; private long initBits = 0x1L; private @javax.annotation.Nullable SearchHits.Relation relation; private long value; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Total} 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(SearchHits.Total instance) { Objects.requireNonNull(instance, "instance"); SearchHits.Relation relationValue = instance.getRelation(); if (relationValue != null) { relation(relationValue); } value(instance.getValue()); return this; } /** * Initializes the value for the {@link SearchHits.Total#getRelation() relation} attribute. * @param relation The value for relation (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("relation") public final Builder relation(@Nullable SearchHits.Relation relation) { this.relation = relation; return this; } /** * Initializes the value for the {@link SearchHits.Total#getValue() value} attribute. * @param value The value for value * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("value") public final Builder value(long value) { this.value = value; initBits &= ~INIT_BIT_VALUE; return this; } /** * Builds a new {@link ImmutableTotal ImmutableTotal}. * @return An immutable instance of Total * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableTotal build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableTotal(this); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_VALUE) != 0) attributes.add("value"); return "Cannot build Total, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy