Skip to content

Instantly share code, notes, and snippets.

@fmerlin
Last active January 16, 2017 09:38
Show Gist options
  • Save fmerlin/32f467b15ff0f55071766874579001e2 to your computer and use it in GitHub Desktop.
Save fmerlin/32f467b15ff0f55071766874579001e2 to your computer and use it in GitHub Desktop.
Tuple is a utility class to encapsulate an array (redefines hashcode and equals).
import java.util.Arrays;
/**
* Tuple is a utility class to encapsulate an array (redefines hashcode and equals).
*/
public class Tuple {
public final Object[] data;
public Tuple(Object... data) {
this.data = data;
}
public Tuple(String... data) {
this.data = data;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tuple tuple = (Tuple) o;
return Arrays.deepEquals(data, tuple.data);
}
@Override
public int hashCode() {
return Arrays.deepHashCode(data);
}
@Override
public String toString() {
return Arrays.toString(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment