Pair.java
package com.mycim.valueobject;
import java.io.Serializable;
import java.util.Objects;
/**
* Class {@code Pair} like {@link java.util.Map.Entry}.
* <p>
* TODO 迁移至 framework
*
* @param <K> key object type
* @param <V> value object type
* @author Qiansheng.Wang
* @since 2020-05-15
*/
public class Pair<K, V> implements Serializable {
/**
* Key of this {@code Pair}.
*/
private final K key;
/**
* Gets the key for this {@code Pair}.
*
* @return key for this pair
*/
public K getKey() {
return key;
}
/**
* Value of this {@code Pair}
*/
private final V value;
/**
* Gets the value for this {@code Pair}.
*
* @return value for this pair
*/
public V getValue() {
return value;
}
/**
* Creates a new pair
*
* @param key The key for this pair
* @param value The value to use for this pair
*/
public Pair(K key, V value) {
this.key = key;
this.value = value;
}
@Override
public String toString() {
return "Pair{" + "key=" + key + ", value=" + value + '}';
}
@Override
public int hashCode() {
return Objects.hash(getKey(), getValue());
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof Pair))
return false;
Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equals(getKey(), pair.getKey()) && Objects.equals(getValue(), pair.getValue());
}
}