1 10 package mondrian.calc.impl; 11 12 import mondrian.olap.*; 13 import mondrian.olap.fun.FunUtil; 14 import mondrian.calc.*; 15 import mondrian.util.UnsupportedList; 16 17 import java.util.Iterator ; 18 import java.util.ArrayList ; 19 import java.util.List ; 20 21 28 public abstract class GenericCalc 29 extends AbstractCalc 30 implements ListCalc, IterCalc, 31 StringCalc, IntegerCalc, DoubleCalc, BooleanCalc, 32 VoidCalc, MemberCalc, LevelCalc, HierarchyCalc, DimensionCalc 33 { 34 35 protected GenericCalc(Exp exp) { 36 super(exp); 37 } 38 39 public List evaluateList(Evaluator evaluator) { 40 Object o = evaluate(evaluator); 41 if (o instanceof List) { 42 return (List) o; 43 } else { 44 final Iterable iter = (Iterable ) o; 46 Iterator it = iter.iterator(); 47 List list = new ArrayList <Object >(); 48 while (it.hasNext()) { 49 list.add(it.next()); 50 } 51 return list; 52 } 53 } 55 56 public Iterable evaluateIterable(Evaluator evaluator) { 57 Object o = evaluate(evaluator); 58 if (o instanceof Iterable ) { 59 return (Iterable ) o; 60 } else { 61 final List list = (List) o; 62 return new Iterable () { 64 public Iterator iterator() { 65 return list.iterator(); 66 } 67 }; 68 } 69 } 70 71 public String evaluateString(Evaluator evaluator) { 72 return (String ) evaluate(evaluator); 73 } 74 75 public int evaluateInteger(Evaluator evaluator) { 76 Object o = evaluate(evaluator); 77 final Number number = (Number ) o; 78 return number == null ? 79 FunUtil.IntegerNull : 80 number.intValue(); 81 } 82 83 public double evaluateDouble(Evaluator evaluator) { 84 final Object o = evaluate(evaluator); 85 final Number number = (Number ) o; 86 return number == null ? 87 FunUtil.DoubleNull : 88 number.doubleValue(); 89 } 90 91 public boolean evaluateBoolean(Evaluator evaluator) { 92 return (Boolean ) evaluate(evaluator); 93 } 94 95 public void evaluateVoid(Evaluator evaluator) { 96 final Object result = evaluate(evaluator); 97 assert result == null; 98 } 99 100 public Member evaluateMember(Evaluator evaluator) { 101 return (Member) evaluate(evaluator); 102 } 103 104 public Level evaluateLevel(Evaluator evaluator) { 105 return (Level) evaluate(evaluator); 106 } 107 108 public Hierarchy evaluateHierarchy(Evaluator evaluator) { 109 return (Hierarchy) evaluate(evaluator); 110 } 111 112 public Dimension evaluateDimension(Evaluator evaluator) { 113 return (Dimension) evaluate(evaluator); 114 } 115 } 116 117 | Popular Tags |