This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
/
BooleanExtensions.java
177 lines (164 loc) · 5.02 KB
/
BooleanExtensions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*******************************************************************************
* Copyright (c) 2011 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.xbase.lib;
import com.google.common.annotations.GwtCompatible;
import com.google.common.primitives.Booleans;
/**
* This is an extension library for {@link Boolean booleans}.
*
* @author Sven Efftinge - Initial contribution and API
*/
@GwtCompatible public class BooleanExtensions {
/**
* The logical <code>and</code> (conjunction). This is the equivalent to the java <code>&&</code> operator.
*
* @param a
* a boolean value.
* @param b
* another boolean value.
* @return <code>a && b</code>
*/
@Pure
@Inline(value="($1 && $2)", constantExpression=true)
public static boolean operator_and(boolean a, boolean b) {
return a && b;
}
/**
* A logical <code>or</code> (disjunction). This is the equivalent to the java <code>||</code> operator.
*
* @param a
* a boolean value.
* @param b
* another boolean value.
* @return <code>a || b</code>
*/
@Pure
@Inline(value="($1 || $2)", constantExpression=true)
public static boolean operator_or(boolean a, boolean b) {
return a || b;
}
/**
* The logical <code>not</code> (negation). This is the equivalent to the java <code>!</code> operator.
*
* @param b
* a boolean value.
* @return <code>!b</code>
*/
@Pure
@Inline(value="(!$1)", constantExpression=true)
public static boolean operator_not(boolean b) {
return !b;
}
/**
* The binary <code>equals</code> operator. This is the equivalent to the java <code>==</code> operator.
*
* @param a
* an boolean.
* @param b
* an boolean.
* @return <code>a==b</code>
*/
@Pure
@Inline(value="($1 == $2)", constantExpression=true)
public static boolean operator_equals(boolean a, boolean b) {
return a == b;
}
/**
* The binary <code>not equals</code> operator. This is the equivalent to the java <code>!=</code> operator.
*
* @param a
* an boolean.
* @param b
* an boolean.
* @return <code>a!=b</code>
*/
@Pure
@Inline(value="($1 != $2)", constantExpression=true)
public static boolean operator_notEquals(boolean a, boolean b) {
return a != b;
}
/**
* A logical <code>xor</code>. This is the equivalent to the java <code>^</code> operator.
*
* @param a
* a boolean value.
* @param b
* another boolean value.
* @return <code>a ^ b</code>
*/
@Pure
@Inline("($1 ^ $2)")
public static boolean xor(boolean a, boolean b) {
return a ^ b;
}
/**
* The binary <code>lessThan</code> operator for boolean values.
* {@code false} is considered less than {@code true}.
*
* @see Boolean#compareTo(Boolean)
* @see Booleans#compare(boolean, boolean)
* @param a a boolean.
* @param b another boolean.
* @return <code>Booleans.compare(a, b)<0</code>
* @since 2.4
*/
@Pure
@Inline(value = "($3.compare($1, $2) < 0)", imported = Booleans.class)
public static boolean operator_lessThan(boolean a, boolean b) {
return Booleans.compare(a, b) < 0;
}
/**
* The binary <code>lessEqualsThan</code> operator for boolean values.
* {@code false} is considered less than {@code true}.
*
* @see Boolean#compareTo(Boolean)
* @see Booleans#compare(boolean, boolean)
* @param a a boolean.
* @param b another boolean.
* @return <code>Booleans.compare(a, b)<=0</code>
* @since 2.4
*/
@Pure
@Inline(value = "($3.compare($1, $2) <= 0)", imported = Booleans.class)
public static boolean operator_lessEqualsThan(boolean a, boolean b) {
return Booleans.compare(a, b) <= 0;
}
/**
* The binary <code>greaterThan</code> operator for boolean values.
* {@code false} is considered less than {@code true}.
*
* @see Boolean#compareTo(Boolean)
* @see Booleans#compare(boolean, boolean)
* @param a a boolean.
* @param b another boolean.
* @return <code>Booleans.compare(a, b)>0</code>
* @since 2.4
*/
@Pure
@Inline(value = "($3.compare($1, $2) > 0)", imported = Booleans.class)
public static boolean operator_greaterThan(boolean a, boolean b) {
return Booleans.compare(a, b) > 0;
}
/**
* The binary <code>greaterEqualsThan</code> operator for boolean values.
* {@code false} is considered less than {@code true}.
*
* @see Boolean#compareTo(Boolean)
* @see Booleans#compare(boolean, boolean)
* @param a a boolean.
* @param b another boolean.
* @return <code>Booleans.compare(a, b)>=0</code>
* @since 2.4
*/
@Pure
@Inline(value = "($3.compare($1, $2) >= 0)", imported = Booleans.class)
public static boolean operator_greaterEqualsThan(boolean a, boolean b) {
return Booleans.compare(a, b) >= 0;
}
}