KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > util > FuzzyBoolean


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.util;
26
27 import java.util.*;
28
29
30 /** This class implements boolean that include a "maybe"
31  */

32
33 public abstract class FuzzyBoolean {
34     public abstract boolean alwaysTrue();
35     public abstract boolean alwaysFalse();
36     public abstract boolean maybeTrue();
37     public abstract boolean maybeFalse();
38     
39     public abstract FuzzyBoolean and(FuzzyBoolean other);
40     public abstract FuzzyBoolean or(FuzzyBoolean other);
41     public abstract FuzzyBoolean not();
42     
43     private static class YesFuzzyBoolean extends FuzzyBoolean {
44         public boolean alwaysFalse() {
45             return false;
46         }
47
48         public boolean alwaysTrue() {
49             return true;
50         }
51
52
53         public boolean maybeFalse() {
54             return false;
55         }
56
57         public boolean maybeTrue() {
58             return true;
59         }
60         
61         public FuzzyBoolean and(FuzzyBoolean other) {
62             return other;
63         }
64
65         public FuzzyBoolean not() {
66             return FuzzyBoolean.NO;
67         }
68
69         public FuzzyBoolean or(FuzzyBoolean other) {
70             return this;
71         }
72
73         public String JavaDoc toString() {
74             return "YES";
75         }
76     }
77     private static class NoFuzzyBoolean extends FuzzyBoolean {
78         public boolean alwaysFalse() {
79             return true;
80         }
81
82         public boolean alwaysTrue() {
83             return false;
84         }
85
86
87         public boolean maybeFalse() {
88             return true;
89         }
90
91         public boolean maybeTrue() {
92             return false;
93         }
94         
95         public FuzzyBoolean and(FuzzyBoolean other) {
96             return this;
97         }
98
99         public FuzzyBoolean not() {
100             return FuzzyBoolean.YES;
101         }
102
103         public FuzzyBoolean or(FuzzyBoolean other) {
104             return other;
105         }
106
107         public String JavaDoc toString() {
108             return "NO";
109         }
110     }
111     private static class NeverFuzzyBoolean extends FuzzyBoolean {
112         public boolean alwaysFalse() {
113             return true;
114         }
115
116         public boolean alwaysTrue() {
117             return false;
118         }
119
120
121         public boolean maybeFalse() {
122             return true;
123         }
124
125         public boolean maybeTrue() {
126             return false;
127         }
128         
129         public FuzzyBoolean and(FuzzyBoolean other) {
130             return this;
131         }
132
133         public FuzzyBoolean not() {
134             return this;
135         }
136
137         public FuzzyBoolean or(FuzzyBoolean other) {
138             return this;
139         }
140
141         public String JavaDoc toString() {
142             return "NEVER";
143         }
144     }
145     
146     private static class MaybeFuzzyBoolean extends FuzzyBoolean {
147         public boolean alwaysFalse() {
148             return false;
149         }
150
151         public boolean alwaysTrue() {
152             return false;
153         }
154
155
156         public boolean maybeFalse() {
157             return true;
158         }
159
160         public boolean maybeTrue() {
161             return true;
162         }
163         
164         public FuzzyBoolean and(FuzzyBoolean other) {
165             return other.alwaysFalse() ? other : this;
166         }
167
168         public FuzzyBoolean not() {
169             return this;
170         }
171
172         public FuzzyBoolean or(FuzzyBoolean other) {
173             return other.alwaysTrue() ? other : this;
174         }
175
176         public String JavaDoc toString() {
177             return "MAYBE";
178         }
179     }
180     
181     public static final FuzzyBoolean YES = new YesFuzzyBoolean();
182     public static final FuzzyBoolean NO = new NoFuzzyBoolean();
183     public static final FuzzyBoolean MAYBE = new MaybeFuzzyBoolean();
184     public static final FuzzyBoolean NEVER = new NeverFuzzyBoolean();
185
186 }
187
Popular Tags