final Position position = positions.get(positionsIndex);
final List<Member> members = position.getMembers();
for (int positionIndex = 0; positionIndex < members.size(); positionIndex++)
{
final LinkedHashSet<String> columnNamesSet = new LinkedHashSet<String>();
Member m = members.get(positionIndex);
final Dimension dimension = m.getDimension();
int hierarchyLevelCount = 0;
while (m != null)
{
final String name = m.getLevel().getUniqueName();
if (columnNamesSet.contains(name) == false)
{
columnNamesSet.add(name);
}
m = m.getParentMember();
}
hierarchyLevelCount = columnNamesSet.size();
if (memberList.size() <= positionIndex)
{
memberList.add(hierarchyLevelCount);
dimensionsForMembers.add(dimension);
}
else
{
final Integer existingLevel = memberList.get(positionIndex);
if (existingLevel.intValue() < hierarchyLevelCount)
{
memberList.set(positionIndex, hierarchyLevelCount);
dimensionsForMembers.set(positionIndex, dimension);
}
}
}
}
int memberCount = 0;
for (int i = 0; i < memberList.size(); i++)
{
memberCount += memberList.get(i);
}
axesMembers[axesIndex] = memberCount;
dimensionsForMembersPerAxis[axesIndex] = dimensionsForMembers;
membersPerAxis[axesIndex] = memberList;
}
if (axesSize.length > 1)
{
rowCount = axesSize[1];
for (int i = 2; i < axesSize.length; i++)
{
final int size = axesSize[i];
rowCount *= size;
}
}
if (noMeasures == false)
{
rowCount = Math.max(1, rowCount);
}
if (axesSize.length == 0)
{
columnCount = 1;
}
else if (axesSize.length > 0)
{
columnCount = axesSize[0];
}
for (int i = 1; i < axesMembers.length; i++)
{
columnCount += axesMembers[i];
}
columnNames = new String[columnCount];
columnToDimensionMapping = new Dimension[columnCount];
columnToAxisPosition = new int[columnCount];
int columnIndex = 0;
int dimColIndex = 0;
final FastStack memberStack = new FastStack();
for (int axesIndex = axes.size() - 1; axesIndex >= 1; axesIndex -= 1)
{
final CellSetAxis axis = axes.get(axesIndex);
final List<Position> positions = axis.getPositions();
final LinkedHashSet<String> columnNamesSet = new LinkedHashSet<String>();
for (int positionsIndex = 0; positionsIndex < positions.size(); positionsIndex++)
{
final Position position = positions.get(positionsIndex);
final List<Member> members = position.getMembers();
for (int positionIndex = 0; positionIndex < members.size(); positionIndex++)
{
memberStack.clear();
Member m = members.get(positionIndex);
while (m != null)
{
memberStack.push(m);
m = m.getParentMember();
}
while (memberStack.isEmpty() == false)
{
m = (Member) memberStack.pop();
final String name = m.getLevel().getUniqueName();
if (columnNamesSet.contains(name) == false)
{
columnNamesSet.add(name);
}
}
}
}
if (columnNamesSet.size() != axesMembers[axesIndex])
{
logger.error("ERROR: Number of names is not equal the pre-counted number.");
}
final List<Dimension> dimForMemberPerAxis = dimensionsForMembersPerAxis[axesIndex];
final List<Integer> memberCntPerAxis = membersPerAxis[axesIndex];
for (int i = 0; i < memberCntPerAxis.size(); i++)
{
final Integer count = memberCntPerAxis.get(i);
final Dimension dim = dimForMemberPerAxis.get(i);
for (int x = 0; x < count.intValue(); x += 1)
{
this.columnToDimensionMapping[dimColIndex + x] = dim;
this.columnToAxisPosition[dimColIndex + x] = axesIndex;
}
dimColIndex = count.intValue() + dimColIndex;
}
final String[] names = columnNamesSet.toArray(new String[columnNamesSet.size()]);
System.arraycopy(names, 0, this.columnNames, columnIndex, names.length);
columnIndex += names.length;
}
if (axesSize.length > 0)
{
// now create the column names for the column-axis
final CellSetAxis axis = axes.get(0);
final List<Position> positions = axis.getPositions();
for (int i = 0; i < positions.size(); i++)
{
final Position position = positions.get(i);
final StringBuffer positionName = new StringBuffer(100);
final List<Member> memberList = position.getMembers();
for (int j = 0; j < memberList.size(); j++)
{
if (j != 0)
{
positionName.append('/');
}
final Member member = memberList.get(j);
positionName.append(Olap4jUtil.getUniqueMemberName(member));
}
columnNames[columnIndex] = positionName.toString();
columnIndex += 1;
}