groovy.lang
Class SpreadList

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractList
          extended by groovy.lang.SpreadList
All Implemented Interfaces:
Iterable, Collection, List

public class SpreadList
extends AbstractList

Spreads a list as individual objects to support the spread operator (*) for lists. For examples,

     def fn(a, b, c, d) { return a + b + c + d }
     println fn(1, 2, 3, 4)
 
     def x = [10, 100]
     def y = [1, *x, 1000, *[10000, 100000]]
     assert y == [1, 10, 100, 1000, 10000, 100000]
 

Version:
$Revision: 1.6 $
Author:
James Strachan, Pilho Kim

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
SpreadList(Object[] contents)
          Generator.
 
Method Summary
 boolean equals(Object that)
          Compares this with another object.
 boolean equals(SpreadList that)
          Compares this with another spreadlist.
 Object get(int index)
          Returns the object in this of the indicated position.
 int hashCode()
          Returns the hash code of this.
 int size()
          Returns the size of this.
 List subList(int fromIndex, int toIndex)
          Returns a sublist of this from fromIndex to toIndex.
 String toString()
          Returns the string expression of this.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

SpreadList

public SpreadList(Object[] contents)
Generator.

Parameters:
contents - an array of objects to be converted to a SpreadList
Method Detail

get

public Object get(int index)
Returns the object in this of the indicated position.

Specified by:
get in interface List
Specified by:
get in class AbstractList
Parameters:
index - the indicated position in this

size

public int size()
Returns the size of this.

Specified by:
size in interface Collection
Specified by:
size in interface List
Specified by:
size in class AbstractCollection
Parameters:
index - the indicated position in this

equals

public boolean equals(Object that)
Compares this with another object.

Specified by:
equals in interface Collection
Specified by:
equals in interface List
Overrides:
equals in class AbstractList
Parameters:
that - another object to be compared with this
Returns:
Returns true if this equals to that, false otherwise

equals

public boolean equals(SpreadList that)
Compares this with another spreadlist.

Parameters:
that - another spreadlist to be compared with this
Returns:
Returns true if this equals to that, false otherwise

hashCode

public int hashCode()
Returns the hash code of this.

Specified by:
hashCode in interface Collection
Specified by:
hashCode in interface List
Overrides:
hashCode in class AbstractList
Returns:
Returns the hash code of this

subList

public List subList(int fromIndex,
                    int toIndex)
Returns a sublist of this from fromIndex to toIndex.

Specified by:
subList in interface List
Overrides:
subList in class AbstractList
Parameters:
fromIndex - the first index in this to be taken
toIndex - the last index in this to be taken
Returns:
Returns the sublist of thin in the given scope

toString

public String toString()
Returns the string expression of this.

Overrides:
toString in class AbstractCollection
Returns:
Returns the string expression of this


Copyright © 2003-2010 The Codehaus. All Rights Reserved.