com.arakelian.elastic.model.ImmutableJsonSelector Maven / Gradle / Ivy
package com.arakelian.elastic.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link JsonSelector}.
*
* Use the builder to create immutable instances:
* {@code ImmutableJsonSelector.builder()}.
*/
@Generated(from = "JsonSelector", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableJsonSelector extends JsonSelector {
private final String selector;
private ImmutableJsonSelector(ImmutableJsonSelector.Builder builder) {
this.selector = builder.selector;
}
/**
* @return The value of the {@code selector} attribute
*/
@JsonProperty("selector")
@Override
public String getSelector() {
return selector;
}
/**
* This instance is equal to all instances of {@code ImmutableJsonSelector} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableJsonSelector
&& equalTo((ImmutableJsonSelector) another);
}
private boolean equalTo(ImmutableJsonSelector another) {
return selector.equals(another.selector);
}
/**
* Computes a hash code from attributes: {@code selector}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + selector.hashCode();
return h;
}
/**
* Prints the immutable value {@code JsonSelector} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("JsonSelector")
.omitNullValues()
.add("selector", selector)
.toString();
}
@SuppressWarnings("Immutable")
private transient volatile long lazyInitBitmap;
private static final long JSON_PATH_LAZY_INIT_BIT = 0x1L;
@SuppressWarnings("Immutable")
private transient JsonPath jsonPath;
/**
* {@inheritDoc}
*
* Returns a lazily initialized value of the {@link JsonSelector#getJsonPath() jsonPath} attribute.
* Initialized once and only once and stored for subsequent access with proper synchronization.
* In case of any exception or error thrown by the lazy value initializer,
* the result will not be memoised (i.e. remembered) and on next call computation
* will be attempted again.
* @return A lazily initialized value of the {@code jsonPath} attribute
*/
@Override
public JsonPath getJsonPath() {
if ((lazyInitBitmap & JSON_PATH_LAZY_INIT_BIT) == 0) {
synchronized (this) {
if ((lazyInitBitmap & JSON_PATH_LAZY_INIT_BIT) == 0) {
this.jsonPath = Objects.requireNonNull(super.getJsonPath(), "jsonPath");
lazyInitBitmap |= JSON_PATH_LAZY_INIT_BIT;
}
}
}
return jsonPath;
}
private static final long CONFIGURATION_LAZY_INIT_BIT = 0x2L;
@SuppressWarnings("Immutable")
private transient Configuration configuration;
/**
* {@inheritDoc}
*
* Returns a lazily initialized value of the {@link JsonSelector#getConfiguration() configuration} attribute.
* Initialized once and only once and stored for subsequent access with proper synchronization.
* In case of any exception or error thrown by the lazy value initializer,
* the result will not be memoised (i.e. remembered) and on next call computation
* will be attempted again.
* @return A lazily initialized value of the {@code configuration} attribute
*/
@Override
public Configuration getConfiguration() {
if ((lazyInitBitmap & CONFIGURATION_LAZY_INIT_BIT) == 0) {
synchronized (this) {
if ((lazyInitBitmap & CONFIGURATION_LAZY_INIT_BIT) == 0) {
this.configuration = Objects.requireNonNull(super.getConfiguration(), "configuration");
lazyInitBitmap |= CONFIGURATION_LAZY_INIT_BIT;
}
}
}
return configuration;
}
/**
* Creates a builder for {@link ImmutableJsonSelector ImmutableJsonSelector}.
*
* ImmutableJsonSelector.builder()
* .selector(String) // required {@link JsonSelector#getSelector() selector}
* .build();
*
* @return A new ImmutableJsonSelector builder
*/
public static ImmutableJsonSelector.Builder builder() {
return new ImmutableJsonSelector.Builder();
}
/**
* Builds instances of type {@link ImmutableJsonSelector ImmutableJsonSelector}.
* 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 = "JsonSelector", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_SELECTOR = 0x1L;
private long initBits = 0x1L;
private @Nullable String selector;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code JsonSelector} 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(JsonSelector instance) {
Objects.requireNonNull(instance, "instance");
selector(instance.getSelector());
return this;
}
/**
* Initializes the value for the {@link JsonSelector#getSelector() selector} attribute.
* @param selector The value for selector
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("selector")
public final Builder selector(String selector) {
this.selector = Objects.requireNonNull(selector, "selector");
initBits &= ~INIT_BIT_SELECTOR;
return this;
}
/**
* Builds a new {@link ImmutableJsonSelector ImmutableJsonSelector}.
* @return An immutable instance of JsonSelector
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableJsonSelector build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableJsonSelector(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_SELECTOR) != 0) attributes.add("selector");
return "Cannot build JsonSelector, some of required attributes are not set " + attributes;
}
}
}