Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## groovy.lang
[Java] Class ListWithDefault

    java.lang.Object
      groovy.lang.ListWithDefault

All Implemented Interfaces:
  java.util.List

    public final class ListWithDefault
    extends java.lang.Object

A wrapper for java.util.List which automatically grows the list when either get(int) or getAt(int) is called with an index greater than or equal to `size()`.

Authors:
  Andre Steingress

Since:
  1.8.7

Method Summary
`boolean` | `add(java.lang.Object t)`
`void` | `add(int i, java.lang.Object t)`
`boolean` | `addAll(java.util.Collection ts)`
`boolean` | `addAll(int i, java.util.Collection ts)`
`void` | `clear()`
`boolean` | `contains(java.lang.Object o)`
`boolean` | `containsAll(java.util.Collection objects)`
`boolean` | `equals(java.lang.Object obj)`
`java.lang.Object` | `get(int index)` Returns the element at the given index but grows the list if needed.
`java.lang.Object` | `getAt(int index)` Overwrites subscript operator handling by redirecting to get(int).
`int` | `hashCode()`
`int` | `indexOf(java.lang.Object o)`
`boolean` | `isEmpty()`
`java.util.Iterator` | `iterator()`
`int` | `lastIndexOf(java.lang.Object o)`
`java.util.ListIterator` | `listIterator()`
`java.util.ListIterator` | `listIterator(int i)`
`static java.util.List` | `newInstance(java.util.List items, boolean lazyDefaultValues, Closure initClosure)`
`boolean` | `remove(java.lang.Object o)`
`java.lang.Object` | `remove(int i)`
`boolean` | `removeAll(java.util.Collection objects)`
`boolean` | `retainAll(java.util.Collection objects)`
`java.lang.Object` | `set(int i, java.lang.Object t)`
`int` | `size()`
`java.util.List` | `subList(int fromIndex, int toIndex)`
`java.lang.Object[]` | `toArray()`
`java.lang.Object[]` | `toArray(java.lang.Object[] ts)`

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Method Detail

### add

    public boolean add(java.lang.Object t)

### add

    public void add(int i, java.lang.Object t)

### addAll

    public boolean addAll(java.util.Collection ts)

### addAll

    public boolean addAll(int i, java.util.Collection ts)

### clear

    public void clear()

### contains

    public boolean contains(java.lang.Object o)

### containsAll

    public boolean containsAll(java.util.Collection objects)

### equals

    public int hashCode() {
    public boolean equals(java.lang.Object obj)

### get

    public java.lang.Object get(int index)

  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 java.util.List#get(int) as it a) possibly modifies the underlying list and b) does NOT throw an java.lang.IndexOutOfBoundsException when `index < 0 || index >= size()`.
  Parameters:
    `index` - an index (might be greater or equal to `size()`, or smaller than 0)
  Returns:
    the value at the given `index` or the default value

### getAt

    public java.lang.Object getAt(int index)

  Overwrites subscript operator handling by redirecting to get(int).
  Parameters:
    `index` - an index (might be greater or equal to `size()`, or smaller than 0)
  Returns:
    the value at the given `index` or the default value

### hashCode

    * Returns a view of a portion of this list. This method returns a list with the same
    public int hashCode()

### indexOf

    public int indexOf(java.lang.Object o)

### isEmpty

    public boolean isEmpty()

### iterator

    public java.util.Iterator iterator()

### lastIndexOf

    public int lastIndexOf(java.lang.Object o)

### listIterator

    public java.util.ListIterator listIterator()

### listIterator

    public java.util.ListIterator listIterator(int i)

### newInstance

    public static java.util.List newInstance(java.util.List items, boolean lazyDefaultValues, Closure initClosure)

### remove

    public boolean remove(java.lang.Object o)

### remove

    public java.lang.Object remove(int i)

### removeAll

    public boolean removeAll(java.util.Collection objects)

### retainAll

    public boolean retainAll(java.util.Collection objects)

### set

    public java.lang.Object set(int i, java.lang.Object t)

### size

    public int size()

### subList

    public java.util.List subList(int fromIndex, int toIndex)

### toArray

    public java.lang.Object[] toArray()

### toArray

    public java.lang.Object[] toArray(java.lang.Object[] ts)

Groovy Documentation