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

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

package com.arakelian.elastic.model.search;

import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.model.enums.GeoShapeType;
import com.arakelian.jackson.model.Coordinate;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
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.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 Shape}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableShape.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableShape implements Shape { private final ImmutableList coordinates; private final @Nullable GeoShapeType type; private ImmutableShape(ImmutableShape.Builder builder) { this.coordinates = builder.coordinates.build(); this.type = builder.type; } /** * Returns the ID of the document that containing the pre-indexed shape. * @return ID of the document that containing the pre-indexed shape. */ @JsonProperty("coordinates") @Override public ImmutableList getCoordinates() { return coordinates; } /** * @return The value of the {@code type} attribute */ @JsonProperty("type") @Override public @Nullable GeoShapeType getType() { return type; } /** * This instance is equal to all instances of {@code ImmutableShape} 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 ImmutableShape && equalTo((ImmutableShape) another); } private boolean equalTo(ImmutableShape another) { return coordinates.equals(another.coordinates) && Objects.equals(type, another.type); } /** * Computes a hash code from attributes: {@code coordinates}, {@code type}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + coordinates.hashCode(); h += (h << 5) + Objects.hashCode(type); return h; } /** * Prints the immutable value {@code Shape} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Shape") .omitNullValues() .add("coordinates", coordinates) .add("type", type) .toString(); } /** * Creates a builder for {@link ImmutableShape ImmutableShape}. * @return A new ImmutableShape builder */ public static ImmutableShape.Builder builder() { return new ImmutableShape.Builder(); } /** * Builds instances of type {@link ImmutableShape ImmutableShape}. * 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 @JsonPropertyOrder("type") public static final class Builder { private ImmutableList.Builder coordinates = ImmutableList.builder(); private @javax.annotation.Nullable GeoShapeType type; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Shape} 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(Shape instance) { Objects.requireNonNull(instance, "instance"); addAllCoordinates(instance.getCoordinates()); GeoShapeType typeValue = instance.getType(); if (typeValue != null) { type(typeValue); } return this; } /** * Adds one element to {@link Shape#getCoordinates() coordinates} list. * @param element A coordinates element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addCoordinate(Coordinate element) { this.coordinates.add(element); return this; } /** * Adds elements to {@link Shape#getCoordinates() coordinates} list. * @param elements An array of coordinates elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addCoordinates(Coordinate... elements) { this.coordinates.add(elements); return this; } /** * Sets or replaces all elements for {@link Shape#getCoordinates() coordinates} list. * @param elements An iterable of coordinates elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("coordinates") public final Builder coordinates(Iterable elements) { this.coordinates = ImmutableList.builder(); return addAllCoordinates(elements); } /** * Adds elements to {@link Shape#getCoordinates() coordinates} list. * @param elements An iterable of coordinates elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllCoordinates(Iterable elements) { this.coordinates.addAll(elements); return this; } /** * Initializes the value for the {@link Shape#getType() type} attribute. * @param type The value for type (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("type") public final Builder type(@Nullable GeoShapeType type) { this.type = type; return this; } /** * Builds a new {@link ImmutableShape ImmutableShape}. * @return An immutable instance of Shape * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableShape build() { return new ImmutableShape(this); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy