1 24 25 package org.aspectj.util; 26 27 import java.util.*; 28 29 30 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 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 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 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 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 |