Package randoop.util

Class 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 Detail

      • 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
    • Method Detail

      • size

        public int size()
        Description copied from interface: SimpleList
        Return the number of elements in this list.
        Specified by:
        size in interface SimpleList<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 interface SimpleList<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 interface SimpleList<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 interface SimpleList<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 interface SimpleList<E>
        Returns:
        List for this list