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

io.stargate.web.docsapi.service.query.condition.impl.ImmutableStringCondition Maven / Gradle / Ivy

The newest version!
package io.stargate.web.docsapi.service.query.condition.impl;

import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.stargate.web.docsapi.service.query.filter.operation.ValueFilterOperation;
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 StringCondition}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableStringCondition.builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableStringCondition.of()}. */ @Generated(from = "StringCondition", generator = "Immutables") @SuppressWarnings({"all"}) @SuppressFBWarnings @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableStringCondition extends StringCondition { private final ValueFilterOperation filterOperation; private final String queryValue; private ImmutableStringCondition( ValueFilterOperation filterOperation, String queryValue) { this.filterOperation = Objects.requireNonNull(filterOperation, "filterOperation"); this.queryValue = Objects.requireNonNull(queryValue, "queryValue"); } private ImmutableStringCondition( ImmutableStringCondition original, ValueFilterOperation filterOperation, String queryValue) { this.filterOperation = filterOperation; this.queryValue = queryValue; } /** *@return Predicate for the condition. */ @Override public ValueFilterOperation getFilterOperation() { return filterOperation; } /** *@return Filter query value. */ @Override public String getQueryValue() { return queryValue; } /** * Copy the current immutable object by setting a value for the {@link StringCondition#getFilterOperation() filterOperation} 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 filterOperation * @return A modified copy of the {@code this} object */ public final ImmutableStringCondition withFilterOperation(ValueFilterOperation value) { if (this.filterOperation == value) return this; ValueFilterOperation newValue = Objects.requireNonNull(value, "filterOperation"); return validate(new ImmutableStringCondition(this, newValue, this.queryValue)); } /** * Copy the current immutable object by setting a value for the {@link StringCondition#getQueryValue() queryValue} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for queryValue * @return A modified copy of the {@code this} object */ public final ImmutableStringCondition withQueryValue(String value) { String newValue = Objects.requireNonNull(value, "queryValue"); if (this.queryValue.equals(newValue)) return this; return validate(new ImmutableStringCondition(this, this.filterOperation, newValue)); } /** * This instance is equal to all instances of {@code ImmutableStringCondition} 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 ImmutableStringCondition && equalTo((ImmutableStringCondition) another); } private boolean equalTo(ImmutableStringCondition another) { return filterOperation.equals(another.filterOperation) && queryValue.equals(another.queryValue); } /** * Computes a hash code from attributes: {@code filterOperation}, {@code queryValue}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + filterOperation.hashCode(); h += (h << 5) + queryValue.hashCode(); return h; } /** * Prints the immutable value {@code StringCondition} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("StringCondition") .omitNullValues() .add("filterOperation", filterOperation) .add("queryValue", queryValue) .toString(); } /** * Construct a new immutable {@code StringCondition} instance. * @param filterOperation The value for the {@code filterOperation} attribute * @param queryValue The value for the {@code queryValue} attribute * @return An immutable StringCondition instance */ public static ImmutableStringCondition of(ValueFilterOperation filterOperation, String queryValue) { return validate(new ImmutableStringCondition(filterOperation, queryValue)); } private static ImmutableStringCondition validate(ImmutableStringCondition instance) { instance.validate(); return instance; } /** * Creates an immutable copy of a {@link StringCondition} 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 StringCondition instance */ public static ImmutableStringCondition copyOf(StringCondition instance) { if (instance instanceof ImmutableStringCondition) { return (ImmutableStringCondition) instance; } return ImmutableStringCondition.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableStringCondition ImmutableStringCondition}. *

   * ImmutableStringCondition.builder()
   *    .filterOperation(io.stargate.web.docsapi.service.query.filter.operation.ValueFilterOperation) // required {@link StringCondition#getFilterOperation() filterOperation}
   *    .queryValue(String) // required {@link StringCondition#getQueryValue() queryValue}
   *    .build();
   * 
* @return A new ImmutableStringCondition builder */ public static ImmutableStringCondition.Builder builder() { return new ImmutableStringCondition.Builder(); } /** * Builds instances of type {@link ImmutableStringCondition ImmutableStringCondition}. * 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 = "StringCondition", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_FILTER_OPERATION = 0x1L; private static final long INIT_BIT_QUERY_VALUE = 0x2L; private long initBits = 0x3L; private @Nullable ValueFilterOperation filterOperation; private @Nullable String queryValue; private Builder() { } /** * Fill a builder with attribute values from the provided {@code StringCondition} 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(StringCondition instance) { Objects.requireNonNull(instance, "instance"); filterOperation(instance.getFilterOperation()); queryValue(instance.getQueryValue()); return this; } /** * Initializes the value for the {@link StringCondition#getFilterOperation() filterOperation} attribute. * @param filterOperation The value for filterOperation * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder filterOperation(ValueFilterOperation filterOperation) { this.filterOperation = Objects.requireNonNull(filterOperation, "filterOperation"); initBits &= ~INIT_BIT_FILTER_OPERATION; return this; } /** * Initializes the value for the {@link StringCondition#getQueryValue() queryValue} attribute. * @param queryValue The value for queryValue * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder queryValue(String queryValue) { this.queryValue = Objects.requireNonNull(queryValue, "queryValue"); initBits &= ~INIT_BIT_QUERY_VALUE; return this; } /** * Builds a new {@link ImmutableStringCondition ImmutableStringCondition}. * @return An immutable instance of StringCondition * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableStringCondition build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return ImmutableStringCondition.validate(new ImmutableStringCondition(null, filterOperation, queryValue)); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_FILTER_OPERATION) != 0) attributes.add("filterOperation"); if ((initBits & INIT_BIT_QUERY_VALUE) != 0) attributes.add("queryValue"); return "Cannot build StringCondition, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy