KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/rolap/agg/LiteralStarPredicate.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.StarPredicate;
13 import mondrian.rolap.RolapStar;
14 import mondrian.rolap.StarColumnPredicate;
15
16 import java.util.Collection JavaDoc;
17 import java.util.List JavaDoc;
18
19 /**
20  * A constraint which always returns true or false.
21  *
22  * @author jhyde
23  * @version $Id: //open/mondrian/src/main/mondrian/rolap/agg/LiteralStarPredicate.java#2 $
24  * @since Nov 2, 2006
25  */

26 public class LiteralStarPredicate extends AbstractColumnPredicate {
27     private final boolean value;
28
29     public static final LiteralStarPredicate TRUE =
30         new LiteralStarPredicate(null, true);
31     public static final LiteralStarPredicate FALSE =
32         new LiteralStarPredicate(null, false);
33
34     /**
35      * Creates a LiteralStarPredicate.
36      *
37      * @param column Constrained column
38      * @param value Truth value
39      */

40     public LiteralStarPredicate(RolapStar.Column column, boolean value) {
41         super(column);
42         this.value = value;
43     }
44
45
46     public int hashCode() {
47         return value ? 2 : 1;
48     }
49
50     public boolean equals(Object JavaDoc obj) {
51         if (obj instanceof LiteralStarPredicate) {
52             LiteralStarPredicate that =
53                 (LiteralStarPredicate) obj;
54             return this.value == that.value;
55         } else {
56             return false;
57         }
58     }
59
60     public boolean evaluate(List JavaDoc<Object JavaDoc> valueList) {
61         assert valueList.isEmpty();
62         return value;
63     }
64
65     public boolean equalConstraint(StarPredicate that) {
66         throw new UnsupportedOperationException JavaDoc();
67     }
68
69     public String JavaDoc toString() {
70         return Boolean.toString(value);
71     }
72
73     public void values(Collection JavaDoc collection) {
74     }
75
76     public boolean evaluate(Object JavaDoc value) {
77         return this.value;
78     }
79
80     public void describe(StringBuilder JavaDoc buf) {
81         buf.append("=any");
82     }
83
84     public Overlap intersect(
85         StarColumnPredicate predicate) {
86         return new Overlap(value, null, 0f);
87     }
88
89     public boolean mightIntersect(StarPredicate other) {
90         // FALSE intersects nothing
91
// TRUE intersects everything except FALSE
92
if (!value) {
93             return false;
94         } else if (other instanceof LiteralStarPredicate) {
95             return ((LiteralStarPredicate) other).value;
96         } else {
97             return true;
98         }
99     }
100
101     public StarColumnPredicate minus(StarPredicate predicate) {
102         assert predicate != null;
103         if (value) {
104             // We have no 'not' operator, so there's no shorter way to represent
105
// "true - constraint".
106
return new MinusStarPredicate(this, (StarColumnPredicate) predicate);
107         } else {
108             // "false - constraint" is "false"
109
return this;
110         }
111     }
112
113     public boolean getValue() {
114         return value;
115     }
116 }
117
118 // End LiteralStarPredicate.java
119
Popular Tags