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

edu.isi.nlp.collections.ImmutableRowKeyColumnKeyPair Maven / Gradle / Ivy

The newest version!
package edu.isi.nlp.collections;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
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 ImmutableMultitable.RowKeyColumnKeyPair}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableRowKeyColumnKeyPair.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "ImmutableMultitable.RowKeyColumnKeyPair"}) @Immutable final class ImmutableRowKeyColumnKeyPair extends ImmutableMultitable.RowKeyColumnKeyPair { private final R row; private final C column; private ImmutableRowKeyColumnKeyPair(R row, C column) { this.row = row; this.column = column; } /** * @return The value of the {@code row} attribute */ @Override public R row() { return row; } /** * @return The value of the {@code column} attribute */ @Override public C column() { return column; } /** * Copy the current immutable object by setting a value for the {@link ImmutableMultitable.RowKeyColumnKeyPair#row() row} 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 row * @return A modified copy of the {@code this} object */ public final ImmutableRowKeyColumnKeyPair withRow(R value) { if (this.row == value) return this; R newValue = Preconditions.checkNotNull(value, "row"); return new ImmutableRowKeyColumnKeyPair(newValue, this.column); } /** * Copy the current immutable object by setting a value for the {@link ImmutableMultitable.RowKeyColumnKeyPair#column() column} 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 column * @return A modified copy of the {@code this} object */ public final ImmutableRowKeyColumnKeyPair withColumn(C value) { if (this.column == value) return this; C newValue = Preconditions.checkNotNull(value, "column"); return new ImmutableRowKeyColumnKeyPair(this.row, newValue); } /** * This instance is equal to all instances of {@code ImmutableRowKeyColumnKeyPair} 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 ImmutableRowKeyColumnKeyPair && equalTo((ImmutableRowKeyColumnKeyPair) another); } private boolean equalTo(ImmutableRowKeyColumnKeyPair another) { return row.equals(another.row) && column.equals(another.column); } /** * Computes a hash code from attributes: {@code row}, {@code column}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + row.hashCode(); h = h * 17 + column.hashCode(); return h; } /** * Prints the immutable value {@code RowKeyColumnKeyPair} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("RowKeyColumnKeyPair") .omitNullValues() .add("row", row) .add("column", column) .toString(); } /** * Creates an immutable copy of a {@link ImmutableMultitable.RowKeyColumnKeyPair} 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 instance The instance to copy * @return A copied immutable RowKeyColumnKeyPair instance */ public static ImmutableMultitable.RowKeyColumnKeyPair copyOf(ImmutableMultitable.RowKeyColumnKeyPair instance) { if (instance instanceof ImmutableRowKeyColumnKeyPair) { return (ImmutableRowKeyColumnKeyPair) instance; } return ImmutableRowKeyColumnKeyPair.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableMultitable.RowKeyColumnKeyPair RowKeyColumnKeyPair}. * @param generic parameter R * @param generic parameter C * @return A new RowKeyColumnKeyPair builder */ public static ImmutableRowKeyColumnKeyPair.Builder builder() { return new ImmutableRowKeyColumnKeyPair.Builder(); } /** * Builds instances of type {@link ImmutableMultitable.RowKeyColumnKeyPair RowKeyColumnKeyPair}. * 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 final class Builder { private static final long INIT_BIT_ROW = 0x1L; private static final long INIT_BIT_COLUMN = 0x2L; private long initBits = 0x3L; private @Nullable R row; private @Nullable C column; private Builder() { } /** * Fill a builder with attribute values from the provided {@code RowKeyColumnKeyPair} 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(ImmutableMultitable.RowKeyColumnKeyPair instance) { Preconditions.checkNotNull(instance, "instance"); row(instance.row()); column(instance.column()); return this; } /** * Initializes the value for the {@link ImmutableMultitable.RowKeyColumnKeyPair#row() row} attribute. * @param row The value for row * @return {@code this} builder for use in a chained invocation */ public final Builder row(R row) { this.row = Preconditions.checkNotNull(row, "row"); initBits &= ~INIT_BIT_ROW; return this; } /** * Initializes the value for the {@link ImmutableMultitable.RowKeyColumnKeyPair#column() column} attribute. * @param column The value for column * @return {@code this} builder for use in a chained invocation */ public final Builder column(C column) { this.column = Preconditions.checkNotNull(column, "column"); initBits &= ~INIT_BIT_COLUMN; return this; } /** * Builds a new {@link ImmutableMultitable.RowKeyColumnKeyPair RowKeyColumnKeyPair}. * @return An immutable instance of RowKeyColumnKeyPair * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableMultitable.RowKeyColumnKeyPair build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableRowKeyColumnKeyPair(row, column); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_ROW) != 0) attributes.add("row"); if ((initBits & INIT_BIT_COLUMN) != 0) attributes.add("column"); return "Cannot build RowKeyColumnKeyPair, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy