public final class ListWithDefault extends Object
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Type | Name and description |
---|---|
boolean |
add(T t) |
void |
add(int i, T t) |
boolean |
addAll(Collection<? extends T> ts) |
boolean |
addAll(int i, Collection<? extends T> ts) |
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> objects) |
boolean |
equals(Object obj) |
T |
get(int index) Returns the element at the given index but grows the list if needed. |
T |
getAt(int index) Overwrites subscript operator handling by redirecting to get(int). |
List<T> |
getDelegate() |
Closure |
getInitClosure() |
int |
hashCode() |
int |
indexOf(Object o) |
boolean |
isEmpty() |
boolean |
isLazyDefaultValues() |
Iterator<T> |
iterator() |
int |
lastIndexOf(Object o) |
ListIterator<T> |
listIterator() |
ListIterator<T> |
listIterator(int i) |
static List<T> |
newInstance(List<T> items, boolean lazyDefaultValues, Closure initClosure) |
boolean |
remove(Object o) |
T |
remove(int i) |
boolean |
removeAll(Collection<?> objects) |
boolean |
retainAll(Collection<?> objects) |
T |
set(int i, T t) |
int |
size() |
List<T> |
subList(int fromIndex, int toIndex) Returns a view of a portion of this list. |
Object[] |
toArray() |
T[] |
toArray(T[] ts) |
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 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)