| 1 10 package mondrian.rolap.agg; 11 12 import mondrian.rolap.RolapStar; 13 import mondrian.rolap.StarPredicate; 14 import mondrian.rolap.StarColumnPredicate; 15 16 import java.util.Collection ; 17 18 25 public class ValueColumnPredicate 26 extends AbstractColumnPredicate 27 implements Comparable  28 { 29 private final Object value; 30 31 38 public ValueColumnPredicate( 39 RolapStar.Column constrainedColumn, 40 Object value) 41 { 42 super(constrainedColumn); 43 assert value != null; 44 assert ! (value instanceof StarColumnPredicate); 45 this.value = value; 46 } 47 48 51 public Object getValue() { 52 return value; 53 } 54 55 public String toString() { 56 return String.valueOf(value); 57 } 58 59 public boolean equalConstraint(StarPredicate that) { 60 return that instanceof ValueColumnPredicate && 61 this.value.equals(((ValueColumnPredicate) that).value); 62 } 63 64 public int compareTo(Object o) { 65 ValueColumnPredicate that = (ValueColumnPredicate) o; 66 if (this.value instanceof Comparable && 67 that.value instanceof Comparable && 68 this.value.getClass() == that.value.getClass()) { 69 return ((Comparable ) this.value).compareTo(that.value); 70 } else { 71 String thisComp = String.valueOf(this.value); 72 String thatComp = String.valueOf(that.value); 73 return thisComp.compareTo(thatComp); 74 } 75 } 76 77 public boolean equals(Object other) { 78 if (!(other instanceof ValueColumnPredicate)) { 79 return false; 80 } 81 final ValueColumnPredicate that = (ValueColumnPredicate) other; 82 if (value != null) { 83 return value.equals(that.getValue()); 84 } else { 85 return null == that.getValue(); 86 } 87 } 88 89 public int hashCode() { 90 if (value != null) { 91 return value.hashCode(); 92 } 93 return 0; 94 } 95 96 public void values(Collection collection) { 97 collection.add(value); 98 } 99 100 public boolean evaluate(Object value) { 101 return this.value.equals(value); 102 } 103 104 public void describe(StringBuilder buf) { 105 buf.append(value); 106 } 107 108 public Overlap intersect(StarColumnPredicate predicate) { 109 throw new UnsupportedOperationException (); 110 } 111 112 public boolean mightIntersect(StarPredicate other) { 113 return ((StarColumnPredicate) other).evaluate(value); 114 } 115 116 public StarColumnPredicate minus(StarPredicate predicate) { 117 assert predicate != null; 118 if (((StarColumnPredicate) predicate).evaluate(value)) { 119 return LiteralStarPredicate.FALSE; 120 } else { 121 return this; 122 } 123 } 124 } 125 126 | Popular Tags |