1 10 package mondrian.calc.impl; 11 12 import mondrian.olap.*; 13 import mondrian.olap.type.*; 14 import mondrian.olap.type.DimensionType; 15 import mondrian.olap.type.LevelType; 16 import mondrian.calc.*; 17 18 25 public class ConstantCalc extends GenericCalc { 26 private final Object o; 27 private final int i; 28 private final double d; 29 30 public ConstantCalc(Type type, Object o) { 31 super(new DummyExp(type)); 32 this.o = o; 33 this.i = (o instanceof Number ) ? ((Number ) o).intValue() : 0; 34 this.d = (o instanceof Number ) ? ((Number ) o).doubleValue() : 0; 35 } 36 37 public void accept(CalcWriter calcWriter) { 38 calcWriter.getWriter().print(o); 39 } 40 41 public Object evaluate(Evaluator evaluator) { 42 return o; 43 } 44 45 public int evaluateInteger(Evaluator evaluator) { 46 return i; 47 } 48 49 public double evaluateDouble(Evaluator evaluator) { 50 return d; 51 } 52 53 public boolean dependsOn(Dimension dimension) { 54 return false; 58 } 59 60 public Calc[] getCalcs() { 61 return new Calc[0]; 62 } 63 64 67 public static ConstantCalc constantInteger(int i) { 68 return new ConstantCalc(new NumericType(), i); 69 } 70 71 74 public static StringCalc constantString(String s) { 75 return new ConstantCalc(new StringType(), s); 76 } 77 78 81 public static ConstantCalc constantNull(Type type) { 82 return new ConstantCalc(type, null); 83 } 84 85 88 public static Calc constantMember(Member member) { 89 return new ConstantCalc( 90 MemberType.forMember(member), 91 member); 92 } 93 94 97 public static Calc constantLevel(Level level) { 98 return new ConstantCalc( 99 LevelType.forLevel(level), 100 level); 101 } 102 103 106 public static Calc constantHierarchy(Hierarchy hierarchy) { 107 return new ConstantCalc( 108 HierarchyType.forHierarchy(hierarchy), 109 hierarchy); 110 } 111 112 115 public static Calc constantDimension(Dimension dimension) { 116 return new ConstantCalc( 117 DimensionType.forDimension(dimension), 118 dimension); 119 } 120 } 121 122 | Popular Tags |