com.arakelian.elastic.model.search.ImmutableSource Maven / Gradle / Ivy
package com.arakelian.elastic.model.search;
import com.arakelian.jackson.MapPath;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
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.Map;
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 Source}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSource.builder()}.
*/
@Generated(from = "Source", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableSource extends Source {
private final ImmutableMap properties;
private ImmutableSource(ImmutableSource.Builder builder) {
this.properties = builder.propertiesIsSet()
? builder.properties.build()
: ImmutableMap.copyOf(super.getProperties());
}
/**
* @return The value of the {@code properties} attribute
*/
@JsonProperty("properties")
@JsonAnyGetter
@Override
public ImmutableMap getProperties() {
return properties;
}
/**
* This instance is equal to all instances of {@code ImmutableSource} 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 ImmutableSource
&& equalTo((ImmutableSource) another);
}
private boolean equalTo(ImmutableSource another) {
return properties.equals(another.properties);
}
/**
* Computes a hash code from attributes: {@code properties}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + properties.hashCode();
return h;
}
/**
* Prints the immutable value {@code Source} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Source")
.omitNullValues()
.add("properties", properties)
.toString();
}
@SuppressWarnings("Immutable")
private transient volatile long lazyInitBitmap;
private static final long MAP_PATH_LAZY_INIT_BIT = 0x1L;
@SuppressWarnings("Immutable")
private transient MapPath mapPath;
/**
* {@inheritDoc}
*
* Returns a lazily initialized value of the {@link Source#getMapPath() mapPath} 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 mapPath} attribute
*/
@Override
MapPath getMapPath() {
if ((lazyInitBitmap & MAP_PATH_LAZY_INIT_BIT) == 0) {
synchronized (this) {
if ((lazyInitBitmap & MAP_PATH_LAZY_INIT_BIT) == 0) {
this.mapPath = Objects.requireNonNull(super.getMapPath(), "mapPath");
lazyInitBitmap |= MAP_PATH_LAZY_INIT_BIT;
}
}
}
return mapPath;
}
private static final long OBJECT_MAPPER_LAZY_INIT_BIT = 0x2L;
@SuppressWarnings("Immutable")
private transient ObjectMapper objectMapper;
/**
* {@inheritDoc}
*
* Returns a lazily initialized value of the {@link Source#getObjectMapper() objectMapper} 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 objectMapper} attribute
*/
@Override
public ObjectMapper getObjectMapper() {
if ((lazyInitBitmap & OBJECT_MAPPER_LAZY_INIT_BIT) == 0) {
synchronized (this) {
if ((lazyInitBitmap & OBJECT_MAPPER_LAZY_INIT_BIT) == 0) {
this.objectMapper = Objects.requireNonNull(super.getObjectMapper(), "objectMapper");
lazyInitBitmap |= OBJECT_MAPPER_LAZY_INIT_BIT;
}
}
}
return objectMapper;
}
/**
* Creates a builder for {@link ImmutableSource ImmutableSource}.
*
* ImmutableSource.builder()
* .putProperty|putAllProperties(String => Object) // {@link Source#getProperties() properties} mappings
* .build();
*
* @return A new ImmutableSource builder
*/
public static ImmutableSource.Builder builder() {
return new ImmutableSource.Builder();
}
/**
* Builds instances of type {@link ImmutableSource ImmutableSource}.
* 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 = "Source", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long OPT_BIT_PROPERTIES = 0x1L;
private long optBits;
private ImmutableMap.Builder properties = ImmutableMap.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Source} 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(Source instance) {
Objects.requireNonNull(instance, "instance");
putAllProperties(instance.getProperties());
return this;
}
/**
* Put one entry to the {@link Source#getProperties() properties} map.
* @param key The key in the properties map
* @param value The associated value in the properties map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonAnySetter
public final Builder putProperty(String key, Object value) {
this.properties.put(key, value);
optBits |= OPT_BIT_PROPERTIES;
return this;
}
/**
* Put one entry to the {@link Source#getProperties() properties} 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 putProperty(Map.Entry entry) {
this.properties.put(entry);
optBits |= OPT_BIT_PROPERTIES;
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link Source#getProperties() properties} map. Nulls are not permitted
* @param entries The entries that will be added to the properties map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("properties")
public final Builder properties(Map entries) {
this.properties = ImmutableMap.builder();
optBits |= OPT_BIT_PROPERTIES;
return putAllProperties(entries);
}
/**
* Put all mappings from the specified map as entries to {@link Source#getProperties() properties} map. Nulls are not permitted
* @param entries The entries that will be added to the properties map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllProperties(Map entries) {
this.properties.putAll(entries);
optBits |= OPT_BIT_PROPERTIES;
return this;
}
/**
* Builds a new {@link ImmutableSource ImmutableSource}.
* @return An immutable instance of Source
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSource build() {
return new ImmutableSource(this);
}
private boolean propertiesIsSet() {
return (optBits & OPT_BIT_PROPERTIES) != 0;
}
}
}