final ProcessingContext prc = new DefaultProcessingContext();
final GlobalMasterRow gmr = GlobalMasterRow.createReportRow
(prc, new DefaultDataSchemaDefinition(), new ParameterDataRow());
gmr.requireStructuralProcessing();
MasterDataRow masterDataRow = gmr.deriveWithQueryData(data);
final CrosstabSpecification crosstabSpecification = new SortedMergeCrosstabSpecification
(new ReportStateKey(), new String[]{"Product", "Time"}, new String[] {"Region"});
int advanceCount = 0;
logger.debug("Building Crosstab: Cursor: " + String.valueOf(masterDataRow.getReportDataRow().getCursor()));
crosstabSpecification.startRow();
crosstabSpecification.add(masterDataRow.getGlobalView());
Object grpVal = masterDataRow.getGlobalView().get("Region");
while (masterDataRow.isAdvanceable())
{
final MasterDataRow nextdata = masterDataRow.advance();
final Object nextGrpVal = nextdata.getGlobalView().get("Region");
if (ObjectUtilities.equal(grpVal, nextGrpVal) == false)
{
crosstabSpecification.endRow();
crosstabSpecification.startRow();
}
crosstabSpecification.add(nextdata.getGlobalView());
logger.debug("Prepare Advance Count: " + nextdata.getReportDataRow().getCursor());
advanceCount += 1;
masterDataRow = nextdata;
grpVal = nextGrpVal;
}
crosstabSpecification.endRow();
crosstabSpecification.endCrosstab();
if (advanceCount != (data.getRowCount() - 1))
{
throw new IllegalStateException("Expected 6 but got " + advanceCount);
}
return crosstabSpecification;