private static void outputFlattenedRecurse( Result result, List<List<Object>> rows, List<Object> rowValues, int[] coords, int axisOrdinal ) { final Axis[] axes = result.getAxes(); if ( axisOrdinal == axes.length ) { final Cell cell = result.getCell( coords ); // Output the raw (unformatted) value of the cell. // NOTE: We could output other properties of the cell here, such as its // formatted value, too. rowValues.add( cell.getValue() ); // Add a copy of the completed row to the list of rows. rows.add( new ArrayList<>( rowValues ) ); } else { final Axis axis = axes[axisOrdinal]; int k = -1; int saveLength = rowValues.size(); for ( Position position : axis.getPositions() ) { coords[axisOrdinal] = ++k; for ( Member member : position ) { rowValues.add( member.getUniqueName() ); } outputFlattenedRecurse( result, rows, rowValues, coords, axisOrdinal + 1 ); while ( rowValues.size() > saveLength ) { rowValues.remove( rowValues.size() - 1 ); } } } }
final List<Position> positions = axis.getPositions(); if ( positions.isEmpty() ) {
for ( Position rowPos : rowsAxis.getPositions() ) { ++rowOrdinal; coords[1] = rowOrdinal; for ( Position columnPos : columnsAxis.getPositions() ) { String heading = ""; for ( Member columnMember : columnPos ) { for ( int columnOrdinal = 0; columnOrdinal < columnsAxis.getPositions().size(); ++columnOrdinal ) { coords[0] = columnOrdinal; final Cell cell = result.getCell( coords );
private Three(final Axis[] axes) { super(axes); int modulo = axes[0].getPositions().size(); this.modulos[1] = modulo; modulo *= axes[1].getPositions().size(); this.modulos[2] = modulo; modulo *= axes[2].getPositions().size(); this.modulos[3] = modulo; } public final int[] getCellPos(final int cellOrdinal) {
private Many(final Axis[] axes) { super(axes); int modulo = 1; for (int i = 0; i < axes.length; i++) { modulo *= axes[i].getPositions().size(); this.modulos[i + 1] = modulo; } } private Many(final int[] lengths) {
private Two(final Axis[] axes) { super(axes); int modulo = axes[0].getPositions().size(); this.modulos[1] = modulo; modulo *= axes[1].getPositions().size(); this.modulos[2] = modulo; } public final int[] getCellPos(final int cellOrdinal) {
private One(final Axis[] axes) { super(axes); this.modulos[1] = axes[0].getPositions().size(); } public final int[] getCellPos(final int cellOrdinal) {
private String getBoundsAsString() { StringBuilder buf = new StringBuilder(); Axis[] axes = result.getAxes(); for (int i = 0; i < axes.length; i++) { if (i > 0) { buf.append(", "); } buf.append(axes[i].getPositions().size()); } return buf.toString(); }
AxisBuilder(Element parent, Axis axis) { this.parent = parent; positions = axis.getPositions(); levels = positions.get(0).size(); prevMembers = new Member[levels]; prevElems = new Element[levels]; prevSpan = new int[levels]; }
public static String toString(Axis axis) { List<Position> pl = axis.getPositions(); return toString(pl); }
void populateEvaluator(Evaluator evaluator, int[] pos) { for (int i = -1; i < axes.length; i++) { Axis axis; int index; if (i < 0) { axis = slicerAxis; if (axis.getPositions().isEmpty()) { continue; } index = 0; } else { axis = axes[i]; index = pos[i]; } Position position = axis.getPositions().get(index); evaluator.setContext(position); } }
void buildCornerElement(Element row) { Element corner = elem("corner", row); corner.setAttribute( "rowspan", Integer.toString( result.getAxes()[0].getPositions().get(0).size())); corner.setAttribute( "colspan", Integer.toString( result.getAxes()[1].getPositions().get(0).size())); } }
private int[] ordinalToCoordinateArray(int ordinal) { Axis[] axes = result.getAxes(); final int[] pos = new int[axes.length]; int modulo = 1; for (int i = 0; i < axes.length; i++) { int prevModulo = modulo; modulo *= axes[i].getPositions().size(); pos[i] = (ordinal % modulo) / prevModulo; } if (ordinal < 0 || ordinal >= modulo) { throw new IndexOutOfBoundsException( "Cell ordinal " + ordinal + ") lies outside CellSet bounds (" + getBoundsAsString() + ")"); } return pos; }
private void printRows(PrintWriter pw, int axis, int[] pos) { if (axis < 0) { printCell(pw, pos); } else { Axis _axis = axes[axis]; List<Position> positions = _axis.getPositions(); for (int i = 0; i < positions.size(); i++) { pos[axis] = i; if (axis == 0) { int row = axis + 1 < pos.length ? pos[axis + 1] : 0; pw.print("Row #" + row + ": "); } printRows(pw, axis - 1, pos); if (axis == 0) { pw.println(); } } } }
private void printAxis(PrintWriter pw, Axis axis) { List<Position> positions = axis.getPositions(); for (Position position : positions) { boolean firstTime = true; pw.print("{"); for (Member member : position) { if (member.getDimension().isHighCardinality()) { pw.println(" -- High cardinality dimension --}"); return; } if (! firstTime) { pw.print(", "); } pw.print(member.getUniqueName()); firstTime = false; } pw.println("}"); } }
private void buildCells(Element row, int[] cellIndex, boolean even) { int columns = result.getAxes()[0].getPositions().size(); for (int i = 0; i < columns; i++) { cellIndex[0] = i; Cell cell = result.getCell(cellIndex); buildCell(cell, row, even); } }
private void buildSlicer(Element parent) { List<Position> positions = result.getSlicerAxis().getPositions(); for (int i = 0; i < positions.size(); i++) { Position position = positions.get(i); if (position.size() > 0) { Element el = elem("position", parent); for (int j = 0; j < position.size(); j++) { createMemberElem("member", el, position.get(j)); } } } }
/** * Returns the current member of a given hierarchy at a given location. * * @param pos Coordinates in cell set * @param hierarchy Hierarchy * @return current member of given hierarchy */ public Member getMember(int[] pos, Hierarchy hierarchy) { for (int i = -1; i < axes.length; i++) { Axis axis = slicerAxis; int index = 0; if (i >= 0) { axis = axes[i]; index = pos[i]; } List<Position> positions = axis.getPositions(); Position position = positions.get(index); for (Member member : position) { if (member.getHierarchy() == hierarchy) { return member; } } } return hierarchy.getHierarchy().getDefaultMember(); }
/** * Called only by RolapCell. Use this when creating an Evaluator * is not required. * * @param pos Coordinates of cell * @return Members which form the context of the given cell */ RolapMember[] getCellMembers(int[] pos) { RolapMember[] members = (RolapMember[]) evaluator.getMembers().clone(); for (int i = 0; i < pos.length; i++) { Position position = axes[i].getPositions().get(pos[i]); for (Member member : position) { RolapMember m = (RolapMember) member; int ordinal = m.getHierarchy().getOrdinalInCube(); members[ordinal] = m; } } return members; }
private boolean isEmptyRecurse(int fixedAxis, int axis) { if (axis < 0) { RolapCell cell = (RolapCell) underlying.getCell(pos); return cell.isNull(); } else if (axis == fixedAxis) { return isEmptyRecurse(fixedAxis, axis - 1); } else { List<Position> positions = getAxes()[axis].getPositions(); final int positionCount = positions.size(); for (int i = 0; i < positionCount; i++) { pos[axis] = i; if (!isEmptyRecurse(fixedAxis, axis - 1)) { return false; } } return true; } }