org.immutables.criteria.backend.ImmutableWatch Maven / Gradle / Ivy
package org.immutables.criteria.backend;
import com.google.common.base.MoreObjects;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.criteria.expression.Query;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link StandardOperations.Watch}.
*
* Use the builder to create immutable instances:
* {@code ImmutableWatch.builder()}.
* Use the static factory method to create immutable instances:
* {@code ImmutableWatch.of()}.
*/
@Generated(from = "StandardOperations.Watch", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class ImmutableWatch implements StandardOperations.Watch {
private final Query query;
private ImmutableWatch(Query query) {
this.query = Objects.requireNonNull(query, "query");
}
private ImmutableWatch(ImmutableWatch original, Query query) {
this.query = query;
}
/**
* @return The value of the {@code query} attribute
*/
@Override
public Query query() {
return query;
}
/**
* Copy the current immutable object by setting a value for the {@link StandardOperations.Watch#query() query} 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 query
* @return A modified copy of the {@code this} object
*/
public final ImmutableWatch withQuery(Query value) {
if (this.query == value) return this;
Query newValue = Objects.requireNonNull(value, "query");
return new ImmutableWatch(this, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableWatch} 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 ImmutableWatch
&& equalTo((ImmutableWatch) another);
}
private boolean equalTo(ImmutableWatch another) {
return query.equals(another.query);
}
/**
* Computes a hash code from attributes: {@code query}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + query.hashCode();
return h;
}
/**
* Prints the immutable value {@code Watch} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Watch")
.omitNullValues()
.add("query", query)
.toString();
}
/**
* Construct a new immutable {@code Watch} instance.
* @param query The value for the {@code query} attribute
* @return An immutable Watch instance
*/
public static ImmutableWatch of(Query query) {
return new ImmutableWatch(query);
}
/**
* Creates an immutable copy of a {@link StandardOperations.Watch} 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 Watch instance
*/
public static ImmutableWatch copyOf(StandardOperations.Watch instance) {
if (instance instanceof ImmutableWatch) {
return (ImmutableWatch) instance;
}
return ImmutableWatch.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableWatch ImmutableWatch}.
*
* ImmutableWatch.builder()
* .query(org.immutables.criteria.expression.Query) // required {@link StandardOperations.Watch#query() query}
* .build();
*
* @return A new ImmutableWatch builder
*/
public static ImmutableWatch.Builder builder() {
return new ImmutableWatch.Builder();
}
/**
* Builds instances of type {@link ImmutableWatch ImmutableWatch}.
* 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 = "StandardOperations.Watch", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_QUERY = 0x1L;
private long initBits = 0x1L;
private @Nullable Query query;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Watch} 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
*/
public final Builder from(StandardOperations.Watch instance) {
Objects.requireNonNull(instance, "instance");
query(instance.query());
return this;
}
/**
* Initializes the value for the {@link StandardOperations.Watch#query() query} attribute.
* @param query The value for query
* @return {@code this} builder for use in a chained invocation
*/
public final Builder query(Query query) {
this.query = Objects.requireNonNull(query, "query");
initBits &= ~INIT_BIT_QUERY;
return this;
}
/**
* Builds a new {@link ImmutableWatch ImmutableWatch}.
* @return An immutable instance of Watch
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableWatch build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableWatch(null, query);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_QUERY) != 0) attributes.add("query");
return "Cannot build Watch, some of required attributes are not set " + attributes;
}
}
}