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

Comparing jsr166/src/main/java/util/concurrent/ConcurrentLinkedQueue.java (file contents):
Revision 1.130 by jsr166, Wed Nov 30 03:31:47 2016 UTC vs.
Revision 1.131 by jsr166, Mon Dec 5 03:02:49 2016 UTC

# Line 18 | Line 18 | import java.util.Queue;
18   import java.util.Spliterator;
19   import java.util.Spliterators;
20   import java.util.function.Consumer;
21 + import java.util.function.Predicate;
22  
23   /**
24   * An unbounded thread-safe {@linkplain Queue queue} based on linked nodes.
# Line 436 | Line 437 | public class ConcurrentLinkedQueue<E> ex
437          if (o != null) {
438              Node<E> next, pred = null;
439              for (Node<E> p = first(); p != null; pred = p, p = next) {
440 +                final E item;
441                  boolean removed = false;
442 <                E item = p.item;
443 <                if (item != null) {
444 <                    if (!o.equals(item)) {
443 <                        next = succ(p);
442 >                next = succ(p);
443 >                if ((item = p.item) != null) {
444 >                    if (!o.equals(item))
445                          continue;
445                    }
446                      removed = ITEM.compareAndSet(p, item, null);
447                  }
448  
449                next = succ(p);
449                  if (pred != null && next != null) // unlink
450                      NEXT.weakCompareAndSet(pred, p, next);
451                  if (removed)
# Line 668 | Line 667 | public class ConcurrentLinkedQueue<E> ex
667              restartFromHead: for (;;) {
668                  Node<E> h, p, q;
669                  for (p = h = head;; p = q) {
670 <                    E item;
670 >                    final E item;
671                      if ((item = p.item) != null) {
672                          nextNode = p;
673                          nextItem = item;
# Line 872 | Line 871 | public class ConcurrentLinkedQueue<E> ex
871          return new CLQSpliterator();
872      }
873  
874 +    /**
875 +     * @throws NullPointerException {@inheritDoc}
876 +     */
877 +    public boolean removeIf(Predicate<? super E> filter) {
878 +        Objects.requireNonNull(filter);
879 +        return bulkRemove(filter);
880 +    }
881 +
882 +    /**
883 +     * @throws NullPointerException {@inheritDoc}
884 +     */
885 +    public boolean removeAll(Collection<?> c) {
886 +        Objects.requireNonNull(c);
887 +        return bulkRemove(e -> c.contains(e));
888 +    }
889 +
890 +    /**
891 +     * @throws NullPointerException {@inheritDoc}
892 +     */
893 +    public boolean retainAll(Collection<?> c) {
894 +        Objects.requireNonNull(c);
895 +        return bulkRemove(e -> !c.contains(e));
896 +    }
897 +
898 +    /** Implementation of bulk remove methods. */
899 +    private boolean bulkRemove(Predicate<? super E> filter) {
900 +        boolean removed = false;
901 +        Node<E> next, pred = null;
902 +        for (Node<E> p = first(); p != null; pred = p, p = next) {
903 +            final E item;
904 +            next = succ(p);
905 +            if ((item = p.item) != null) {
906 +                if (!filter.test(item))
907 +                    continue;
908 +                if (ITEM.compareAndSet(p, item, null))
909 +                    removed = true;
910 +            }
911 +
912 +            if (pred != null && next != null) // unlink
913 +                NEXT.weakCompareAndSet(pred, p, next);
914 +        }
915 +        return removed;
916 +    }
917 +
918 +    public void forEach(Consumer<? super E> action) {
919 +        Objects.requireNonNull(action);
920 +        E item;
921 +        for (Node<E> p = first(); p != null; p = succ(p))
922 +            if ((item = p.item) != null)
923 +                action.accept(item);
924 +    }
925 +
926      // VarHandle mechanics
927      private static final VarHandle HEAD;
928      private static final VarHandle TAIL;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines