1 10 package mondrian.olap.type; 11 12 import mondrian.olap.*; 13 14 21 public class MemberType implements Type { 22 private final Hierarchy hierarchy; 23 private final Dimension dimension; 24 private final Level level; 25 private final Member member; 26 private final String digest; 27 28 public static final MemberType Unknown = new MemberType(null, null, null, null); 29 30 38 public MemberType( 39 Dimension dimension, 40 Hierarchy hierarchy, 41 Level level, 42 Member member) { 43 this.dimension = dimension; 44 this.hierarchy = hierarchy; 45 this.level = level; 46 this.member = member; 47 if (member != null) { 48 Util.assertPrecondition(level != null); 49 Util.assertPrecondition(member.getLevel() == level); 50 } 51 if (level != null) { 52 Util.assertPrecondition(hierarchy != null); 53 Util.assertPrecondition(level.getHierarchy() == hierarchy); 54 } 55 if (hierarchy != null) { 56 Util.assertPrecondition(dimension != null); 57 Util.assertPrecondition(hierarchy.getDimension() == dimension); 58 } 59 StringBuilder buf = new StringBuilder ("MemberType<"); 60 if (member != null) { 61 buf.append("member=").append(member.getUniqueName()); 62 } else if (level != null) { 63 buf.append("level=").append(level.getUniqueName()); 64 } else if (hierarchy != null) { 65 buf.append("hierarchy=").append(hierarchy.getUniqueName()); 66 } else if (dimension != null) { 67 buf.append("dimension=").append(dimension.getUniqueName()); 68 } 69 buf.append(">"); 70 this.digest = buf.toString(); 71 } 72 73 public static MemberType forDimension(Dimension dimension) { 74 return new MemberType(dimension, null, null, null); 75 } 76 77 public static MemberType forHierarchy(Hierarchy hierarchy) { 78 return new MemberType(hierarchy.getDimension(), hierarchy, null, null); 79 } 80 81 public static MemberType forLevel(Level level) { 82 return new MemberType(level.getDimension(), level.getHierarchy(), level, null); 83 } 84 85 public static MemberType forMember(Member member) { 86 return new MemberType(member.getDimension(), member.getHierarchy(), member.getLevel(), member); 87 } 88 89 public String toString() { 90 return digest; 91 } 92 93 public Hierarchy getHierarchy() { 94 return hierarchy; 95 } 96 97 public Level getLevel() { 98 return level; 99 } 100 101 public boolean usesDimension(Dimension dimension, boolean maybe) { 102 if (this.dimension == null) { 103 return maybe; 104 } else { 105 return this.dimension == dimension || 106 (maybe && this.dimension == null); 107 } 108 } 109 110 public Type getValueType() { 111 return new ScalarType(); 114 } 115 116 public Dimension getDimension() { 117 return dimension; 118 } 119 120 public static MemberType forType(Type type) { 121 if (type instanceof MemberType) { 122 return (MemberType) type; 123 } else { 124 return new MemberType( 125 type.getDimension(), 126 type.getHierarchy(), 127 type.getLevel(), 128 null); 129 } 130 } 131 } 132 133 | Popular Tags |