
cdc.util.tuples.TupleN Maven / Gradle / Ivy
package cdc.util.tuples;
import java.util.Arrays;
/**
* Tuple of N values, all with the same type.
*
* @author Damien Carbonne
*
* @param Value type.
*/
public class TupleN implements Tuple {
private final T[] values;
@SafeVarargs
public TupleN(T... values) {
this.values = values.clone();
}
@Override
public int size() {
return values.length;
}
@Override
public T getValue(int index) {
if (index >= 0 && index < size()) {
return values[index];
} else {
throw new IndexOutOfBoundsException();
}
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof TupleN>)) {
return false;
}
final TupleN> o = (TupleN>) other;
return Arrays.equals(values, o.values);
}
@Override
public int hashCode() {
return Arrays.hashCode(values);
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
boolean first = true;
builder.append('[');
for (int index = 0; index < values.length; index++) {
if (first) {
first = false;
} else {
builder.append(", ");
}
builder.append(values[index]);
}
builder.append(']');
return builder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy