1 10 package mondrian.olap.type; 11 12 import mondrian.olap.Level; 13 import mondrian.olap.Dimension; 14 import mondrian.olap.Hierarchy; 15 import mondrian.olap.Util; 16 17 24 public class LevelType implements Type { 25 private final Dimension dimension; 26 private final Hierarchy hierarchy; 27 private final Level level; 28 private final String digest; 29 30 38 public LevelType(Dimension dimension, Hierarchy hierarchy, Level level) { 39 this.dimension = dimension; 40 this.hierarchy = hierarchy; 41 this.level = level; 42 if (level != null) { 43 Util.assertPrecondition(hierarchy != null, "hierarchy != null"); 44 Util.assertPrecondition(level.getHierarchy() == hierarchy, 45 "level.getHierarchy() == hierarchy"); 46 } 47 if (hierarchy != null) { 48 Util.assertPrecondition(dimension != null, "dimension != null"); 49 Util.assertPrecondition(hierarchy.getDimension() == dimension, 50 "hierarchy.getDimension() == dimension"); 51 } 52 StringBuilder buf = new StringBuilder ("LevelType<"); 53 if (level != null) { 54 buf.append("level=").append(level.getUniqueName()); 55 } else if (hierarchy != null) { 56 buf.append("hierarchy=").append(hierarchy.getUniqueName()); 57 } else if (dimension != null) { 58 buf.append("dimension=").append(dimension.getUniqueName()); 59 } 60 buf.append(">"); 61 this.digest = buf.toString(); 62 } 63 64 public static LevelType forType(Type type) { 65 return new LevelType( 66 type.getDimension(), 67 type.getHierarchy(), 68 type.getLevel()); 69 70 } 71 72 public static LevelType forLevel(Level level) { 73 return new LevelType( 74 level.getDimension(), 75 level.getHierarchy(), 76 level); 77 } 78 79 public boolean usesDimension(Dimension dimension, boolean maybe) { 80 if (this.dimension == null) { 81 return maybe; 82 } else { 83 return this.dimension == dimension; 84 } 85 } 86 87 public Dimension getDimension() { 88 return dimension; 89 } 90 91 public Hierarchy getHierarchy() { 92 return hierarchy; 93 } 94 95 public Level getLevel() { 96 return level; 97 } 98 99 public String toString() { 100 return digest; 101 } 102 } 103 104 | Popular Tags |