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

org.immutables.criteria.backend.ImmutableSelect 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.Select}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableSelect.builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableSelect.of()}. */ @Generated(from = "StandardOperations.Select", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @Immutable public final class ImmutableSelect implements StandardOperations.Select { private final Query query; private ImmutableSelect(Query query) { this.query = Objects.requireNonNull(query, "query"); } private ImmutableSelect(ImmutableSelect 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.Select#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 ImmutableSelect withQuery(Query value) { if (this.query == value) return this; Query newValue = Objects.requireNonNull(value, "query"); return new ImmutableSelect(this, newValue); } /** * This instance is equal to all instances of {@code ImmutableSelect} 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 ImmutableSelect && equalTo((ImmutableSelect) another); } private boolean equalTo(ImmutableSelect 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 Select} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Select") .omitNullValues() .add("query", query) .toString(); } /** * Construct a new immutable {@code Select} instance. * @param query The value for the {@code query} attribute * @return An immutable Select instance */ public static ImmutableSelect of(Query query) { return new ImmutableSelect(query); } /** * Creates an immutable copy of a {@link StandardOperations.Select} 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 Select instance */ public static ImmutableSelect copyOf(StandardOperations.Select instance) { if (instance instanceof ImmutableSelect) { return (ImmutableSelect) instance; } return ImmutableSelect.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableSelect ImmutableSelect}. *

   * ImmutableSelect.builder()
   *    .query(org.immutables.criteria.expression.Query) // required {@link StandardOperations.Select#query() query}
   *    .build();
   * 
* @return A new ImmutableSelect builder */ public static ImmutableSelect.Builder builder() { return new ImmutableSelect.Builder(); } /** * Builds instances of type {@link ImmutableSelect ImmutableSelect}. * 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.Select", 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 Select} 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.Select instance) { Objects.requireNonNull(instance, "instance"); query(instance.query()); return this; } /** * Initializes the value for the {@link StandardOperations.Select#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 ImmutableSelect ImmutableSelect}. * @return An immutable instance of Select * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableSelect build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableSelect(null, query); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_QUERY) != 0) attributes.add("query"); return "Cannot build Select, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy