com.anysoft.util.Pair Maven / Gradle / Ivy
package com.anysoft.util;
/**
* Pair
*
* @author duanyy
*
* @param
* @param
*
* @since 1.3.6
* @version 1.6.4.16 [duanyy 20151110]
* - 根据sonar建议优化代码
*/
public interface Pair{
/**
* 获取Key
* @return Key
*/
public K key();
/**
* 获取Value
* @return Key
*/
public V value();
public static class Default implements Pair{
protected K key = null;
protected V value = null;
public Default(K k,V v){
key = k;
value = v;
}
@Override
public int hashCode(){
return key == null ? 0 : key.hashCode();
}
@Override
public boolean equals(Object other){
if (!(other instanceof Default)){
return false;
}
if (this == other){
return true;
}
@SuppressWarnings("unchecked")
Default another = (Default)other;
if (another.key == null){
return false;
}
if (key == null){
return false;
}
return key.equals(another.key);
}
@Override
public K key() {
return key;
}
@Override
public V value() {
return value;
}
@Override
public String toString(){
return key.toString() + "=" + value.toString();
}
}
}