Last active
January 16, 2017 09:38
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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