| Type Params | Return Type | Name and description |
|---|---|---|
|
public boolean |
add(T t)Appends the specified element to the end of this list (optional operation). Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.
|
|
public void |
add(int i, T t)Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
|
|
public boolean |
addAll(Collection<? extends T> ts)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
|
|
public boolean |
addAll(int i, Collection<? extends T> ts)Inserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
|
|
public void |
clear()Removes all of the elements from this list (optional operation). The list will be empty after this call returns.
|
|
public boolean |
contains(Object o)Returns true if this list contains the specified element.
More formally, returns true if and only if this list contains
at least one element e such that
Objects.equals(o, e).
|
|
public boolean |
containsAll(Collection<?> objects)Returns true if this list contains all of the elements of the
specified collection.
|
|
public boolean |
equals(Object obj)Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
|
|
public T |
get(int index)Returns the element at the given index but grows the list if needed. |
|
public T |
getAt(int index)Overwrites subscript operator handling by redirecting to get(int). |
|
public List<T> |
getDelegate()Returns a copy of the wrapped list. |
|
public Closure |
getInitClosure()Returns a clone of the initialization closure. |
|
public int |
hashCode()Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.
The general contract of
|
|
public int |
indexOf(Object o)Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that
Objects.equals(o, get(i)),
or -1 if there is no such index.
|
|
public boolean |
isEmpty()Returns true if this list contains no elements.
|
|
public boolean |
isLazyDefaultValues()Indicates whether missing values are initialized lazily. |
|
public Iterator<T> |
iterator()Returns an iterator over the elements in this list in proper sequence.
|
|
public int |
lastIndexOf(Object o)Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that
Objects.equals(o, get(i)),
or -1 if there is no such index.
|
|
public ListIterator<T> |
listIterator()Returns a list iterator over the elements in this list (in proper sequence).
|
|
public ListIterator<T> |
listIterator(int i)Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to previous would return the element with the specified index minus one.
|
<T> |
public static ListWithDefault<T> |
newInstance(List<T> items, boolean lazyDefaultValues, Closure initClosure)Creates a new list wrapper with the supplied defaulting behavior. |
|
public boolean |
remove(Object o)Removes the first occurrence of the specified element from this list, if it is present (optional operation). If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that
Objects.equals(o, get(i))
(if such an element exists). Returns true if this list
contained the specified element (or equivalently, if this list changed
as a result of the call).
|
|
public T |
remove(int i)Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
|
|
public boolean |
removeAll(Collection<?> objects)Removes from this list all of its elements that are contained in the specified collection (optional operation).
|
|
public boolean |
retainAll(Collection<?> objects)Retains only the elements in this list that are contained in the specified collection (optional operation). In other words, removes from this list all of its elements that are not contained in the specified collection.
|
|
public T |
set(int i, T t)Replaces the element at the specified position in this list with the specified element (optional operation).
|
|
public int |
size()Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns
Integer.MAX_VALUE.
|
|
public ListWithDefault<T> |
subList(int fromIndex, int toIndex)Returns a view of a portion of this list. |
|
public Object[] |
toArray()Returns an array containing all of the elements in this list in proper sequence (from first to last element). The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array. This method acts as bridge between array-based and collection-based APIs.
|
<U> |
public U[] |
toArray(U[] ts)Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list. If the list fits in the specified array with room to spare (i.e.,
the array has more elements than the list), the element in the array
immediately following the end of the list is set to Like the toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs. Suppose
Note that toArray(new Object[0]) is identical in function to
toArray().
|
Appends the specified element to the end of this list (optional operation).
Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.
add operation
is not supported by this liste - element to be appended to this listtrue (as specified by Collection.add)Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
add operation
is not supported by this listindex < 0 || index > size())index - index at which the specified element is to be insertedelement - element to be insertedAppends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
addAll operation
is not supported by this listc - collection containing elements to be added to this listtrue if this list changed as a result of the callInserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)
addAll operation
is not supported by this listindex < 0 || index > size())index - index at which to insert the first element from the
specified collectionc - collection containing elements to be added to this listtrue if this list changed as a result of the callRemoves all of the elements from this list (optional operation). The list will be empty after this call returns.
clear operation
is not supported by this list Returns true if this list contains the specified element.
More formally, returns true if and only if this list contains
at least one element e such that
Objects.equals(o, e).
o - element whose presence in this list is to be testedtrue if this list contains the specified element Returns true if this list contains all of the elements of the
specified collection.
c - collection to be checked for containment in this listtrue if this list contains all of the elements of the
specified collectionIndicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation
on non-null object references:
x, x.equals(x) should return
true.
x and y, x.equals(y)
should return true if and only if
y.equals(x) returns true.
x, y, and z, if
x.equals(y) returns true and
y.equals(z) returns true, then
x.equals(z) should return true.
x and y, multiple invocations of
x.equals(y) consistently return true
or consistently return false, provided no
information used in equals comparisons on the
objects is modified.
x,
x.equals(null) should return false.
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
equals method for class Object implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x and
y, this method returns true if and only
if x and y refer to the same object
(x == y has the value true).
In other words, under the reference equality equivalence
relation, each equivalence class only has a single element.hashCode method, which states
that equal objects must have equal hash codes.obj - the reference object with which to compare.true if this object is the same as the obj
argument; false otherwise. Returns the element at the given index but grows the list if needed. If the requested index is
greater than or equal to size(), the list will grow to the new size and a default value calculated
using the initClosure will be used to populate the missing value and returned.
If lazyDefaultValues is true any gaps when growing the list are filled
with nulls. Subsequent attempts to retrieve items from the list from those gap index values
will, upon finding null, call the initClosure to populate the list for the
given list value. Hence, when in this mode, nulls cannot be stored in this list.
If lazyDefaultValues is false any gaps when growing the list are filled
eagerly by calling the initClosure for all gap indexes during list growth.
No calls to initClosure are made except during list growth and it is ok to
store null values in the list when in this mode.
This implementation breaks
the contract of List.get as it a) possibly modifies the underlying list and b) does
NOT throw an IndexOutOfBoundsException when index < 0 || index >= size().
index - an index (might be greater or equal to size(), or smaller than 0)index or the default valueOverwrites subscript operator handling by redirecting to get(int).
index - an index (might be greater or equal to size(), or smaller than 0)index or the default valueReturns a copy of the wrapped list.
Returns a clone of the initialization closure.
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.
The general contract of hashCode is:
hashCode method
must consistently return the same integer, provided no information
used in equals comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
hashCode method on each of the two objects must produce the
same integer result.
hashCode method on each of the two objects
must produce distinct integer results. However, the programmer
should be aware that producing distinct integer results for
unequal objects may improve the performance of hash tables.
hashCode method defined
by class Object returns distinct integers for distinct objects. Returns the index of the first occurrence of the specified element
in this list, or -1 if this list does not contain the element.
More formally, returns the lowest index i such that
Objects.equals(o, get(i)),
or -1 if there is no such index.
o - element to search for Returns true if this list contains no elements.
true if this list contains no elementsIndicates whether missing values are initialized lazily.
true if defaults are created lazilyReturns an iterator over the elements in this list in proper sequence.
Returns the index of the last occurrence of the specified element
in this list, or -1 if this list does not contain the element.
More formally, returns the highest index i such that
Objects.equals(o, get(i)),
or -1 if there is no such index.
o - element to search forReturns a list iterator over the elements in this list (in proper sequence).
Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to previous would return the element with the specified index minus one.
index < 0 || index > size())index - index of the first element to be returned from the
list iterator (by a call to next)Creates a new list wrapper with the supplied defaulting behavior.
items - the source itemslazyDefaultValues - whether default values are created lazilyinitClosure - the closure used to create default valuesT - the element type Removes the first occurrence of the specified element from this list,
if it is present (optional operation). If this list does not contain
the element, it is unchanged. More formally, removes the element with
the lowest index i such that
Objects.equals(o, get(i))
(if such an element exists). Returns true if this list
contained the specified element (or equivalently, if this list changed
as a result of the call).
remove operation
is not supported by this listo - element to be removed from this list, if presenttrue if this list contained the specified elementRemoves the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
remove operation
is not supported by this listindex < 0 || index >= size())index - the index of the element to be removedRemoves from this list all of its elements that are contained in the specified collection (optional operation).
removeAll operation
is not supported by this listc - collection containing elements to be removed from this listtrue if this list changed as a result of the callRetains only the elements in this list that are contained in the specified collection (optional operation). In other words, removes from this list all of its elements that are not contained in the specified collection.
retainAll operation
is not supported by this listc - collection containing elements to be retained in this listtrue if this list changed as a result of the callReplaces the element at the specified position in this list with the specified element (optional operation).
set operation
is not supported by this listindex < 0 || index >= size())index - index of the element to replaceelement - element to be stored at the specified position Returns the number of elements in this list. If this list contains
more than Integer.MAX_VALUE elements, returns
Integer.MAX_VALUE.
Returns a view of a portion of this list. This method returns a list with the same lazy list settings as the original list.
fromIndex - low endpoint of the subList (inclusive)toIndex - upper endpoint of the subList (exclusive)Returns an array containing all of the elements in this list in proper sequence (from first to last element).
The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.
If the list fits in the specified array with room to spare (i.e.,
the array has more elements than the list), the element in the array
immediately following the end of the list is set to null.
(This is useful in determining the length of the list only if
the caller knows that the list does not contain any null elements.)
Like the toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.
Suppose x is a list known to contain only strings.
The following code can be used to dump the list into a newly
allocated array of String:
String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to
toArray().a - the array into which the elements of this list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.