public abstract class ForwardingCollection<E> extends Object implements Collection<E>
Warning: The methods of ForwardingCollection
forward
indiscriminately to the methods of the delegate. For example,
overriding add(E)
alone will not change the behavior of addAll(java.util.Collection<? extends E>)
, which can lead to unexpected behavior. In this case, you should
override addAll
as well, either providing your own implementation, or
delegating to the provided standardAddAll
method.
The standard
methods are not guaranteed to be thread-safe, even
when all of the methods that they depend on are thread-safe.
Modifier and Type | Method and Description |
---|---|
boolean |
add(E element) |
boolean |
addAll(Collection<? extends E> collection) |
void |
clear() |
boolean |
contains(Object object) |
boolean |
containsAll(Collection<?> collection) |
protected abstract Collection<E> |
delegate()
Returns the backing delegate instance that methods are forwarded to.
|
boolean |
isEmpty() |
Iterator<E> |
iterator() |
boolean |
remove(Object object) |
boolean |
removeAll(Collection<?> collection) |
boolean |
retainAll(Collection<?> collection) |
int |
size() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] array) |
String |
toString()
Returns the string representation generated by the delegate's
toString method. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals, hashCode, parallelStream, removeIf, spliterator, stream
protected abstract Collection<E> delegate()
ForwardingSet.delegate()
. Concrete subclasses override this method to supply
the instance being decorated.public int size()
size
in interface Collection<E>
public boolean removeAll(Collection<?> collection)
removeAll
in interface Collection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
public boolean contains(Object object)
contains
in interface Collection<E>
public boolean add(E element)
add
in interface Collection<E>
public boolean remove(Object object)
remove
in interface Collection<E>
public boolean containsAll(Collection<?> collection)
containsAll
in interface Collection<E>
public boolean addAll(Collection<? extends E> collection)
addAll
in interface Collection<E>
public boolean retainAll(Collection<?> collection)
retainAll
in interface Collection<E>
public void clear()
clear
in interface Collection<E>
public Object[] toArray()
toArray
in interface Collection<E>
public <T> T[] toArray(T[] array)
toArray
in interface Collection<E>
Copyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.