edu.isi.nlp.collections.ImmutableSetMulticell Maven / Gradle / Ivy
package edu.isi.nlp.collections;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link ImmutableSetMultitable.SetMulticell}.
*
* Use the builder to create immutable instances:
* {@code new ImmutableSetMultitable.SetMulticell.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ImmutableSetMultitable.SetMulticell"})
@Immutable
final class ImmutableSetMulticell
extends ImmutableSetMultitable.SetMulticell {
private final R rowKey;
private final C columnKey;
private final ImmutableSet values;
private ImmutableSetMulticell(R rowKey, C columnKey, ImmutableSet values) {
this.rowKey = rowKey;
this.columnKey = columnKey;
this.values = values;
}
/**
* @return The value of the {@code rowKey} attribute
*/
@Override
public R getRowKey() {
return rowKey;
}
/**
* @return The value of the {@code columnKey} attribute
*/
@Override
public C getColumnKey() {
return columnKey;
}
/**
* @return The value of the {@code values} attribute
*/
@Override
public ImmutableSet getValues() {
return values;
}
/**
* Copy the current immutable object by setting a value for the {@link ImmutableSetMultitable.SetMulticell#getRowKey() rowKey} 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 rowKey
* @return A modified copy of the {@code this} object
*/
public final ImmutableSetMulticell withRowKey(R value) {
if (this.rowKey == value) return this;
R newValue = Preconditions.checkNotNull(value, "rowKey");
return new ImmutableSetMulticell(newValue, this.columnKey, this.values);
}
/**
* Copy the current immutable object by setting a value for the {@link ImmutableSetMultitable.SetMulticell#getColumnKey() columnKey} 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 columnKey
* @return A modified copy of the {@code this} object
*/
public final ImmutableSetMulticell withColumnKey(C value) {
if (this.columnKey == value) return this;
C newValue = Preconditions.checkNotNull(value, "columnKey");
return new ImmutableSetMulticell(this.rowKey, newValue, this.values);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ImmutableSetMultitable.SetMulticell#getValues() values}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
@SafeVarargs
public final ImmutableSetMulticell withValues(V... elements) {
ImmutableSet newValue = ImmutableSet.copyOf(elements);
return new ImmutableSetMulticell(this.rowKey, this.columnKey, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ImmutableSetMultitable.SetMulticell#getValues() values}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of values elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableSetMulticell withValues(Iterable extends V> elements) {
if (this.values == elements) return this;
ImmutableSet newValue = ImmutableSet.copyOf(elements);
return new ImmutableSetMulticell(this.rowKey, this.columnKey, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableSetMulticell} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@SuppressWarnings("unchecked")
@Override
public boolean equals(@Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableSetMulticell, ?, ?>
&& equalTo((ImmutableSetMulticell) another);
}
private boolean equalTo(ImmutableSetMulticell another) {
return rowKey.equals(another.rowKey)
&& columnKey.equals(another.columnKey)
&& values.equals(another.values);
}
/**
* Computes a hash code from attributes: {@code rowKey}, {@code columnKey}, {@code values}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + rowKey.hashCode();
h = h * 17 + columnKey.hashCode();
h = h * 17 + values.hashCode();
return h;
}
/**
* Prints the immutable value {@code SetMulticell} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SetMulticell")
.omitNullValues()
.add("rowKey", rowKey)
.add("columnKey", columnKey)
.add("values", values)
.toString();
}
/**
* Creates an immutable copy of a {@link ImmutableSetMultitable.SetMulticell} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param generic parameter R
* @param generic parameter C
* @param generic parameter V
* @param instance The instance to copy
* @return A copied immutable SetMulticell instance
*/
public static ImmutableSetMultitable.SetMulticell copyOf(ImmutableSetMultitable.SetMulticell instance) {
if (instance instanceof ImmutableSetMulticell, ?, ?>) {
return (ImmutableSetMulticell) instance;
}
return new ImmutableSetMultitable.SetMulticell.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableSetMultitable.SetMulticell SetMulticell}.
* 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.
*/
@NotThreadSafe
static class Builder {
private static final long INIT_BIT_ROW_KEY = 0x1L;
private static final long INIT_BIT_COLUMN_KEY = 0x2L;
private long initBits = 0x3L;
private @Nullable R rowKey;
private @Nullable C columnKey;
private ImmutableSet.Builder values = ImmutableSet.builder();
/**
* Creates a builder for {@link ImmutableSetMultitable.SetMulticell SetMulticell} instances.
*/
Builder() {
if (!(this instanceof ImmutableSetMultitable.SetMulticell.Builder, ?, ?>)) {
throw new UnsupportedOperationException("Use: new ImmutableSetMultitable.SetMulticell.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code SetMulticell} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final ImmutableSetMultitable.SetMulticell.Builder from(ImmutableSetMultitable.SetMulticell instance) {
Preconditions.checkNotNull(instance, "instance");
rowKey(instance.getRowKey());
columnKey(instance.getColumnKey());
addAllValues(instance.getValues());
return (ImmutableSetMultitable.SetMulticell.Builder) this;
}
/**
* Initializes the value for the {@link ImmutableSetMultitable.SetMulticell#getRowKey() rowKey} attribute.
* @param rowKey The value for rowKey
* @return {@code this} builder for use in a chained invocation
*/
public final ImmutableSetMultitable.SetMulticell.Builder rowKey(R rowKey) {
this.rowKey = Preconditions.checkNotNull(rowKey, "rowKey");
initBits &= ~INIT_BIT_ROW_KEY;
return (ImmutableSetMultitable.SetMulticell.Builder) this;
}
/**
* Initializes the value for the {@link ImmutableSetMultitable.SetMulticell#getColumnKey() columnKey} attribute.
* @param columnKey The value for columnKey
* @return {@code this} builder for use in a chained invocation
*/
public final ImmutableSetMultitable.SetMulticell.Builder columnKey(C columnKey) {
this.columnKey = Preconditions.checkNotNull(columnKey, "columnKey");
initBits &= ~INIT_BIT_COLUMN_KEY;
return (ImmutableSetMultitable.SetMulticell.Builder) this;
}
/**
* Adds one element to {@link ImmutableSetMultitable.SetMulticell#getValues() values} set.
* @param element A values element
* @return {@code this} builder for use in a chained invocation
*/
public final ImmutableSetMultitable.SetMulticell.Builder addValues(V element) {
this.values.add(element);
return (ImmutableSetMultitable.SetMulticell.Builder) this;
}
/**
* Adds elements to {@link ImmutableSetMultitable.SetMulticell#getValues() values} set.
* @param elements An array of values elements
* @return {@code this} builder for use in a chained invocation
*/
@SafeVarargs
public final ImmutableSetMultitable.SetMulticell.Builder addValues(V... elements) {
this.values.add(elements);
return (ImmutableSetMultitable.SetMulticell.Builder) this;
}
/**
* Sets or replaces all elements for {@link ImmutableSetMultitable.SetMulticell#getValues() values} set.
* @param elements An iterable of values elements
* @return {@code this} builder for use in a chained invocation
*/
public final ImmutableSetMultitable.SetMulticell.Builder values(Iterable extends V> elements) {
this.values = ImmutableSet.builder();
return addAllValues(elements);
}
/**
* Adds elements to {@link ImmutableSetMultitable.SetMulticell#getValues() values} set.
* @param elements An iterable of values elements
* @return {@code this} builder for use in a chained invocation
*/
public final ImmutableSetMultitable.SetMulticell.Builder addAllValues(Iterable extends V> elements) {
this.values.addAll(elements);
return (ImmutableSetMultitable.SetMulticell.Builder) this;
}
/**
* Builds a new {@link ImmutableSetMultitable.SetMulticell SetMulticell}.
* @return An immutable instance of SetMulticell
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSetMultitable.SetMulticell build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableSetMulticell(rowKey, columnKey, values.build());
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_ROW_KEY) != 0) attributes.add("rowKey");
if ((initBits & INIT_BIT_COLUMN_KEY) != 0) attributes.add("columnKey");
return "Cannot build SetMulticell, some of required attributes are not set " + attributes;
}
}
}