ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/AbstractMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/AbstractMap.java (file contents):
Revision 1.16 by jsr166, Wed Aug 24 04:47:24 2005 UTC vs.
Revision 1.17 by jsr166, Sat Sep 10 20:15:50 2005 UTC

# Line 253 | Line 253 | public abstract class AbstractMap<K,V> i
253       * @throws IllegalArgumentException      {@inheritDoc}
254       */
255      public void putAll(Map<? extends K, ? extends V> m) {
256 <        Iterator<? extends Entry<? extends K, ? extends V>> i = m.entrySet().iterator();
257 <        while (i.hasNext()) {
258 <            Entry<? extends K, ? extends V> e = i.next();
259 <            put(e.getKey(), e.getValue());
260 <        }
256 >        for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
257 >            put(e.getKey(), e.getValue());
258      }
259  
260      /**
# Line 474 | Line 471 | public abstract class AbstractMap<K,V> i
471       * <tt>", "</tt> (comma and space).  Each key-value mapping is rendered as
472       * the key followed by an equals sign (<tt>"="</tt>) followed by the
473       * associated value.  Keys and values are converted to strings as by
474 <     * <tt>String.valueOf(Object)</tt>.<p>
478 <     *
479 <     * This implementation creates an empty string buffer, appends a left
480 <     * brace, and iterates over the map's <tt>entrySet</tt> view, appending
481 <     * the string representation of each <tt>map.entry</tt> in turn.  After
482 <     * appending each entry except the last, the string <tt>", "</tt> is
483 <     * appended.  Finally a right brace is appended.  A string is obtained
484 <     * from the stringbuffer, and returned.
474 >     * {@link String#valueOf(Object)}.
475       *
476 <     * @return a String representation of this map
476 >     * @return a string representation of this map
477       */
478      public String toString() {
489        StringBuilder sb = new StringBuilder();
490        sb.append("{");
491
479          Iterator<Entry<K,V>> i = entrySet().iterator();
480 <        boolean hasNext = i.hasNext();
481 <        while (hasNext) {
480 >        if (! i.hasNext())
481 >            return "{}";
482 >
483 >        StringBuilder sb = new StringBuilder();
484 >        sb.append('{');
485 >        for (;;) {
486              Entry<K,V> e = i.next();
487              K key = e.getKey();
488 <            V value = e.getValue();
489 <            if (key == this)
490 <                sb.append("(this Map)");
491 <            else
492 <                sb.append(key);
493 <            sb.append("=");
494 <            if (value == this)
495 <                sb.append("(this Map)");
505 <            else
506 <                sb.append(value);
507 <            hasNext = i.hasNext();
508 <            if (hasNext)
509 <                sb.append(", ");
510 <        }
511 <
512 <        sb.append("}");
513 <        return sb.toString();
488 >            V value = e.getValue();
489 >            sb.append(key   == this ? "(this Map)" : key);
490 >            sb.append('=');
491 >            sb.append(value == this ? "(this Map)" : value);
492 >            if (! i.hasNext())
493 >                return sb.append('}').toString();
494 >            sb.append(", ");
495 >        }
496      }
497  
498      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines