
com.magictools.core.map.AbsEntry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magic-tools-all Show documentation
Show all versions of magic-tools-all Show documentation
magic-tools 是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
The newest version!
package com.magictools.core.map;
import com.magictools.core.util.ObjectUtil;
import java.util.Map;
/**
* 抽象的{@link Map.Entry}实现,来自Guava
* 实现了默认的{@link #equals(Object)}、{@link #hashCode()}、{@link #toString()}方法。
* 默认{@link #setValue(Object)}抛出异常。
*
* @param 键类型
* @param 值类型
* @author Guava
* @since 5.7.23
*/
public abstract class AbsEntry implements Map.Entry {
@Override
public V setValue(V value) {
throw new UnsupportedOperationException("Entry is read only.");
}
@Override
public boolean equals(Object object) {
if (object instanceof Map.Entry) {
final Map.Entry, ?> that = (Map.Entry, ?>) object;
return ObjectUtil.equals(this.getKey(), that.getKey())
&& ObjectUtil.equals(this.getValue(), that.getValue());
}
return false;
}
@Override
public int hashCode() {
//copy from 1.8 HashMap.Node
K k = getKey();
V v = getValue();
return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode());
}
@Override
public String toString() {
return getKey() + "=" + getValue();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy