Class ForwardingList<E extends @Nullable java.lang.Object>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingCollection<E>
-
- com.google.common.collect.ForwardingList<E>
-
- All Implemented Interfaces:
java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.List<E>
@GwtCompatible public abstract class ForwardingList<E extends @Nullable java.lang.Object> extends ForwardingCollection<E> implements java.util.List<E>
A list which forwards all its method calls to another list. Subclasses should override one or more methods to modify the behavior of the backing list as desired per the decorator pattern.This class does not implement
RandomAccess
. If the delegate supports random access, theForwardingList
subclass should implement theRandomAccess
interface.Warning: The methods of
ForwardingList
forward indiscriminately to the methods of the delegate. For example, overridingadd(int, E)
alone will not change the behavior ofaddAll(int, java.util.Collection<? extends E>)
, which can lead to unexpected behavior. In this case, you should overrideaddAll
as well, either providing your own implementation, or delegating to the providedstandardAddAll
method.default
method warning: This class does not forward calls todefault
methods. Instead, it inherits their default implementations. When those implementations invoke methods, they invoke methods on theForwardingList
.The
standard
methods and any collection views they return are not guaranteed to be thread-safe, even when all of the methods that they depend on are thread-safe.- Since:
- 2.0
- Author:
- Mike Bostock, Louis Wasserman
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ForwardingList()
Constructor for use by subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
boolean
addAll(int index, java.util.Collection<? extends E> elements)
protected abstract java.util.List<E>
delegate()
Returns the backing delegate instance that methods are forwarded to.boolean
equals(java.lang.Object object)
E
get(int index)
int
hashCode()
int
indexOf(java.lang.Object element)
int
lastIndexOf(java.lang.Object element)
java.util.ListIterator<E>
listIterator()
java.util.ListIterator<E>
listIterator(int index)
E
remove(int index)
E
set(int index, E element)
protected boolean
standardAdd(E element)
A sensible default implementation ofForwardingCollection.add(Object)
, in terms ofadd(int, Object)
.protected boolean
standardAddAll(int index, java.lang.Iterable<? extends E> elements)
A sensible default implementation ofaddAll(int, Collection)
, in terms of theadd
method oflistIterator(int)
.protected boolean
standardEquals(java.lang.Object object)
A sensible definition ofequals(Object)
in terms ofForwardingCollection.size()
andForwardingCollection.iterator()
.protected int
standardHashCode()
A sensible definition ofhashCode()
in terms ofForwardingCollection.iterator()
.protected int
standardIndexOf(java.lang.Object element)
A sensible default implementation ofindexOf(java.lang.Object)
, in terms oflistIterator()
.protected java.util.Iterator<E>
standardIterator()
A sensible default implementation ofForwardingCollection.iterator()
, in terms oflistIterator()
.protected int
standardLastIndexOf(java.lang.Object element)
A sensible default implementation oflastIndexOf(java.lang.Object)
, in terms oflistIterator(int)
.protected java.util.ListIterator<E>
standardListIterator()
A sensible default implementation oflistIterator()
, in terms oflistIterator(int)
.protected java.util.ListIterator<E>
standardListIterator(int start)
A sensible default implementation oflistIterator(int)
, in terms ofForwardingCollection.size()
,get(int)
,set(int, Object)
,add(int, Object)
, andremove(int)
.protected java.util.List<E>
standardSubList(int fromIndex, int toIndex)
A sensible default implementation ofsubList(int, int)
.java.util.List<E>
subList(int fromIndex, int toIndex)
-
Methods inherited from class com.google.common.collect.ForwardingCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, standardAddAll, standardClear, standardContains, standardContainsAll, standardIsEmpty, standardRemove, standardRemoveAll, standardRetainAll, standardToArray, standardToArray, standardToString, toArray, toArray
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
-
-
-
Constructor Detail
-
ForwardingList
protected ForwardingList()
Constructor for use by subclasses.
-
-
Method Detail
-
delegate
protected abstract java.util.List<E> delegate()
Description copied from class:ForwardingObject
Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such asForwardingSet.delegate()
. Concrete subclasses override this method to supply the instance being decorated.- Specified by:
delegate
in classForwardingCollection<E extends @Nullable java.lang.Object>
-
addAll
@CanIgnoreReturnValue public boolean addAll(int index, java.util.Collection<? extends E> elements)
-
indexOf
public int indexOf(@CheckForNull java.lang.Object element)
-
lastIndexOf
public int lastIndexOf(@CheckForNull java.lang.Object element)
-
listIterator
public java.util.ListIterator<E> listIterator()
-
listIterator
public java.util.ListIterator<E> listIterator(int index)
-
remove
@CanIgnoreReturnValue public E remove(int index)
-
set
@CanIgnoreReturnValue public E set(int index, E element)
-
equals
public boolean equals(@CheckForNull java.lang.Object object)
-
hashCode
public int hashCode()
-
standardAdd
protected boolean standardAdd(E element)
A sensible default implementation ofForwardingCollection.add(Object)
, in terms ofadd(int, Object)
. If you overrideadd(int, Object)
, you may wish to overrideForwardingCollection.add(Object)
to forward to this implementation.- Since:
- 7.0
-
standardAddAll
protected boolean standardAddAll(int index, java.lang.Iterable<? extends E> elements)
A sensible default implementation ofaddAll(int, Collection)
, in terms of theadd
method oflistIterator(int)
. If you overridelistIterator(int)
, you may wish to overrideaddAll(int, Collection)
to forward to this implementation.- Since:
- 7.0
-
standardIndexOf
protected int standardIndexOf(@CheckForNull java.lang.Object element)
A sensible default implementation ofindexOf(java.lang.Object)
, in terms oflistIterator()
. If you overridelistIterator()
, you may wish to overrideindexOf(java.lang.Object)
to forward to this implementation.- Since:
- 7.0
-
standardLastIndexOf
protected int standardLastIndexOf(@CheckForNull java.lang.Object element)
A sensible default implementation oflastIndexOf(java.lang.Object)
, in terms oflistIterator(int)
. If you overridelistIterator(int)
, you may wish to overridelastIndexOf(java.lang.Object)
to forward to this implementation.- Since:
- 7.0
-
standardIterator
protected java.util.Iterator<E> standardIterator()
A sensible default implementation ofForwardingCollection.iterator()
, in terms oflistIterator()
. If you overridelistIterator()
, you may wish to overrideForwardingCollection.iterator()
to forward to this implementation.- Since:
- 7.0
-
standardListIterator
protected java.util.ListIterator<E> standardListIterator()
A sensible default implementation oflistIterator()
, in terms oflistIterator(int)
. If you overridelistIterator(int)
, you may wish to overridelistIterator()
to forward to this implementation.- Since:
- 7.0
-
standardListIterator
protected java.util.ListIterator<E> standardListIterator(int start)
A sensible default implementation oflistIterator(int)
, in terms ofForwardingCollection.size()
,get(int)
,set(int, Object)
,add(int, Object)
, andremove(int)
. If you override any of these methods, you may wish to overridelistIterator(int)
to forward to this implementation.- Since:
- 7.0
-
standardSubList
protected java.util.List<E> standardSubList(int fromIndex, int toIndex)
A sensible default implementation ofsubList(int, int)
. If you override any other methods, you may wish to overridesubList(int, int)
to forward to this implementation.- Since:
- 7.0
-
standardEquals
protected boolean standardEquals(@CheckForNull java.lang.Object object)
A sensible definition ofequals(Object)
in terms ofForwardingCollection.size()
andForwardingCollection.iterator()
. If you override either of those methods, you may wish to overrideequals(Object)
to forward to this implementation.- Since:
- 7.0
-
standardHashCode
protected int standardHashCode()
A sensible definition ofhashCode()
in terms ofForwardingCollection.iterator()
. If you overrideForwardingCollection.iterator()
, you may wish to overridehashCode()
to forward to this implementation.- Since:
- 7.0
-
-