class library changes
authorjzhou <jzhou>
Fri, 18 Nov 2011 00:41:22 +0000 (00:41 +0000)
committerjzhou <jzhou>
Fri, 18 Nov 2011 00:41:22 +0000 (00:41 +0000)
Robust/src/ClassLibrary/MGC/HashMap.java
Robust/src/ClassLibrary/MGC/Map.java

index a2b729c910349d7c5676ae08e31e91efd630bf99..1edd6c8f59cc7c046e542aa6eb099c3c06e01011 100644 (file)
@@ -153,11 +153,6 @@ public class HashMap implements Map {
       // wouldn't provide any significant performance advantage.
       values = new AbstractCollection()
       {
-        HashMap map;
-        
-        public AbstractCollection(HashMap m) {
-          this.map = m;
-        }
         
         public int size()
         {
@@ -167,12 +162,12 @@ public class HashMap implements Map {
         public Iterator iterator()
         {
           // Cannot create the iterator directly, because of LinkedHashMap.
-          return HashMapIterator(this.map, 1);
+          return HashMapIterator(HashMap.this, 1);
         }
 
         public void clear()
         {
-          map.clear();
+          HashMap.this.clear();
         }
       };
     return values;
@@ -185,11 +180,6 @@ public class HashMap implements Map {
       // that can be overridden easily and efficiently.
       keys = new AbstractSet()
       {
-      HashMap map;
-      
-      public AbstractSet(HashMap m) {
-        this.map = m;
-      }
         public int size()
         {
           return size;
@@ -199,7 +189,7 @@ public class HashMap implements Map {
         {
           // Cannot create the iterator directly, because of LinkedHashMap.
           //return HashMap.this.iterator(KEYS);
-          return HashMapIterator(this.map, 0);
+          return HashMapIterator(HashMap.this, 0);
         }
 
         public void clear()
@@ -218,8 +208,7 @@ public class HashMap implements Map {
           // really got removed. This is necessary because the return value
           // of HashMap.remove() is ambiguous in the null case.
           int oldsize = size;
-          //HashMap.this.remove(o);
-          this.map.remove(o);
+          HashMap.this.remove(o);
           return oldsize != size;
         }
       };
index bc5c0e9a095ca6f24cac733d0c36cf464dec6d65..ec00ba39645340d2ad7e6a1761dc7e84e1317050 100644 (file)
@@ -248,4 +248,81 @@ public interface Map//<K, V>
   int size();
   
   Collection values();
+  
+  /**
+   * A map entry (key-value pair). The Map.entrySet() method returns a set
+   * view of these objects; there is no other valid way to come across them.
+   * These objects are only valid for the duration of an iteration; in other
+   * words, if you mess with one after modifying the map, you are asking
+   * for undefined behavior.
+   *
+   * @author Original author unknown
+   * @author Eric Blake (ebb9@email.byu.edu)
+   * @see Map
+   * @see Map#entrySet()
+   * @since 1.2
+   * @status updated to 1.4
+   */
+  interface Entry
+  {
+    /**
+     * Get the key corresponding to this entry.
+     *
+     * @return the key
+     */
+    Object getKey();
+    /**
+     * Get the value corresponding to this entry. If you already called
+     * Iterator.remove(), this is undefined.
+     *
+     * @return the value
+     */
+    Object getValue();
+    
+    /**
+     * Replaces the value with the specified object (optional operation).
+     * This writes through to the map, and is undefined if you already
+     * called Iterator.remove().
+     *
+     * @param value the new value to store
+     * @return the old value
+     * @throws UnsupportedOperationException if the operation is not supported
+     * @throws ClassCastException if the value is of the wrong type
+     * @throws IllegalArgumentException if something about the value
+     *         prevents it from existing in this map
+     * @throws NullPointerException if the map forbids null values
+     */
+    Object setValue(Object value);
+    /**
+     * Returns the hash code of the entry.  This is defined as the
+     * exclusive-or of the hashcodes of the key and value (using 0 for
+     * <code>null</code>). In other words, this must be:
+     * 
+<p><pre>(getKey() == null ? 0 : getKey().hashCode())
+^ (getValue() == null ? 0 : getValue().hashCode())</pre>
+     *
+     * @return the hash code
+     */
+    int hashCode();
+
+    /**
+     * Compares the specified object with this entry. Returns true only if
+     * the object is a mapping of identical key and value. In other words,
+     * this must be:
+     * 
+<p><pre>(o instanceof Map.Entry)
+&& (getKey() == null ? ((Map.Entry) o).getKey() == null
+                     : getKey().equals(((Map.Entry) o).getKey()))
+&& (getValue() == null ? ((Map.Entry) o).getValue() == null
+                       : getValue().equals(((Map.Entry) o).getValue()))</pre>
+     *
+     * @param o the object to compare
+     *
+     * @return <code>true</code> if it is equal
+     */
+    boolean equals(Object o);
+  }
+
 }