提交 e1473e20 编写于 作者: J Jesse Glick

Missing equals/hashCode/toString impls for CopyOnWriteMap.

上级 42fb9c71
......@@ -148,6 +148,19 @@ public abstract class CopyOnWriteMap<K,V> implements Map<K,V> {
return view.entrySet();
}
@Override public int hashCode() {
return copy().hashCode();
}
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Override public boolean equals(Object obj) {
return copy().equals(obj);
}
@Override public String toString() {
return copy().toString();
}
/**
* {@link CopyOnWriteMap} backed by {@link HashMap}.
*/
......
......@@ -25,6 +25,7 @@ package hudson.util;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import static org.junit.Assert.*;
import org.junit.Test;
......@@ -112,4 +113,18 @@ public class CopyOnWriteMapTest {
assertEquals("bar1", td2.map1.get("foo1"));
assertEquals("bar2", td2.map2.get("foo2"));
}
@Test public void equalsHashCodeToString() throws Exception {
Map<String,Integer> m1 = new TreeMap<String,Integer>();
Map<String,Integer> m2 = new CopyOnWriteMap.Tree<String,Integer>();
m1.put("foo", 5);
m1.put("bar", 7);
m2.put("foo", 5);
m2.put("bar", 7);
assertEquals(m1.hashCode(), m2.hashCode());
assertTrue(m2.equals(m1));
assertTrue(m1.equals(m2));
assertEquals(m1.toString(), m2.toString());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册