Implemented equals(Object) and hashCode() as per the Map interface.
Also, added a toString() method for simpler debugging. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130702 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e2af015a2f
commit
5d8832a059
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SequencedHashMap.java,v 1.9 2002/05/09 03:20:59 mas Exp $
|
||||
* $Revision: 1.9 $
|
||||
* $Date: 2002/05/09 03:20:59 $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/SequencedHashMap.java,v 1.10 2002/05/24 04:00:30 mas Exp $
|
||||
* $Revision: 1.10 $
|
||||
* $Date: 2002/05/24 04:00:30 $
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
|
@ -523,6 +523,44 @@ public class SequencedHashMap implements Map, Cloneable, Externalizable {
|
|||
sentinel.prev = sentinel;
|
||||
}
|
||||
|
||||
// per Map.equals(Object)
|
||||
public boolean equals(Object obj) {
|
||||
if(obj == null) return false;
|
||||
if(obj == this) return true;
|
||||
|
||||
if(!(obj instanceof Map)) return false;
|
||||
|
||||
return entrySet().equals(((Map)obj).entrySet());
|
||||
}
|
||||
|
||||
// per Map.hashCode()
|
||||
public int hashCode() {
|
||||
return entrySet().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a string representation of the entries within the map. The
|
||||
* format of the returned string may change with different releases, so this
|
||||
* method is suitable for debugging purposes only. If a specific format is
|
||||
* required, use {@link #entrySet()}.{@link Set#iterator() iterator()} and
|
||||
* iterate over the entries in the map formatting them as appropriate.
|
||||
**/
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append('[');
|
||||
for(Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
|
||||
buf.append(pos.getKey());
|
||||
buf.append('=');
|
||||
buf.append(pos.getValue());
|
||||
if(pos.next != sentinel) {
|
||||
buf.append(',');
|
||||
}
|
||||
}
|
||||
buf.append(']');
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
// per Map.keySet()
|
||||
public Set keySet() {
|
||||
return new AbstractSet() {
|
||||
|
|
Loading…
Reference in New Issue