23
23
import java .util .function .Supplier ;
24
24
25
25
/**
26
- * The {@link BranchUtil} class provides static methods to simplify conditional
27
- * logic in Java development by leveraging lambda expressions. It offers
28
- * convenient methods to replace verbose {@code if...else} statements with more
29
- * concise and expressive functional constructs.
26
+ * The {@link BranchUtil} class provides static methods to simplify conditional logic in Java
27
+ * development by leveraging lambda expressions. It offers convenient methods to replace verbose
28
+ * {@code if...else} statements with more concise and expressive functional constructs.
30
29
* <p>
31
- * Developers can use methods in this utility class to streamline their code,
32
- * enhance readability, and promote a more functional style of programming when
33
- * dealing with branching logic and conditional statements.
30
+ * Developers can use methods in this utility class to streamline their code, enhance readability,
31
+ * and promote a more functional style of programming when dealing with branching logic and
32
+ * conditional statements.
34
33
* <p>
35
34
* <b>Example:</b>
36
35
* <pre>
64
63
* </pre>
65
64
* <p>
66
65
* <b>Note:</b>
67
- * The {@link #and(Boolean...)} and {@link #or(Boolean...)} methods accept any
68
- * number of boolean expressions.
66
+ * The {@link #and(Boolean...)} and {@link #or(Boolean...)} methods accept any number of boolean
67
+ * expressions.
69
68
*
70
69
* @param <T> the type of the result to be handled by the methods
71
- * @author Zihlu Wang
70
+ * @author zihluwang
72
71
* @version 1.1.0
73
72
* @see java.util.function.Supplier
74
73
* @see java.util.function.BooleanSupplier
@@ -87,13 +86,12 @@ private BranchUtil(boolean result) {
87
86
}
88
87
89
88
/**
90
- * Creates a {@code BranchUtil} instance to evaluate a logical OR operation
91
- * on the provided boolean expressions.
89
+ * Creates a {@code BranchUtil} instance to evaluate a logical OR operation on the provided
90
+ * boolean expressions.
92
91
*
93
92
* @param booleans the boolean expressions to be evaluated
94
93
* @param <T> the type of the result to be handled by the methods
95
- * @return a {@code BranchUtil} instance representing the result of the
96
- * logical OR operation
94
+ * @return a {@code BranchUtil} instance representing the result of the logical OR operation
97
95
*/
98
96
public static <T > BranchUtil <T > or (Boolean ... booleans ) {
99
97
var result = Arrays .stream (booleans )
@@ -103,13 +101,12 @@ public static <T> BranchUtil<T> or(Boolean... booleans) {
103
101
}
104
102
105
103
/**
106
- * Creates a {@code BranchUtil} instance to evaluate a logical AND
107
- * operation on the provided boolean expressions.
104
+ * Creates a {@code BranchUtil} instance to evaluate a logical AND operation on the provided
105
+ * boolean expressions.
108
106
*
109
107
* @param booleans the boolean expressions to be evaluated
110
108
* @param <T> the type of the result to be handled by the methods
111
- * @return a {@code BranchUtil} instance representing the result of the
112
- * logical AND operation
109
+ * @return a {@code BranchUtil} instance representing the result of the logical AND operation
113
110
*/
114
111
public static <T > BranchUtil <T > and (Boolean ... booleans ) {
115
112
var result = Arrays .stream (booleans )
@@ -119,12 +116,11 @@ public static <T> BranchUtil<T> and(Boolean... booleans) {
119
116
}
120
117
121
118
/**
122
- * Creates a {@code BranchUtil} instance to evaluate a logical OR operation
123
- * on the provided boolean suppliers.
119
+ * Creates a {@code BranchUtil} instance to evaluate a logical OR operation on the provided
120
+ * boolean suppliers.
124
121
*
125
122
* @param booleanSuppliers the boolean suppliers to be evaluated
126
- * @param <T> the type of the result to be handled by the
127
- * methods
123
+ * @param <T> the type of the result to be handled by the methods
128
124
* @return a {@code BranchUtil} instance representing the result of the
129
125
* logical OR operation
130
126
*/
@@ -136,12 +132,11 @@ public static <T> BranchUtil<T> or(BooleanSupplier... booleanSuppliers) {
136
132
}
137
133
138
134
/**
139
- * Creates a {@code BranchUtil} instance to evaluate a logical AND
140
- * operation on the provided boolean suppliers.
135
+ * Creates a {@code BranchUtil} instance to evaluate a logical AND operation on the provided
136
+ * boolean suppliers.
141
137
*
142
138
* @param booleanSuppliers the boolean suppliers to be evaluated
143
- * @param <T> the type of the result to be handled by the
144
- * methods
139
+ * @param <T> the type of the result to be handled by the methods
145
140
* @return a {@code BranchUtil} instance representing the result of the
146
141
* logical AND operation
147
142
*/
@@ -153,22 +148,18 @@ public static <T> BranchUtil<T> and(BooleanSupplier... booleanSuppliers) {
153
148
}
154
149
155
150
/**
156
- * Handles the result of the boolean expressions by executing the
157
- * appropriate handler based on the result.
151
+ * Handles the result of the boolean expressions by executing the appropriate handler based
152
+ * on the result.
158
153
* <p>
159
- * If the result is {@code true}, the {@code ifHandler} is executed. If the
160
- * result is {@code false} and an {@code elseHandler} is provided, it is
161
- * executed.
154
+ * If the result is {@code true}, the {@code ifHandler} is executed. If the result is
155
+ * {@code false} and an {@code elseHandler} is provided, it is executed.
162
156
* <p>
163
157
* Returns the result of the executed handler.
164
158
*
165
- * @param ifHandler the handler to be executed if the result is
166
- * {@code true}
167
- * @param elseHandler the handler to be executed if the result is
168
- * {@code false} (optional)
169
- * @return the result of the executed handler, or {@code null} if no
170
- * {@code elseHandler} is provided and the result of the evaluation is
171
- * {@code false}
159
+ * @param ifHandler the handler to be executed if the result is {@code true}
160
+ * @param elseHandler the handler to be executed if the result is {@code false} (optional)
161
+ * @return the result of the executed handler, or {@code null} if no {@code elseHandler} is
162
+ * provided and the result of the evaluation is {@code false}
172
163
*/
173
164
public T handle (Supplier <T > ifHandler , Supplier <T > elseHandler ) {
174
165
if (this .result && Objects .nonNull (ifHandler )) {
@@ -183,32 +174,28 @@ public T handle(Supplier<T> ifHandler, Supplier<T> elseHandler) {
183
174
}
184
175
185
176
/**
186
- * Handles the result of the boolean expressions by executing the provided
187
- * handler if the result is {@code true}.
177
+ * Handles the result of the boolean expressions by executing the provided handler if the
178
+ * result is {@code true}.
188
179
* <p>
189
180
* Returns the result of the executed handler.
190
181
*
191
- * @param ifHandler the handler to be executed if the result is
192
- * {@code true}
193
- * @return the result of the executed handler, or {@code null} if result of
194
- * evaluation is {@code false}
182
+ * @param ifHandler the handler to be executed if the result is {@code true}
183
+ * @return the result of the executed handler, or {@code null} if result of evaluation is
184
+ * {@code false}
195
185
*/
196
186
public T handle (Supplier <T > ifHandler ) {
197
187
return handle (ifHandler , null );
198
188
}
199
189
200
190
/**
201
- * Handles the result of the boolean expressions by executing the
202
- * appropriate handler based on the result.
191
+ * Handles the result of the boolean expressions by executing the appropriate handler based
192
+ * on the result.
203
193
* <p>
204
- * If the result is {@code true}, the {@code ifHandler} is executed. If the
205
- * result is {@code false} and an {@code elseHandler} is provided, it is
206
- * executed.
194
+ * If the result is {@code true}, the {@code ifHandler} is executed. If the result is
195
+ * {@code false} and an {@code elseHandler} is provided, it is executed.
207
196
*
208
- * @param ifHandler the handler to be executed if the result is
209
- * {@code true}
210
- * @param elseHandler the handler to be executed if the result is
211
- * {@code false} (optional)
197
+ * @param ifHandler the handler to be executed if the result is {@code true}
198
+ * @param elseHandler the handler to be executed if the result is {@code false} (optional)
212
199
*/
213
200
public void handle (Runnable ifHandler , Runnable elseHandler ) {
214
201
if (this .result && Objects .nonNull (ifHandler )) {
@@ -224,11 +211,10 @@ public void handle(Runnable ifHandler, Runnable elseHandler) {
224
211
}
225
212
226
213
/**
227
- * Handles the result of the boolean expressions by executing the provided
228
- * handler if the result is {@code true}.
214
+ * Handles the result of the boolean expressions by executing the provided handler if the
215
+ * result is {@code true}.
229
216
*
230
- * @param ifHandler the handler to be executed if the result is
231
- * {@code true}
217
+ * @param ifHandler the handler to be executed if the result is {@code true}
232
218
*/
233
219
public void handle (Runnable ifHandler ) {
234
220
handle (ifHandler , null );
0 commit comments