001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2011-2011 Pentaho
008// All Rights Reserved.
009*/
010package mondrian.calc.impl;
011
012import mondrian.calc.*;
013import mondrian.olap.Member;
014
015import java.util.Iterator;
016import java.util.List;
017
018/**
019* Abstract implementation of {@link mondrian.calc.TupleIterable}.
020 *
021 * <p>Derived classes need to implement only {@link #tupleCursor()},
022 * and this implementation will implement {@link #tupleIterator()} and
023 * {@link #iterator()} by creating a wrapper around that cursor. (The cursor
024 * interface is easier to implement efficiently than the wider iterator
025 * interface.) If you have a more efficient implementation of cursor, override
026 * the {@code tupleIterator} method.
027 *
028 * @author jhyde
029 */
030public abstract class AbstractTupleIterable
031    implements TupleIterable
032{
033    protected final int arity;
034
035    /**
036     * Creates an AbstractTupleIterable.
037     *
038     * @param arity Arity (number of members per tuple)
039     */
040    public AbstractTupleIterable(int arity) {
041        this.arity = arity;
042    }
043
044    public int getArity() {
045        return arity;
046    }
047
048    public Iterable<Member> slice(int column) {
049        return TupleCollections.slice(this, column);
050    }
051
052    public final Iterator<List<Member>> iterator() {
053        return tupleIterator();
054    }
055
056    public TupleIterator tupleIterator() {
057        return TupleCollections.iterator(tupleCursor());
058    }
059}
060
061// End AbstractTupleIterable.java