1 10 package mondrian.rolap.agg; 11 12 import mondrian.rolap.StarPredicate; 13 import mondrian.rolap.StarColumnPredicate; 14 import mondrian.rolap.RolapStar; 15 16 import java.util.Collection ; 17 18 26 public class RangeColumnPredicate extends AbstractColumnPredicate { 27 private final boolean lowerInclusive; 28 private final ValueColumnPredicate lowerBound; 29 private final boolean upperInclusive; 30 private final ValueColumnPredicate upperBound; 31 32 43 public RangeColumnPredicate( 44 RolapStar.Column column, 45 boolean lowerInclusive, 46 ValueColumnPredicate lowerBound, 47 boolean upperInclusive, 48 ValueColumnPredicate upperBound) 49 { 50 super(column); 51 assert lowerBound == null || 52 lowerBound.getConstrainedColumn() == column; 53 assert !(lowerBound == null && lowerInclusive); 54 assert upperBound == null || 55 upperBound.getConstrainedColumn() == column; 56 assert !(upperBound == null && upperInclusive); 57 this.lowerInclusive = lowerInclusive; 58 this.lowerBound = lowerBound; 59 this.upperInclusive = upperInclusive; 60 this.upperBound = upperBound; 61 } 62 63 public String toString() { 64 final StringBuilder buf = new StringBuilder (); 65 describe(buf); 66 return buf.toString(); 67 } 68 69 70 public int hashCode() { 71 int h = lowerInclusive ? 2 : 1; 72 h = 31 * h + lowerBound.hashCode(); 73 h = 31 * h + (upperInclusive ? 2 : 1); 74 h = 31 * h + upperBound.hashCode(); 75 return h; 76 } 77 78 public boolean equals(Object obj) { 79 if (obj instanceof RangeColumnPredicate) { 80 RangeColumnPredicate that = 81 (RangeColumnPredicate) obj; 82 return this.lowerInclusive == that.lowerInclusive && 83 this.lowerBound.equals(that.lowerBound) && 84 this.upperInclusive == that.upperInclusive && 85 this.upperBound.equals(that.upperBound); 86 } else { 87 return false; 88 } 89 } 90 91 public void values(Collection collection) { 92 throw new UnsupportedOperationException (); 95 } 96 97 public boolean evaluate(Object value) { 98 if (lowerBound != null) { 99 int c = ((Comparable <Object >) lowerBound.getValue()).compareTo(value); 100 if (lowerInclusive ? c > 0 : c >= 0) { 101 return false; 102 } 103 } 104 if (upperBound != null) { 105 int c = ((Comparable <Object >) upperBound.getValue()).compareTo(value); 106 if (upperInclusive ? c < 0 : c <= 0) { 107 return false; 108 } 109 } 110 return true; 111 } 112 113 public void describe(StringBuilder buf) { 114 buf.append("Range("); 115 if (lowerBound == null) { 116 buf.append("unbounded"); 117 } else { 118 lowerBound.describe(buf); 119 if (lowerInclusive) { 120 buf.append(" inclusive"); 121 } 122 } 123 buf.append(" to "); 124 if (upperBound == null) { 125 buf.append("unbounded"); 126 } else { 127 upperBound.describe(buf); 128 if (upperInclusive) { 129 buf.append(" inclusive"); 130 } 131 } 132 buf.append(")"); 133 } 134 135 public Overlap intersect(StarColumnPredicate predicate) { 136 throw new UnsupportedOperationException (); 137 } 138 139 public boolean mightIntersect(StarPredicate other) { 140 if (other instanceof ValueColumnPredicate) { 141 return evaluate(((ValueColumnPredicate) other).getValue()); 142 } else { 143 return true; 146 } 147 } 148 149 public StarColumnPredicate minus(StarPredicate predicate) { 150 assert predicate != null; 151 return new MinusStarPredicate( 154 this, (StarColumnPredicate) predicate); 155 } 156 157 public ValueColumnPredicate getLowerBound() { 158 return lowerBound; 159 } 160 161 public boolean getLowerInclusive() { 162 return lowerInclusive; 163 } 164 165 public ValueColumnPredicate getUpperBound() { 166 return upperBound; 167 } 168 169 public boolean getUpperInclusive() { 170 return upperInclusive; 171 } 172 } 173 174 | Popular Tags |