Package randoop.util
Class ListOfLists<E>
- java.lang.Object
-
- randoop.util.ListOfLists<E>
-
- All Implemented Interfaces:
Serializable
,SimpleList<E>
public class ListOfLists<E> extends Object implements SimpleList<E>, Serializable
Given a list of lists, defines methods that can access all the elements as if they were part of a single list, without actually merging the lists.This class is used for performance reasons. We want the ability to select elements collected across several lists, but we observed that creating a brand new list (i.e. via a sequence of List.addAll(..) operations can be very expensive, because it happened in a hot spot (method SequenceCollection.getSequencesThatYield).
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private int[]
cumulativeSize
The i-th value is the number of elements in the sublists up to the i-th one, inclusive.List<SimpleList<E>>
lists
The lists themselves.private static long
serialVersionUID
private int
totalelements
The size of this collection.
-
Constructor Summary
Constructors Constructor Description ListOfLists(List<SimpleList<E>> lists)
ListOfLists(SimpleList<E>... lists)
Create a ListOfLists from ...
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E
get(int index)
Return the element at the given position of this list.SimpleList<E>
getSublist(int index)
Return a sublist of this list that contains the index.boolean
isEmpty()
Test if this list is empty.int
size()
Return the number of elements in this list.List<E>
toJDKList()
Returns a java.util.List version of this list.String
toString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
lists
public final List<SimpleList<E>> lists
The lists themselves.
-
cumulativeSize
private int[] cumulativeSize
The i-th value is the number of elements in the sublists up to the i-th one, inclusive.
-
totalelements
private int totalelements
The size of this collection.
-
-
Constructor Detail
-
ListOfLists
public ListOfLists(SimpleList<E>... lists)
Create a ListOfLists from ... a list of lists.- Parameters:
lists
- the lists that will compose the newly-created ListOfLists
-
ListOfLists
public ListOfLists(List<SimpleList<E>> lists)
-
-
Method Detail
-
size
public int size()
Description copied from interface:SimpleList
Return the number of elements in this list.- Specified by:
size
in interfaceSimpleList<E>
- Returns:
- the number of elements in this list
-
isEmpty
public boolean isEmpty()
Description copied from interface:SimpleList
Test if this list is empty.- Specified by:
isEmpty
in interfaceSimpleList<E>
- Returns:
- true if this list is empty, false otherwise
-
get
public E get(int index)
Description copied from interface:SimpleList
Return the element at the given position of this list.- Specified by:
get
in interfaceSimpleList<E>
- Parameters:
index
- the position for the element- Returns:
- the element at the index
-
getSublist
public SimpleList<E> getSublist(int index)
Description copied from interface:SimpleList
Return a sublist of this list that contains the index. Does not necessarily contain the first element.The result is always an existing SimpleList, the smallest one that contains the index. Currently, it is always a
SimpleArrayList
.- Specified by:
getSublist
in interfaceSimpleList<E>
- Parameters:
index
- the index into this list- Returns:
- the sublist containing this index
-
toJDKList
public List<E> toJDKList()
Description copied from interface:SimpleList
Returns a java.util.List version of this list. Caution: this operation can be expensive.- Specified by:
toJDKList
in interfaceSimpleList<E>
- Returns:
List
for this list
-
-