src/share/classes/java/util/AbstractMap.java

Print this page




 506      * {@link String#valueOf(Object)}.
 507      *
 508      * @return a string representation of this map
 509      */
 510     public String toString() {
 511         Iterator<Entry<K,V>> i = entrySet().iterator();
 512         if (! i.hasNext())
 513             return "{}";
 514 
 515         StringBuilder sb = new StringBuilder();
 516         sb.append('{');
 517         for (;;) {
 518             Entry<K,V> e = i.next();
 519             K key = e.getKey();
 520             V value = e.getValue();
 521             sb.append(key   == this ? "(this Map)" : key);
 522             sb.append('=');
 523             sb.append(value == this ? "(this Map)" : value);
 524             if (! i.hasNext())
 525                 return sb.append('}').toString();
 526             sb.append(", ");
 527         }
 528     }
 529 
 530     /**
 531      * Returns a shallow copy of this <tt>AbstractMap</tt> instance: the keys
 532      * and values themselves are not cloned.
 533      *
 534      * @return a shallow copy of this map
 535      */
 536     protected Object clone() throws CloneNotSupportedException {
 537         AbstractMap<K,V> result = (AbstractMap<K,V>)super.clone();
 538         result.keySet = null;
 539         result.values = null;
 540         return result;
 541     }
 542 
 543     /**
 544      * Utility method for SimpleEntry and SimpleImmutableEntry.
 545      * Test for equality, checking for nulls.
 546      */




 506      * {@link String#valueOf(Object)}.
 507      *
 508      * @return a string representation of this map
 509      */
 510     public String toString() {
 511         Iterator<Entry<K,V>> i = entrySet().iterator();
 512         if (! i.hasNext())
 513             return "{}";
 514 
 515         StringBuilder sb = new StringBuilder();
 516         sb.append('{');
 517         for (;;) {
 518             Entry<K,V> e = i.next();
 519             K key = e.getKey();
 520             V value = e.getValue();
 521             sb.append(key   == this ? "(this Map)" : key);
 522             sb.append('=');
 523             sb.append(value == this ? "(this Map)" : value);
 524             if (! i.hasNext())
 525                 return sb.append('}').toString();
 526             sb.append(',').append(' ');
 527         }
 528     }
 529 
 530     /**
 531      * Returns a shallow copy of this <tt>AbstractMap</tt> instance: the keys
 532      * and values themselves are not cloned.
 533      *
 534      * @return a shallow copy of this map
 535      */
 536     protected Object clone() throws CloneNotSupportedException {
 537         AbstractMap<K,V> result = (AbstractMap<K,V>)super.clone();
 538         result.keySet = null;
 539         result.values = null;
 540         return result;
 541     }
 542 
 543     /**
 544      * Utility method for SimpleEntry and SimpleImmutableEntry.
 545      * Test for equality, checking for nulls.
 546      */