org.immutables.criteria.mongo.ImmutableMongoSetup Maven / Gradle / Ivy
package org.immutables.criteria.mongo;
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.backend.KeyExtractor;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link MongoSetup}.
*
* Use the builder to create immutable instances:
* {@code new MongoSetup.Builder()}.
* Use the static factory method to create immutable instances:
* {@code ImmutableMongoSetup.of()}.
*/
@Generated(from = "MongoSetup", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
final class ImmutableMongoSetup implements MongoSetup {
private final CollectionResolver collectionResolver;
private final KeyExtractor.Factory keyExtractorFactory;
private ImmutableMongoSetup(CollectionResolver collectionResolver) {
this.collectionResolver = Objects.requireNonNull(collectionResolver, "collectionResolver");
this.keyExtractorFactory = Objects.requireNonNull(MongoSetup.super.keyExtractorFactory(), "keyExtractorFactory");
}
private ImmutableMongoSetup(ImmutableMongoSetup.Builder builder) {
this.collectionResolver = builder.collectionResolver;
this.keyExtractorFactory = builder.keyExtractorFactory != null
? builder.keyExtractorFactory
: Objects.requireNonNull(MongoSetup.super.keyExtractorFactory(), "keyExtractorFactory");
}
private ImmutableMongoSetup(
CollectionResolver collectionResolver,
KeyExtractor.Factory keyExtractorFactory) {
this.collectionResolver = collectionResolver;
this.keyExtractorFactory = keyExtractorFactory;
}
/**
* @return The value of the {@code collectionResolver} attribute
*/
@Override
public CollectionResolver collectionResolver() {
return collectionResolver;
}
/**
* @return The value of the {@code keyExtractorFactory} attribute
*/
@Override
public KeyExtractor.Factory keyExtractorFactory() {
return keyExtractorFactory;
}
/**
* Copy the current immutable object by setting a value for the {@link MongoSetup#collectionResolver() collectionResolver} 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 collectionResolver
* @return A modified copy of the {@code this} object
*/
public final ImmutableMongoSetup withCollectionResolver(CollectionResolver value) {
if (this.collectionResolver == value) return this;
CollectionResolver newValue = Objects.requireNonNull(value, "collectionResolver");
return new ImmutableMongoSetup(newValue, this.keyExtractorFactory);
}
/**
* Copy the current immutable object by setting a value for the {@link MongoSetup#keyExtractorFactory() keyExtractorFactory} 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 keyExtractorFactory
* @return A modified copy of the {@code this} object
*/
public final ImmutableMongoSetup withKeyExtractorFactory(KeyExtractor.Factory value) {
if (this.keyExtractorFactory == value) return this;
KeyExtractor.Factory newValue = Objects.requireNonNull(value, "keyExtractorFactory");
return new ImmutableMongoSetup(this.collectionResolver, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableMongoSetup} 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 ImmutableMongoSetup
&& equalTo(0, (ImmutableMongoSetup) another);
}
private boolean equalTo(int synthetic, ImmutableMongoSetup another) {
return collectionResolver.equals(another.collectionResolver)
&& keyExtractorFactory.equals(another.keyExtractorFactory);
}
/**
* Computes a hash code from attributes: {@code collectionResolver}, {@code keyExtractorFactory}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + collectionResolver.hashCode();
h += (h << 5) + keyExtractorFactory.hashCode();
return h;
}
/**
* Prints the immutable value {@code MongoSetup} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("MongoSetup")
.omitNullValues()
.add("collectionResolver", collectionResolver)
.add("keyExtractorFactory", keyExtractorFactory)
.toString();
}
/**
* Construct a new immutable {@code MongoSetup} instance.
* @param collectionResolver The value for the {@code collectionResolver} attribute
* @return An immutable MongoSetup instance
*/
public static ImmutableMongoSetup of(CollectionResolver collectionResolver) {
return new ImmutableMongoSetup(collectionResolver);
}
/**
* Creates an immutable copy of a {@link MongoSetup} 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 MongoSetup instance
*/
public static ImmutableMongoSetup copyOf(MongoSetup instance) {
if (instance instanceof ImmutableMongoSetup) {
return (ImmutableMongoSetup) instance;
}
return new MongoSetup.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableMongoSetup ImmutableMongoSetup}.
* 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 = "MongoSetup", generator = "Immutables")
@NotThreadSafe
public static class Builder {
private static final long INIT_BIT_COLLECTION_RESOLVER = 0x1L;
private long initBits = 0x1L;
private @Nullable CollectionResolver collectionResolver;
private @Nullable KeyExtractor.Factory keyExtractorFactory;
/**
* Creates a builder for {@link ImmutableMongoSetup ImmutableMongoSetup} instances.
*
* new MongoSetup.Builder()
* .collectionResolver(org.immutables.criteria.mongo.CollectionResolver) // required {@link MongoSetup#collectionResolver() collectionResolver}
* .keyExtractorFactory(org.immutables.criteria.backend.KeyExtractor.Factory) // optional {@link MongoSetup#keyExtractorFactory() keyExtractorFactory}
* .build();
*
*/
public Builder() {
if (!(this instanceof MongoSetup.Builder)) {
throw new UnsupportedOperationException("Use: new MongoSetup.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code MongoSetup} 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 MongoSetup.Builder from(MongoSetup instance) {
Objects.requireNonNull(instance, "instance");
collectionResolver(instance.collectionResolver());
keyExtractorFactory(instance.keyExtractorFactory());
return (MongoSetup.Builder) this;
}
/**
* Initializes the value for the {@link MongoSetup#collectionResolver() collectionResolver} attribute.
* @param collectionResolver The value for collectionResolver
* @return {@code this} builder for use in a chained invocation
*/
public final MongoSetup.Builder collectionResolver(CollectionResolver collectionResolver) {
this.collectionResolver = Objects.requireNonNull(collectionResolver, "collectionResolver");
initBits &= ~INIT_BIT_COLLECTION_RESOLVER;
return (MongoSetup.Builder) this;
}
/**
* Initializes the value for the {@link MongoSetup#keyExtractorFactory() keyExtractorFactory} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link MongoSetup#keyExtractorFactory() keyExtractorFactory}.
* @param keyExtractorFactory The value for keyExtractorFactory
* @return {@code this} builder for use in a chained invocation
*/
public final MongoSetup.Builder keyExtractorFactory(KeyExtractor.Factory keyExtractorFactory) {
this.keyExtractorFactory = Objects.requireNonNull(keyExtractorFactory, "keyExtractorFactory");
return (MongoSetup.Builder) this;
}
/**
* Builds a new {@link ImmutableMongoSetup ImmutableMongoSetup}.
* @return An immutable instance of MongoSetup
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableMongoSetup build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableMongoSetup(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_COLLECTION_RESOLVER) != 0) attributes.add("collectionResolver");
return "Cannot build MongoSetup, some of required attributes are not set " + attributes;
}
}
}