commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections SequencedHashMap.java
Date Fri, 24 May 2002 04:00:31 GMT
mas         02/05/23 21:00:30

  Modified:    collections/src/java/org/apache/commons/collections
                        SequencedHashMap.java
  Log:
  Implemented equals(Object) and hashCode() as per the Map interface.
  Also, added a toString() method for simpler debugging.
  
  Revision  Changes    Path
  1.10      +41 -3     jakarta-commons/collections/src/java/org/apache/commons/collections/SequencedHashMap.java
  
  Index: SequencedHashMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SequencedHashMap.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SequencedHashMap.java	9 May 2002 03:20:59 -0000	1.9
  +++ SequencedHashMap.java	24 May 2002 04:00:30 -0000	1.10
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /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/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 $
    *
    * ====================================================================
    *
  @@ -521,6 +521,44 @@
       // and the list
       sentinel.next = sentinel;
       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()
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message