Search in sources :

Example 1 with CoordinateIterator

use of org.olap4j.impl.CoordinateIterator in project mondrian by pentaho.

the class TestContext method cellIter.

/**
 * Returns an iterator over cells in an olap4j cell set.
 */
static Iterable<org.olap4j.Cell> cellIter(final CellSet cellSet) {
    return new Iterable<org.olap4j.Cell>() {

        public Iterator<org.olap4j.Cell> iterator() {
            int[] axisDimensions = new int[cellSet.getAxes().size()];
            int k = 0;
            for (CellSetAxis axis : cellSet.getAxes()) {
                axisDimensions[k++] = axis.getPositions().size();
            }
            final CoordinateIterator coordIter = new CoordinateIterator(axisDimensions);
            return new Iterator<org.olap4j.Cell>() {

                public boolean hasNext() {
                    return coordIter.hasNext();
                }

                public org.olap4j.Cell next() {
                    final int[] ints = coordIter.next();
                    final List<Integer> list = new AbstractList<Integer>() {

                        public Integer get(int index) {
                            return ints[index];
                        }

                        public int size() {
                            return ints.length;
                        }
                    };
                    return cellSet.getCell(list);
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : AbstractList(java.util.AbstractList) CoordinateIterator(org.olap4j.impl.CoordinateIterator) CellSetAxis(org.olap4j.CellSetAxis) CoordinateIterator(org.olap4j.impl.CoordinateIterator) Iterator(java.util.Iterator) Cell(mondrian.olap.Cell)

Example 2 with CoordinateIterator

use of org.olap4j.impl.CoordinateIterator in project mondrian by pentaho.

the class TestContext method cellIter.

/**
 * Returns an iterator over cells in a result.
 */
static Iterable<Cell> cellIter(final Result result) {
    return new Iterable<Cell>() {

        public Iterator<Cell> iterator() {
            int[] axisDimensions = new int[result.getAxes().length];
            int k = 0;
            for (Axis axis : result.getAxes()) {
                axisDimensions[k++] = axis.getPositions().size();
            }
            final CoordinateIterator coordIter = new CoordinateIterator(axisDimensions);
            return new Iterator<Cell>() {

                public boolean hasNext() {
                    return coordIter.hasNext();
                }

                public Cell next() {
                    final int[] ints = coordIter.next();
                    return result.getCell(ints);
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : CoordinateIterator(org.olap4j.impl.CoordinateIterator) CoordinateIterator(org.olap4j.impl.CoordinateIterator) Iterator(java.util.Iterator) Cell(mondrian.olap.Cell) Axis(mondrian.olap.Axis) CellSetAxis(org.olap4j.CellSetAxis)

Example 3 with CoordinateIterator

use of org.olap4j.impl.CoordinateIterator in project pentaho-kettle by pentaho.

the class CellSetFormatter method cellIter.

/**
 * Returns an iterator over cells in a result.
 */
private static Iterable<Cell> cellIter(final int[] pageCoords, final CellSet cellSet) {
    return new Iterable<Cell>() {

        public Iterator<Cell> iterator() {
            final int[] axisDimensions = new int[cellSet.getAxes().size() - pageCoords.length];
            assert pageCoords.length <= axisDimensions.length;
            for (int i = 0; i < axisDimensions.length; i++) {
                final CellSetAxis axis = cellSet.getAxes().get(i);
                axisDimensions[i] = axis.getPositions().size();
            }
            final CoordinateIterator coordIter = new CoordinateIterator(axisDimensions, true);
            return new Iterator<Cell>() {

                public boolean hasNext() {
                    return coordIter.hasNext();
                }

                public Cell next() {
                    final int[] ints = coordIter.next();
                    final AbstractList<Integer> intList = new AbstractList<Integer>() {

                        @Override
                        public Integer get(final int index) {
                            return index < ints.length ? ints[index] : pageCoords[index - ints.length];
                        }

                        @Override
                        public int size() {
                            return pageCoords.length + ints.length;
                        }
                    };
                    return cellSet.getCell(intList);
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : AbstractList(java.util.AbstractList) CoordinateIterator(org.olap4j.impl.CoordinateIterator) CellSetAxis(org.olap4j.CellSetAxis) Iterator(java.util.Iterator) CoordinateIterator(org.olap4j.impl.CoordinateIterator) Cell(org.olap4j.Cell)

Aggregations

Iterator (java.util.Iterator)3 CellSetAxis (org.olap4j.CellSetAxis)3 CoordinateIterator (org.olap4j.impl.CoordinateIterator)3 AbstractList (java.util.AbstractList)2 Cell (mondrian.olap.Cell)2 Axis (mondrian.olap.Axis)1 Cell (org.olap4j.Cell)1