Groovy 2.2.1

groovy.lang
[Java] Class ListWithDefault

java.lang.Object
  groovy.lang.ListWithDefault
All Implemented Interfaces:
List

public final class ListWithDefault
extends Object

A wrapper for 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(Object t)

void add(int i, Object t)

boolean addAll(Collection ts)

boolean addAll(int i, Collection ts)

void clear()

boolean contains(Object o)

boolean containsAll(Collection objects)

boolean equals(Object obj)

Object get(int index)

Returns the element at the given index but grows the list if needed.

Object getAt(int index)

Overwrites subscript operator handling by redirecting to get(int).

List getDelegate()

Closure getInitClosure()

int hashCode()

int indexOf(Object o)

boolean isEmpty()

boolean isLazyDefaultValues()

Iterator iterator()

int lastIndexOf(Object o)

ListIterator listIterator()

ListIterator listIterator(int i)

static List newInstance(List items, boolean lazyDefaultValues, Closure initClosure)

boolean remove(Object o)

Object remove(int i)

boolean removeAll(Collection objects)

boolean retainAll(Collection objects)

Object set(int i, Object t)

int size()

List subList(int fromIndex, int toIndex)

Object[] toArray()

Object[] toArray(Object[] ts)

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Method Detail

add

public boolean add(Object t)


add

public void add(int i, Object t)


addAll

public boolean addAll(Collection ts)


addAll

public boolean addAll(int i, Collection ts)


clear

public void clear()


contains

public boolean contains(Object o)


containsAll

public boolean containsAll(Collection objects)


equals

@Overridepublic int hashCode() {
public boolean equals(Object obj)


get

public 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 List.get as it a) possibly modifies the underlying list and b) does NOT throw an 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 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


getDelegate

public List getDelegate()


getInitClosure

public Closure getInitClosure()


hashCode

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


indexOf

public int indexOf(Object o)


isEmpty

public boolean isEmpty()


isLazyDefaultValues

public boolean isLazyDefaultValues()


iterator

public Iterator iterator()


lastIndexOf

public int lastIndexOf(Object o)


listIterator

public ListIterator listIterator()


listIterator

public ListIterator listIterator(int i)


newInstance

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


remove

public boolean remove(Object o)


remove

public Object remove(int i)


removeAll

public boolean removeAll(Collection objects)


retainAll

public boolean retainAll(Collection objects)


set

public Object set(int i, Object t)


size

public int size()


subList

public List subList(int fromIndex, int toIndex)


toArray

public Object[] toArray()


toArray

public Object[] toArray(Object[] ts)


 

Copyright &copy; 2003-2013 The Codehaus. All rights reserved.