/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE file at the root of the source
* tree and available online at
*
* https://github.com/keeps/roda
*/
package org.roda.core.data.v2.common;
public class Pair<K, V> {
private K first;
private V second;
public Pair() {
super();
}
/**
* Instead of using this construtor, the of function should be used
*/
public Pair(K first, V second) {
this.first = first;
this.second = second;
}
public static <K, V> Pair<K, V> of(K key, V value) {
return new Pair<>(key, value);
}
public K getFirst() {
return this.first;
}
public void setFirst(K value) {
this.first = value;
}
public V getSecond() {
return this.second;
}
public void setSecond(V value) {
this.second = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((first == null) ? 0 : first.hashCode());
result = prime * result + ((second == null) ? 0 : second.hashCode());
return result;
}
@Override
public String toString() {
return "(" + first + ", " + second + ")";
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Pair)) {
return false;
}
Pair<?, ?> other = (Pair<?, ?>) obj;
if (first == null) {
if (other.first != null) {
return false;
}
} else if (!first.equals(other.first)) {
return false;
}
if (second == null) {
if (other.second != null) {
return false;
}
} else if (!second.equals(other.second)) {
return false;
}
return true;
}
}