io.resys.thena.docdb.api.actions.ImmutableMatchCriteria Maven / Gradle / Ivy
package io.resys.thena.docdb.api.actions;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.time.LocalDateTime;
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 ObjectsActions.MatchCriteria}.
*
* Use the builder to create immutable instances:
* {@code ImmutableMatchCriteria.builder()}.
*/
@Generated(from = "ObjectsActions.MatchCriteria", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableMatchCriteria
implements ObjectsActions.MatchCriteria {
private final ObjectsActions.MatchCriteriaType type;
private final String key;
private final @Nullable String value;
private final @Nullable LocalDateTime targetDate;
private ImmutableMatchCriteria(
ObjectsActions.MatchCriteriaType type,
String key,
@Nullable String value,
@Nullable LocalDateTime targetDate) {
this.type = type;
this.key = key;
this.value = value;
this.targetDate = targetDate;
}
/**
* @return The value of the {@code type} attribute
*/
@Override
public ObjectsActions.MatchCriteriaType getType() {
return type;
}
/**
* @return The value of the {@code key} attribute
*/
@Override
public String getKey() {
return key;
}
/**
* @return The value of the {@code value} attribute
*/
@Override
public @Nullable String getValue() {
return value;
}
/**
* @return The value of the {@code targetDate} attribute
*/
@Override
public @Nullable LocalDateTime getTargetDate() {
return targetDate;
}
/**
* Copy the current immutable object by setting a value for the {@link ObjectsActions.MatchCriteria#getType() type} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for type
* @return A modified copy of the {@code this} object
*/
public final ImmutableMatchCriteria withType(ObjectsActions.MatchCriteriaType value) {
ObjectsActions.MatchCriteriaType newValue = Objects.requireNonNull(value, "type");
if (this.type == newValue) return this;
return new ImmutableMatchCriteria(newValue, this.key, this.value, this.targetDate);
}
/**
* Copy the current immutable object by setting a value for the {@link ObjectsActions.MatchCriteria#getKey() key} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for key
* @return A modified copy of the {@code this} object
*/
public final ImmutableMatchCriteria withKey(String value) {
String newValue = Objects.requireNonNull(value, "key");
if (this.key.equals(newValue)) return this;
return new ImmutableMatchCriteria(this.type, newValue, this.value, this.targetDate);
}
/**
* Copy the current immutable object by setting a value for the {@link ObjectsActions.MatchCriteria#getValue() value} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for value (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableMatchCriteria withValue(@Nullable String value) {
if (Objects.equals(this.value, value)) return this;
return new ImmutableMatchCriteria(this.type, this.key, value, this.targetDate);
}
/**
* Copy the current immutable object by setting a value for the {@link ObjectsActions.MatchCriteria#getTargetDate() targetDate} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for targetDate (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableMatchCriteria withTargetDate(@Nullable LocalDateTime value) {
if (this.targetDate == value) return this;
return new ImmutableMatchCriteria(this.type, this.key, this.value, value);
}
/**
* This instance is equal to all instances of {@code ImmutableMatchCriteria} 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 ImmutableMatchCriteria
&& equalTo(0, (ImmutableMatchCriteria) another);
}
private boolean equalTo(int synthetic, ImmutableMatchCriteria another) {
return type.equals(another.type)
&& key.equals(another.key)
&& Objects.equals(value, another.value)
&& Objects.equals(targetDate, another.targetDate);
}
/**
* Computes a hash code from attributes: {@code type}, {@code key}, {@code value}, {@code targetDate}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + type.hashCode();
h += (h << 5) + key.hashCode();
h += (h << 5) + Objects.hashCode(value);
h += (h << 5) + Objects.hashCode(targetDate);
return h;
}
/**
* Prints the immutable value {@code MatchCriteria} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("MatchCriteria")
.omitNullValues()
.add("type", type)
.add("key", key)
.add("value", value)
.add("targetDate", targetDate)
.toString();
}
/**
* Creates an immutable copy of a {@link ObjectsActions.MatchCriteria} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance The instance to copy
* @return A copied immutable MatchCriteria instance
*/
public static ImmutableMatchCriteria copyOf(ObjectsActions.MatchCriteria instance) {
if (instance instanceof ImmutableMatchCriteria) {
return (ImmutableMatchCriteria) instance;
}
return ImmutableMatchCriteria.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableMatchCriteria ImmutableMatchCriteria}.
*
* ImmutableMatchCriteria.builder()
* .type(io.resys.thena.docdb.api.actions.ObjectsActions.MatchCriteriaType) // required {@link ObjectsActions.MatchCriteria#getType() type}
* .key(String) // required {@link ObjectsActions.MatchCriteria#getKey() key}
* .value(String | null) // nullable {@link ObjectsActions.MatchCriteria#getValue() value}
* .targetDate(java.time.LocalDateTime | null) // nullable {@link ObjectsActions.MatchCriteria#getTargetDate() targetDate}
* .build();
*
* @return A new ImmutableMatchCriteria builder
*/
public static ImmutableMatchCriteria.Builder builder() {
return new ImmutableMatchCriteria.Builder();
}
/**
* Builds instances of type {@link ImmutableMatchCriteria ImmutableMatchCriteria}.
* 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 = "ObjectsActions.MatchCriteria", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_TYPE = 0x1L;
private static final long INIT_BIT_KEY = 0x2L;
private long initBits = 0x3L;
private @Nullable ObjectsActions.MatchCriteriaType type;
private @Nullable String key;
private @Nullable String value;
private @Nullable LocalDateTime targetDate;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code MatchCriteria} 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(ObjectsActions.MatchCriteria instance) {
Objects.requireNonNull(instance, "instance");
this.type(instance.getType());
this.key(instance.getKey());
@Nullable String valueValue = instance.getValue();
if (valueValue != null) {
value(valueValue);
}
@Nullable LocalDateTime targetDateValue = instance.getTargetDate();
if (targetDateValue != null) {
targetDate(targetDateValue);
}
return this;
}
/**
* Initializes the value for the {@link ObjectsActions.MatchCriteria#getType() type} attribute.
* @param type The value for type
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder type(ObjectsActions.MatchCriteriaType type) {
this.type = Objects.requireNonNull(type, "type");
initBits &= ~INIT_BIT_TYPE;
return this;
}
/**
* Initializes the value for the {@link ObjectsActions.MatchCriteria#getKey() key} attribute.
* @param key The value for key
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder key(String key) {
this.key = Objects.requireNonNull(key, "key");
initBits &= ~INIT_BIT_KEY;
return this;
}
/**
* Initializes the value for the {@link ObjectsActions.MatchCriteria#getValue() value} attribute.
* @param value The value for value (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder value(@Nullable String value) {
this.value = value;
return this;
}
/**
* Initializes the value for the {@link ObjectsActions.MatchCriteria#getTargetDate() targetDate} attribute.
* @param targetDate The value for targetDate (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder targetDate(@Nullable LocalDateTime targetDate) {
this.targetDate = targetDate;
return this;
}
/**
* Builds a new {@link ImmutableMatchCriteria ImmutableMatchCriteria}.
* @return An immutable instance of MatchCriteria
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableMatchCriteria build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableMatchCriteria(type, key, value, targetDate);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type");
if ((initBits & INIT_BIT_KEY) != 0) attributes.add("key");
return "Cannot build MatchCriteria, some of required attributes are not set " + attributes;
}
}
}