mondrian.calc
Class TupleCollections

java.lang.Object
  extended by mondrian.calc.TupleCollections

public final class TupleCollections
extends Object

Utility methods for tuple collections and iterators.

Author:
jhyde
See Also:
TupleList, TupleIterator

Method Summary
static Iterable<Member[]> asMemberArrayIterable(TupleIterable tupleIterable)
          Converts a TupleIterable to an old-style iterable that creates an iterator over member arrays.
static List<Member[]> asMemberArrayList(TupleList tupleList)
          Converts a TupleList to an old-style list of member arrays.
static TupleList asTupleList(List list)
          Converts an old-style list (members or member arrays) to a TupleList.
static TupleList createList(int arity)
          Creates a list of given arity.
static TupleList createList(int arity, int initialCapacity)
          Creates a list of given arity and initial capacity.
static TupleList emptyList(int arity)
          Returns an empty TupleList of given arity.
static TupleIterator iterator(TupleCursor cursor)
          Adapts a TupleCursor into a TupleIterator.
static TupleList materialize(TupleIterable tupleIterable, boolean eager)
          Converts a TupleIterable into a TupleList.
static Iterable<Member> slice(TupleIterable tupleIterable, int column)
          Creates a slice of a TupleIterable.
static TupleList unmodifiableList(TupleList list)
          Creates an unmodifiable TupleList backed by a given list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createList

public static TupleList createList(int arity)
Creates a list of given arity.

If arity == 1, creates a UnaryTupleList; if arity == 0, creates a DelegatingTupleList; otherwise creates a ArrayTupleList.

Parameters:
arity - Arity
Returns:
Tuple list
See Also:
TupleList.cloneList(int), createList(int, int)

createList

public static TupleList createList(int arity,
                                   int initialCapacity)
Creates a list of given arity and initial capacity.

If arity == 1, creates a UnaryTupleList; if arity == 0, creates a DelegatingTupleList; otherwise creates a ArrayTupleList.

Parameters:
arity - Arity
initialCapacity - Initial capacity
Returns:
Tuple list
See Also:
TupleList.cloneList(int)

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)

iterator

public static TupleIterator iterator(TupleCursor cursor)
Adapts a TupleCursor into a TupleIterator.

Since the latter is a more difficult API to implement, the wrapper has some extra state.

This method may be used to implement TupleIterable.tupleIterator() for a TupleIterable or TupleList that only has a TupleCursor implementation.

Parameters:
cursor - Cursor
Returns:
Tuple iterator view onto the cursor

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

Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads