package example.utils; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; public class Pair<K, V> { private final K key; private final V value; public Pair(K key, V value) { this.key = key; this.value = value; } public static <K, V> Pair<K, V> pair(K key, V value) { return new Pair<K, V>(key, value); } public K getKey() { return key; } public V getValue() { return value; } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof Pair) { Pair other = (Pair) obj; return new EqualsBuilder() .append(this.getKey(), other.getKey()) .append(this.getValue(), other.getValue()) .isEquals(); } return false; } @Override public int hashCode() { return new HashCodeBuilder().append(key).append(value).toHashCode(); } @Override public String toString() { return Strings.toString(this); } }