KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > rolap > agg > ValueColumnPredicate


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/rolap/agg/ValueColumnPredicate.java#2 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2006-2007 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

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 JavaDoc;
17
18 /**
19  * A constraint which requires a column to have a particular value.
20  *
21  * @author jhyde
22  * @version $Id: //open/mondrian/src/main/mondrian/rolap/agg/ValueColumnPredicate.java#2 $
23  * @since Nov 2, 2006
24  */

25 public class ValueColumnPredicate
26     extends AbstractColumnPredicate
27     implements Comparable JavaDoc
28 {
29     private final Object JavaDoc value;
30
31     /**
32      * Creates a column constraint.
33      *
34      * @param value Value to constraint the column to. (We require that it is
35      * {@link Comparable} because we will sort the values in order to
36      * generate deterministic SQL.)
37      */

38     public ValueColumnPredicate(
39         RolapStar.Column constrainedColumn,
40         Object JavaDoc value)
41     {
42         super(constrainedColumn);
43         assert value != null;
44         assert ! (value instanceof StarColumnPredicate);
45         this.value = value;
46     }
47
48     /**
49      * Returns the value which the column is compared to.
50      */

51     public Object JavaDoc getValue() {
52         return value;
53     }
54
55     public String JavaDoc 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 JavaDoc o) {
65         ValueColumnPredicate that = (ValueColumnPredicate) o;
66         if (this.value instanceof Comparable JavaDoc &&
67                 that.value instanceof Comparable JavaDoc &&
68                 this.value.getClass() == that.value.getClass()) {
69             return ((Comparable JavaDoc) this.value).compareTo(that.value);
70         } else {
71             String JavaDoc thisComp = String.valueOf(this.value);
72             String JavaDoc thatComp = String.valueOf(that.value);
73             return thisComp.compareTo(thatComp);
74         }
75     }
76
77     public boolean equals(Object JavaDoc 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 JavaDoc collection) {
97         collection.add(value);
98     }
99
100     public boolean evaluate(Object JavaDoc value) {
101         return this.value.equals(value);
102     }
103
104     public void describe(StringBuilder JavaDoc buf) {
105         buf.append(value);
106     }
107
108     public Overlap intersect(StarColumnPredicate predicate) {
109         throw new UnsupportedOperationException JavaDoc();
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 // End ValueColumnPredicate.java
127
Popular Tags