You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FuzzyBoolean.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.util;
  14. /**
  15. * This class implements boolean that include a "maybe"
  16. */
  17. public abstract class FuzzyBoolean {
  18. public abstract boolean alwaysTrue();
  19. public abstract boolean alwaysFalse();
  20. public abstract boolean maybeTrue();
  21. public abstract boolean maybeFalse();
  22. public abstract FuzzyBoolean and(FuzzyBoolean other);
  23. public abstract FuzzyBoolean or(FuzzyBoolean other);
  24. public abstract FuzzyBoolean not();
  25. private static class YesFuzzyBoolean extends FuzzyBoolean {
  26. public boolean alwaysFalse() {
  27. return false;
  28. }
  29. public boolean alwaysTrue() {
  30. return true;
  31. }
  32. public boolean maybeFalse() {
  33. return false;
  34. }
  35. public boolean maybeTrue() {
  36. return true;
  37. }
  38. public FuzzyBoolean and(FuzzyBoolean other) {
  39. return other;
  40. }
  41. public FuzzyBoolean not() {
  42. return FuzzyBoolean.NO;
  43. }
  44. public FuzzyBoolean or(FuzzyBoolean other) {
  45. return this;
  46. }
  47. public String toString() {
  48. return "YES";
  49. }
  50. }
  51. private static class NoFuzzyBoolean extends FuzzyBoolean {
  52. public boolean alwaysFalse() {
  53. return true;
  54. }
  55. public boolean alwaysTrue() {
  56. return false;
  57. }
  58. public boolean maybeFalse() {
  59. return true;
  60. }
  61. public boolean maybeTrue() {
  62. return false;
  63. }
  64. public FuzzyBoolean and(FuzzyBoolean other) {
  65. return this;
  66. }
  67. public FuzzyBoolean not() {
  68. return FuzzyBoolean.YES;
  69. }
  70. public FuzzyBoolean or(FuzzyBoolean other) {
  71. return other;
  72. }
  73. public String toString() {
  74. return "NO";
  75. }
  76. }
  77. private static class NeverFuzzyBoolean extends FuzzyBoolean {
  78. public boolean alwaysFalse() {
  79. return true;
  80. }
  81. public boolean alwaysTrue() {
  82. return false;
  83. }
  84. public boolean maybeFalse() {
  85. return true;
  86. }
  87. public boolean maybeTrue() {
  88. return false;
  89. }
  90. public FuzzyBoolean and(FuzzyBoolean other) {
  91. return this;
  92. }
  93. public FuzzyBoolean not() {
  94. return this;
  95. }
  96. public FuzzyBoolean or(FuzzyBoolean other) {
  97. return this;
  98. }
  99. public String toString() {
  100. return "NEVER";
  101. }
  102. }
  103. private static class MaybeFuzzyBoolean extends FuzzyBoolean {
  104. public boolean alwaysFalse() {
  105. return false;
  106. }
  107. public boolean alwaysTrue() {
  108. return false;
  109. }
  110. public boolean maybeFalse() {
  111. return true;
  112. }
  113. public boolean maybeTrue() {
  114. return true;
  115. }
  116. public FuzzyBoolean and(FuzzyBoolean other) {
  117. return other.alwaysFalse() ? other : this;
  118. }
  119. public FuzzyBoolean not() {
  120. return this;
  121. }
  122. public FuzzyBoolean or(FuzzyBoolean other) {
  123. return other.alwaysTrue() ? other : this;
  124. }
  125. public String toString() {
  126. return "MAYBE";
  127. }
  128. }
  129. public static final FuzzyBoolean YES = new YesFuzzyBoolean();
  130. public static final FuzzyBoolean NO = new NoFuzzyBoolean();
  131. public static final FuzzyBoolean MAYBE = new MaybeFuzzyBoolean();
  132. public static final FuzzyBoolean NEVER = new NeverFuzzyBoolean();
  133. public static final FuzzyBoolean fromBoolean(boolean b) {
  134. return b ? YES : NO;
  135. }
  136. }