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