1 /***************************************************************************************
2 * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. *
3 * http://aspectwerkz.codehaus.org *
4 * ---------------------------------------------------------------------------------- *
5 * The software in this package is published under the terms of the LGPL license *
6 * a copy of which has been included with this distribution in the license.txt file. *
7 **************************************************************************************/
8 package org.codehaus.aspectwerkz.expression;
9
10 /***
11 * Helper class to have boolean operation on true / false and null, null is assumed to be undetermined, and "not null"="null"
12 * A "false && null" will stay false, but a "true && null" will become undetermined (null).
13 *
14 * <p/>
15 * This is used when the expression cannot be resolved entirely (early matching, cflow, runtime check residuals)
16 *
17 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
18 */
19 public abstract class Undeterministic {
20
21 /***
22 * And operation
23 *
24 * @param lhs
25 * @param rhs
26 * @return
27 */
28 public static Boolean and(Boolean lhs, Boolean rhs) {
29 if (lhs != null && rhs != null) {
30
31 if (lhs.equals(Boolean.TRUE) && rhs.equals(Boolean.TRUE)) {
32 return Boolean.TRUE;
33 } else {
34 return Boolean.FALSE;
35 }
36 } else if (lhs != null && lhs.equals(Boolean.FALSE)) {
37
38 return Boolean.FALSE;
39 } else if (rhs != null && rhs.equals(Boolean.FALSE)) {
40
41 return Boolean.FALSE;
42 } else {
43
44 return null;
45 }
46 }
47
48 /***
49 * Or operation
50 *
51 * @param lhs
52 * @param rhs
53 * @return
54 */
55 public static Boolean or(Boolean lhs, Boolean rhs) {
56 if (lhs != null && rhs != null) {
57
58 if (lhs.equals(Boolean.TRUE) || rhs.equals(Boolean.TRUE)) {
59 return Boolean.TRUE;
60 } else {
61 return Boolean.FALSE;
62 }
63 } else {
64
65
66 return null;
67 }
68 }
69
70 /***
71 * Not operation
72 *
73 * @param b
74 * @return
75 */
76 public static Boolean not(Boolean b) {
77 if (b != null) {
78
79 if (b.equals(Boolean.TRUE)) {
80 return Boolean.FALSE;
81 } else {
82 return Boolean.TRUE;
83 }
84 } else {
85 return null;
86 }
87 }
88
89
90 }