1 13 package com.tonbeller.jpivot.test.olap; 14 15 import com.tonbeller.jpivot.olap.model.Hierarchy; 16 import com.tonbeller.jpivot.olap.model.impl.LevelImpl; 17 18 23 public class DimensionBuilder { 24 String hierName; 25 String [] levelNames; 26 int[] childCount; 27 28 LevelImpl[] levels; 29 30 public TestDimension build(String hierName, String [] levelNames, int[] childCount) { 31 this.hierName = hierName; 32 this.levelNames = levelNames; 33 this.childCount = childCount; 34 35 TestDimension dim = new TestDimension(); 37 dim.setLabel(hierName); 38 TestHierarchy hier = new TestHierarchy(); 39 hier.setLabel(hierName); 40 hier.setDimension(dim); 41 dim.setHierarchies(new Hierarchy[] { hier }); 42 43 levels = new LevelImpl[levelNames.length]; 44 for (int i = 0; i < levels.length; i++) { 45 TestLevel level = new TestLevel(); 46 level.setLabel(levelNames[i]); 47 level.setHierarchy(hier); 48 levels[i] = level; 49 } 50 hier.setLevels(levels); 51 52 TestMember[] roots = buildRoots(); 54 hier.rootMembers = roots; 55 56 return dim; 57 } 58 59 TestMember[] buildRoots() { 60 TestMember[] members = new TestMember[childCount[0]]; 61 for (int i = 0; i < childCount[0]; i++) { 62 TestMember member = new TestMember(); 63 member.setLabel(levelNames[0] + "[" + i + "]"); 64 member.setLevel(levels[0]); 65 member.setVisible(true); 66 appendChildren(member, 1); 67 members[i] = member; 68 } 69 return members; 70 } 71 72 73 void appendChildren(TestMember parent, int levelIndex) { 74 if (levelIndex >= childCount.length) 75 return; 76 77 for (int i = 0; i < childCount[levelIndex]; i++) { 78 TestMember member = new TestMember(); 79 member.setLabel(levelNames[levelIndex] + "[" + i + "]"); 80 member.setParentMember(parent); 81 member.setLevel(levels[levelIndex]); 82 member.setRootDistance(levelIndex); 83 parent.addChildMember(member); 84 appendChildren(member, levelIndex + 1); 85 } 86 } 87 88 } 89 | Popular Tags |