Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/AbstractCollection.java
          +++ new/src/share/classes/java/util/AbstractCollection.java
↓ open down ↓ 88 lines elided ↑ open up ↑
  89   89      /**
  90   90       * {@inheritDoc}
  91   91       *
  92   92       * <p>This implementation iterates over the elements in the collection,
  93   93       * checking each element in turn for equality with the specified element.
  94   94       *
  95   95       * @throws ClassCastException   {@inheritDoc}
  96   96       * @throws NullPointerException {@inheritDoc}
  97   97       */
  98   98      public boolean contains(Object o) {
  99      -        Iterator<E> e = iterator();
       99 +        Iterator<E> it = iterator();
 100  100          if (o==null) {
 101      -            while (e.hasNext())
 102      -                if (e.next()==null)
      101 +            while (it.hasNext())
      102 +                if (it.next()==null)
 103  103                      return true;
 104  104          } else {
 105      -            while (e.hasNext())
 106      -                if (o.equals(e.next()))
      105 +            while (it.hasNext())
      106 +                if (o.equals(it.next()))
 107  107                      return true;
 108  108          }
 109  109          return false;
 110  110      }
 111  111  
 112  112      /**
 113  113       * {@inheritDoc}
 114  114       *
 115  115       * <p>This implementation returns an array containing all the elements
 116  116       * returned by this collection's iterator, in the same order, stored in
↓ open down ↓ 145 lines elided ↑ open up ↑
 262  262       * <p>Note that this implementation throws an
 263  263       * <tt>UnsupportedOperationException</tt> if the iterator returned by this
 264  264       * collection's iterator method does not implement the <tt>remove</tt>
 265  265       * method and this collection contains the specified object.
 266  266       *
 267  267       * @throws UnsupportedOperationException {@inheritDoc}
 268  268       * @throws ClassCastException            {@inheritDoc}
 269  269       * @throws NullPointerException          {@inheritDoc}
 270  270       */
 271  271      public boolean remove(Object o) {
 272      -        Iterator<E> e = iterator();
      272 +        Iterator<E> it = iterator();
 273  273          if (o==null) {
 274      -            while (e.hasNext()) {
 275      -                if (e.next()==null) {
 276      -                    e.remove();
      274 +            while (it.hasNext()) {
      275 +                if (it.next()==null) {
      276 +                    it.remove();
 277  277                      return true;
 278  278                  }
 279  279              }
 280  280          } else {
 281      -            while (e.hasNext()) {
 282      -                if (o.equals(e.next())) {
 283      -                    e.remove();
      281 +            while (it.hasNext()) {
      282 +                if (o.equals(it.next())) {
      283 +                    it.remove();
 284  284                      return true;
 285  285                  }
 286  286              }
 287  287          }
 288  288          return false;
 289  289      }
 290  290  
 291  291  
 292  292      // Bulk Operations
 293  293  
↓ open down ↓ 3 lines elided ↑ open up ↑
 297  297       * <p>This implementation iterates over the specified collection,
 298  298       * checking each element returned by the iterator in turn to see
 299  299       * if it's contained in this collection.  If all elements are so
 300  300       * contained <tt>true</tt> is returned, otherwise <tt>false</tt>.
 301  301       *
 302  302       * @throws ClassCastException            {@inheritDoc}
 303  303       * @throws NullPointerException          {@inheritDoc}
 304  304       * @see #contains(Object)
 305  305       */
 306  306      public boolean containsAll(Collection<?> c) {
 307      -        Iterator<?> e = c.iterator();
 308      -        while (e.hasNext())
 309      -            if (!contains(e.next()))
      307 +        for (Object e : c)
      308 +            if (!contains(e))
 310  309                  return false;
 311  310          return true;
 312  311      }
 313  312  
 314  313      /**
 315  314       * {@inheritDoc}
 316  315       *
 317  316       * <p>This implementation iterates over the specified collection, and adds
 318  317       * each object returned by the iterator to this collection, in turn.
 319  318       *
↓ open down ↓ 4 lines elided ↑ open up ↑
 324  323       * @throws UnsupportedOperationException {@inheritDoc}
 325  324       * @throws ClassCastException            {@inheritDoc}
 326  325       * @throws NullPointerException          {@inheritDoc}
 327  326       * @throws IllegalArgumentException      {@inheritDoc}
 328  327       * @throws IllegalStateException         {@inheritDoc}
 329  328       *
 330  329       * @see #add(Object)
 331  330       */
 332  331      public boolean addAll(Collection<? extends E> c) {
 333  332          boolean modified = false;
 334      -        Iterator<? extends E> e = c.iterator();
 335      -        while (e.hasNext()) {
 336      -            if (add(e.next()))
      333 +        for (E e : c)
      334 +            if (add(e))
 337  335                  modified = true;
 338      -        }
 339  336          return modified;
 340  337      }
 341  338  
 342  339      /**
 343  340       * {@inheritDoc}
 344  341       *
 345  342       * <p>This implementation iterates over this collection, checking each
 346  343       * element returned by the iterator in turn to see if it's contained
 347  344       * in the specified collection.  If it's so contained, it's removed from
 348  345       * this collection with the iterator's <tt>remove</tt> method.
↓ open down ↓ 6 lines elided ↑ open up ↑
 355  352       *
 356  353       * @throws UnsupportedOperationException {@inheritDoc}
 357  354       * @throws ClassCastException            {@inheritDoc}
 358  355       * @throws NullPointerException          {@inheritDoc}
 359  356       *
 360  357       * @see #remove(Object)
 361  358       * @see #contains(Object)
 362  359       */
 363  360      public boolean removeAll(Collection<?> c) {
 364  361          boolean modified = false;
 365      -        Iterator<?> e = iterator();
 366      -        while (e.hasNext()) {
 367      -            if (c.contains(e.next())) {
 368      -                e.remove();
      362 +        Iterator<?> it = iterator();
      363 +        while (it.hasNext()) {
      364 +            if (c.contains(it.next())) {
      365 +                it.remove();
 369  366                  modified = true;
 370  367              }
 371  368          }
 372  369          return modified;
 373  370      }
 374  371  
 375  372      /**
 376  373       * {@inheritDoc}
 377  374       *
 378  375       * <p>This implementation iterates over this collection, checking each
↓ open down ↓ 9 lines elided ↑ open up ↑
 388  385       *
 389  386       * @throws UnsupportedOperationException {@inheritDoc}
 390  387       * @throws ClassCastException            {@inheritDoc}
 391  388       * @throws NullPointerException          {@inheritDoc}
 392  389       *
 393  390       * @see #remove(Object)
 394  391       * @see #contains(Object)
 395  392       */
 396  393      public boolean retainAll(Collection<?> c) {
 397  394          boolean modified = false;
 398      -        Iterator<E> e = iterator();
 399      -        while (e.hasNext()) {
 400      -            if (!c.contains(e.next())) {
 401      -                e.remove();
      395 +        Iterator<E> it = iterator();
      396 +        while (it.hasNext()) {
      397 +            if (!c.contains(it.next())) {
      398 +                it.remove();
 402  399                  modified = true;
 403  400              }
 404  401          }
 405  402          return modified;
 406  403      }
 407  404  
 408  405      /**
 409  406       * {@inheritDoc}
 410  407       *
 411  408       * <p>This implementation iterates over this collection, removing each
↓ open down ↓ 2 lines elided ↑ open up ↑
 414  411       * efficiency.
 415  412       *
 416  413       * <p>Note that this implementation will throw an
 417  414       * <tt>UnsupportedOperationException</tt> if the iterator returned by this
 418  415       * collection's <tt>iterator</tt> method does not implement the
 419  416       * <tt>remove</tt> method and this collection is non-empty.
 420  417       *
 421  418       * @throws UnsupportedOperationException {@inheritDoc}
 422  419       */
 423  420      public void clear() {
 424      -        Iterator<E> e = iterator();
 425      -        while (e.hasNext()) {
 426      -            e.next();
 427      -            e.remove();
      421 +        Iterator<E> it = iterator();
      422 +        while (it.hasNext()) {
      423 +            it.next();
      424 +            it.remove();
 428  425          }
 429  426      }
 430  427  
 431  428  
 432  429      //  String conversion
 433  430  
 434  431      /**
 435  432       * Returns a string representation of this collection.  The string
 436  433       * representation consists of a list of the collection's elements in the
 437  434       * order they are returned by its iterator, enclosed in square brackets
 438  435       * (<tt>"[]"</tt>).  Adjacent elements are separated by the characters
 439  436       * <tt>", "</tt> (comma and space).  Elements are converted to strings as
 440  437       * by {@link String#valueOf(Object)}.
 441  438       *
 442  439       * @return a string representation of this collection
 443  440       */
 444  441      public String toString() {
 445      -        Iterator<E> i = iterator();
 446      -        if (! i.hasNext())
      442 +        Iterator<E> it = iterator();
      443 +        if (! it.hasNext())
 447  444              return "[]";
 448  445  
 449  446          StringBuilder sb = new StringBuilder();
 450  447          sb.append('[');
 451  448          for (;;) {
 452      -            E e = i.next();
      449 +            E e = it.next();
 453  450              sb.append(e == this ? "(this Collection)" : e);
 454      -            if (! i.hasNext())
      451 +            if (! it.hasNext())
 455  452                  return sb.append(']').toString();
 456      -            sb.append(", ");
      453 +            sb.append(',').append(' ');
 457  454          }
 458  455      }
 459  456  
 460  457  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX