E - the type of elements held in this collectionpublic class CopyOnWriteArrayNavigableSet<E> extends AbstractSet<E> implements Serializable, NavigableSet<E>
NavigableSet that uses an internal
CopyOnWriteArrayList for all of its operations. Thus, it shares the
same basic properties:
add, set, remove, etc.)
are expensive since they usually entail copying the entire underlying
array.
remove operation.
Sample Usage. The following code sketch uses a copy-on-write navigable set to maintain a set of ordered Handler objects that perform some action upon state updates until one of the handlers returns true indicating that the update has been handled.
public abstract class Handler implements Comparable<Handler> {
final int priority;
protected Handler(int priority) {
this.priority = priority;
}
// returns true if update has been handled
abstract boolean handle();
// ordered from highest to lowest
public final int compareTo(Handler other) {
return -Integer.compare(priority, other.priority);
}
}
class X {
// Will use "Natural Order" of Comparables
private final CopyOnWriteArrayNavigableSet<Handler> handlers
= new CopyOnWriteArrayNavigableSet<>();
public void addHandler(Handler h) { handlers.add(h); }
private long internalState;
private synchronized void changeState() { internalState = ...; }
public void update() {
changeState();
for (Handler handler : handlers)
if(handler.handle()) break;
}
}
This class is a member of the Java Collections Framework.
CopyOnWriteArrayList,
Serialized Form| Constructor and Description |
|---|
CopyOnWriteArrayNavigableSet()
Creates an empty set which can be used for mutually
Comparable objects. |
CopyOnWriteArrayNavigableSet(Comparator<? super E> comparator)
Creates an empty set with the specified comparator.
|
CopyOnWriteArrayNavigableSet(Iterable<? extends E> c)
Creates a set containing all of unique elements of the specified
Iterable.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e) |
boolean |
addAll(Collection<? extends E> c) |
E |
ceiling(E e) |
void |
clear() |
Comparator<? super E> |
comparator() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
static <E extends Comparable<? super E>> |
create()
Creates a new empty CopyOnWriteArrayNavigableSet using natural order
ordering.
|
static <E> CopyOnWriteArrayNavigableSet<E> |
create(Comparator<? super E> comparator)
Creates a new empty CopyOnWriteArrayNavigableSet using provided
comparator for ordering.
|
static <E extends Comparable<? super E>> |
create(Iterable<E> contents)
Creates a new CopyOnWriteArrayNavigableSet of the provided elements using
natural order ordering.
|
Iterator<E> |
descendingIterator() |
NavigableSet<E> |
descendingSet() |
E |
first() |
E |
floor(E e) |
void |
forEach(Consumer<? super E> action) |
SortedSet<E> |
headSet(E toElement) |
NavigableSet<E> |
headSet(E toElement,
boolean inclusive) |
E |
higher(E e) |
Iterator<E> |
iterator() |
E |
last() |
E |
lower(E e) |
E |
pollFirst() |
E |
pollLast() |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
removeIf(Predicate<? super E> filter) |
boolean |
retainAll(Collection<?> c) |
int |
size() |
Spliterator<E> |
spliterator()
Returns a
Spliterator over the elements in this set in the order
in which these elements were added. |
NavigableSet<E> |
subSet(E fromElement,
boolean fromInclusive,
E toElement,
boolean toInclusive) |
SortedSet<E> |
subSet(E fromElement,
E toElement) |
SortedSet<E> |
tailSet(E fromElement) |
NavigableSet<E> |
tailSet(E fromElement,
boolean inclusive) |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
equals, hashCodeisEmpty, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitparallelStream, streampublic CopyOnWriteArrayNavigableSet()
Comparable objects.public CopyOnWriteArrayNavigableSet(Comparator<? super E> comparator)
comparator - Used for ordering elements. For
Comparable objects use
Comparator.naturalOrder()public CopyOnWriteArrayNavigableSet(Iterable<? extends E> c)
sorted set then
the same Comparator is used.c - the elements to initially containNullPointerException - if the specified collection is nullCopyOnWriteArrayNavigableSet.public static <E extends Comparable<? super E>> CopyOnWriteArrayNavigableSet<E> create()
E - Type of elementspublic static <E extends Comparable<? super E>> CopyOnWriteArrayNavigableSet<E> create(Iterable<E> contents)
E - Type of elementscontents - initial elements for the set.public static <E> CopyOnWriteArrayNavigableSet<E> create(Comparator<? super E> comparator)
E - Type of elementscomparator - The comparator to use for ordering.public boolean contains(Object o)
contains in interface Collection<E>contains in interface Set<E>contains in class AbstractCollection<E>public boolean remove(Object o)
remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>public boolean add(E e)
add in interface Collection<E>add in interface Set<E>add in class AbstractCollection<E>public boolean containsAll(Collection<?> c)
containsAll in interface Collection<E>containsAll in interface Set<E>containsAll in class AbstractCollection<E>public boolean addAll(Collection<? extends E> c)
addAll in interface Collection<E>addAll in interface Set<E>addAll in class AbstractCollection<E>public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in interface NavigableSet<E>iterator in interface Set<E>iterator in class AbstractCollection<E>public int size()
size in interface Collection<E>size in interface Set<E>size in class AbstractCollection<E>public boolean removeIf(Predicate<? super E> filter)
removeIf in interface Collection<E>public boolean retainAll(Collection<?> c)
retainAll in interface Collection<E>retainAll in interface Set<E>retainAll in class AbstractCollection<E>public boolean removeAll(Collection<?> c)
removeAll in interface Collection<E>removeAll in interface Set<E>removeAll in class AbstractSet<E>public Object[] toArray()
toArray in interface Collection<E>toArray in interface Set<E>toArray in class AbstractCollection<E>public <T> T[] toArray(T[] a)
toArray in interface Collection<E>toArray in interface Set<E>toArray in class AbstractCollection<E>public void clear()
clear in interface Collection<E>clear in interface Set<E>clear in class AbstractCollection<E>public Spliterator<E> spliterator()
Spliterator over the elements in this set in the order
in which these elements were added.
The Spliterator reports Spliterator.ORDERED,
Spliterator.NONNULL, Spliterator.IMMUTABLE,
Spliterator.DISTINCT, and Spliterator.SIZED.
The spliterator provides a snapshot of the state of the set when the spliterator was constructed. No synchronization is needed while operating on the spliterator.
spliterator in interface Iterable<E>spliterator in interface Collection<E>spliterator in interface Set<E>spliterator in interface SortedSet<E>Spliterator over the elements in this setpublic E lower(E e)
lower in interface NavigableSet<E>public E floor(E e)
floor in interface NavigableSet<E>public E ceiling(E e)
ceiling in interface NavigableSet<E>public E higher(E e)
higher in interface NavigableSet<E>public E pollFirst()
pollFirst in interface NavigableSet<E>public E pollLast()
pollLast in interface NavigableSet<E>public NavigableSet<E> descendingSet()
descendingSet in interface NavigableSet<E>public Iterator<E> descendingIterator()
descendingIterator in interface NavigableSet<E>public NavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
subSet in interface NavigableSet<E>public NavigableSet<E> headSet(E toElement, boolean inclusive)
headSet in interface NavigableSet<E>public NavigableSet<E> tailSet(E fromElement, boolean inclusive)
tailSet in interface NavigableSet<E>public Comparator<? super E> comparator()
comparator in interface SortedSet<E>Copyright © 2016. All rights reserved.