123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- /* *******************************************************************
- * Copyright (c) 1999-2001 Xerox Corporation,
- * 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Xerox/PARC initial implementation
- * ******************************************************************/
- package org.aspectj.util;
-
- /**
- * This class implements boolean that include a "maybe"
- */
- public abstract class FuzzyBoolean {
- public abstract boolean alwaysTrue();
- public abstract boolean alwaysFalse();
- public abstract boolean maybeTrue();
- public abstract boolean maybeFalse();
-
- public abstract FuzzyBoolean and(FuzzyBoolean other);
- public abstract FuzzyBoolean or(FuzzyBoolean other);
- public abstract FuzzyBoolean not();
-
- private static class YesFuzzyBoolean extends FuzzyBoolean {
- public boolean alwaysFalse() {
- return false;
- }
-
- public boolean alwaysTrue() {
- return true;
- }
-
-
- public boolean maybeFalse() {
- return false;
- }
-
- public boolean maybeTrue() {
- return true;
- }
-
- public FuzzyBoolean and(FuzzyBoolean other) {
- return other;
- }
-
- public FuzzyBoolean not() {
- return FuzzyBoolean.NO;
- }
-
- public FuzzyBoolean or(FuzzyBoolean other) {
- return this;
- }
-
- public String toString() {
- return "YES";
- }
- }
- private static class NoFuzzyBoolean extends FuzzyBoolean {
- public boolean alwaysFalse() {
- return true;
- }
-
- public boolean alwaysTrue() {
- return false;
- }
-
-
- public boolean maybeFalse() {
- return true;
- }
-
- public boolean maybeTrue() {
- return false;
- }
-
- public FuzzyBoolean and(FuzzyBoolean other) {
- return this;
- }
-
- public FuzzyBoolean not() {
- return FuzzyBoolean.YES;
- }
-
- public FuzzyBoolean or(FuzzyBoolean other) {
- return other;
- }
-
- public String toString() {
- return "NO";
- }
- }
- private static class NeverFuzzyBoolean extends FuzzyBoolean {
- public boolean alwaysFalse() {
- return true;
- }
-
- public boolean alwaysTrue() {
- return false;
- }
-
-
- public boolean maybeFalse() {
- return true;
- }
-
- public boolean maybeTrue() {
- return false;
- }
-
- public FuzzyBoolean and(FuzzyBoolean other) {
- return this;
- }
-
- public FuzzyBoolean not() {
- return this;
- }
-
- public FuzzyBoolean or(FuzzyBoolean other) {
- return this;
- }
-
- public String toString() {
- return "NEVER";
- }
- }
-
- private static class MaybeFuzzyBoolean extends FuzzyBoolean {
- public boolean alwaysFalse() {
- return false;
- }
-
- public boolean alwaysTrue() {
- return false;
- }
-
-
- public boolean maybeFalse() {
- return true;
- }
-
- public boolean maybeTrue() {
- return true;
- }
-
- public FuzzyBoolean and(FuzzyBoolean other) {
- return other.alwaysFalse() ? other : this;
- }
-
- public FuzzyBoolean not() {
- return this;
- }
-
- public FuzzyBoolean or(FuzzyBoolean other) {
- return other.alwaysTrue() ? other : this;
- }
-
- public String toString() {
- return "MAYBE";
- }
- }
-
- public static final FuzzyBoolean YES = new YesFuzzyBoolean();
- public static final FuzzyBoolean NO = new NoFuzzyBoolean();
- public static final FuzzyBoolean MAYBE = new MaybeFuzzyBoolean();
- public static final FuzzyBoolean NEVER = new NeverFuzzyBoolean();
-
- public static final FuzzyBoolean fromBoolean(boolean b) {
- return b ? YES : NO;
- }
-
- }
|