Package mondrian.calc

Class TupleCollections


  • public final class TupleCollections
    extends Object
    Utility methods for tuple collections and iterators.
    Author:
    jhyde
    See Also:
    TupleList, TupleIterator
    • Method Detail

      • emptyList

        public static TupleList emptyList​(int arity)
        Returns an empty TupleList of given arity.
        Parameters:
        arity - Number of members per tuple
        Returns:
        Empty tuple list
      • unmodifiableList

        public static TupleList unmodifiableList​(TupleList list)
        Creates an unmodifiable TupleList backed by a given list.
        Parameters:
        list - the list for which an unmodifiable view is to be returned.
        Returns:
        an unmodifiable view of the specified list.
        See Also:
        Collections.unmodifiableList(java.util.List)
      • slice

        public static Iterable<Member> slice​(TupleIterable tupleIterable,
                                             int column)
        Creates a slice of a TupleIterable.

        Can be used as an implementation for TupleList.slice(int).

        Parameters:
        tupleIterable - Iterable
        column - Which member of each tuple of project.
        Returns:
        Iterable that returns a given member of each tuple
      • asMemberArrayIterable

        public static Iterable<Member[]> asMemberArrayIterable​(TupleIterable tupleIterable)
        Converts a TupleIterable to an old-style iterable that creates an iterator over member arrays.
        Parameters:
        tupleIterable - Tuple iterable
        Returns:
        Iterable that creates an iterator over tuples represented as member arrays
      • asMemberArrayList

        public static List<Member[]> asMemberArrayList​(TupleList tupleList)
        Converts a TupleList to an old-style list of member arrays.
        Parameters:
        tupleList - Tuple list
        Returns:
        List of member arrays
      • asTupleList

        public static TupleList asTupleList​(List list)
        Converts an old-style list (members or member arrays) to a TupleList.

        Deduces the arity of the list from the first element, if the list is not empty. Otherwise assumes arity 1.

        If the list happens to be a tuple list, returns unchanged.

        Parameters:
        list - Old-style list
        Returns:
        Tuple list
      • materialize

        public static TupleList materialize​(TupleIterable tupleIterable,
                                            boolean eager)
        Converts a TupleIterable into a TupleList.

        If the iterable is already a list, returns the iterable. If it is not a list, the behavior depends on the eager parameter. With eager = true, creates a list and populates it with the contents of the iterable. With eager = false, wraps in an adapter that implements the list interface and materializes to a list the first time that an operation that is in TupleList but not TupleIterable -- for example, TupleList.get(int, int) or List.size() -- is called.

        Parameters:
        tupleIterable - Iterable
        eager - Whether to convert into a list now, as opposed to on first use of a random-access method such as size or get.
        Returns:
        List