com.arakelian.elastic.model.ImmutableDocuments Maven / Gradle / Ivy
package com.arakelian.elastic.model;
import com.arakelian.core.feature.Nullable;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link Documents}.
*
* Use the builder to create immutable instances:
* {@code ImmutableDocuments.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableDocuments implements Documents {
private final @Nullable ImmutableList docs;
private ImmutableDocuments(ImmutableDocuments.Builder builder) {
this.docs = builder.docs == null ? null : builder.docs.build();
}
/**
* @return The value of the {@code docs} attribute
*/
@JsonProperty("docs")
@Override
public @Nullable ImmutableList getDocs() {
return docs;
}
/**
* This instance is equal to all instances of {@code ImmutableDocuments} 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 ImmutableDocuments
&& equalTo((ImmutableDocuments) another);
}
private boolean equalTo(ImmutableDocuments another) {
return Objects.equals(docs, another.docs);
}
/**
* Computes a hash code from attributes: {@code docs}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(docs);
return h;
}
/**
* Prints the immutable value {@code Documents} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Documents")
.omitNullValues()
.add("docs", docs)
.toString();
}
/**
* Creates a builder for {@link ImmutableDocuments ImmutableDocuments}.
* @return A new ImmutableDocuments builder
*/
public static ImmutableDocuments.Builder builder() {
return new ImmutableDocuments.Builder();
}
/**
* Builds instances of type {@link ImmutableDocuments ImmutableDocuments}.
* 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.
*/
@NotThreadSafe
public static final class Builder {
private ImmutableList.Builder docs = null;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Documents} 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(Documents instance) {
Objects.requireNonNull(instance, "instance");
List docsValue = instance.getDocs();
if (docsValue != null) {
addAllDocs(docsValue);
}
return this;
}
/**
* Adds one element to {@link Documents#getDocs() docs} list.
* @param element A docs element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addDoc(Document element) {
if (this.docs == null) {
this.docs = ImmutableList.builder();
}
this.docs.add(element);
return this;
}
/**
* Adds elements to {@link Documents#getDocs() docs} list.
* @param elements An array of docs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addDocs(Document... elements) {
if (this.docs == null) {
this.docs = ImmutableList.builder();
}
this.docs.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link Documents#getDocs() docs} list.
* @param elements An iterable of docs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("docs")
public final Builder docs(@Nullable Iterable extends Document> elements) {
if (elements == null) {
this.docs = null;
return this;
}
this.docs = ImmutableList.builder();
return addAllDocs(elements);
}
/**
* Adds elements to {@link Documents#getDocs() docs} list.
* @param elements An iterable of docs elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllDocs(Iterable extends Document> elements) {
Objects.requireNonNull(elements, "docs element");
if (this.docs == null) {
this.docs = ImmutableList.builder();
}
this.docs.addAll(elements);
return this;
}
/**
* Builds a new {@link ImmutableDocuments ImmutableDocuments}.
* @return An immutable instance of Documents
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableDocuments build() {
return new ImmutableDocuments(this);
}
}
}