src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java
changeset 48541 946e34c2dec9
parent 47423 4fc2a4a29f3d
child 49433 b6671a111395
equal deleted inserted replaced
48540:221cf8307606 48541:946e34c2dec9
   506      * @return {@code true} if this list contained the specified element
   506      * @return {@code true} if this list contained the specified element
   507      */
   507      */
   508     public boolean remove(Object o) {
   508     public boolean remove(Object o) {
   509         Object[] snapshot = getArray();
   509         Object[] snapshot = getArray();
   510         int index = indexOf(o, snapshot, 0, snapshot.length);
   510         int index = indexOf(o, snapshot, 0, snapshot.length);
   511         return (index < 0) ? false : remove(o, snapshot, index);
   511         return index >= 0 && remove(o, snapshot, index);
   512     }
   512     }
   513 
   513 
   514     /**
   514     /**
   515      * A version of remove(Object) using the strong hint that given
   515      * A version of remove(Object) using the strong hint that given
   516      * recent snapshot contains o at the given index.
   516      * recent snapshot contains o at the given index.
   585      * @param e element to be added to this list, if absent
   585      * @param e element to be added to this list, if absent
   586      * @return {@code true} if the element was added
   586      * @return {@code true} if the element was added
   587      */
   587      */
   588     public boolean addIfAbsent(E e) {
   588     public boolean addIfAbsent(E e) {
   589         Object[] snapshot = getArray();
   589         Object[] snapshot = getArray();
   590         return indexOf(e, snapshot, 0, snapshot.length) >= 0 ? false :
   590         return indexOf(e, snapshot, 0, snapshot.length) < 0
   591             addIfAbsent(e, snapshot);
   591             && addIfAbsent(e, snapshot);
   592     }
   592     }
   593 
   593 
   594     /**
   594     /**
   595      * A version of addIfAbsent using the strong hint that given
   595      * A version of addIfAbsent using the strong hint that given
   596      * recent snapshot does not contain e.
   596      * recent snapshot does not contain e.
   978         if (!(o instanceof List))
   978         if (!(o instanceof List))
   979             return false;
   979             return false;
   980 
   980 
   981         List<?> list = (List<?>)o;
   981         List<?> list = (List<?>)o;
   982         Iterator<?> it = list.iterator();
   982         Iterator<?> it = list.iterator();
   983         Object[] elements = getArray();
   983         for (Object element : getArray())
   984         for (int i = 0, len = elements.length; i < len; i++)
   984             if (!it.hasNext() || !Objects.equals(element, it.next()))
   985             if (!it.hasNext() || !Objects.equals(elements[i], it.next()))
       
   986                 return false;
   985                 return false;
   987         if (it.hasNext())
   986         return !it.hasNext();
   988             return false;
       
   989         return true;
       
   990     }
   987     }
   991 
   988 
   992     /**
   989     /**
   993      * Returns the hash code value for this list.
   990      * Returns the hash code value for this list.
   994      *
   991      *