001 /*
002 * SPDX-License-Identifier: Apache-2.0
003 *
004 * Copyright 2008-2017 the original author or authors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package griffon.javafx.beans.binding;
019
020 import javafx.beans.binding.BooleanBinding;
021 import javafx.beans.value.ObservableValue;
022 import javafx.collections.ObservableList;
023 import javafx.collections.ObservableMap;
024 import javafx.collections.ObservableSet;
025
026 import javax.annotation.Nonnull;
027 import java.util.function.Function;
028 import java.util.function.Predicate;
029
030 import static java.util.Objects.requireNonNull;
031 import static javafx.beans.binding.Bindings.createBooleanBinding;
032
033 /**
034 * @author Andres Almiray
035 * @since 2.11.0
036 */
037 public final class MatchingBindings {
038 private static final String ERROR_ITEMS_NULL = "Argument 'items' must not be null";
039 private static final String ERROR_PREDICATE_NULL = "Argument 'predicate' must not be null";
040 private static final String ERROR_MAPPER_NULL = "Argument 'mapper' must not be null";
041
042 private MatchingBindings() {
043 // prevent instantiation
044 }
045
046 /**
047 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
048 *
049 * @param items the observable list of items.
050 * @param predicate a non-interfering, stateless predicate to apply to the each element.
051 *
052 * @return a boolean binding
053 */
054 @Nonnull
055 public static <T> BooleanBinding anyMatch(@Nonnull final ObservableList<T> items, @Nonnull final Predicate<? super T> predicate) {
056 requireNonNull(items, ERROR_ITEMS_NULL);
057 requireNonNull(predicate, ERROR_PREDICATE_NULL);
058 return createBooleanBinding(() -> items.stream().anyMatch(predicate), items);
059 }
060
061 /**
062 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
063 *
064 * @param items the observable list of items.
065 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
066 * @param predicate a non-interfering, stateless predicate to apply to the each element.
067 *
068 * @return a boolean binding
069 */
070 @Nonnull
071 public static <T, R> BooleanBinding anyMatch(@Nonnull final ObservableList<T> items, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> predicate) {
072 requireNonNull(items, ERROR_ITEMS_NULL);
073 requireNonNull(mapper, ERROR_MAPPER_NULL);
074 requireNonNull(predicate, ERROR_PREDICATE_NULL);
075 return createBooleanBinding(() -> items.stream().map(mapper).anyMatch(predicate), items);
076 }
077
078 /**
079 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
080 *
081 * @param items the observable list of items.
082 * @param predicate a non-interfering, stateless predicate to apply to the each element.
083 *
084 * @return a boolean binding
085 */
086 @Nonnull
087 public static <T> BooleanBinding anyMatch(@Nonnull final ObservableList<T> items, @Nonnull final ObservableValue<Predicate<? super T>> predicate) {
088 requireNonNull(items, ERROR_ITEMS_NULL);
089 requireNonNull(predicate, ERROR_PREDICATE_NULL);
090 return createBooleanBinding(() -> {
091 Predicate<? super T> predicateValue = predicate.getValue();
092 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
093 return items.stream().anyMatch(predicateValue);
094 }, items, predicate);
095 }
096
097 /**
098 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
099 *
100 * @param items the observable list of items.
101 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
102 * @param predicate a non-interfering, stateless predicate to apply to the each element.
103 *
104 * @return a boolean binding
105 */
106 @Nonnull
107 public static <T, R> BooleanBinding anyMatch(@Nonnull final ObservableList<T> items, @Nonnull final ObservableValue<Function<? super T, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> predicate) {
108 requireNonNull(items, ERROR_ITEMS_NULL);
109 requireNonNull(mapper, ERROR_MAPPER_NULL);
110 requireNonNull(predicate, ERROR_PREDICATE_NULL);
111 return createBooleanBinding(() -> {
112 Function<? super T, R> mapperValue = mapper.getValue();
113 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
114 Predicate<? super R> predicateValue = predicate.getValue();
115 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
116 return items.stream().map(mapperValue).anyMatch(predicateValue);
117 }, items, predicate, mapper);
118 }
119
120 /**
121 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
122 *
123 * @param items the observable list of items.
124 * @param predicate a non-interfering, stateless predicate to apply to the each element.
125 *
126 * @return a boolean binding
127 */
128 @Nonnull
129 public static <T> BooleanBinding noneMatch(@Nonnull final ObservableList<T> items, @Nonnull final Predicate<? super T> predicate) {
130 requireNonNull(items, ERROR_ITEMS_NULL);
131 requireNonNull(predicate, ERROR_PREDICATE_NULL);
132 return createBooleanBinding(() -> items.stream().noneMatch(predicate), items);
133 }
134
135 /**
136 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
137 *
138 * @param items the observable list of items.
139 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
140 * @param predicate a non-interfering, stateless predicate to apply to the each element.
141 *
142 * @return a boolean binding
143 */
144 @Nonnull
145 public static <T, R> BooleanBinding noneMatch(@Nonnull final ObservableList<T> items, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> predicate) {
146 requireNonNull(items, ERROR_ITEMS_NULL);
147 requireNonNull(mapper, ERROR_MAPPER_NULL);
148 requireNonNull(predicate, ERROR_PREDICATE_NULL);
149 return createBooleanBinding(() -> items.stream().map(mapper).noneMatch(predicate), items);
150 }
151
152 /**
153 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
154 *
155 * @param items the observable list of items.
156 * @param predicate a non-interfering, stateless predicate to apply to the each element.
157 *
158 * @return a boolean binding
159 */
160 @Nonnull
161 public static <T> BooleanBinding noneMatch(@Nonnull final ObservableList<T> items, @Nonnull final ObservableValue<Predicate<? super T>> predicate) {
162 requireNonNull(items, ERROR_ITEMS_NULL);
163 requireNonNull(predicate, ERROR_PREDICATE_NULL);
164 return createBooleanBinding(() -> {
165 Predicate<? super T> predicateValue = predicate.getValue();
166 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
167 return items.stream().noneMatch(predicateValue);
168 }, items, predicate);
169 }
170
171 /**
172 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
173 *
174 * @param items the observable list of items.
175 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
176 * @param predicate a non-interfering, stateless predicate to apply to the each element.
177 *
178 * @return a boolean binding
179 */
180 @Nonnull
181 public static <T, R> BooleanBinding noneMatch(@Nonnull final ObservableList<T> items, @Nonnull final ObservableValue<Function<? super T, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> predicate) {
182 requireNonNull(items, ERROR_ITEMS_NULL);
183 requireNonNull(mapper, ERROR_MAPPER_NULL);
184 requireNonNull(predicate, ERROR_PREDICATE_NULL);
185 return createBooleanBinding(() -> {
186 Function<? super T, R> mapperValue = mapper.getValue();
187 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
188 Predicate<? super R> predicateValue = predicate.getValue();
189 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
190 return items.stream().map(mapperValue).noneMatch(predicateValue);
191 }, items, predicate, mapper);
192 }
193
194 /**
195 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
196 *
197 * @param items the observable list of items.
198 * @param predicate a non-interfering, stateless predicate to apply to the each element.
199 *
200 * @return a boolean binding
201 */
202 @Nonnull
203 public static <T> BooleanBinding allMatch(@Nonnull final ObservableList<T> items, @Nonnull final Predicate<? super T> predicate) {
204 requireNonNull(items, ERROR_ITEMS_NULL);
205 requireNonNull(predicate, ERROR_PREDICATE_NULL);
206 return createBooleanBinding(() -> items.stream().allMatch(predicate), items);
207 }
208
209 /**
210 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
211 *
212 * @param items the observable list of items.
213 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
214 * @param predicate a non-interfering, stateless predicate to apply to the each element.
215 *
216 * @return a boolean binding
217 */
218 @Nonnull
219 public static <T, R> BooleanBinding allMatch(@Nonnull final ObservableList<T> items, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> predicate) {
220 requireNonNull(items, ERROR_ITEMS_NULL);
221 requireNonNull(mapper, ERROR_MAPPER_NULL);
222 requireNonNull(predicate, ERROR_PREDICATE_NULL);
223 return createBooleanBinding(() -> items.stream().map(mapper).allMatch(predicate), items);
224 }
225
226 /**
227 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
228 *
229 * @param items the observable list of items.
230 * @param predicate a non-interfering, stateless predicate to apply to the each element.
231 *
232 * @return a boolean binding
233 */
234 @Nonnull
235 public static <T> BooleanBinding allMatch(@Nonnull final ObservableList<T> items, @Nonnull final ObservableValue<Predicate<? super T>> predicate) {
236 requireNonNull(items, ERROR_ITEMS_NULL);
237 requireNonNull(predicate, ERROR_PREDICATE_NULL);
238 return createBooleanBinding(() -> {
239 Predicate<? super T> predicateValue = predicate.getValue();
240 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
241 return items.stream().allMatch(predicateValue);
242 }, items, predicate);
243 }
244
245 /**
246 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
247 *
248 * @param items the observable list of items.
249 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
250 * @param predicate a non-interfering, stateless predicate to apply to the each element.
251 *
252 * @return a boolean binding
253 */
254 @Nonnull
255 public static <T, R> BooleanBinding allMatch(@Nonnull final ObservableList<T> items, @Nonnull final ObservableValue<Function<? super T, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> predicate) {
256 requireNonNull(items, ERROR_ITEMS_NULL);
257 requireNonNull(mapper, ERROR_MAPPER_NULL);
258 requireNonNull(predicate, ERROR_PREDICATE_NULL);
259 return createBooleanBinding(() -> {
260 Function<? super T, R> mapperValue = mapper.getValue();
261 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
262 Predicate<? super R> predicateValue = predicate.getValue();
263 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
264 return items.stream().map(mapperValue).allMatch(predicateValue);
265 }, items, predicate, mapper);
266 }
267
268 /**
269 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
270 *
271 * @param items the observable set of items.
272 * @param predicate a non-interfering, stateless predicate to apply to the each element.
273 *
274 * @return a boolean binding
275 */
276 @Nonnull
277 public static <T> BooleanBinding anyMatch(@Nonnull final ObservableSet<T> items, @Nonnull final Predicate<? super T> predicate) {
278 requireNonNull(items, ERROR_ITEMS_NULL);
279 requireNonNull(predicate, ERROR_PREDICATE_NULL);
280 return createBooleanBinding(() -> items.stream().anyMatch(predicate), items);
281 }
282
283 /**
284 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
285 *
286 * @param items the observable set of items.
287 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
288 * @param predicate a non-interfering, stateless predicate to apply to the each element.
289 *
290 * @return a boolean binding
291 */
292 @Nonnull
293 public static <T, R> BooleanBinding anyMatch(@Nonnull final ObservableSet<T> items, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> predicate) {
294 requireNonNull(items, ERROR_ITEMS_NULL);
295 requireNonNull(mapper, ERROR_MAPPER_NULL);
296 requireNonNull(predicate, ERROR_PREDICATE_NULL);
297 return createBooleanBinding(() -> items.stream().map(mapper).anyMatch(predicate), items);
298 }
299
300 /**
301 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
302 *
303 * @param items the observable set of items.
304 * @param predicate a non-interfering, stateless predicate to apply to the each element.
305 *
306 * @return a boolean binding
307 */
308 @Nonnull
309 public static <T> BooleanBinding anyMatch(@Nonnull final ObservableSet<T> items, @Nonnull final ObservableValue<Predicate<? super T>> predicate) {
310 requireNonNull(items, ERROR_ITEMS_NULL);
311 requireNonNull(predicate, ERROR_PREDICATE_NULL);
312 return createBooleanBinding(() -> {
313 Predicate<? super T> predicateValue = predicate.getValue();
314 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
315 return items.stream().anyMatch(predicateValue);
316 }, items, predicate);
317 }
318
319 /**
320 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
321 *
322 * @param items the observable set of items.
323 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
324 * @param predicate a non-interfering, stateless predicate to apply to the each element.
325 *
326 * @return a boolean binding
327 */
328 @Nonnull
329 public static <T, R> BooleanBinding anyMatch(@Nonnull final ObservableSet<T> items, @Nonnull final ObservableValue<Function<? super T, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> predicate) {
330 requireNonNull(items, ERROR_ITEMS_NULL);
331 requireNonNull(mapper, ERROR_MAPPER_NULL);
332 requireNonNull(predicate, ERROR_PREDICATE_NULL);
333 return createBooleanBinding(() -> {
334 Function<? super T, R> mapperValue = mapper.getValue();
335 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
336 Predicate<? super R> predicateValue = predicate.getValue();
337 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
338 return items.stream().map(mapperValue).anyMatch(predicateValue);
339 }, items, predicate, mapper);
340 }
341
342 /**
343 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
344 *
345 * @param items the observable set of items.
346 * @param predicate a non-interfering, stateless predicate to apply to the each element.
347 *
348 * @return a boolean binding
349 */
350 @Nonnull
351 public static <T> BooleanBinding noneMatch(@Nonnull final ObservableSet<T> items, @Nonnull final Predicate<? super T> predicate) {
352 requireNonNull(items, ERROR_ITEMS_NULL);
353 requireNonNull(predicate, ERROR_PREDICATE_NULL);
354 return createBooleanBinding(() -> items.stream().noneMatch(predicate), items);
355 }
356
357 /**
358 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
359 *
360 * @param items the observable set of items.
361 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
362 * @param predicate a non-interfering, stateless predicate to apply to the each element.
363 *
364 * @return a boolean binding
365 */
366 @Nonnull
367 public static <T, R> BooleanBinding noneMatch(@Nonnull final ObservableSet<T> items, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> predicate) {
368 requireNonNull(items, ERROR_ITEMS_NULL);
369 requireNonNull(mapper, ERROR_MAPPER_NULL);
370 requireNonNull(predicate, ERROR_PREDICATE_NULL);
371 return createBooleanBinding(() -> items.stream().map(mapper).noneMatch(predicate), items);
372 }
373
374 /**
375 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
376 *
377 * @param items the observable set of items.
378 * @param predicate a non-interfering, stateless predicate to apply to the each element.
379 *
380 * @return a boolean binding
381 */
382 @Nonnull
383 public static <T> BooleanBinding noneMatch(@Nonnull final ObservableSet<T> items, @Nonnull final ObservableValue<Predicate<? super T>> predicate) {
384 requireNonNull(items, ERROR_ITEMS_NULL);
385 requireNonNull(predicate, ERROR_PREDICATE_NULL);
386 return createBooleanBinding(() -> {
387 Predicate<? super T> predicateValue = predicate.getValue();
388 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
389 return items.stream().noneMatch(predicateValue);
390 }, items, predicate);
391 }
392
393 /**
394 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
395 *
396 * @param items the observable set of items.
397 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
398 * @param predicate a non-interfering, stateless predicate to apply to the each element.
399 *
400 * @return a boolean binding
401 */
402 @Nonnull
403 public static <T, R> BooleanBinding noneMatch(@Nonnull final ObservableSet<T> items, @Nonnull final ObservableValue<Function<? super T, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> predicate) {
404 requireNonNull(items, ERROR_ITEMS_NULL);
405 requireNonNull(mapper, ERROR_MAPPER_NULL);
406 requireNonNull(predicate, ERROR_PREDICATE_NULL);
407 return createBooleanBinding(() -> {
408 Function<? super T, R> mapperValue = mapper.getValue();
409 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
410 Predicate<? super R> predicateValue = predicate.getValue();
411 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
412 return items.stream().map(mapperValue).noneMatch(predicateValue);
413 }, items, predicate, mapper);
414 }
415
416 /**
417 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
418 *
419 * @param items the observable set of items.
420 * @param predicate a non-interfering, stateless predicate to apply to the each element.
421 *
422 * @return a boolean binding
423 */
424 @Nonnull
425 public static <T> BooleanBinding allMatch(@Nonnull final ObservableSet<T> items, @Nonnull final Predicate<? super T> predicate) {
426 requireNonNull(items, ERROR_ITEMS_NULL);
427 requireNonNull(predicate, ERROR_PREDICATE_NULL);
428 return createBooleanBinding(() -> items.stream().allMatch(predicate), items);
429 }
430
431 /**
432 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
433 *
434 * @param items the observable set of items.
435 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
436 * @param predicate a non-interfering, stateless predicate to apply to the each element.
437 *
438 * @return a boolean binding
439 */
440 @Nonnull
441 public static <T, R> BooleanBinding allMatch(@Nonnull final ObservableSet<T> items, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> predicate) {
442 requireNonNull(items, ERROR_ITEMS_NULL);
443 requireNonNull(mapper, ERROR_MAPPER_NULL);
444 requireNonNull(predicate, ERROR_PREDICATE_NULL);
445 return createBooleanBinding(() -> items.stream().map(mapper).allMatch(predicate), items);
446 }
447
448 /**
449 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
450 *
451 * @param items the observable set of items.
452 * @param predicate a non-interfering, stateless predicate to apply to the each element.
453 *
454 * @return a boolean binding
455 */
456 @Nonnull
457 public static <T> BooleanBinding allMatch(@Nonnull final ObservableSet<T> items, @Nonnull final ObservableValue<Predicate<? super T>> predicate) {
458 requireNonNull(items, ERROR_ITEMS_NULL);
459 requireNonNull(predicate, ERROR_PREDICATE_NULL);
460 return createBooleanBinding(() -> {
461 Predicate<? super T> predicateValue = predicate.getValue();
462 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
463 return items.stream().allMatch(predicateValue);
464 }, items, predicate);
465 }
466
467 /**
468 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
469 *
470 * @param items the observable set of items.
471 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
472 * @param predicate a non-interfering, stateless predicate to apply to the each element.
473 *
474 * @return a boolean binding
475 */
476 @Nonnull
477 public static <T, R> BooleanBinding allMatch(@Nonnull final ObservableSet<T> items, @Nonnull final ObservableValue<Function<? super T, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> predicate) {
478 requireNonNull(items, ERROR_ITEMS_NULL);
479 requireNonNull(mapper, ERROR_MAPPER_NULL);
480 requireNonNull(predicate, ERROR_PREDICATE_NULL);
481 return createBooleanBinding(() -> {
482 Function<? super T, R> mapperValue = mapper.getValue();
483 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
484 Predicate<? super R> predicateValue = predicate.getValue();
485 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
486 return items.stream().map(mapperValue).allMatch(predicateValue);
487 }, items, predicate, mapper);
488 }
489
490 /**
491 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
492 *
493 * @param items the observable map of items.
494 * @param predicate a non-interfering, stateless predicate to apply to the each element.
495 *
496 * @return a boolean binding
497 */
498 @Nonnull
499 public static <K, V> BooleanBinding anyMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final Predicate<? super V> predicate) {
500 requireNonNull(items, ERROR_ITEMS_NULL);
501 requireNonNull(predicate, ERROR_PREDICATE_NULL);
502 return createBooleanBinding(() -> items.values().stream().anyMatch(predicate), items);
503 }
504
505 /**
506 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
507 *
508 * @param items the observable map of items.
509 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
510 * @param predicate a non-interfering, stateless predicate to apply to the each element.
511 *
512 * @return a boolean binding
513 */
514 @Nonnull
515 public static <K, V, R> BooleanBinding anyMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final Function<? super V, R> mapper, @Nonnull final Predicate<? super R> predicate) {
516 requireNonNull(items, ERROR_ITEMS_NULL);
517 requireNonNull(mapper, ERROR_MAPPER_NULL);
518 requireNonNull(predicate, ERROR_PREDICATE_NULL);
519 return createBooleanBinding(() -> items.values().stream().map(mapper).anyMatch(predicate), items);
520 }
521
522 /**
523 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
524 *
525 * @param items the observable map of items.
526 * @param predicate a non-interfering, stateless predicate to apply to the each element.
527 *
528 * @return a boolean binding
529 */
530 @Nonnull
531 public static <K, V> BooleanBinding anyMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final ObservableValue<Predicate<? super V>> predicate) {
532 requireNonNull(items, ERROR_ITEMS_NULL);
533 requireNonNull(predicate, ERROR_PREDICATE_NULL);
534 return createBooleanBinding(() -> {
535 Predicate<? super V> predicateValue = predicate.getValue();
536 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
537 return items.values().stream().anyMatch(predicateValue);
538 }, items, predicate);
539 }
540
541 /**
542 * Creates a boolean binding based on a <tt>anyMatch</tt> predicate applied to the items.
543 *
544 * @param items the observable map of items.
545 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
546 * @param predicate a non-interfering, stateless predicate to apply to the each element.
547 *
548 * @return a boolean binding
549 */
550 @Nonnull
551 public static <K, V, R> BooleanBinding anyMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final ObservableValue<Function<? super V, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> predicate) {
552 requireNonNull(items, ERROR_ITEMS_NULL);
553 requireNonNull(mapper, ERROR_MAPPER_NULL);
554 requireNonNull(predicate, ERROR_PREDICATE_NULL);
555 return createBooleanBinding(() -> {
556 Function<? super V, R> mapperValue = mapper.getValue();
557 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
558 Predicate<? super R> predicateValue = predicate.getValue();
559 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
560 return items.values().stream().map(mapperValue).anyMatch(predicateValue);
561 }, items, predicate, mapper);
562 }
563
564 /**
565 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
566 *
567 * @param items the observable map of items.
568 * @param predicate a non-interfering, stateless predicate to apply to the each element.
569 *
570 * @return a boolean binding
571 */
572 @Nonnull
573 public static <K, V> BooleanBinding noneMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final Predicate<? super V> predicate) {
574 requireNonNull(items, ERROR_ITEMS_NULL);
575 requireNonNull(predicate, ERROR_PREDICATE_NULL);
576 return createBooleanBinding(() -> items.values().stream().noneMatch(predicate), items);
577 }
578
579 /**
580 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
581 *
582 * @param items the observable map of items.
583 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
584 * @param predicate a non-interfering, stateless predicate to apply to the each element.
585 *
586 * @return a boolean binding
587 */
588 @Nonnull
589 public static <K, V, R> BooleanBinding noneMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final Function<? super V, R> mapper, @Nonnull final Predicate<? super R> predicate) {
590 requireNonNull(items, ERROR_ITEMS_NULL);
591 requireNonNull(mapper, ERROR_MAPPER_NULL);
592 requireNonNull(predicate, ERROR_PREDICATE_NULL);
593 return createBooleanBinding(() -> items.values().stream().map(mapper).noneMatch(predicate), items);
594 }
595
596 /**
597 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
598 *
599 * @param items the observable map of items.
600 * @param predicate a non-interfering, stateless predicate to apply to the each element.
601 *
602 * @return a boolean binding
603 */
604 @Nonnull
605 public static <K, V> BooleanBinding noneMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final ObservableValue<Predicate<? super V>> predicate) {
606 requireNonNull(items, ERROR_ITEMS_NULL);
607 requireNonNull(predicate, ERROR_PREDICATE_NULL);
608 return createBooleanBinding(() -> {
609 Predicate<? super V> predicateValue = predicate.getValue();
610 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
611 return items.values().stream().noneMatch(predicateValue);
612 }, items, predicate);
613 }
614
615 /**
616 * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items.
617 *
618 * @param items the observable map of items.
619 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
620 * @param predicate a non-interfering, stateless predicate to apply to the each element.
621 *
622 * @return a boolean binding
623 */
624 @Nonnull
625 public static <K, V, R> BooleanBinding noneMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final ObservableValue<Function<? super V, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> predicate) {
626 requireNonNull(items, ERROR_ITEMS_NULL);
627 requireNonNull(mapper, ERROR_MAPPER_NULL);
628 requireNonNull(predicate, ERROR_PREDICATE_NULL);
629 return createBooleanBinding(() -> {
630 Function<? super V, R> mapperValue = mapper.getValue();
631 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
632 Predicate<? super R> predicateValue = predicate.getValue();
633 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
634 return items.values().stream().map(mapperValue).noneMatch(predicateValue);
635 }, items, predicate, mapper);
636 }
637
638 /**
639 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
640 *
641 * @param items the observable map of items.
642 * @param predicate a non-interfering, stateless predicate to apply to the each element.
643 *
644 * @return a boolean binding
645 */
646 @Nonnull
647 public static <K, V> BooleanBinding allMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final Predicate<? super V> predicate) {
648 requireNonNull(items, ERROR_ITEMS_NULL);
649 requireNonNull(predicate, ERROR_PREDICATE_NULL);
650 return createBooleanBinding(() -> items.values().stream().allMatch(predicate), items);
651 }
652
653 /**
654 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
655 *
656 * @param items the observable map of items.
657 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
658 * @param predicate a non-interfering, stateless predicate to apply to the each element.
659 *
660 * @return a boolean binding
661 */
662 @Nonnull
663 public static <K, V, R> BooleanBinding allMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final Function<? super V, R> mapper, @Nonnull final Predicate<? super R> predicate) {
664 requireNonNull(items, ERROR_ITEMS_NULL);
665 requireNonNull(mapper, ERROR_MAPPER_NULL);
666 requireNonNull(predicate, ERROR_PREDICATE_NULL);
667 return createBooleanBinding(() -> items.values().stream().map(mapper).allMatch(predicate), items);
668 }
669
670 /**
671 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
672 *
673 * @param items the observable map of items.
674 * @param predicate a non-interfering, stateless predicate to apply to the each element.
675 *
676 * @return a boolean binding
677 */
678 @Nonnull
679 public static <K, V> BooleanBinding allMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final ObservableValue<Predicate<? super V>> predicate) {
680 requireNonNull(items, ERROR_ITEMS_NULL);
681 requireNonNull(predicate, ERROR_PREDICATE_NULL);
682 return createBooleanBinding(() -> {
683 Predicate<? super V> predicateValue = predicate.getValue();
684 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
685 return items.values().stream().allMatch(predicateValue);
686 }, items, predicate);
687 }
688
689 /**
690 * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items.
691 *
692 * @param items the observable map of items.
693 * @param mapper a non-interfering, stateless function to apply to the each value before matching.
694 * @param predicate a non-interfering, stateless predicate to apply to the each element.
695 *
696 * @return a boolean binding
697 */
698 @Nonnull
699 public static <K, V, R> BooleanBinding allMatch(@Nonnull final ObservableMap<K, V> items, @Nonnull final ObservableValue<Function<? super V, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> predicate) {
700 requireNonNull(items, ERROR_ITEMS_NULL);
701 requireNonNull(mapper, ERROR_MAPPER_NULL);
702 requireNonNull(predicate, ERROR_PREDICATE_NULL);
703 return createBooleanBinding(() -> {
704 Function<? super V, R> mapperValue = mapper.getValue();
705 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
706 Predicate<? super R> predicateValue = predicate.getValue();
707 requireNonNull(predicateValue, ERROR_PREDICATE_NULL);
708 return items.values().stream().map(mapperValue).allMatch(predicateValue);
709 }, items, predicate, mapper);
710 }
711 }
|