0001 /*
0002 * SPDX-License-Identifier: Apache-2.0
0003 *
0004 * Copyright 2008-2018 the original author or authors.
0005 *
0006 * Licensed under the Apache License, Version 2.0 (the "License");
0007 * you may not use this file except in compliance with the License.
0008 * You may obtain a copy of the License at
0009 *
0010 * http://www.apache.org/licenses/LICENSE-2.0
0011 *
0012 * Unless required by applicable law or agreed to in writing, software
0013 * distributed under the License is distributed on an "AS IS" BASIS,
0014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015 * See the License for the specific language governing permissions and
0016 * limitations under the License.
0017 */
0018 package griffon.javafx.beans.binding;
0019
0020 import javafx.beans.binding.BooleanBinding;
0021 import javafx.beans.binding.DoubleBinding;
0022 import javafx.beans.binding.FloatBinding;
0023 import javafx.beans.binding.IntegerBinding;
0024 import javafx.beans.binding.LongBinding;
0025 import javafx.beans.binding.ObjectBinding;
0026 import javafx.beans.binding.StringBinding;
0027 import javafx.beans.value.ObservableValue;
0028 import javafx.collections.ObservableList;
0029 import javafx.collections.ObservableMap;
0030 import javafx.collections.ObservableSet;
0031
0032 import javax.annotation.Nonnull;
0033 import java.util.function.Function;
0034 import java.util.function.Predicate;
0035 import java.util.function.Supplier;
0036
0037 import static java.util.Objects.requireNonNull;
0038 import static javafx.beans.binding.Bindings.createBooleanBinding;
0039 import static javafx.beans.binding.Bindings.createDoubleBinding;
0040 import static javafx.beans.binding.Bindings.createFloatBinding;
0041 import static javafx.beans.binding.Bindings.createIntegerBinding;
0042 import static javafx.beans.binding.Bindings.createLongBinding;
0043 import static javafx.beans.binding.Bindings.createObjectBinding;
0044 import static javafx.beans.binding.Bindings.createStringBinding;
0045
0046 /**
0047 * @author Andres Almiray
0048 * @since 2.10.0
0049 */
0050 public final class FilteringBindings {
0051 private static final String ERROR_ITEMS_NULL = "Argument 'items' must not be null";
0052 private static final String ERROR_FILTER_NULL = "Argument 'filter' must not be null";
0053 private static final String ERROR_MAPPER_NULL = "Argument 'mapper' must not be null";
0054 private static final String ERROR_SUPPLIER_NULL = "Argument 'supplier' must not be null";
0055
0056 private FilteringBindings() {
0057 // prevent instantiation
0058 }
0059
0060 /**
0061 * Creates an object binding with the first element of an observable list after filtering.
0062 *
0063 * @param items the observable list of items.
0064 * @param defaultValue the value to be returned if there is no value present.
0065 * @param filter a non-interfering, stateless predicate to apply to the each element.
0066 *
0067 * @return an object binding
0068 */
0069 @Nonnull
0070 public static <T> ObjectBinding<T> filterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final T defaultValue, @Nonnull final Predicate<? super T> filter) {
0071 requireNonNull(items, ERROR_ITEMS_NULL);
0072 requireNonNull(filter, ERROR_FILTER_NULL);
0073 return createObjectBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0074 }
0075
0076 /**
0077 * Creates an object binding with the first element of an observable list after filtering.
0078 *
0079 * @param items the observable list of items.
0080 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0081 * @param filter a non-interfering, stateless predicate to apply to the each element.
0082 *
0083 * @return an object binding
0084 */
0085 @Nonnull
0086 public static <T> ObjectBinding<T> filterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<T> supplier, @Nonnull final Predicate<? super T> filter) {
0087 requireNonNull(items, ERROR_ITEMS_NULL);
0088 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0089 requireNonNull(filter, ERROR_FILTER_NULL);
0090 return createObjectBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0091 }
0092
0093 /**
0094 * Creates an object binding with the first element of an observable list after filtering.
0095 *
0096 * @param items the observable list of items.
0097 * @param defaultValue the value to be returned if there is no value present.
0098 * @param filter a non-interfering, stateless predicate to apply to the each element.
0099 *
0100 * @return an object binding
0101 */
0102 @Nonnull
0103 public static <T> ObjectBinding<T> filterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final T defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter) {
0104 requireNonNull(items, ERROR_ITEMS_NULL);
0105 requireNonNull(filter, ERROR_FILTER_NULL);
0106 return createObjectBinding(() -> {
0107 Predicate<? super T> filterValue = filter.getValue();
0108 requireNonNull(filterValue, ERROR_FILTER_NULL);
0109 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0110 }, items, filter);
0111 }
0112
0113 /**
0114 * Creates an object binding with the first element of an observable list after filtering.
0115 *
0116 * @param items the observable list of items.
0117 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0118 * @param filter a non-interfering, stateless predicate to apply to the each element.
0119 *
0120 * @return an object binding
0121 */
0122 @Nonnull
0123 public static <T> ObjectBinding<T> filterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<T> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter) {
0124 requireNonNull(items, ERROR_ITEMS_NULL);
0125 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0126 requireNonNull(filter, ERROR_FILTER_NULL);
0127 return createObjectBinding(() -> {
0128 Predicate<? super T> filterValue = filter.getValue();
0129 requireNonNull(filterValue, ERROR_FILTER_NULL);
0130 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0131 }, items, filter);
0132 }
0133
0134 /**
0135 * Creates a boolean binding with the first element of an observable list after filtering.
0136 *
0137 * @param items the observable list of items.
0138 * @param defaultValue the value to be returned if there is no value present.
0139 * @param filter a non-interfering, stateless predicate to apply to the each element.
0140 *
0141 * @return a boolean binding
0142 */
0143 @Nonnull
0144 public static BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableList<Boolean> items, @Nonnull final Boolean defaultValue, @Nonnull final Predicate<? super Boolean> filter) {
0145 requireNonNull(items, ERROR_ITEMS_NULL);
0146 requireNonNull(filter, ERROR_FILTER_NULL);
0147 return createBooleanBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0148 }
0149
0150 /**
0151 * Creates a boolean binding with the first element of an observable list after filtering.
0152 *
0153 * @param items the observable list of items.
0154 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0155 * @param filter a non-interfering, stateless predicate to apply to the each element.
0156 *
0157 * @return a boolean binding
0158 */
0159 @Nonnull
0160 public static BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableList<Boolean> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final Predicate<? super Boolean> filter) {
0161 requireNonNull(items, ERROR_ITEMS_NULL);
0162 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0163 requireNonNull(filter, ERROR_FILTER_NULL);
0164 return createBooleanBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0165 }
0166
0167 /**
0168 * Creates a boolean binding with the first element of an observable list after filtering.
0169 *
0170 * @param items the observable list of items.
0171 * @param defaultValue the value to be returned if there is no value present.
0172 * @param filter a non-interfering, stateless predicate to apply to the each element.
0173 *
0174 * @return a boolean binding
0175 */
0176 @Nonnull
0177 public static BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableList<Boolean> items, @Nonnull final Boolean defaultValue, @Nonnull final ObservableValue<Predicate<? super Boolean>> filter) {
0178 requireNonNull(items, ERROR_ITEMS_NULL);
0179 requireNonNull(filter, ERROR_FILTER_NULL);
0180 return createBooleanBinding(() -> {
0181 Predicate<? super Boolean> filterValue = filter.getValue();
0182 requireNonNull(filterValue, ERROR_FILTER_NULL);
0183 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0184 }, items, filter);
0185 }
0186
0187 /**
0188 * Creates a boolean binding with the first element of an observable list after filtering.
0189 *
0190 * @param items the observable list of items.
0191 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0192 * @param filter a non-interfering, stateless predicate to apply to the each element.
0193 *
0194 * @return a boolean binding
0195 */
0196 @Nonnull
0197 public static BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableList<Boolean> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final ObservableValue<Predicate<? super Boolean>> filter) {
0198 requireNonNull(items, ERROR_ITEMS_NULL);
0199 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0200 requireNonNull(filter, ERROR_FILTER_NULL);
0201 return createBooleanBinding(() -> {
0202 Predicate<? super Boolean> filterValue = filter.getValue();
0203 requireNonNull(filterValue, ERROR_FILTER_NULL);
0204 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0205 }, items, filter);
0206 }
0207
0208 /**
0209 * Creates an integer binding with the first element of an observable list after filtering.
0210 *
0211 * @param items the observable list of items.
0212 * @param defaultValue the value to be returned if there is no value present.
0213 * @param filter a non-interfering, stateless predicate to apply to the each element.
0214 *
0215 * @return an integer binding
0216 */
0217 @Nonnull
0218 public static IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableList<Integer> items, @Nonnull final Integer defaultValue, @Nonnull final Predicate<? super Integer> filter) {
0219 requireNonNull(items, ERROR_ITEMS_NULL);
0220 requireNonNull(filter, ERROR_FILTER_NULL);
0221 return createIntegerBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0222 }
0223
0224 /**
0225 * Creates an integer binding with the first element of an observable list after filtering.
0226 *
0227 * @param items the observable list of items.
0228 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0229 * @param filter a non-interfering, stateless predicate to apply to the each element.
0230 *
0231 * @return an integer binding
0232 */
0233 @Nonnull
0234 public static IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableList<Integer> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final Predicate<? super Integer> filter) {
0235 requireNonNull(items, ERROR_ITEMS_NULL);
0236 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0237 requireNonNull(filter, ERROR_FILTER_NULL);
0238 return createIntegerBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0239 }
0240
0241 /**
0242 * Creates an integer binding with the first element of an observable list after filtering.
0243 *
0244 * @param items the observable list of items.
0245 * @param defaultValue the value to be returned if there is no value present.
0246 * @param filter a non-interfering, stateless predicate to apply to the each element.
0247 *
0248 * @return an integer binding
0249 */
0250 @Nonnull
0251 public static IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableList<Integer> items, @Nonnull final Integer defaultValue, @Nonnull final ObservableValue<Predicate<? super Integer>> filter) {
0252 requireNonNull(items, ERROR_ITEMS_NULL);
0253 requireNonNull(filter, ERROR_FILTER_NULL);
0254 return createIntegerBinding(() -> {
0255 Predicate<? super Integer> filterValue = filter.getValue();
0256 requireNonNull(filterValue, ERROR_FILTER_NULL);
0257 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0258 }, items, filter);
0259 }
0260
0261 /**
0262 * Creates an integer binding with the first element of an observable list after filtering.
0263 *
0264 * @param items the observable list of items.
0265 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0266 * @param filter a non-interfering, stateless predicate to apply to the each element.
0267 *
0268 * @return an integer binding
0269 */
0270 @Nonnull
0271 public static IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableList<Integer> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final ObservableValue<Predicate<? super Integer>> filter) {
0272 requireNonNull(items, ERROR_ITEMS_NULL);
0273 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0274 requireNonNull(filter, ERROR_FILTER_NULL);
0275 return createIntegerBinding(() -> {
0276 Predicate<? super Integer> filterValue = filter.getValue();
0277 requireNonNull(filterValue, ERROR_FILTER_NULL);
0278 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0279 }, items, filter);
0280 }
0281
0282 /**
0283 * Creates a long binding with the first element of an observable list after filtering.
0284 *
0285 * @param items the observable list of items.
0286 * @param defaultValue the value to be returned if there is no value present.
0287 * @param filter a non-interfering, stateless predicate to apply to the each element.
0288 *
0289 * @return a long binding
0290 */
0291 @Nonnull
0292 public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableList<Long> items, @Nonnull final Long defaultValue, @Nonnull final Predicate<? super Long> filter) {
0293 requireNonNull(items, ERROR_ITEMS_NULL);
0294 requireNonNull(filter, ERROR_FILTER_NULL);
0295 return createLongBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0296 }
0297
0298 /**
0299 * Creates a long binding with the first element of an observable list after filtering.
0300 *
0301 * @param items the observable list of items.
0302 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0303 * @param filter a non-interfering, stateless predicate to apply to the each element.
0304 *
0305 * @return a long binding
0306 */
0307 @Nonnull
0308 public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableList<Long> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Predicate<? super Long> filter) {
0309 requireNonNull(items, ERROR_ITEMS_NULL);
0310 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0311 requireNonNull(filter, ERROR_FILTER_NULL);
0312 return createLongBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0313 }
0314
0315 /**
0316 * Creates a long binding with the first element of an observable list after filtering.
0317 *
0318 * @param items the observable list of items.
0319 * @param defaultValue the value to be returned if there is no value present.
0320 * @param filter a non-interfering, stateless predicate to apply to the each element.
0321 *
0322 * @return a long binding
0323 */
0324 @Nonnull
0325 public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableList<Long> items, @Nonnull final Long defaultValue, @Nonnull final ObservableValue<Predicate<? super Long>> filter) {
0326 requireNonNull(items, ERROR_ITEMS_NULL);
0327 requireNonNull(filter, ERROR_FILTER_NULL);
0328 return createLongBinding(() -> {
0329 Predicate<? super Long> filterValue = filter.getValue();
0330 requireNonNull(filterValue, ERROR_FILTER_NULL);
0331 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0332 }, items, filter);
0333 }
0334
0335 /**
0336 * Creates a long binding with the first element of an observable list after filtering.
0337 *
0338 * @param items the observable list of items.
0339 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0340 * @param filter a non-interfering, stateless predicate to apply to the each element.
0341 *
0342 * @return a long binding
0343 */
0344 @Nonnull
0345 public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableList<Long> items, @Nonnull final Supplier<Long> supplier, @Nonnull final ObservableValue<Predicate<? super Long>> filter) {
0346 requireNonNull(items, ERROR_ITEMS_NULL);
0347 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0348 requireNonNull(filter, ERROR_FILTER_NULL);
0349 return createLongBinding(() -> {
0350 Predicate<? super Long> filterValue = filter.getValue();
0351 requireNonNull(filterValue, ERROR_FILTER_NULL);
0352 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0353 }, items, filter);
0354 }
0355
0356 /**
0357 * Creates a float binding with the first element of an observable list after filtering.
0358 *
0359 * @param items the observable list of items.
0360 * @param defaultValue the value to be returned if there is no value present.
0361 * @param filter a non-interfering, stateless predicate to apply to the each element.
0362 *
0363 * @return a float binding
0364 */
0365 @Nonnull
0366 public static FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableList<Float> items, @Nonnull final Float defaultValue, @Nonnull final Predicate<? super Float> filter) {
0367 requireNonNull(items, ERROR_ITEMS_NULL);
0368 requireNonNull(filter, ERROR_FILTER_NULL);
0369 return createFloatBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0370 }
0371
0372 /**
0373 * Creates a float binding with the first element of an observable list after filtering.
0374 *
0375 * @param items the observable list of items.
0376 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0377 * @param filter a non-interfering, stateless predicate to apply to the each element.
0378 *
0379 * @return a float binding
0380 */
0381 @Nonnull
0382 public static FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableList<Float> items, @Nonnull final Supplier<Float> supplier, @Nonnull final Predicate<? super Float> filter) {
0383 requireNonNull(items, ERROR_ITEMS_NULL);
0384 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0385 requireNonNull(filter, ERROR_FILTER_NULL);
0386 return createFloatBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0387 }
0388
0389 /**
0390 * Creates a float binding with the first element of an observable list after filtering.
0391 *
0392 * @param items the observable list of items.
0393 * @param defaultValue the value to be returned if there is no value present.
0394 * @param filter a non-interfering, stateless predicate to apply to the each element.
0395 *
0396 * @return a float binding
0397 */
0398 @Nonnull
0399 public static FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableList<Float> items, @Nonnull final Float defaultValue, @Nonnull final ObservableValue<Predicate<? super Float>> filter) {
0400 requireNonNull(items, ERROR_ITEMS_NULL);
0401 requireNonNull(filter, ERROR_FILTER_NULL);
0402 return createFloatBinding(() -> {
0403 Predicate<? super Float> filterValue = filter.getValue();
0404 requireNonNull(filterValue, ERROR_FILTER_NULL);
0405 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0406 }, items, filter);
0407 }
0408
0409 /**
0410 * Creates a float binding with the first element of an observable list after filtering.
0411 *
0412 * @param items the observable list of items.
0413 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0414 * @param filter a non-interfering, stateless predicate to apply to the each element.
0415 *
0416 * @return a float binding
0417 */
0418 @Nonnull
0419 public static FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableList<Float> items, @Nonnull final Supplier<Float> supplier, @Nonnull final ObservableValue<Predicate<? super Float>> filter) {
0420 requireNonNull(items, ERROR_ITEMS_NULL);
0421 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0422 requireNonNull(filter, ERROR_FILTER_NULL);
0423 return createFloatBinding(() -> {
0424 Predicate<? super Float> filterValue = filter.getValue();
0425 requireNonNull(filterValue, ERROR_FILTER_NULL);
0426 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0427 }, items, filter);
0428 }
0429
0430 /**
0431 * Creates a double binding with the first element of an observable list after filtering.
0432 *
0433 * @param items the observable list of items.
0434 * @param defaultValue the value to be returned if there is no value present.
0435 * @param filter a non-interfering, stateless predicate to apply to the each element.
0436 *
0437 * @return a double binding
0438 */
0439 @Nonnull
0440 public static DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableList<Double> items, @Nonnull final Double defaultValue, @Nonnull final Predicate<? super Double> filter) {
0441 requireNonNull(items, ERROR_ITEMS_NULL);
0442 requireNonNull(filter, ERROR_FILTER_NULL);
0443 return createDoubleBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0444 }
0445
0446 /**
0447 * Creates a double binding with the first element of an observable list after filtering.
0448 *
0449 * @param items the observable list of items.
0450 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0451 * @param filter a non-interfering, stateless predicate to apply to the each element.
0452 *
0453 * @return a double binding
0454 */
0455 @Nonnull
0456 public static DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableList<Double> items, @Nonnull final Supplier<Double> supplier, @Nonnull final Predicate<? super Double> filter) {
0457 requireNonNull(items, ERROR_ITEMS_NULL);
0458 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0459 requireNonNull(filter, ERROR_FILTER_NULL);
0460 return createDoubleBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0461 }
0462
0463 /**
0464 * Creates a double binding with the first element of an observable list after filtering.
0465 *
0466 * @param items the observable list of items.
0467 * @param defaultValue the value to be returned if there is no value present.
0468 * @param filter a non-interfering, stateless predicate to apply to the each element.
0469 *
0470 * @return a double binding
0471 */
0472 @Nonnull
0473 public static DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableList<Double> items, @Nonnull final Double defaultValue, @Nonnull final ObservableValue<Predicate<? super Double>> filter) {
0474 requireNonNull(items, ERROR_ITEMS_NULL);
0475 requireNonNull(filter, ERROR_FILTER_NULL);
0476 return createDoubleBinding(() -> {
0477 Predicate<? super Double> filterValue = filter.getValue();
0478 requireNonNull(filterValue, ERROR_FILTER_NULL);
0479 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0480 }, items, filter);
0481 }
0482
0483 /**
0484 * Creates a double binding with the first element of an observable list after filtering.
0485 *
0486 * @param items the observable list of items.
0487 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0488 * @param filter a non-interfering, stateless predicate to apply to the each element.
0489 *
0490 * @return a double binding
0491 */
0492 @Nonnull
0493 public static DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableList<Double> items, @Nonnull final Supplier<Double> supplier, @Nonnull final ObservableValue<Predicate<? super Double>> filter) {
0494 requireNonNull(items, ERROR_ITEMS_NULL);
0495 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0496 requireNonNull(filter, ERROR_FILTER_NULL);
0497 return createDoubleBinding(() -> {
0498 Predicate<? super Double> filterValue = filter.getValue();
0499 requireNonNull(filterValue, ERROR_FILTER_NULL);
0500 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0501 }, items, filter);
0502 }
0503
0504 /**
0505 * Creates a string binding with the first element of an observable list after filtering.
0506 *
0507 * @param items the observable list of items.
0508 * @param defaultValue the value to be returned if there is no value present.
0509 * @param filter a non-interfering, stateless predicate to apply to the each element.
0510 *
0511 * @return a string binding
0512 */
0513 @Nonnull
0514 public static StringBinding filterThenFindFirstString(@Nonnull final ObservableList<String> items, @Nonnull final String defaultValue, @Nonnull final Predicate<? super String> filter) {
0515 requireNonNull(items, ERROR_ITEMS_NULL);
0516 requireNonNull(filter, ERROR_FILTER_NULL);
0517 return createStringBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0518 }
0519
0520 /**
0521 * Creates a string binding with the first element of an observable list after filtering.
0522 *
0523 * @param items the observable list of items.
0524 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0525 * @param filter a non-interfering, stateless predicate to apply to the each element.
0526 *
0527 * @return a string binding
0528 */
0529 @Nonnull
0530 public static StringBinding filterThenFindFirstString(@Nonnull final ObservableList<String> items, @Nonnull final Supplier<String> supplier, @Nonnull final Predicate<? super String> filter) {
0531 requireNonNull(items, ERROR_ITEMS_NULL);
0532 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0533 requireNonNull(filter, ERROR_FILTER_NULL);
0534 return createStringBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0535 }
0536
0537 /**
0538 * Creates a string binding with the first element of an observable list after filtering.
0539 *
0540 * @param items the observable list of items.
0541 * @param defaultValue the value to be returned if there is no value present.
0542 * @param filter a non-interfering, stateless predicate to apply to the each element.
0543 *
0544 * @return a string binding
0545 */
0546 @Nonnull
0547 public static StringBinding filterThenFindFirstString(@Nonnull final ObservableList<String> items, @Nonnull final String defaultValue, @Nonnull final ObservableValue<Predicate<? super String>> filter) {
0548 requireNonNull(items, ERROR_ITEMS_NULL);
0549 requireNonNull(filter, ERROR_FILTER_NULL);
0550 return createStringBinding(() -> {
0551 Predicate<? super String> filterValue = filter.getValue();
0552 requireNonNull(filterValue, ERROR_FILTER_NULL);
0553 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0554 }, items, filter);
0555 }
0556
0557 /**
0558 * Creates a string binding with the first element of an observable list after filtering.
0559 *
0560 * @param items the observable list of items.
0561 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0562 * @param filter a non-interfering, stateless predicate to apply to the each element.
0563 *
0564 * @return a string binding
0565 */
0566 @Nonnull
0567 public static StringBinding filterThenFindFirstString(@Nonnull final ObservableList<String> items, @Nonnull final Supplier<String> supplier, @Nonnull final ObservableValue<Predicate<? super String>> filter) {
0568 requireNonNull(items, ERROR_ITEMS_NULL);
0569 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0570 requireNonNull(filter, ERROR_FILTER_NULL);
0571 return createStringBinding(() -> {
0572 Predicate<? super String> filterValue = filter.getValue();
0573 requireNonNull(filterValue, ERROR_FILTER_NULL);
0574 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0575 }, items, filter);
0576 }
0577
0578 /**
0579 * Creates an object binding with the first element of an observable set after filtering.
0580 *
0581 * @param items the observable set of items.
0582 * @param defaultValue the value to be returned if there is no value present.
0583 * @param filter a non-interfering, stateless predicate to apply to the each element.
0584 *
0585 * @return an object binding
0586 */
0587 @Nonnull
0588 public static <T> ObjectBinding<T> filterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final T defaultValue, @Nonnull final Predicate<? super T> filter) {
0589 requireNonNull(items, ERROR_ITEMS_NULL);
0590 requireNonNull(filter, ERROR_FILTER_NULL);
0591 return createObjectBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0592 }
0593
0594 /**
0595 * Creates an object binding with the first element of an observable set after filtering.
0596 *
0597 * @param items the observable set of items.
0598 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0599 * @param filter a non-interfering, stateless predicate to apply to the each element.
0600 *
0601 * @return an object binding
0602 */
0603 @Nonnull
0604 public static <T> ObjectBinding<T> filterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<T> supplier, @Nonnull final Predicate<? super T> filter) {
0605 requireNonNull(items, ERROR_ITEMS_NULL);
0606 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0607 requireNonNull(filter, ERROR_FILTER_NULL);
0608 return createObjectBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0609 }
0610
0611 /**
0612 * Creates an object binding with the first element of an observable set after filtering.
0613 *
0614 * @param items the observable set of items.
0615 * @param defaultValue the value to be returned if there is no value present.
0616 * @param filter a non-interfering, stateless predicate to apply to the each element.
0617 *
0618 * @return an object binding
0619 */
0620 @Nonnull
0621 public static <T> ObjectBinding<T> filterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final T defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter) {
0622 requireNonNull(items, ERROR_ITEMS_NULL);
0623 requireNonNull(filter, ERROR_FILTER_NULL);
0624 return createObjectBinding(() -> {
0625 Predicate<? super T> filterValue = filter.getValue();
0626 requireNonNull(filterValue, ERROR_FILTER_NULL);
0627 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0628 }, items, filter);
0629 }
0630
0631 /**
0632 * Creates an object binding with the first element of an observable set after filtering.
0633 *
0634 * @param items the observable set of items.
0635 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0636 * @param filter a non-interfering, stateless predicate to apply to the each element.
0637 *
0638 * @return an object binding
0639 */
0640 @Nonnull
0641 public static <T> ObjectBinding<T> filterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<T> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter) {
0642 requireNonNull(items, ERROR_ITEMS_NULL);
0643 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0644 requireNonNull(filter, ERROR_FILTER_NULL);
0645 return createObjectBinding(() -> {
0646 Predicate<? super T> filterValue = filter.getValue();
0647 requireNonNull(filterValue, ERROR_FILTER_NULL);
0648 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0649 }, items, filter);
0650 }
0651
0652 /**
0653 * Creates a boolean binding with the first element of an observable set after filtering.
0654 *
0655 * @param items the observable set of items.
0656 * @param defaultValue the value to be returned if there is no value present.
0657 * @param filter a non-interfering, stateless predicate to apply to the each element.
0658 *
0659 * @return a boolean binding
0660 */
0661 @Nonnull
0662 public static BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableSet<Boolean> items, @Nonnull final Boolean defaultValue, @Nonnull final Predicate<? super Boolean> filter) {
0663 requireNonNull(items, ERROR_ITEMS_NULL);
0664 requireNonNull(filter, ERROR_FILTER_NULL);
0665 return createBooleanBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0666 }
0667
0668 /**
0669 * Creates a boolean binding with the first element of an observable set after filtering.
0670 *
0671 * @param items the observable set of items.
0672 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0673 * @param filter a non-interfering, stateless predicate to apply to the each element.
0674 *
0675 * @return a boolean binding
0676 */
0677 @Nonnull
0678 public static BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableSet<Boolean> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final Predicate<? super Boolean> filter) {
0679 requireNonNull(items, ERROR_ITEMS_NULL);
0680 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0681 requireNonNull(filter, ERROR_FILTER_NULL);
0682 return createBooleanBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0683 }
0684
0685 /**
0686 * Creates a boolean binding with the first element of an observable set after filtering.
0687 *
0688 * @param items the observable set of items.
0689 * @param defaultValue the value to be returned if there is no value present.
0690 * @param filter a non-interfering, stateless predicate to apply to the each element.
0691 *
0692 * @return a boolean binding
0693 */
0694 @Nonnull
0695 public static BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableSet<Boolean> items, @Nonnull final Boolean defaultValue, @Nonnull final ObservableValue<Predicate<? super Boolean>> filter) {
0696 requireNonNull(items, ERROR_ITEMS_NULL);
0697 requireNonNull(filter, ERROR_FILTER_NULL);
0698 return createBooleanBinding(() -> {
0699 Predicate<? super Boolean> filterValue = filter.getValue();
0700 requireNonNull(filterValue, ERROR_FILTER_NULL);
0701 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0702 }, items, filter);
0703 }
0704
0705 /**
0706 * Creates a boolean binding with the first element of an observable set after filtering.
0707 *
0708 * @param items the observable set of items.
0709 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0710 * @param filter a non-interfering, stateless predicate to apply to the each element.
0711 *
0712 * @return a boolean binding
0713 */
0714 @Nonnull
0715 public static BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableSet<Boolean> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final ObservableValue<Predicate<? super Boolean>> filter) {
0716 requireNonNull(items, ERROR_ITEMS_NULL);
0717 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0718 requireNonNull(filter, ERROR_FILTER_NULL);
0719 return createBooleanBinding(() -> {
0720 Predicate<? super Boolean> filterValue = filter.getValue();
0721 requireNonNull(filterValue, ERROR_FILTER_NULL);
0722 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0723 }, items, filter);
0724 }
0725
0726 /**
0727 * Creates an integer binding with the first element of an observable set after filtering.
0728 *
0729 * @param items the observable set of items.
0730 * @param defaultValue the value to be returned if there is no value present.
0731 * @param filter a non-interfering, stateless predicate to apply to the each element.
0732 *
0733 * @return an integer binding
0734 */
0735 @Nonnull
0736 public static IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableSet<Integer> items, @Nonnull final Integer defaultValue, @Nonnull final Predicate<? super Integer> filter) {
0737 requireNonNull(items, ERROR_ITEMS_NULL);
0738 requireNonNull(filter, ERROR_FILTER_NULL);
0739 return createIntegerBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0740 }
0741
0742 /**
0743 * Creates an integer binding with the first element of an observable set after filtering.
0744 *
0745 * @param items the observable set of items.
0746 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0747 * @param filter a non-interfering, stateless predicate to apply to the each element.
0748 *
0749 * @return an integer binding
0750 */
0751 @Nonnull
0752 public static IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableSet<Integer> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final Predicate<? super Integer> filter) {
0753 requireNonNull(items, ERROR_ITEMS_NULL);
0754 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0755 requireNonNull(filter, ERROR_FILTER_NULL);
0756 return createIntegerBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0757 }
0758
0759 /**
0760 * Creates an integer binding with the first element of an observable set after filtering.
0761 *
0762 * @param items the observable set of items.
0763 * @param defaultValue the value to be returned if there is no value present.
0764 * @param filter a non-interfering, stateless predicate to apply to the each element.
0765 *
0766 * @return an integer binding
0767 */
0768 @Nonnull
0769 public static IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableSet<Integer> items, @Nonnull final Integer defaultValue, @Nonnull final ObservableValue<Predicate<? super Integer>> filter) {
0770 requireNonNull(items, ERROR_ITEMS_NULL);
0771 requireNonNull(filter, ERROR_FILTER_NULL);
0772 return createIntegerBinding(() -> {
0773 Predicate<? super Integer> filterValue = filter.getValue();
0774 requireNonNull(filterValue, ERROR_FILTER_NULL);
0775 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0776 }, items, filter);
0777 }
0778
0779 /**
0780 * Creates an integer binding with the first element of an observable set after filtering.
0781 *
0782 * @param items the observable set of items.
0783 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0784 * @param filter a non-interfering, stateless predicate to apply to the each element.
0785 *
0786 * @return an integer binding
0787 */
0788 @Nonnull
0789 public static IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableSet<Integer> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final ObservableValue<Predicate<? super Integer>> filter) {
0790 requireNonNull(items, ERROR_ITEMS_NULL);
0791 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0792 requireNonNull(filter, ERROR_FILTER_NULL);
0793 return createIntegerBinding(() -> {
0794 Predicate<? super Integer> filterValue = filter.getValue();
0795 requireNonNull(filterValue, ERROR_FILTER_NULL);
0796 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0797 }, items, filter);
0798 }
0799
0800 /**
0801 * Creates a long binding with the first element of an observable set after filtering.
0802 *
0803 * @param items the observable set of items.
0804 * @param defaultValue the value to be returned if there is no value present.
0805 * @param filter a non-interfering, stateless predicate to apply to the each element.
0806 *
0807 * @return a long binding
0808 */
0809 @Nonnull
0810 public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableSet<Long> items, @Nonnull final Long defaultValue, @Nonnull final Predicate<? super Long> filter) {
0811 requireNonNull(items, ERROR_ITEMS_NULL);
0812 requireNonNull(filter, ERROR_FILTER_NULL);
0813 return createLongBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0814 }
0815
0816 /**
0817 * Creates a long binding with the first element of an observable set after filtering.
0818 *
0819 * @param items the observable set of items.
0820 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0821 * @param filter a non-interfering, stateless predicate to apply to the each element.
0822 *
0823 * @return a long binding
0824 */
0825 @Nonnull
0826 public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableSet<Long> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Predicate<? super Long> filter) {
0827 requireNonNull(items, ERROR_ITEMS_NULL);
0828 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0829 requireNonNull(filter, ERROR_FILTER_NULL);
0830 return createLongBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0831 }
0832
0833 /**
0834 * Creates a long binding with the first element of an observable set after filtering.
0835 *
0836 * @param items the observable set of items.
0837 * @param defaultValue the value to be returned if there is no value present.
0838 * @param filter a non-interfering, stateless predicate to apply to the each element.
0839 *
0840 * @return a long binding
0841 */
0842 @Nonnull
0843 public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableSet<Long> items, @Nonnull final Long defaultValue, @Nonnull final ObservableValue<Predicate<? super Long>> filter) {
0844 requireNonNull(items, ERROR_ITEMS_NULL);
0845 requireNonNull(filter, ERROR_FILTER_NULL);
0846 return createLongBinding(() -> {
0847 Predicate<? super Long> filterValue = filter.getValue();
0848 requireNonNull(filterValue, ERROR_FILTER_NULL);
0849 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0850 }, items, filter);
0851 }
0852
0853 /**
0854 * Creates a long binding with the first element of an observable set after filtering.
0855 *
0856 * @param items the observable set of items.
0857 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0858 * @param filter a non-interfering, stateless predicate to apply to the each element.
0859 *
0860 * @return a long binding
0861 */
0862 @Nonnull
0863 public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableSet<Long> items, @Nonnull final Supplier<Long> supplier, @Nonnull final ObservableValue<Predicate<? super Long>> filter) {
0864 requireNonNull(items, ERROR_ITEMS_NULL);
0865 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0866 requireNonNull(filter, ERROR_FILTER_NULL);
0867 return createLongBinding(() -> {
0868 Predicate<? super Long> filterValue = filter.getValue();
0869 requireNonNull(filterValue, ERROR_FILTER_NULL);
0870 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0871 }, items, filter);
0872 }
0873
0874 /**
0875 * Creates a float binding with the first element of an observable set after filtering.
0876 *
0877 * @param items the observable set of items.
0878 * @param defaultValue the value to be returned if there is no value present.
0879 * @param filter a non-interfering, stateless predicate to apply to the each element.
0880 *
0881 * @return a float binding
0882 */
0883 @Nonnull
0884 public static FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableSet<Float> items, @Nonnull final Float defaultValue, @Nonnull final Predicate<? super Float> filter) {
0885 requireNonNull(items, ERROR_ITEMS_NULL);
0886 requireNonNull(filter, ERROR_FILTER_NULL);
0887 return createFloatBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0888 }
0889
0890 /**
0891 * Creates a float binding with the first element of an observable set after filtering.
0892 *
0893 * @param items the observable set of items.
0894 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0895 * @param filter a non-interfering, stateless predicate to apply to the each element.
0896 *
0897 * @return a float binding
0898 */
0899 @Nonnull
0900 public static FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableSet<Float> items, @Nonnull final Supplier<Float> supplier, @Nonnull final Predicate<? super Float> filter) {
0901 requireNonNull(items, ERROR_ITEMS_NULL);
0902 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0903 requireNonNull(filter, ERROR_FILTER_NULL);
0904 return createFloatBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0905 }
0906
0907 /**
0908 * Creates a float binding with the first element of an observable set after filtering.
0909 *
0910 * @param items the observable set of items.
0911 * @param defaultValue the value to be returned if there is no value present.
0912 * @param filter a non-interfering, stateless predicate to apply to the each element.
0913 *
0914 * @return a float binding
0915 */
0916 @Nonnull
0917 public static FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableSet<Float> items, @Nonnull final Float defaultValue, @Nonnull final ObservableValue<Predicate<? super Float>> filter) {
0918 requireNonNull(items, ERROR_ITEMS_NULL);
0919 requireNonNull(filter, ERROR_FILTER_NULL);
0920 return createFloatBinding(() -> {
0921 Predicate<? super Float> filterValue = filter.getValue();
0922 requireNonNull(filterValue, ERROR_FILTER_NULL);
0923 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0924 }, items, filter);
0925 }
0926
0927 /**
0928 * Creates a float binding with the first element of an observable set after filtering.
0929 *
0930 * @param items the observable set of items.
0931 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0932 * @param filter a non-interfering, stateless predicate to apply to the each element.
0933 *
0934 * @return a float binding
0935 */
0936 @Nonnull
0937 public static FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableSet<Float> items, @Nonnull final Supplier<Float> supplier, @Nonnull final ObservableValue<Predicate<? super Float>> filter) {
0938 requireNonNull(items, ERROR_ITEMS_NULL);
0939 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0940 requireNonNull(filter, ERROR_FILTER_NULL);
0941 return createFloatBinding(() -> {
0942 Predicate<? super Float> filterValue = filter.getValue();
0943 requireNonNull(filterValue, ERROR_FILTER_NULL);
0944 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
0945 }, items, filter);
0946 }
0947
0948 /**
0949 * Creates a double binding with the first element of an observable set after filtering.
0950 *
0951 * @param items the observable set of items.
0952 * @param defaultValue the value to be returned if there is no value present.
0953 * @param filter a non-interfering, stateless predicate to apply to the each element.
0954 *
0955 * @return a double binding
0956 */
0957 @Nonnull
0958 public static DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableSet<Double> items, @Nonnull final Double defaultValue, @Nonnull final Predicate<? super Double> filter) {
0959 requireNonNull(items, ERROR_ITEMS_NULL);
0960 requireNonNull(filter, ERROR_FILTER_NULL);
0961 return createDoubleBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
0962 }
0963
0964 /**
0965 * Creates a double binding with the first element of an observable set after filtering.
0966 *
0967 * @param items the observable set of items.
0968 * @param supplier a {@code Supplier} whose result is returned if no value is present.
0969 * @param filter a non-interfering, stateless predicate to apply to the each element.
0970 *
0971 * @return a double binding
0972 */
0973 @Nonnull
0974 public static DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableSet<Double> items, @Nonnull final Supplier<Double> supplier, @Nonnull final Predicate<? super Double> filter) {
0975 requireNonNull(items, ERROR_ITEMS_NULL);
0976 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
0977 requireNonNull(filter, ERROR_FILTER_NULL);
0978 return createDoubleBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
0979 }
0980
0981 /**
0982 * Creates a double binding with the first element of an observable set after filtering.
0983 *
0984 * @param items the observable set of items.
0985 * @param defaultValue the value to be returned if there is no value present.
0986 * @param filter a non-interfering, stateless predicate to apply to the each element.
0987 *
0988 * @return a double binding
0989 */
0990 @Nonnull
0991 public static DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableSet<Double> items, @Nonnull final Double defaultValue, @Nonnull final ObservableValue<Predicate<? super Double>> filter) {
0992 requireNonNull(items, ERROR_ITEMS_NULL);
0993 requireNonNull(filter, ERROR_FILTER_NULL);
0994 return createDoubleBinding(() -> {
0995 Predicate<? super Double> filterValue = filter.getValue();
0996 requireNonNull(filterValue, ERROR_FILTER_NULL);
0997 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
0998 }, items, filter);
0999 }
1000
1001 /**
1002 * Creates a double binding with the first element of an observable set after filtering.
1003 *
1004 * @param items the observable set of items.
1005 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1006 * @param filter a non-interfering, stateless predicate to apply to the each element.
1007 *
1008 * @return a double binding
1009 */
1010 @Nonnull
1011 public static DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableSet<Double> items, @Nonnull final Supplier<Double> supplier, @Nonnull final ObservableValue<Predicate<? super Double>> filter) {
1012 requireNonNull(items, ERROR_ITEMS_NULL);
1013 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1014 requireNonNull(filter, ERROR_FILTER_NULL);
1015 return createDoubleBinding(() -> {
1016 Predicate<? super Double> filterValue = filter.getValue();
1017 requireNonNull(filterValue, ERROR_FILTER_NULL);
1018 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
1019 }, items, filter);
1020 }
1021
1022 /**
1023 * Creates a string binding with the first element of an observable set after filtering.
1024 *
1025 * @param items the observable set of items.
1026 * @param defaultValue the value to be returned if there is no value present.
1027 * @param filter a non-interfering, stateless predicate to apply to the each element.
1028 *
1029 * @return a string binding
1030 */
1031 @Nonnull
1032 public static StringBinding filterThenFindFirstString(@Nonnull final ObservableSet<String> items, @Nonnull final String defaultValue, @Nonnull final Predicate<? super String> filter) {
1033 requireNonNull(items, ERROR_ITEMS_NULL);
1034 requireNonNull(filter, ERROR_FILTER_NULL);
1035 return createStringBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items);
1036 }
1037
1038 /**
1039 * Creates a string binding with the first element of an observable set after filtering.
1040 *
1041 * @param items the observable set of items.
1042 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1043 * @param filter a non-interfering, stateless predicate to apply to the each element.
1044 *
1045 * @return a string binding
1046 */
1047 @Nonnull
1048 public static StringBinding filterThenFindFirstString(@Nonnull final ObservableSet<String> items, @Nonnull final Supplier<String> supplier, @Nonnull final Predicate<? super String> filter) {
1049 requireNonNull(items, ERROR_ITEMS_NULL);
1050 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1051 requireNonNull(filter, ERROR_FILTER_NULL);
1052 return createStringBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items);
1053 }
1054
1055 /**
1056 * Creates a string binding with the first element of an observable set after filtering.
1057 *
1058 * @param items the observable set of items.
1059 * @param defaultValue the value to be returned if there is no value present.
1060 * @param filter a non-interfering, stateless predicate to apply to the each element.
1061 *
1062 * @return a string binding
1063 */
1064 @Nonnull
1065 public static StringBinding filterThenFindFirstString(@Nonnull final ObservableSet<String> items, @Nonnull final String defaultValue, @Nonnull final ObservableValue<Predicate<? super String>> filter) {
1066 requireNonNull(items, ERROR_ITEMS_NULL);
1067 requireNonNull(filter, ERROR_FILTER_NULL);
1068 return createStringBinding(() -> {
1069 Predicate<? super String> filterValue = filter.getValue();
1070 requireNonNull(filterValue, ERROR_FILTER_NULL);
1071 return items.stream().filter(filterValue).findFirst().orElse(defaultValue);
1072 }, items, filter);
1073 }
1074
1075 /**
1076 * Creates a string binding with the first element of an observable set after filtering.
1077 *
1078 * @param items the observable set of items.
1079 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1080 * @param filter a non-interfering, stateless predicate to apply to the each element.
1081 *
1082 * @return a string binding
1083 */
1084 @Nonnull
1085 public static StringBinding filterThenFindFirstString(@Nonnull final ObservableSet<String> items, @Nonnull final Supplier<String> supplier, @Nonnull final ObservableValue<Predicate<? super String>> filter) {
1086 requireNonNull(items, ERROR_ITEMS_NULL);
1087 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1088 requireNonNull(filter, ERROR_FILTER_NULL);
1089 return createStringBinding(() -> {
1090 Predicate<? super String> filterValue = filter.getValue();
1091 requireNonNull(filterValue, ERROR_FILTER_NULL);
1092 return items.stream().filter(filterValue).findFirst().orElseGet(supplier);
1093 }, items, filter);
1094 }
1095
1096 /**
1097 * Creates an object binding with the first value of an observable map after filtering.
1098 *
1099 * @param items the observable map of items.
1100 * @param defaultValue the value to be returned if there is no value present.
1101 * @param filter a non-interfering, stateless predicate to apply to the each value
1102 *
1103 * @return an object binding
1104 */
1105 @Nonnull
1106 public static <K, V> ObjectBinding<V> filterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final V defaultValue, @Nonnull final Predicate<? super V> filter) {
1107 requireNonNull(items, ERROR_ITEMS_NULL);
1108 requireNonNull(filter, ERROR_FILTER_NULL);
1109 return createObjectBinding(() -> items.values().stream().filter(filter).findFirst().orElse(defaultValue), items);
1110 }
1111
1112 /**
1113 * Creates an object binding with the first value of an observable map after filtering.
1114 *
1115 * @param items the observable map of items.
1116 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1117 * @param filter a non-interfering, stateless predicate to apply to the each value
1118 *
1119 * @return an object binding
1120 */
1121 @Nonnull
1122 public static <K, V> ObjectBinding<V> filterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<V> supplier, @Nonnull final Predicate<? super V> filter) {
1123 requireNonNull(items, ERROR_ITEMS_NULL);
1124 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1125 requireNonNull(filter, ERROR_FILTER_NULL);
1126 return createObjectBinding(() -> items.values().stream().filter(filter).findFirst().orElseGet(supplier), items);
1127 }
1128
1129 /**
1130 * Creates an object binding with the first value of an observable map after filtering.
1131 *
1132 * @param items the observable map of items.
1133 * @param defaultValue the value to be returned if there is no value present.
1134 * @param filter a non-interfering, stateless predicate to apply to the each value
1135 *
1136 * @return an object binding
1137 */
1138 @Nonnull
1139 public static <K, V> ObjectBinding<V> filterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final V defaultValue, @Nonnull final ObservableValue<Predicate<? super V>> filter) {
1140 requireNonNull(items, ERROR_ITEMS_NULL);
1141 requireNonNull(filter, ERROR_FILTER_NULL);
1142 return createObjectBinding(() -> {
1143 Predicate<? super V> filterValue = filter.getValue();
1144 requireNonNull(filterValue, ERROR_FILTER_NULL);
1145 return items.values().stream().filter(filterValue).findFirst().orElse(defaultValue);
1146 }, items, filter);
1147 }
1148
1149 /**
1150 * Creates an object binding with the first value of an observable map after filtering.
1151 *
1152 * @param items the observable map of items.
1153 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1154 * @param filter a non-interfering, stateless predicate to apply to the each value
1155 *
1156 * @return an object binding
1157 */
1158 @Nonnull
1159 public static <K, V> ObjectBinding<V> filterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<V> supplier, @Nonnull final ObservableValue<Predicate<? super V>> filter) {
1160 requireNonNull(items, ERROR_ITEMS_NULL);
1161 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1162 requireNonNull(filter, ERROR_FILTER_NULL);
1163 return createObjectBinding(() -> {
1164 Predicate<? super V> filterValue = filter.getValue();
1165 requireNonNull(filterValue, ERROR_FILTER_NULL);
1166 return items.values().stream().filter(filterValue).findFirst().orElseGet(supplier);
1167 }, items, filter);
1168 }
1169
1170 /**
1171 * Creates a boolean binding with the first value of an observable map after filtering.
1172 *
1173 * @param items the observable map of items.
1174 * @param defaultValue the value to be returned if there is no value present.
1175 * @param filter a non-interfering, stateless predicate to apply to the each value
1176 *
1177 * @return a boolean binding
1178 */
1179 @Nonnull
1180 public static <K> BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableMap<K, Boolean> items, @Nonnull final Boolean defaultValue, @Nonnull final Predicate<? super Boolean> filter) {
1181 requireNonNull(items, ERROR_ITEMS_NULL);
1182 requireNonNull(filter, ERROR_FILTER_NULL);
1183 return createBooleanBinding(() -> items.values().stream().filter(filter).findFirst().orElse(defaultValue), items);
1184 }
1185
1186 /**
1187 * Creates a boolean binding with the first value of an observable map after filtering.
1188 *
1189 * @param items the observable map of items.
1190 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1191 * @param filter a non-interfering, stateless predicate to apply to the each value
1192 *
1193 * @return a boolean binding
1194 */
1195 @Nonnull
1196 public static <K> BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableMap<K, Boolean> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final Predicate<? super Boolean> filter) {
1197 requireNonNull(items, ERROR_ITEMS_NULL);
1198 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1199 requireNonNull(filter, ERROR_FILTER_NULL);
1200 return createBooleanBinding(() -> items.values().stream().filter(filter).findFirst().orElseGet(supplier), items);
1201 }
1202
1203 /**
1204 * Creates a boolean binding with the first value of an observable map after filtering.
1205 *
1206 * @param items the observable map of items.
1207 * @param defaultValue the value to be returned if there is no value present.
1208 * @param filter a non-interfering, stateless predicate to apply to the each value
1209 *
1210 * @return a boolean binding
1211 */
1212 @Nonnull
1213 public static <K> BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableMap<K, Boolean> items, @Nonnull final Boolean defaultValue, @Nonnull final ObservableValue<Predicate<? super Boolean>> filter) {
1214 requireNonNull(items, ERROR_ITEMS_NULL);
1215 requireNonNull(filter, ERROR_FILTER_NULL);
1216 return createBooleanBinding(() -> {
1217 Predicate<? super Boolean> filterValue = filter.getValue();
1218 requireNonNull(filterValue, ERROR_FILTER_NULL);
1219 return items.values().stream().filter(filterValue).findFirst().orElse(defaultValue);
1220 }, items, filter);
1221 }
1222
1223 /**
1224 * Creates a boolean binding with the first value of an observable map after filtering.
1225 *
1226 * @param items the observable map of items.
1227 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1228 * @param filter a non-interfering, stateless predicate to apply to the each value
1229 *
1230 * @return a boolean binding
1231 */
1232 @Nonnull
1233 public static <K> BooleanBinding filterThenFindFirstBoolean(@Nonnull final ObservableMap<K, Boolean> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final ObservableValue<Predicate<? super Boolean>> filter) {
1234 requireNonNull(items, ERROR_ITEMS_NULL);
1235 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1236 requireNonNull(filter, ERROR_FILTER_NULL);
1237 return createBooleanBinding(() -> {
1238 Predicate<? super Boolean> filterValue = filter.getValue();
1239 requireNonNull(filterValue, ERROR_FILTER_NULL);
1240 return items.values().stream().filter(filterValue).findFirst().orElseGet(supplier);
1241 }, items, filter);
1242 }
1243
1244 /**
1245 * Creates an integer binding with the first value of an observable map after filtering.
1246 *
1247 * @param items the observable map of items.
1248 * @param defaultValue the value to be returned if there is no value present.
1249 * @param filter a non-interfering, stateless predicate to apply to the each value
1250 *
1251 * @return an integer binding
1252 */
1253 @Nonnull
1254 public static <K> IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableMap<K, Integer> items, @Nonnull final Integer defaultValue, @Nonnull final Predicate<? super Integer> filter) {
1255 requireNonNull(items, ERROR_ITEMS_NULL);
1256 requireNonNull(filter, ERROR_FILTER_NULL);
1257 return createIntegerBinding(() -> items.values().stream().filter(filter).findFirst().orElse(defaultValue), items);
1258 }
1259
1260 /**
1261 * Creates an integer binding with the first value of an observable map after filtering.
1262 *
1263 * @param items the observable map of items.
1264 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1265 * @param filter a non-interfering, stateless predicate to apply to the each value
1266 *
1267 * @return an integer binding
1268 */
1269 @Nonnull
1270 public static <K> IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableMap<K, Integer> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final Predicate<? super Integer> filter) {
1271 requireNonNull(items, ERROR_ITEMS_NULL);
1272 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1273 requireNonNull(filter, ERROR_FILTER_NULL);
1274 return createIntegerBinding(() -> items.values().stream().filter(filter).findFirst().orElseGet(supplier), items);
1275 }
1276
1277 /**
1278 * Creates an integer binding with the first value of an observable map after filtering.
1279 *
1280 * @param items the observable map of items.
1281 * @param defaultValue the value to be returned if there is no value present.
1282 * @param filter a non-interfering, stateless predicate to apply to the each value
1283 *
1284 * @return an integer binding
1285 */
1286 @Nonnull
1287 public static <K> IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableMap<K, Integer> items, @Nonnull final Integer defaultValue, @Nonnull final ObservableValue<Predicate<? super Integer>> filter) {
1288 requireNonNull(items, ERROR_ITEMS_NULL);
1289 requireNonNull(filter, ERROR_FILTER_NULL);
1290 return createIntegerBinding(() -> {
1291 Predicate<? super Integer> filterValue = filter.getValue();
1292 requireNonNull(filterValue, ERROR_FILTER_NULL);
1293 return items.values().stream().filter(filterValue).findFirst().orElse(defaultValue);
1294 }, items, filter);
1295 }
1296
1297 /**
1298 * Creates an integer binding with the first value of an observable map after filtering.
1299 *
1300 * @param items the observable map of items.
1301 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1302 * @param filter a non-interfering, stateless predicate to apply to the each value
1303 *
1304 * @return an integer binding
1305 */
1306 @Nonnull
1307 public static <K> IntegerBinding filterThenFindFirstInteger(@Nonnull final ObservableMap<K, Integer> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final ObservableValue<Predicate<? super Integer>> filter) {
1308 requireNonNull(items, ERROR_ITEMS_NULL);
1309 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1310 requireNonNull(filter, ERROR_FILTER_NULL);
1311 return createIntegerBinding(() -> {
1312 Predicate<? super Integer> filterValue = filter.getValue();
1313 requireNonNull(filterValue, ERROR_FILTER_NULL);
1314 return items.values().stream().filter(filterValue).findFirst().orElseGet(supplier);
1315 }, items, filter);
1316 }
1317
1318 /**
1319 * Creates a long binding with the first value of an observable map after filtering.
1320 *
1321 * @param items the observable map of items.
1322 * @param defaultValue the value to be returned if there is no value present.
1323 * @param filter a non-interfering, stateless predicate to apply to the each value
1324 *
1325 * @return a long binding
1326 */
1327 @Nonnull
1328 public static <K> LongBinding filterThenFindFirstLong(@Nonnull final ObservableMap<K, Long> items, @Nonnull final Long defaultValue, @Nonnull final Predicate<? super Long> filter) {
1329 requireNonNull(items, ERROR_ITEMS_NULL);
1330 requireNonNull(filter, ERROR_FILTER_NULL);
1331 return createLongBinding(() -> items.values().stream().filter(filter).findFirst().orElse(defaultValue), items);
1332 }
1333
1334 /**
1335 * Creates a long binding with the first value of an observable map after filtering.
1336 *
1337 * @param items the observable map of items.
1338 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1339 * @param filter a non-interfering, stateless predicate to apply to the each value
1340 *
1341 * @return a long binding
1342 */
1343 @Nonnull
1344 public static <K> LongBinding filterThenFindFirstLong(@Nonnull final ObservableMap<K, Long> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Predicate<? super Long> filter) {
1345 requireNonNull(items, ERROR_ITEMS_NULL);
1346 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1347 requireNonNull(filter, ERROR_FILTER_NULL);
1348 return createLongBinding(() -> items.values().stream().filter(filter).findFirst().orElseGet(supplier), items);
1349 }
1350
1351 /**
1352 * Creates a long binding with the first value of an observable map after filtering.
1353 *
1354 * @param items the observable map of items.
1355 * @param defaultValue the value to be returned if there is no value present.
1356 * @param filter a non-interfering, stateless predicate to apply to the each value
1357 *
1358 * @return a long binding
1359 */
1360 @Nonnull
1361 public static <K> LongBinding filterThenFindFirstLong(@Nonnull final ObservableMap<K, Long> items, @Nonnull final Long defaultValue, @Nonnull final ObservableValue<Predicate<? super Long>> filter) {
1362 requireNonNull(items, ERROR_ITEMS_NULL);
1363 requireNonNull(filter, ERROR_FILTER_NULL);
1364 return createLongBinding(() -> {
1365 Predicate<? super Long> filterValue = filter.getValue();
1366 requireNonNull(filterValue, ERROR_FILTER_NULL);
1367 return items.values().stream().filter(filterValue).findFirst().orElse(defaultValue);
1368 }, items, filter);
1369 }
1370
1371 /**
1372 * Creates a long binding with the first value of an observable map after filtering.
1373 *
1374 * @param items the observable map of items.
1375 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1376 * @param filter a non-interfering, stateless predicate to apply to the each value
1377 *
1378 * @return a long binding
1379 */
1380 @Nonnull
1381 public static <K> LongBinding filterThenFindFirstLong(@Nonnull final ObservableMap<K, Long> items, @Nonnull final Supplier<Long> supplier, @Nonnull final ObservableValue<Predicate<? super Long>> filter) {
1382 requireNonNull(items, ERROR_ITEMS_NULL);
1383 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1384 requireNonNull(filter, ERROR_FILTER_NULL);
1385 return createLongBinding(() -> {
1386 Predicate<? super Long> filterValue = filter.getValue();
1387 requireNonNull(filterValue, ERROR_FILTER_NULL);
1388 return items.values().stream().filter(filterValue).findFirst().orElseGet(supplier);
1389 }, items, filter);
1390 }
1391
1392 /**
1393 * Creates a float binding with the first value of an observable map after filtering.
1394 *
1395 * @param items the observable map of items.
1396 * @param defaultValue the value to be returned if there is no value present.
1397 * @param filter a non-interfering, stateless predicate to apply to the each value
1398 *
1399 * @return a float binding
1400 */
1401 @Nonnull
1402 public static <K> FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableMap<K, Float> items, @Nonnull final Float defaultValue, @Nonnull final Predicate<? super Float> filter) {
1403 requireNonNull(items, ERROR_ITEMS_NULL);
1404 requireNonNull(filter, ERROR_FILTER_NULL);
1405 return createFloatBinding(() -> items.values().stream().filter(filter).findFirst().orElse(defaultValue), items);
1406 }
1407
1408 /**
1409 * Creates a float binding with the first value of an observable map after filtering.
1410 *
1411 * @param items the observable map of items.
1412 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1413 * @param filter a non-interfering, stateless predicate to apply to the each value
1414 *
1415 * @return a float binding
1416 */
1417 @Nonnull
1418 public static <K> FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableMap<K, Float> items, @Nonnull final Supplier<Float> supplier, @Nonnull final Predicate<? super Float> filter) {
1419 requireNonNull(items, ERROR_ITEMS_NULL);
1420 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1421 requireNonNull(filter, ERROR_FILTER_NULL);
1422 return createFloatBinding(() -> items.values().stream().filter(filter).findFirst().orElseGet(supplier), items);
1423 }
1424
1425 /**
1426 * Creates a float binding with the first value of an observable map after filtering.
1427 *
1428 * @param items the observable map of items.
1429 * @param defaultValue the value to be returned if there is no value present.
1430 * @param filter a non-interfering, stateless predicate to apply to the each value
1431 *
1432 * @return a float binding
1433 */
1434 @Nonnull
1435 public static <K> FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableMap<K, Float> items, @Nonnull final Float defaultValue, @Nonnull final ObservableValue<Predicate<? super Float>> filter) {
1436 requireNonNull(items, ERROR_ITEMS_NULL);
1437 requireNonNull(filter, ERROR_FILTER_NULL);
1438 return createFloatBinding(() -> {
1439 Predicate<? super Float> filterValue = filter.getValue();
1440 requireNonNull(filterValue, ERROR_FILTER_NULL);
1441 return items.values().stream().filter(filterValue).findFirst().orElse(defaultValue);
1442 }, items, filter);
1443 }
1444
1445 /**
1446 * Creates a float binding with the first value of an observable map after filtering.
1447 *
1448 * @param items the observable map of items.
1449 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1450 * @param filter a non-interfering, stateless predicate to apply to the each value
1451 *
1452 * @return a float binding
1453 */
1454 @Nonnull
1455 public static <K> FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableMap<K, Float> items, @Nonnull final Supplier<Float> supplier, @Nonnull final ObservableValue<Predicate<? super Float>> filter) {
1456 requireNonNull(items, ERROR_ITEMS_NULL);
1457 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1458 requireNonNull(filter, ERROR_FILTER_NULL);
1459 return createFloatBinding(() -> {
1460 Predicate<? super Float> filterValue = filter.getValue();
1461 requireNonNull(filterValue, ERROR_FILTER_NULL);
1462 return items.values().stream().filter(filterValue).findFirst().orElseGet(supplier);
1463 }, items, filter);
1464 }
1465
1466 /**
1467 * Creates a double binding with the first value of an observable map after filtering.
1468 *
1469 * @param items the observable map of items.
1470 * @param defaultValue the value to be returned if there is no value present.
1471 * @param filter a non-interfering, stateless predicate to apply to the each value
1472 *
1473 * @return a double binding
1474 */
1475 @Nonnull
1476 public static <K> DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableMap<K, Double> items, @Nonnull final Double defaultValue, @Nonnull final Predicate<? super Double> filter) {
1477 requireNonNull(items, ERROR_ITEMS_NULL);
1478 requireNonNull(filter, ERROR_FILTER_NULL);
1479 return createDoubleBinding(() -> items.values().stream().filter(filter).findFirst().orElse(defaultValue), items);
1480 }
1481
1482 /**
1483 * Creates a double binding with the first value of an observable map after filtering.
1484 *
1485 * @param items the observable map of items.
1486 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1487 * @param filter a non-interfering, stateless predicate to apply to the each value
1488 *
1489 * @return a double binding
1490 */
1491 @Nonnull
1492 public static <K> DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableMap<K, Double> items, @Nonnull final Supplier<Double> supplier, @Nonnull final Predicate<? super Double> filter) {
1493 requireNonNull(items, ERROR_ITEMS_NULL);
1494 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1495 requireNonNull(filter, ERROR_FILTER_NULL);
1496 return createDoubleBinding(() -> items.values().stream().filter(filter).findFirst().orElseGet(supplier), items);
1497 }
1498
1499 /**
1500 * Creates a double binding with the first value of an observable map after filtering.
1501 *
1502 * @param items the observable map of items.
1503 * @param defaultValue the value to be returned if there is no value present.
1504 * @param filter a non-interfering, stateless predicate to apply to the each value
1505 *
1506 * @return a double binding
1507 */
1508 @Nonnull
1509 public static <K> DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableMap<K, Double> items, @Nonnull final Double defaultValue, @Nonnull final ObservableValue<Predicate<? super Double>> filter) {
1510 requireNonNull(items, ERROR_ITEMS_NULL);
1511 requireNonNull(filter, ERROR_FILTER_NULL);
1512 return createDoubleBinding(() -> {
1513 Predicate<? super Double> filterValue = filter.getValue();
1514 requireNonNull(filterValue, ERROR_FILTER_NULL);
1515 return items.values().stream().filter(filterValue).findFirst().orElse(defaultValue);
1516 }, items, filter);
1517 }
1518
1519 /**
1520 * Creates a double binding with the first value of an observable map after filtering.
1521 *
1522 * @param items the observable map of items.
1523 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1524 * @param filter a non-interfering, stateless predicate to apply to the each value
1525 *
1526 * @return a double binding
1527 */
1528 @Nonnull
1529 public static <K> DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableMap<K, Double> items, @Nonnull final Supplier<Double> supplier, @Nonnull final ObservableValue<Predicate<? super Double>> filter) {
1530 requireNonNull(items, ERROR_ITEMS_NULL);
1531 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1532 requireNonNull(filter, ERROR_FILTER_NULL);
1533 return createDoubleBinding(() -> {
1534 Predicate<? super Double> filterValue = filter.getValue();
1535 requireNonNull(filterValue, ERROR_FILTER_NULL);
1536 return items.values().stream().filter(filterValue).findFirst().orElseGet(supplier);
1537 }, items, filter);
1538 }
1539
1540 /**
1541 * Creates a string binding with the first value of an observable map after filtering.
1542 *
1543 * @param items the observable map of items.
1544 * @param defaultValue the value to be returned if there is no value present.
1545 * @param filter a non-interfering, stateless predicate to apply to the each value
1546 *
1547 * @return a string binding
1548 */
1549 @Nonnull
1550 public static <K> StringBinding filterThenFindFirstString(@Nonnull final ObservableMap<K, String> items, @Nonnull final String defaultValue, @Nonnull final Predicate<? super String> filter) {
1551 requireNonNull(items, ERROR_ITEMS_NULL);
1552 requireNonNull(filter, ERROR_FILTER_NULL);
1553 return createStringBinding(() -> items.values().stream().filter(filter).findFirst().orElse(defaultValue), items);
1554 }
1555
1556 /**
1557 * Creates a string binding with the first value of an observable map after filtering.
1558 *
1559 * @param items the observable map of items.
1560 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1561 * @param filter a non-interfering, stateless predicate to apply to the each value
1562 *
1563 * @return a string binding
1564 */
1565 @Nonnull
1566 public static <K> StringBinding filterThenFindFirstString(@Nonnull final ObservableMap<K, String> items, @Nonnull final Supplier<String> supplier, @Nonnull final Predicate<? super String> filter) {
1567 requireNonNull(items, ERROR_ITEMS_NULL);
1568 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1569 requireNonNull(filter, ERROR_FILTER_NULL);
1570 return createStringBinding(() -> items.values().stream().filter(filter).findFirst().orElseGet(supplier), items);
1571 }
1572
1573 /**
1574 * Creates a string binding with the first value of an observable map after filtering.
1575 *
1576 * @param items the observable map of items.
1577 * @param defaultValue the value to be returned if there is no value present.
1578 * @param filter a non-interfering, stateless predicate to apply to the each value
1579 *
1580 * @return a string binding
1581 */
1582 @Nonnull
1583 public static <K> StringBinding filterThenFindFirstString(@Nonnull final ObservableMap<K, String> items, @Nonnull final String defaultValue, @Nonnull final ObservableValue<Predicate<? super String>> filter) {
1584 requireNonNull(items, ERROR_ITEMS_NULL);
1585 requireNonNull(filter, ERROR_FILTER_NULL);
1586 return createStringBinding(() -> {
1587 Predicate<? super String> filterValue = filter.getValue();
1588 requireNonNull(filterValue, ERROR_FILTER_NULL);
1589 return items.values().stream().filter(filterValue).findFirst().orElse(defaultValue);
1590 }, items, filter);
1591 }
1592
1593 /**
1594 * Creates a string binding with the first value of an observable map after filtering.
1595 *
1596 * @param items the observable map of items.
1597 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1598 * @param filter a non-interfering, stateless predicate to apply to the each value
1599 *
1600 * @return a string binding
1601 */
1602 @Nonnull
1603 public static <K> StringBinding filterThenFindFirstString(@Nonnull final ObservableMap<K, String> items, @Nonnull final Supplier<String> supplier, @Nonnull final ObservableValue<Predicate<? super String>> filter) {
1604 requireNonNull(items, ERROR_ITEMS_NULL);
1605 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1606 requireNonNull(filter, ERROR_FILTER_NULL);
1607 return createStringBinding(() -> {
1608 Predicate<? super String> filterValue = filter.getValue();
1609 requireNonNull(filterValue, ERROR_FILTER_NULL);
1610 return items.values().stream().filter(filterValue).findFirst().orElseGet(supplier);
1611 }, items, filter);
1612 }
1613
1614 /**
1615 * Creates an object binding with the first element of an observable list after mapping and filtering.
1616 *
1617 * @param items the observable list of items.
1618 * @param defaultValue the value to be returned if there is no value present.
1619 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1620 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1621 *
1622 * @return an object binding
1623 */
1624 @Nonnull
1625 public static <T, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final R defaultValue, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> filter) {
1626 requireNonNull(items, ERROR_ITEMS_NULL);
1627 requireNonNull(mapper, ERROR_MAPPER_NULL);
1628 requireNonNull(filter, ERROR_FILTER_NULL);
1629 return createObjectBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
1630 }
1631
1632 /**
1633 * Creates an object binding with the first element of an observable list after mapping and filtering.
1634 *
1635 * @param items the observable list of items.
1636 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1637 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1638 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1639 *
1640 * @return an object binding
1641 */
1642 @Nonnull
1643 public static <T, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<R> supplier, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> filter) {
1644 requireNonNull(items, ERROR_ITEMS_NULL);
1645 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1646 requireNonNull(mapper, ERROR_MAPPER_NULL);
1647 requireNonNull(filter, ERROR_FILTER_NULL);
1648 return createObjectBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
1649 }
1650
1651 /**
1652 * Creates an object binding with the first element of an observable list after mapping and filtering.
1653 *
1654 * @param items the observable list of items.
1655 * @param defaultValue the value to be returned if there is no value present.
1656 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1657 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1658 *
1659 * @return an object binding
1660 */
1661 @Nonnull
1662 public static <T, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final R defaultValue, @Nonnull final ObservableValue<Function<? super T, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> filter) {
1663 requireNonNull(items, ERROR_ITEMS_NULL);
1664 requireNonNull(mapper, ERROR_MAPPER_NULL);
1665 requireNonNull(filter, ERROR_FILTER_NULL);
1666 return createObjectBinding(() -> {
1667 Function<? super T, R> mapperValue = mapper.getValue();
1668 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
1669 Predicate<? super R> filterValue = filter.getValue();
1670 requireNonNull(filterValue, ERROR_FILTER_NULL);
1671 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
1672 }, items, mapper, filter);
1673 }
1674
1675 /**
1676 * Creates an object binding with the first element of an observable list after mapping and filtering.
1677 *
1678 * @param items the observable list of items.
1679 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1680 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1681 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1682 *
1683 * @return an object binding
1684 */
1685 @Nonnull
1686 public static <T, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<R> supplier, @Nonnull final ObservableValue<Function<? super T, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> filter) {
1687 requireNonNull(items, ERROR_ITEMS_NULL);
1688 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1689 requireNonNull(mapper, ERROR_MAPPER_NULL);
1690 requireNonNull(filter, ERROR_FILTER_NULL);
1691 return createObjectBinding(() -> {
1692 Function<? super T, R> mapperValue = mapper.getValue();
1693 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
1694 Predicate<? super R> filterValue = filter.getValue();
1695 requireNonNull(filterValue, ERROR_FILTER_NULL);
1696 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
1697 }, items, mapper, filter);
1698 }
1699
1700 /**
1701 * Creates a boolean binding with the first element of an observable list after mapping and filtering.
1702 *
1703 * @param items the observable list of items.
1704 * @param defaultValue the value to be returned if there is no value present.
1705 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1706 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1707 *
1708 * @return a boolean binding
1709 */
1710 @Nonnull
1711 public static <T> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Boolean defaultValue, @Nonnull final Function<? super T, Boolean> mapper, @Nonnull final Predicate<Boolean> filter) {
1712 requireNonNull(items, ERROR_ITEMS_NULL);
1713 requireNonNull(mapper, ERROR_MAPPER_NULL);
1714 requireNonNull(filter, ERROR_FILTER_NULL);
1715 return createBooleanBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
1716 }
1717
1718 /**
1719 * Creates a boolean binding with the first element of an observable list after mapping and filtering.
1720 *
1721 * @param items the observable list of items.
1722 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1723 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1724 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1725 *
1726 * @return a boolean binding
1727 */
1728 @Nonnull
1729 public static <T> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final Function<? super T, Boolean> mapper, @Nonnull final Predicate<Boolean> filter) {
1730 requireNonNull(items, ERROR_ITEMS_NULL);
1731 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1732 requireNonNull(mapper, ERROR_MAPPER_NULL);
1733 requireNonNull(filter, ERROR_FILTER_NULL);
1734 return createBooleanBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
1735 }
1736
1737 /**
1738 * Creates a boolean binding with the first element of an observable list after mapping and filtering.
1739 *
1740 * @param items the observable list of items.
1741 * @param defaultValue the value to be returned if there is no value present.
1742 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1743 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1744 *
1745 * @return a boolean binding
1746 */
1747 @Nonnull
1748 public static <T> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Boolean defaultValue, @Nonnull final ObservableValue<Function<? super T, Boolean>> mapper, @Nonnull final ObservableValue<Predicate<Boolean>> filter) {
1749 requireNonNull(items, ERROR_ITEMS_NULL);
1750 requireNonNull(mapper, ERROR_MAPPER_NULL);
1751 requireNonNull(filter, ERROR_FILTER_NULL);
1752 return createBooleanBinding(() -> {
1753 Function<? super T, Boolean> mapperValue = mapper.getValue();
1754 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
1755 Predicate<Boolean> filterValue = filter.getValue();
1756 requireNonNull(filterValue, ERROR_FILTER_NULL);
1757 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
1758 }, items, mapper, filter);
1759 }
1760
1761 /**
1762 * Creates a boolean binding with the first element of an observable list after mapping and filtering.
1763 *
1764 * @param items the observable list of items.
1765 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1766 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1767 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1768 *
1769 * @return a boolean binding
1770 */
1771 @Nonnull
1772 public static <T> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final ObservableValue<Function<? super T, Boolean>> mapper, @Nonnull final ObservableValue<Predicate<Boolean>> filter) {
1773 requireNonNull(items, ERROR_ITEMS_NULL);
1774 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1775 requireNonNull(mapper, ERROR_MAPPER_NULL);
1776 requireNonNull(filter, ERROR_FILTER_NULL);
1777 return createBooleanBinding(() -> {
1778 Function<? super T, Boolean> mapperValue = mapper.getValue();
1779 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
1780 Predicate<Boolean> filterValue = filter.getValue();
1781 requireNonNull(filterValue, ERROR_FILTER_NULL);
1782 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
1783 }, items, mapper, filter);
1784 }
1785
1786 /**
1787 * Creates an integer binding with the first element of an observable list after mapping and filtering.
1788 *
1789 * @param items the observable list of items.
1790 * @param defaultValue the value to be returned if there is no value present.
1791 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1792 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1793 *
1794 * @return an integer binding
1795 */
1796 @Nonnull
1797 public static <T> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Integer defaultValue, @Nonnull final Function<? super T, Integer> mapper, @Nonnull final Predicate<Integer> filter) {
1798 requireNonNull(items, ERROR_ITEMS_NULL);
1799 requireNonNull(mapper, ERROR_MAPPER_NULL);
1800 requireNonNull(filter, ERROR_FILTER_NULL);
1801 return createIntegerBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
1802 }
1803
1804 /**
1805 * Creates an integer binding with the first element of an observable list after mapping and filtering.
1806 *
1807 * @param items the observable list of items.
1808 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1809 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1810 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1811 *
1812 * @return an integer binding
1813 */
1814 @Nonnull
1815 public static <T> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final Function<? super T, Integer> mapper, @Nonnull final Predicate<Integer> filter) {
1816 requireNonNull(items, ERROR_ITEMS_NULL);
1817 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1818 requireNonNull(mapper, ERROR_MAPPER_NULL);
1819 requireNonNull(filter, ERROR_FILTER_NULL);
1820 return createIntegerBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
1821 }
1822
1823 /**
1824 * Creates an integer binding with the first element of an observable list after mapping and filtering.
1825 *
1826 * @param items the observable list of items.
1827 * @param defaultValue the value to be returned if there is no value present.
1828 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1829 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1830 *
1831 * @return an integer binding
1832 */
1833 @Nonnull
1834 public static <T> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Integer defaultValue, @Nonnull final ObservableValue<Function<? super T, Integer>> mapper, @Nonnull final ObservableValue<Predicate<Integer>> filter) {
1835 requireNonNull(items, ERROR_ITEMS_NULL);
1836 requireNonNull(mapper, ERROR_MAPPER_NULL);
1837 requireNonNull(filter, ERROR_FILTER_NULL);
1838 return createIntegerBinding(() -> {
1839 Function<? super T, Integer> mapperValue = mapper.getValue();
1840 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
1841 Predicate<Integer> filterValue = filter.getValue();
1842 requireNonNull(filterValue, ERROR_FILTER_NULL);
1843 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
1844 }, items, mapper, filter);
1845 }
1846
1847 /**
1848 * Creates an integer binding with the first element of an observable list after mapping and filtering.
1849 *
1850 * @param items the observable list of items.
1851 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1852 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1853 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1854 *
1855 * @return an integer binding
1856 */
1857 @Nonnull
1858 public static <T> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final ObservableValue<Function<? super T, Integer>> mapper, @Nonnull final ObservableValue<Predicate<Integer>> filter) {
1859 requireNonNull(items, ERROR_ITEMS_NULL);
1860 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1861 requireNonNull(mapper, ERROR_MAPPER_NULL);
1862 requireNonNull(filter, ERROR_FILTER_NULL);
1863 return createIntegerBinding(() -> {
1864 Function<? super T, Integer> mapperValue = mapper.getValue();
1865 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
1866 Predicate<Integer> filterValue = filter.getValue();
1867 requireNonNull(filterValue, ERROR_FILTER_NULL);
1868 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
1869 }, items, mapper, filter);
1870 }
1871
1872 /**
1873 * Creates a long binding with the first element of an observable list after mapping and filtering.
1874 *
1875 * @param items the observable list of items.
1876 * @param defaultValue the value to be returned if there is no value present.
1877 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1878 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1879 *
1880 * @return a long binding
1881 */
1882 @Nonnull
1883 public static <T> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Long defaultValue, @Nonnull final Function<? super T, Long> mapper, @Nonnull final Predicate<Long> filter) {
1884 requireNonNull(items, ERROR_ITEMS_NULL);
1885 requireNonNull(mapper, ERROR_MAPPER_NULL);
1886 requireNonNull(filter, ERROR_FILTER_NULL);
1887 return createLongBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
1888 }
1889
1890 /**
1891 * Creates a long binding with the first element of an observable list after mapping and filtering.
1892 *
1893 * @param items the observable list of items.
1894 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1895 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1896 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1897 *
1898 * @return a long binding
1899 */
1900 @Nonnull
1901 public static <T> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Function<? super T, Long> mapper, @Nonnull final Predicate<Long> filter) {
1902 requireNonNull(items, ERROR_ITEMS_NULL);
1903 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1904 requireNonNull(mapper, ERROR_MAPPER_NULL);
1905 requireNonNull(filter, ERROR_FILTER_NULL);
1906 return createLongBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
1907 }
1908
1909 /**
1910 * Creates a long binding with the first element of an observable list after mapping and filtering.
1911 *
1912 * @param items the observable list of items.
1913 * @param defaultValue the value to be returned if there is no value present.
1914 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1915 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1916 *
1917 * @return a long binding
1918 */
1919 @Nonnull
1920 public static <T> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Long defaultValue, @Nonnull final ObservableValue<Function<? super T, Long>> mapper, @Nonnull final ObservableValue<Predicate<Long>> filter) {
1921 requireNonNull(items, ERROR_ITEMS_NULL);
1922 requireNonNull(mapper, ERROR_MAPPER_NULL);
1923 requireNonNull(filter, ERROR_FILTER_NULL);
1924 return createLongBinding(() -> {
1925 Function<? super T, Long> mapperValue = mapper.getValue();
1926 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
1927 Predicate<Long> filterValue = filter.getValue();
1928 requireNonNull(filterValue, ERROR_FILTER_NULL);
1929 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
1930 }, items, mapper, filter);
1931 }
1932
1933 /**
1934 * Creates a long binding with the first element of an observable list after mapping and filtering.
1935 *
1936 * @param items the observable list of items.
1937 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1938 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1939 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1940 *
1941 * @return a long binding
1942 */
1943 @Nonnull
1944 public static <T> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Long> supplier, @Nonnull final ObservableValue<Function<? super T, Long>> mapper, @Nonnull final ObservableValue<Predicate<Long>> filter) {
1945 requireNonNull(items, ERROR_ITEMS_NULL);
1946 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1947 requireNonNull(mapper, ERROR_MAPPER_NULL);
1948 requireNonNull(filter, ERROR_FILTER_NULL);
1949 return createLongBinding(() -> {
1950 Function<? super T, Long> mapperValue = mapper.getValue();
1951 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
1952 Predicate<Long> filterValue = filter.getValue();
1953 requireNonNull(filterValue, ERROR_FILTER_NULL);
1954 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
1955 }, items, mapper, filter);
1956 }
1957
1958 /**
1959 * Creates a float binding with the first element of an observable list after mapping and filtering.
1960 *
1961 * @param items the observable list of items.
1962 * @param defaultValue the value to be returned if there is no value present.
1963 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1964 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1965 *
1966 * @return a float binding
1967 */
1968 @Nonnull
1969 public static <T> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Float defaultValue, @Nonnull final Function<? super T, Float> mapper, @Nonnull final Predicate<Float> filter) {
1970 requireNonNull(items, ERROR_ITEMS_NULL);
1971 requireNonNull(mapper, ERROR_MAPPER_NULL);
1972 requireNonNull(filter, ERROR_FILTER_NULL);
1973 return createFloatBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
1974 }
1975
1976 /**
1977 * Creates a float binding with the first element of an observable list after mapping and filtering.
1978 *
1979 * @param items the observable list of items.
1980 * @param supplier a {@code Supplier} whose result is returned if no value is present.
1981 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
1982 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
1983 *
1984 * @return a float binding
1985 */
1986 @Nonnull
1987 public static <T> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Float> supplier, @Nonnull final Function<? super T, Float> mapper, @Nonnull final Predicate<Float> filter) {
1988 requireNonNull(items, ERROR_ITEMS_NULL);
1989 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
1990 requireNonNull(mapper, ERROR_MAPPER_NULL);
1991 requireNonNull(filter, ERROR_FILTER_NULL);
1992 return createFloatBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
1993 }
1994
1995 /**
1996 * Creates a float binding with the first element of an observable list after mapping and filtering.
1997 *
1998 * @param items the observable list of items.
1999 * @param defaultValue the value to be returned if there is no value present.
2000 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2001 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2002 *
2003 * @return a float binding
2004 */
2005 @Nonnull
2006 public static <T> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Float defaultValue, @Nonnull final ObservableValue<Function<? super T, Float>> mapper, @Nonnull final ObservableValue<Predicate<Float>> filter) {
2007 requireNonNull(items, ERROR_ITEMS_NULL);
2008 requireNonNull(mapper, ERROR_MAPPER_NULL);
2009 requireNonNull(filter, ERROR_FILTER_NULL);
2010 return createFloatBinding(() -> {
2011 Function<? super T, Float> mapperValue = mapper.getValue();
2012 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2013 Predicate<Float> filterValue = filter.getValue();
2014 requireNonNull(filterValue, ERROR_FILTER_NULL);
2015 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2016 }, items, mapper, filter);
2017 }
2018
2019 /**
2020 * Creates a float binding with the first element of an observable list after mapping and filtering.
2021 *
2022 * @param items the observable list of items.
2023 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2024 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2025 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2026 *
2027 * @return a float binding
2028 */
2029 @Nonnull
2030 public static <T> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Float> supplier, @Nonnull final ObservableValue<Function<? super T, Float>> mapper, @Nonnull final ObservableValue<Predicate<Float>> filter) {
2031 requireNonNull(items, ERROR_ITEMS_NULL);
2032 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2033 requireNonNull(mapper, ERROR_MAPPER_NULL);
2034 requireNonNull(filter, ERROR_FILTER_NULL);
2035 return createFloatBinding(() -> {
2036 Function<? super T, Float> mapperValue = mapper.getValue();
2037 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2038 Predicate<Float> filterValue = filter.getValue();
2039 requireNonNull(filterValue, ERROR_FILTER_NULL);
2040 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2041 }, items, mapper, filter);
2042 }
2043
2044 /**
2045 * Creates a double binding with the first element of an observable list after mapping and filtering.
2046 *
2047 * @param items the observable list of items.
2048 * @param defaultValue the value to be returned if there is no value present.
2049 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2050 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2051 *
2052 * @return a double binding
2053 */
2054 @Nonnull
2055 public static <T> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Double defaultValue, @Nonnull final Function<? super T, Double> mapper, @Nonnull final Predicate<Double> filter) {
2056 requireNonNull(items, ERROR_ITEMS_NULL);
2057 requireNonNull(mapper, ERROR_MAPPER_NULL);
2058 requireNonNull(filter, ERROR_FILTER_NULL);
2059 return createDoubleBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2060 }
2061
2062 /**
2063 * Creates a double binding with the first element of an observable list after mapping and filtering.
2064 *
2065 * @param items the observable list of items.
2066 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2067 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2068 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2069 *
2070 * @return a double binding
2071 */
2072 @Nonnull
2073 public static <T> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Double> supplier, @Nonnull final Function<? super T, Double> mapper, @Nonnull final Predicate<Double> filter) {
2074 requireNonNull(items, ERROR_ITEMS_NULL);
2075 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2076 requireNonNull(mapper, ERROR_MAPPER_NULL);
2077 requireNonNull(filter, ERROR_FILTER_NULL);
2078 return createDoubleBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2079 }
2080
2081 /**
2082 * Creates a double binding with the first element of an observable list after mapping and filtering.
2083 *
2084 * @param items the observable list of items.
2085 * @param defaultValue the value to be returned if there is no value present.
2086 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2087 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2088 *
2089 * @return a double binding
2090 */
2091 @Nonnull
2092 public static <T> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Double defaultValue, @Nonnull final ObservableValue<Function<? super T, Double>> mapper, @Nonnull final ObservableValue<Predicate<Double>> filter) {
2093 requireNonNull(items, ERROR_ITEMS_NULL);
2094 requireNonNull(mapper, ERROR_MAPPER_NULL);
2095 requireNonNull(filter, ERROR_FILTER_NULL);
2096 return createDoubleBinding(() -> {
2097 Function<? super T, Double> mapperValue = mapper.getValue();
2098 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2099 Predicate<Double> filterValue = filter.getValue();
2100 requireNonNull(filterValue, ERROR_FILTER_NULL);
2101 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2102 }, items, mapper, filter);
2103 }
2104
2105 /**
2106 * Creates a double binding with the first element of an observable list after mapping and filtering.
2107 *
2108 * @param items the observable list of items.
2109 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2110 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2111 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2112 *
2113 * @return a double binding
2114 */
2115 @Nonnull
2116 public static <T> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Double> supplier, @Nonnull final ObservableValue<Function<? super T, Double>> mapper, @Nonnull final ObservableValue<Predicate<Double>> filter) {
2117 requireNonNull(items, ERROR_ITEMS_NULL);
2118 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2119 requireNonNull(mapper, ERROR_MAPPER_NULL);
2120 requireNonNull(filter, ERROR_FILTER_NULL);
2121 return createDoubleBinding(() -> {
2122 Function<? super T, Double> mapperValue = mapper.getValue();
2123 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2124 Predicate<Double> filterValue = filter.getValue();
2125 requireNonNull(filterValue, ERROR_FILTER_NULL);
2126 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2127 }, items, mapper, filter);
2128 }
2129
2130 /**
2131 * Creates a string binding with the first element of an observable list after mapping and filtering.
2132 *
2133 * @param items the observable list of items.
2134 * @param defaultValue the value to be returned if there is no value present.
2135 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2136 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2137 *
2138 * @return a string binding
2139 */
2140 @Nonnull
2141 public static <T> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final String defaultValue, @Nonnull final Function<? super T, String> mapper, @Nonnull final Predicate<String> filter) {
2142 requireNonNull(items, ERROR_ITEMS_NULL);
2143 requireNonNull(mapper, ERROR_MAPPER_NULL);
2144 requireNonNull(filter, ERROR_FILTER_NULL);
2145 return createStringBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2146 }
2147
2148 /**
2149 * Creates a string binding with the first element of an observable list after mapping and filtering.
2150 *
2151 * @param items the observable list of items.
2152 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2153 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2154 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2155 *
2156 * @return a string binding
2157 */
2158 @Nonnull
2159 public static <T> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<String> supplier, @Nonnull final Function<? super T, String> mapper, @Nonnull final Predicate<String> filter) {
2160 requireNonNull(items, ERROR_ITEMS_NULL);
2161 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2162 requireNonNull(mapper, ERROR_MAPPER_NULL);
2163 requireNonNull(filter, ERROR_FILTER_NULL);
2164 return createStringBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2165 }
2166
2167 /**
2168 * Creates a string binding with the first element of an observable list after mapping and filtering.
2169 *
2170 * @param items the observable list of items.
2171 * @param defaultValue the value to be returned if there is no value present.
2172 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2173 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2174 *
2175 * @return a string binding
2176 */
2177 @Nonnull
2178 public static <T> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final String defaultValue, @Nonnull final ObservableValue<Function<? super T, String>> mapper, @Nonnull final ObservableValue<Predicate<String>> filter) {
2179 requireNonNull(items, ERROR_ITEMS_NULL);
2180 requireNonNull(mapper, ERROR_MAPPER_NULL);
2181 requireNonNull(filter, ERROR_FILTER_NULL);
2182 return createStringBinding(() -> {
2183 Function<? super T, String> mapperValue = mapper.getValue();
2184 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2185 Predicate<String> filterValue = filter.getValue();
2186 requireNonNull(filterValue, ERROR_FILTER_NULL);
2187 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2188 }, items, mapper, filter);
2189 }
2190
2191 /**
2192 * Creates a string binding with the first element of an observable list after mapping and filtering.
2193 *
2194 * @param items the observable list of items.
2195 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2196 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2197 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2198 *
2199 * @return a string binding
2200 */
2201 @Nonnull
2202 public static <T> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<String> supplier, @Nonnull final ObservableValue<Function<? super T, String>> mapper, @Nonnull final ObservableValue<Predicate<String>> filter) {
2203 requireNonNull(items, ERROR_ITEMS_NULL);
2204 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2205 requireNonNull(mapper, ERROR_MAPPER_NULL);
2206 requireNonNull(filter, ERROR_FILTER_NULL);
2207 return createStringBinding(() -> {
2208 Function<? super T, String> mapperValue = mapper.getValue();
2209 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2210 Predicate<String> filterValue = filter.getValue();
2211 requireNonNull(filterValue, ERROR_FILTER_NULL);
2212 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2213 }, items, mapper, filter);
2214 }
2215
2216 /**
2217 * Creates an object binding with the first element of an observable set after mapping and filtering.
2218 *
2219 * @param items the observable set of items.
2220 * @param defaultValue the value to be returned if there is no value present.
2221 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2222 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2223 *
2224 * @return an object binding
2225 */
2226 @Nonnull
2227 public static <T, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final R defaultValue, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> filter) {
2228 requireNonNull(items, ERROR_ITEMS_NULL);
2229 requireNonNull(mapper, ERROR_MAPPER_NULL);
2230 requireNonNull(filter, ERROR_FILTER_NULL);
2231 return createObjectBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2232 }
2233
2234 /**
2235 * Creates an object binding with the first element of an observable set after mapping and filtering.
2236 *
2237 * @param items the observable set of items.
2238 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2239 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2240 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2241 *
2242 * @return an object binding
2243 */
2244 @Nonnull
2245 public static <T, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<R> supplier, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> filter) {
2246 requireNonNull(items, ERROR_ITEMS_NULL);
2247 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2248 requireNonNull(mapper, ERROR_MAPPER_NULL);
2249 requireNonNull(filter, ERROR_FILTER_NULL);
2250 return createObjectBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2251 }
2252
2253 /**
2254 * Creates an object binding with the first element of an observable set after mapping and filtering.
2255 *
2256 * @param items the observable set of items.
2257 * @param defaultValue the value to be returned if there is no value present.
2258 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2259 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2260 *
2261 * @return an object binding
2262 */
2263 @Nonnull
2264 public static <T, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final R defaultValue, @Nonnull final ObservableValue<Function<? super T, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> filter) {
2265 requireNonNull(items, ERROR_ITEMS_NULL);
2266 requireNonNull(mapper, ERROR_MAPPER_NULL);
2267 requireNonNull(filter, ERROR_FILTER_NULL);
2268 return createObjectBinding(() -> {
2269 Function<? super T, R> mapperValue = mapper.getValue();
2270 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2271 Predicate<? super R> filterValue = filter.getValue();
2272 requireNonNull(filterValue, ERROR_FILTER_NULL);
2273 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2274 }, items, mapper, filter);
2275 }
2276
2277 /**
2278 * Creates an object binding with the first element of an observable set after mapping and filtering.
2279 *
2280 * @param items the observable set of items.
2281 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2282 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2283 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2284 *
2285 * @return an object binding
2286 */
2287 @Nonnull
2288 public static <T, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<R> supplier, @Nonnull final ObservableValue<Function<? super T, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> filter) {
2289 requireNonNull(items, ERROR_ITEMS_NULL);
2290 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2291 requireNonNull(mapper, ERROR_MAPPER_NULL);
2292 requireNonNull(filter, ERROR_FILTER_NULL);
2293 return createObjectBinding(() -> {
2294 Function<? super T, R> mapperValue = mapper.getValue();
2295 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2296 Predicate<? super R> filterValue = filter.getValue();
2297 requireNonNull(filterValue, ERROR_FILTER_NULL);
2298 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2299 }, items, mapper, filter);
2300 }
2301
2302 /**
2303 * Creates a boolean binding with the first element of an observable set after mapping and filtering.
2304 *
2305 * @param items the observable set of items.
2306 * @param defaultValue the value to be returned if there is no value present.
2307 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2308 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2309 *
2310 * @return a boolean binding
2311 */
2312 @Nonnull
2313 public static <T> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Boolean defaultValue, @Nonnull final Function<? super T, Boolean> mapper, @Nonnull final Predicate<Boolean> filter) {
2314 requireNonNull(items, ERROR_ITEMS_NULL);
2315 requireNonNull(mapper, ERROR_MAPPER_NULL);
2316 requireNonNull(filter, ERROR_FILTER_NULL);
2317 return createBooleanBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2318 }
2319
2320 /**
2321 * Creates a boolean binding with the first element of an observable set after mapping and filtering.
2322 *
2323 * @param items the observable set of items.
2324 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2325 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2326 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2327 *
2328 * @return a boolean binding
2329 */
2330 @Nonnull
2331 public static <T> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final Function<? super T, Boolean> mapper, @Nonnull final Predicate<Boolean> filter) {
2332 requireNonNull(items, ERROR_ITEMS_NULL);
2333 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2334 requireNonNull(mapper, ERROR_MAPPER_NULL);
2335 requireNonNull(filter, ERROR_FILTER_NULL);
2336 return createBooleanBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2337 }
2338
2339 /**
2340 * Creates a boolean binding with the first element of an observable set after mapping and filtering.
2341 *
2342 * @param items the observable set of items.
2343 * @param defaultValue the value to be returned if there is no value present.
2344 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2345 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2346 *
2347 * @return a boolean binding
2348 */
2349 @Nonnull
2350 public static <T> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Boolean defaultValue, @Nonnull final ObservableValue<Function<? super T, Boolean>> mapper, @Nonnull final ObservableValue<Predicate<Boolean>> filter) {
2351 requireNonNull(items, ERROR_ITEMS_NULL);
2352 requireNonNull(mapper, ERROR_MAPPER_NULL);
2353 requireNonNull(filter, ERROR_FILTER_NULL);
2354 return createBooleanBinding(() -> {
2355 Function<? super T, Boolean> mapperValue = mapper.getValue();
2356 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2357 Predicate<Boolean> filterValue = filter.getValue();
2358 requireNonNull(filterValue, ERROR_FILTER_NULL);
2359 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2360 }, items, mapper, filter);
2361 }
2362
2363 /**
2364 * Creates a boolean binding with the first element of an observable set after mapping and filtering.
2365 *
2366 * @param items the observable set of items.
2367 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2368 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2369 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2370 *
2371 * @return a boolean binding
2372 */
2373 @Nonnull
2374 public static <T> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final ObservableValue<Function<? super T, Boolean>> mapper, @Nonnull final ObservableValue<Predicate<Boolean>> filter) {
2375 requireNonNull(items, ERROR_ITEMS_NULL);
2376 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2377 requireNonNull(mapper, ERROR_MAPPER_NULL);
2378 requireNonNull(filter, ERROR_FILTER_NULL);
2379 return createBooleanBinding(() -> {
2380 Function<? super T, Boolean> mapperValue = mapper.getValue();
2381 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2382 Predicate<Boolean> filterValue = filter.getValue();
2383 requireNonNull(filterValue, ERROR_FILTER_NULL);
2384 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2385 }, items, mapper, filter);
2386 }
2387
2388 /**
2389 * Creates an integer binding with the first element of an observable set after mapping and filtering.
2390 *
2391 * @param items the observable set of items.
2392 * @param defaultValue the value to be returned if there is no value present.
2393 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2394 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2395 *
2396 * @return an integer binding
2397 */
2398 @Nonnull
2399 public static <T> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Integer defaultValue, @Nonnull final Function<? super T, Integer> mapper, @Nonnull final Predicate<Integer> filter) {
2400 requireNonNull(items, ERROR_ITEMS_NULL);
2401 requireNonNull(mapper, ERROR_MAPPER_NULL);
2402 requireNonNull(filter, ERROR_FILTER_NULL);
2403 return createIntegerBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2404 }
2405
2406 /**
2407 * Creates an integer binding with the first element of an observable set after mapping and filtering.
2408 *
2409 * @param items the observable set of items.
2410 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2411 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2412 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2413 *
2414 * @return an integer binding
2415 */
2416 @Nonnull
2417 public static <T> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final Function<? super T, Integer> mapper, @Nonnull final Predicate<Integer> filter) {
2418 requireNonNull(items, ERROR_ITEMS_NULL);
2419 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2420 requireNonNull(mapper, ERROR_MAPPER_NULL);
2421 requireNonNull(filter, ERROR_FILTER_NULL);
2422 return createIntegerBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2423 }
2424
2425 /**
2426 * Creates an integer binding with the first element of an observable set after mapping and filtering.
2427 *
2428 * @param items the observable set of items.
2429 * @param defaultValue the value to be returned if there is no value present.
2430 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2431 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2432 *
2433 * @return an integer binding
2434 */
2435 @Nonnull
2436 public static <T> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Integer defaultValue, @Nonnull final ObservableValue<Function<? super T, Integer>> mapper, @Nonnull final ObservableValue<Predicate<Integer>> filter) {
2437 requireNonNull(items, ERROR_ITEMS_NULL);
2438 requireNonNull(mapper, ERROR_MAPPER_NULL);
2439 requireNonNull(filter, ERROR_FILTER_NULL);
2440 return createIntegerBinding(() -> {
2441 Function<? super T, Integer> mapperValue = mapper.getValue();
2442 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2443 Predicate<Integer> filterValue = filter.getValue();
2444 requireNonNull(filterValue, ERROR_FILTER_NULL);
2445 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2446 }, items, mapper, filter);
2447 }
2448
2449 /**
2450 * Creates an integer binding with the first element of an observable set after mapping and filtering.
2451 *
2452 * @param items the observable set of items.
2453 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2454 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2455 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2456 *
2457 * @return an integer binding
2458 */
2459 @Nonnull
2460 public static <T> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final ObservableValue<Function<? super T, Integer>> mapper, @Nonnull final ObservableValue<Predicate<Integer>> filter) {
2461 requireNonNull(items, ERROR_ITEMS_NULL);
2462 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2463 requireNonNull(mapper, ERROR_MAPPER_NULL);
2464 requireNonNull(filter, ERROR_FILTER_NULL);
2465 return createIntegerBinding(() -> {
2466 Function<? super T, Integer> mapperValue = mapper.getValue();
2467 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2468 Predicate<Integer> filterValue = filter.getValue();
2469 requireNonNull(filterValue, ERROR_FILTER_NULL);
2470 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2471 }, items, mapper, filter);
2472 }
2473
2474 /**
2475 * Creates a long binding with the first element of an observable set after mapping and filtering.
2476 *
2477 * @param items the observable set of items.
2478 * @param defaultValue the value to be returned if there is no value present.
2479 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2480 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2481 *
2482 * @return a long binding
2483 */
2484 @Nonnull
2485 public static <T> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Long defaultValue, @Nonnull final Function<? super T, Long> mapper, @Nonnull final Predicate<Long> filter) {
2486 requireNonNull(items, ERROR_ITEMS_NULL);
2487 requireNonNull(mapper, ERROR_MAPPER_NULL);
2488 requireNonNull(filter, ERROR_FILTER_NULL);
2489 return createLongBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2490 }
2491
2492 /**
2493 * Creates a long binding with the first element of an observable set after mapping and filtering.
2494 *
2495 * @param items the observable set of items.
2496 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2497 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2498 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2499 *
2500 * @return a long binding
2501 */
2502 @Nonnull
2503 public static <T> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Function<? super T, Long> mapper, @Nonnull final Predicate<Long> filter) {
2504 requireNonNull(items, ERROR_ITEMS_NULL);
2505 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2506 requireNonNull(mapper, ERROR_MAPPER_NULL);
2507 requireNonNull(filter, ERROR_FILTER_NULL);
2508 return createLongBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2509 }
2510
2511 /**
2512 * Creates a long binding with the first element of an observable set after mapping and filtering.
2513 *
2514 * @param items the observable set of items.
2515 * @param defaultValue the value to be returned if there is no value present.
2516 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2517 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2518 *
2519 * @return a long binding
2520 */
2521 @Nonnull
2522 public static <T> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Long defaultValue, @Nonnull final ObservableValue<Function<? super T, Long>> mapper, @Nonnull final ObservableValue<Predicate<Long>> filter) {
2523 requireNonNull(items, ERROR_ITEMS_NULL);
2524 requireNonNull(mapper, ERROR_MAPPER_NULL);
2525 requireNonNull(filter, ERROR_FILTER_NULL);
2526 return createLongBinding(() -> {
2527 Function<? super T, Long> mapperValue = mapper.getValue();
2528 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2529 Predicate<Long> filterValue = filter.getValue();
2530 requireNonNull(filterValue, ERROR_FILTER_NULL);
2531 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2532 }, items, mapper, filter);
2533 }
2534
2535 /**
2536 * Creates a long binding with the first element of an observable set after mapping and filtering.
2537 *
2538 * @param items the observable set of items.
2539 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2540 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2541 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2542 *
2543 * @return a long binding
2544 */
2545 @Nonnull
2546 public static <T> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Long> supplier, @Nonnull final ObservableValue<Function<? super T, Long>> mapper, @Nonnull final ObservableValue<Predicate<Long>> filter) {
2547 requireNonNull(items, ERROR_ITEMS_NULL);
2548 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2549 requireNonNull(mapper, ERROR_MAPPER_NULL);
2550 requireNonNull(filter, ERROR_FILTER_NULL);
2551 return createLongBinding(() -> {
2552 Function<? super T, Long> mapperValue = mapper.getValue();
2553 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2554 Predicate<Long> filterValue = filter.getValue();
2555 requireNonNull(filterValue, ERROR_FILTER_NULL);
2556 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2557 }, items, mapper, filter);
2558 }
2559
2560 /**
2561 * Creates a float binding with the first element of an observable set after mapping and filtering.
2562 *
2563 * @param items the observable set of items.
2564 * @param defaultValue the value to be returned if there is no value present.
2565 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2566 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2567 *
2568 * @return a float binding
2569 */
2570 @Nonnull
2571 public static <T> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Float defaultValue, @Nonnull final Function<? super T, Float> mapper, @Nonnull final Predicate<Float> filter) {
2572 requireNonNull(items, ERROR_ITEMS_NULL);
2573 requireNonNull(mapper, ERROR_MAPPER_NULL);
2574 requireNonNull(filter, ERROR_FILTER_NULL);
2575 return createFloatBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2576 }
2577
2578 /**
2579 * Creates a float binding with the first element of an observable set after mapping and filtering.
2580 *
2581 * @param items the observable set of items.
2582 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2583 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2584 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2585 *
2586 * @return a float binding
2587 */
2588 @Nonnull
2589 public static <T> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Float> supplier, @Nonnull final Function<? super T, Float> mapper, @Nonnull final Predicate<Float> filter) {
2590 requireNonNull(items, ERROR_ITEMS_NULL);
2591 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2592 requireNonNull(mapper, ERROR_MAPPER_NULL);
2593 requireNonNull(filter, ERROR_FILTER_NULL);
2594 return createFloatBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2595 }
2596
2597 /**
2598 * Creates a float binding with the first element of an observable set after mapping and filtering.
2599 *
2600 * @param items the observable set of items.
2601 * @param defaultValue the value to be returned if there is no value present.
2602 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2603 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2604 *
2605 * @return a float binding
2606 */
2607 @Nonnull
2608 public static <T> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Float defaultValue, @Nonnull final ObservableValue<Function<? super T, Float>> mapper, @Nonnull final ObservableValue<Predicate<Float>> filter) {
2609 requireNonNull(items, ERROR_ITEMS_NULL);
2610 requireNonNull(mapper, ERROR_MAPPER_NULL);
2611 requireNonNull(filter, ERROR_FILTER_NULL);
2612 return createFloatBinding(() -> {
2613 Function<? super T, Float> mapperValue = mapper.getValue();
2614 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2615 Predicate<Float> filterValue = filter.getValue();
2616 requireNonNull(filterValue, ERROR_FILTER_NULL);
2617 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2618 }, items, mapper, filter);
2619 }
2620
2621 /**
2622 * Creates a float binding with the first element of an observable set after mapping and filtering.
2623 *
2624 * @param items the observable set of items.
2625 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2626 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2627 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2628 *
2629 * @return a float binding
2630 */
2631 @Nonnull
2632 public static <T> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Float> supplier, @Nonnull final ObservableValue<Function<? super T, Float>> mapper, @Nonnull final ObservableValue<Predicate<Float>> filter) {
2633 requireNonNull(items, ERROR_ITEMS_NULL);
2634 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2635 requireNonNull(mapper, ERROR_MAPPER_NULL);
2636 requireNonNull(filter, ERROR_FILTER_NULL);
2637 return createFloatBinding(() -> {
2638 Function<? super T, Float> mapperValue = mapper.getValue();
2639 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2640 Predicate<Float> filterValue = filter.getValue();
2641 requireNonNull(filterValue, ERROR_FILTER_NULL);
2642 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2643 }, items, mapper, filter);
2644 }
2645
2646 /**
2647 * Creates a double binding with the first element of an observable set after mapping and filtering.
2648 *
2649 * @param items the observable set of items.
2650 * @param defaultValue the value to be returned if there is no value present.
2651 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2652 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2653 *
2654 * @return a double binding
2655 */
2656 @Nonnull
2657 public static <T> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Double defaultValue, @Nonnull final Function<? super T, Double> mapper, @Nonnull final Predicate<Double> filter) {
2658 requireNonNull(items, ERROR_ITEMS_NULL);
2659 requireNonNull(mapper, ERROR_MAPPER_NULL);
2660 requireNonNull(filter, ERROR_FILTER_NULL);
2661 return createDoubleBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2662 }
2663
2664 /**
2665 * Creates a double binding with the first element of an observable set after mapping and filtering.
2666 *
2667 * @param items the observable set of items.
2668 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2669 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2670 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2671 *
2672 * @return a double binding
2673 */
2674 @Nonnull
2675 public static <T> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Double> supplier, @Nonnull final Function<? super T, Double> mapper, @Nonnull final Predicate<Double> filter) {
2676 requireNonNull(items, ERROR_ITEMS_NULL);
2677 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2678 requireNonNull(mapper, ERROR_MAPPER_NULL);
2679 requireNonNull(filter, ERROR_FILTER_NULL);
2680 return createDoubleBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2681 }
2682
2683 /**
2684 * Creates a double binding with the first element of an observable set after mapping and filtering.
2685 *
2686 * @param items the observable set of items.
2687 * @param defaultValue the value to be returned if there is no value present.
2688 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2689 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2690 *
2691 * @return a double binding
2692 */
2693 @Nonnull
2694 public static <T> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Double defaultValue, @Nonnull final ObservableValue<Function<? super T, Double>> mapper, @Nonnull final ObservableValue<Predicate<Double>> filter) {
2695 requireNonNull(items, ERROR_ITEMS_NULL);
2696 requireNonNull(mapper, ERROR_MAPPER_NULL);
2697 requireNonNull(filter, ERROR_FILTER_NULL);
2698 return createDoubleBinding(() -> {
2699 Function<? super T, Double> mapperValue = mapper.getValue();
2700 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2701 Predicate<Double> filterValue = filter.getValue();
2702 requireNonNull(filterValue, ERROR_FILTER_NULL);
2703 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2704 }, items, mapper, filter);
2705 }
2706
2707 /**
2708 * Creates a double binding with the first element of an observable set after mapping and filtering.
2709 *
2710 * @param items the observable set of items.
2711 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2712 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2713 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2714 *
2715 * @return a double binding
2716 */
2717 @Nonnull
2718 public static <T> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Double> supplier, @Nonnull final ObservableValue<Function<? super T, Double>> mapper, @Nonnull final ObservableValue<Predicate<Double>> filter) {
2719 requireNonNull(items, ERROR_ITEMS_NULL);
2720 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2721 requireNonNull(mapper, ERROR_MAPPER_NULL);
2722 requireNonNull(filter, ERROR_FILTER_NULL);
2723 return createDoubleBinding(() -> {
2724 Function<? super T, Double> mapperValue = mapper.getValue();
2725 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2726 Predicate<Double> filterValue = filter.getValue();
2727 requireNonNull(filterValue, ERROR_FILTER_NULL);
2728 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2729 }, items, mapper, filter);
2730 }
2731
2732 /**
2733 * Creates a string binding with the first element of an observable set after mapping and filtering.
2734 *
2735 * @param items the observable set of items.
2736 * @param defaultValue the value to be returned if there is no value present.
2737 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2738 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2739 *
2740 * @return a string binding
2741 */
2742 @Nonnull
2743 public static <T> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final String defaultValue, @Nonnull final Function<? super T, String> mapper, @Nonnull final Predicate<String> filter) {
2744 requireNonNull(items, ERROR_ITEMS_NULL);
2745 requireNonNull(mapper, ERROR_MAPPER_NULL);
2746 requireNonNull(filter, ERROR_FILTER_NULL);
2747 return createStringBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2748 }
2749
2750 /**
2751 * Creates a string binding with the first element of an observable set after mapping and filtering.
2752 *
2753 * @param items the observable set of items.
2754 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2755 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2756 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2757 *
2758 * @return a string binding
2759 */
2760 @Nonnull
2761 public static <T> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<String> supplier, @Nonnull final Function<? super T, String> mapper, @Nonnull final Predicate<String> filter) {
2762 requireNonNull(items, ERROR_ITEMS_NULL);
2763 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2764 requireNonNull(mapper, ERROR_MAPPER_NULL);
2765 requireNonNull(filter, ERROR_FILTER_NULL);
2766 return createStringBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2767 }
2768
2769 /**
2770 * Creates a string binding with the first element of an observable set after mapping and filtering.
2771 *
2772 * @param items the observable set of items.
2773 * @param defaultValue the value to be returned if there is no value present.
2774 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2775 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2776 *
2777 * @return a string binding
2778 */
2779 @Nonnull
2780 public static <T> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final String defaultValue, @Nonnull final ObservableValue<Function<? super T, String>> mapper, @Nonnull final ObservableValue<Predicate<String>> filter) {
2781 requireNonNull(items, ERROR_ITEMS_NULL);
2782 requireNonNull(mapper, ERROR_MAPPER_NULL);
2783 requireNonNull(filter, ERROR_FILTER_NULL);
2784 return createStringBinding(() -> {
2785 Function<? super T, String> mapperValue = mapper.getValue();
2786 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2787 Predicate<String> filterValue = filter.getValue();
2788 requireNonNull(filterValue, ERROR_FILTER_NULL);
2789 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2790 }, items, mapper, filter);
2791 }
2792
2793 /**
2794 * Creates a string binding with the first element of an observable set after mapping and filtering.
2795 *
2796 * @param items the observable set of items.
2797 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2798 * @param mapper a non-interfering, stateless function to apply to the each element before filtering.
2799 * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping.
2800 *
2801 * @return a string binding
2802 */
2803 @Nonnull
2804 public static <T> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<String> supplier, @Nonnull final ObservableValue<Function<? super T, String>> mapper, @Nonnull final ObservableValue<Predicate<String>> filter) {
2805 requireNonNull(items, ERROR_ITEMS_NULL);
2806 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2807 requireNonNull(mapper, ERROR_MAPPER_NULL);
2808 requireNonNull(filter, ERROR_FILTER_NULL);
2809 return createStringBinding(() -> {
2810 Function<? super T, String> mapperValue = mapper.getValue();
2811 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2812 Predicate<String> filterValue = filter.getValue();
2813 requireNonNull(filterValue, ERROR_FILTER_NULL);
2814 return items.stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2815 }, items, mapper, filter);
2816 }
2817
2818 /**
2819 * Creates an object binding with the first value of an observable map after mapping and filtering.
2820 *
2821 * @param items the observable map of items.
2822 * @param defaultValue the value to be returned if there is no value present.
2823 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
2824 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
2825 *
2826 * @return an object binding
2827 */
2828 @Nonnull
2829 public static <K, V, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final R defaultValue, @Nonnull final Function<? super V, R> mapper, @Nonnull final Predicate<? super R> filter) {
2830 requireNonNull(items, ERROR_ITEMS_NULL);
2831 requireNonNull(mapper, ERROR_MAPPER_NULL);
2832 requireNonNull(filter, ERROR_FILTER_NULL);
2833 return createObjectBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2834 }
2835
2836 /**
2837 * Creates an object binding with the first value of an observable map after mapping and filtering.
2838 *
2839 * @param items the observable map of items.
2840 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2841 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
2842 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
2843 *
2844 * @return an object binding
2845 */
2846 @Nonnull
2847 public static <K, V, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<R> supplier, @Nonnull final Function<? super V, R> mapper, @Nonnull final Predicate<? super R> filter) {
2848 requireNonNull(items, ERROR_ITEMS_NULL);
2849 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2850 requireNonNull(mapper, ERROR_MAPPER_NULL);
2851 requireNonNull(filter, ERROR_FILTER_NULL);
2852 return createObjectBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2853 }
2854
2855 /**
2856 * Creates an object binding with the first value of an observable map after mapping and filtering.
2857 *
2858 * @param items the observable map of items.
2859 * @param defaultValue the value to be returned if there is no value present.
2860 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
2861 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
2862 *
2863 * @return an object binding
2864 */
2865 @Nonnull
2866 public static <K, V, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final R defaultValue, @Nonnull final ObservableValue<Function<? super V, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> filter) {
2867 requireNonNull(items, ERROR_ITEMS_NULL);
2868 requireNonNull(mapper, ERROR_MAPPER_NULL);
2869 requireNonNull(filter, ERROR_FILTER_NULL);
2870 return createObjectBinding(() -> {
2871 Function<? super V, R> mapperValue = mapper.getValue();
2872 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2873 Predicate<? super R> filterValue = filter.getValue();
2874 requireNonNull(filterValue, ERROR_FILTER_NULL);
2875 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2876 }, items, mapper, filter);
2877 }
2878
2879 /**
2880 * Creates an object binding with the first value of an observable map after mapping and filtering.
2881 *
2882 * @param items the observable map of items.
2883 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2884 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
2885 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
2886 *
2887 * @return an object binding
2888 */
2889 @Nonnull
2890 public static <K, V, R> ObjectBinding<R> mapThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<R> supplier, @Nonnull final ObservableValue<Function<? super V, R>> mapper, @Nonnull final ObservableValue<Predicate<? super R>> filter) {
2891 requireNonNull(items, ERROR_ITEMS_NULL);
2892 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2893 requireNonNull(mapper, ERROR_MAPPER_NULL);
2894 requireNonNull(filter, ERROR_FILTER_NULL);
2895 return createObjectBinding(() -> {
2896 Function<? super V, R> mapperValue = mapper.getValue();
2897 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2898 Predicate<? super R> filterValue = filter.getValue();
2899 requireNonNull(filterValue, ERROR_FILTER_NULL);
2900 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2901 }, items, mapper, filter);
2902 }
2903
2904 /**
2905 * Creates a boolean binding with the first value of an observable map after mapping and filtering.
2906 *
2907 * @param items the observable map of items.
2908 * @param defaultValue the value to be returned if there is no value present.
2909 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
2910 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
2911 *
2912 * @return a boolean binding
2913 */
2914 @Nonnull
2915 public static <K, V> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Boolean defaultValue, @Nonnull final Function<? super V, Boolean> mapper, @Nonnull final Predicate<Boolean> filter) {
2916 requireNonNull(items, ERROR_ITEMS_NULL);
2917 requireNonNull(mapper, ERROR_MAPPER_NULL);
2918 requireNonNull(filter, ERROR_FILTER_NULL);
2919 return createBooleanBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
2920 }
2921
2922 /**
2923 * Creates a boolean binding with the first value of an observable map after mapping and filtering.
2924 *
2925 * @param items the observable map of items.
2926 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2927 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
2928 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
2929 *
2930 * @return a boolean binding
2931 */
2932 @Nonnull
2933 public static <K, V> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final Function<? super V, Boolean> mapper, @Nonnull final Predicate<Boolean> filter) {
2934 requireNonNull(items, ERROR_ITEMS_NULL);
2935 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2936 requireNonNull(mapper, ERROR_MAPPER_NULL);
2937 requireNonNull(filter, ERROR_FILTER_NULL);
2938 return createBooleanBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
2939 }
2940
2941 /**
2942 * Creates a boolean binding with the first value of an observable map after mapping and filtering.
2943 *
2944 * @param items the observable map of items.
2945 * @param defaultValue the value to be returned if there is no value present.
2946 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
2947 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
2948 *
2949 * @return a boolean binding
2950 */
2951 @Nonnull
2952 public static <K, V> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Boolean defaultValue, @Nonnull final ObservableValue<Function<? super V, Boolean>> mapper, @Nonnull final ObservableValue<Predicate<Boolean>> filter) {
2953 requireNonNull(items, ERROR_ITEMS_NULL);
2954 requireNonNull(mapper, ERROR_MAPPER_NULL);
2955 requireNonNull(filter, ERROR_FILTER_NULL);
2956 return createBooleanBinding(() -> {
2957 Function<? super V, Boolean> mapperValue = mapper.getValue();
2958 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2959 Predicate<Boolean> filterValue = filter.getValue();
2960 requireNonNull(filterValue, ERROR_FILTER_NULL);
2961 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
2962 }, items, mapper, filter);
2963 }
2964
2965 /**
2966 * Creates a boolean binding with the first value of an observable map after mapping and filtering.
2967 *
2968 * @param items the observable map of items.
2969 * @param supplier a {@code Supplier} whose result is returned if no value is present.
2970 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
2971 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
2972 *
2973 * @return a boolean binding
2974 */
2975 @Nonnull
2976 public static <K, V> BooleanBinding mapToBooleanThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final ObservableValue<Function<? super V, Boolean>> mapper, @Nonnull final ObservableValue<Predicate<Boolean>> filter) {
2977 requireNonNull(items, ERROR_ITEMS_NULL);
2978 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
2979 requireNonNull(mapper, ERROR_MAPPER_NULL);
2980 requireNonNull(filter, ERROR_FILTER_NULL);
2981 return createBooleanBinding(() -> {
2982 Function<? super V, Boolean> mapperValue = mapper.getValue();
2983 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
2984 Predicate<Boolean> filterValue = filter.getValue();
2985 requireNonNull(filterValue, ERROR_FILTER_NULL);
2986 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
2987 }, items, mapper, filter);
2988 }
2989
2990 /**
2991 * Creates an integer binding with the first value of an observable map after mapping and filtering.
2992 *
2993 * @param items the observable map of items.
2994 * @param defaultValue the value to be returned if there is no value present.
2995 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
2996 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
2997 *
2998 * @return an integer binding
2999 */
3000 @Nonnull
3001 public static <K, V> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Integer defaultValue, @Nonnull final Function<? super V, Integer> mapper, @Nonnull final Predicate<Integer> filter) {
3002 requireNonNull(items, ERROR_ITEMS_NULL);
3003 requireNonNull(mapper, ERROR_MAPPER_NULL);
3004 requireNonNull(filter, ERROR_FILTER_NULL);
3005 return createIntegerBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
3006 }
3007
3008 /**
3009 * Creates an integer binding with the first value of an observable map after mapping and filtering.
3010 *
3011 * @param items the observable map of items.
3012 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3013 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3014 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3015 *
3016 * @return an integer binding
3017 */
3018 @Nonnull
3019 public static <K, V> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final Function<? super V, Integer> mapper, @Nonnull final Predicate<Integer> filter) {
3020 requireNonNull(items, ERROR_ITEMS_NULL);
3021 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3022 requireNonNull(mapper, ERROR_MAPPER_NULL);
3023 requireNonNull(filter, ERROR_FILTER_NULL);
3024 return createIntegerBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
3025 }
3026
3027 /**
3028 * Creates an integer binding with the first value of an observable map after mapping and filtering.
3029 *
3030 * @param items the observable map of items.
3031 * @param defaultValue the value to be returned if there is no value present.
3032 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3033 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3034 *
3035 * @return an integer binding
3036 */
3037 @Nonnull
3038 public static <K, V> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Integer defaultValue, @Nonnull final ObservableValue<Function<? super V, Integer>> mapper, @Nonnull final ObservableValue<Predicate<Integer>> filter) {
3039 requireNonNull(items, ERROR_ITEMS_NULL);
3040 requireNonNull(mapper, ERROR_MAPPER_NULL);
3041 requireNonNull(filter, ERROR_FILTER_NULL);
3042 return createIntegerBinding(() -> {
3043 Function<? super V, Integer> mapperValue = mapper.getValue();
3044 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3045 Predicate<Integer> filterValue = filter.getValue();
3046 requireNonNull(filterValue, ERROR_FILTER_NULL);
3047 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
3048 }, items, mapper, filter);
3049 }
3050
3051 /**
3052 * Creates an integer binding with the first value of an observable map after mapping and filtering.
3053 *
3054 * @param items the observable map of items.
3055 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3056 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3057 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3058 *
3059 * @return an integer binding
3060 */
3061 @Nonnull
3062 public static <K, V> IntegerBinding mapToIntegerThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final ObservableValue<Function<? super V, Integer>> mapper, @Nonnull final ObservableValue<Predicate<Integer>> filter) {
3063 requireNonNull(items, ERROR_ITEMS_NULL);
3064 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3065 requireNonNull(mapper, ERROR_MAPPER_NULL);
3066 requireNonNull(filter, ERROR_FILTER_NULL);
3067 return createIntegerBinding(() -> {
3068 Function<? super V, Integer> mapperValue = mapper.getValue();
3069 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3070 Predicate<Integer> filterValue = filter.getValue();
3071 requireNonNull(filterValue, ERROR_FILTER_NULL);
3072 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
3073 }, items, mapper, filter);
3074 }
3075
3076 /**
3077 * Creates a long binding with the first value of an observable map after mapping and filtering.
3078 *
3079 * @param items the observable map of items.
3080 * @param defaultValue the value to be returned if there is no value present.
3081 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3082 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3083 *
3084 * @return a long binding
3085 */
3086 @Nonnull
3087 public static <K, V> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Long defaultValue, @Nonnull final Function<? super V, Long> mapper, @Nonnull final Predicate<Long> filter) {
3088 requireNonNull(items, ERROR_ITEMS_NULL);
3089 requireNonNull(mapper, ERROR_MAPPER_NULL);
3090 requireNonNull(filter, ERROR_FILTER_NULL);
3091 return createLongBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
3092 }
3093
3094 /**
3095 * Creates a long binding with the first value of an observable map after mapping and filtering.
3096 *
3097 * @param items the observable map of items.
3098 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3099 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3100 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3101 *
3102 * @return a long binding
3103 */
3104 @Nonnull
3105 public static <K, V> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Function<? super V, Long> mapper, @Nonnull final Predicate<Long> filter) {
3106 requireNonNull(items, ERROR_ITEMS_NULL);
3107 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3108 requireNonNull(mapper, ERROR_MAPPER_NULL);
3109 requireNonNull(filter, ERROR_FILTER_NULL);
3110 return createLongBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
3111 }
3112
3113 /**
3114 * Creates a long binding with the first value of an observable map after mapping and filtering.
3115 *
3116 * @param items the observable map of items.
3117 * @param defaultValue the value to be returned if there is no value present.
3118 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3119 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3120 *
3121 * @return a long binding
3122 */
3123 @Nonnull
3124 public static <K, V> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Long defaultValue, @Nonnull final ObservableValue<Function<? super V, Long>> mapper, @Nonnull final ObservableValue<Predicate<Long>> filter) {
3125 requireNonNull(items, ERROR_ITEMS_NULL);
3126 requireNonNull(mapper, ERROR_MAPPER_NULL);
3127 requireNonNull(filter, ERROR_FILTER_NULL);
3128 return createLongBinding(() -> {
3129 Function<? super V, Long> mapperValue = mapper.getValue();
3130 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3131 Predicate<Long> filterValue = filter.getValue();
3132 requireNonNull(filterValue, ERROR_FILTER_NULL);
3133 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
3134 }, items, mapper, filter);
3135 }
3136
3137 /**
3138 * Creates a long binding with the first value of an observable map after mapping and filtering.
3139 *
3140 * @param items the observable map of items.
3141 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3142 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3143 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3144 *
3145 * @return a long binding
3146 */
3147 @Nonnull
3148 public static <K, V> LongBinding mapToLongThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Long> supplier, @Nonnull final ObservableValue<Function<? super V, Long>> mapper, @Nonnull final ObservableValue<Predicate<Long>> filter) {
3149 requireNonNull(items, ERROR_ITEMS_NULL);
3150 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3151 requireNonNull(mapper, ERROR_MAPPER_NULL);
3152 requireNonNull(filter, ERROR_FILTER_NULL);
3153 return createLongBinding(() -> {
3154 Function<? super V, Long> mapperValue = mapper.getValue();
3155 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3156 Predicate<Long> filterValue = filter.getValue();
3157 requireNonNull(filterValue, ERROR_FILTER_NULL);
3158 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
3159 }, items, mapper, filter);
3160 }
3161
3162 /**
3163 * Creates a float binding with the first value of an observable map after mapping and filtering.
3164 *
3165 * @param items the observable map of items.
3166 * @param defaultValue the value to be returned if there is no value present.
3167 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3168 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3169 *
3170 * @return a float binding
3171 */
3172 @Nonnull
3173 public static <K, V> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Float defaultValue, @Nonnull final Function<? super V, Float> mapper, @Nonnull final Predicate<Float> filter) {
3174 requireNonNull(items, ERROR_ITEMS_NULL);
3175 requireNonNull(mapper, ERROR_MAPPER_NULL);
3176 requireNonNull(filter, ERROR_FILTER_NULL);
3177 return createFloatBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
3178 }
3179
3180 /**
3181 * Creates a float binding with the first value of an observable map after mapping and filtering.
3182 *
3183 * @param items the observable map of items.
3184 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3185 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3186 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3187 *
3188 * @return a float binding
3189 */
3190 @Nonnull
3191 public static <K, V> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Float> supplier, @Nonnull final Function<? super V, Float> mapper, @Nonnull final Predicate<Float> filter) {
3192 requireNonNull(items, ERROR_ITEMS_NULL);
3193 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3194 requireNonNull(mapper, ERROR_MAPPER_NULL);
3195 requireNonNull(filter, ERROR_FILTER_NULL);
3196 return createFloatBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
3197 }
3198
3199 /**
3200 * Creates a float binding with the first value of an observable map after mapping and filtering.
3201 *
3202 * @param items the observable map of items.
3203 * @param defaultValue the value to be returned if there is no value present.
3204 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3205 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3206 *
3207 * @return a float binding
3208 */
3209 @Nonnull
3210 public static <K, V> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Float defaultValue, @Nonnull final ObservableValue<Function<? super V, Float>> mapper, @Nonnull final ObservableValue<Predicate<Float>> filter) {
3211 requireNonNull(items, ERROR_ITEMS_NULL);
3212 requireNonNull(mapper, ERROR_MAPPER_NULL);
3213 requireNonNull(filter, ERROR_FILTER_NULL);
3214 return createFloatBinding(() -> {
3215 Function<? super V, Float> mapperValue = mapper.getValue();
3216 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3217 Predicate<Float> filterValue = filter.getValue();
3218 requireNonNull(filterValue, ERROR_FILTER_NULL);
3219 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
3220 }, items, mapper, filter);
3221 }
3222
3223 /**
3224 * Creates a float binding with the first value of an observable map after mapping and filtering.
3225 *
3226 * @param items the observable map of items.
3227 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3228 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3229 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3230 *
3231 * @return a float binding
3232 */
3233 @Nonnull
3234 public static <K, V> FloatBinding mapToFloatThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Float> supplier, @Nonnull final ObservableValue<Function<? super V, Float>> mapper, @Nonnull final ObservableValue<Predicate<Float>> filter) {
3235 requireNonNull(items, ERROR_ITEMS_NULL);
3236 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3237 requireNonNull(mapper, ERROR_MAPPER_NULL);
3238 requireNonNull(filter, ERROR_FILTER_NULL);
3239 return createFloatBinding(() -> {
3240 Function<? super V, Float> mapperValue = mapper.getValue();
3241 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3242 Predicate<Float> filterValue = filter.getValue();
3243 requireNonNull(filterValue, ERROR_FILTER_NULL);
3244 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
3245 }, items, mapper, filter);
3246 }
3247
3248 /**
3249 * Creates a double binding with the first value of an observable map after mapping and filtering.
3250 *
3251 * @param items the observable map of items.
3252 * @param defaultValue the value to be returned if there is no value present.
3253 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3254 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3255 *
3256 * @return a double binding
3257 */
3258 @Nonnull
3259 public static <K, V> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Double defaultValue, @Nonnull final Function<? super V, Double> mapper, @Nonnull final Predicate<Double> filter) {
3260 requireNonNull(items, ERROR_ITEMS_NULL);
3261 requireNonNull(mapper, ERROR_MAPPER_NULL);
3262 requireNonNull(filter, ERROR_FILTER_NULL);
3263 return createDoubleBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
3264 }
3265
3266 /**
3267 * Creates a double binding with the first value of an observable map after mapping and filtering.
3268 *
3269 * @param items the observable map of items.
3270 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3271 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3272 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3273 *
3274 * @return a double binding
3275 */
3276 @Nonnull
3277 public static <K, V> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Double> supplier, @Nonnull final Function<? super V, Double> mapper, @Nonnull final Predicate<Double> filter) {
3278 requireNonNull(items, ERROR_ITEMS_NULL);
3279 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3280 requireNonNull(mapper, ERROR_MAPPER_NULL);
3281 requireNonNull(filter, ERROR_FILTER_NULL);
3282 return createDoubleBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
3283 }
3284
3285 /**
3286 * Creates a double binding with the first value of an observable map after mapping and filtering.
3287 *
3288 * @param items the observable map of items.
3289 * @param defaultValue the value to be returned if there is no value present.
3290 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3291 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3292 *
3293 * @return a double binding
3294 */
3295 @Nonnull
3296 public static <K, V> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Double defaultValue, @Nonnull final ObservableValue<Function<? super V, Double>> mapper, @Nonnull final ObservableValue<Predicate<Double>> filter) {
3297 requireNonNull(items, ERROR_ITEMS_NULL);
3298 requireNonNull(mapper, ERROR_MAPPER_NULL);
3299 requireNonNull(filter, ERROR_FILTER_NULL);
3300 return createDoubleBinding(() -> {
3301 Function<? super V, Double> mapperValue = mapper.getValue();
3302 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3303 Predicate<Double> filterValue = filter.getValue();
3304 requireNonNull(filterValue, ERROR_FILTER_NULL);
3305 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
3306 }, items, mapper, filter);
3307 }
3308
3309 /**
3310 * Creates a double binding with the first value of an observable map after mapping and filtering.
3311 *
3312 * @param items the observable map of items.
3313 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3314 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3315 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3316 *
3317 * @return a double binding
3318 */
3319 @Nonnull
3320 public static <K, V> DoubleBinding mapToDoubleThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Double> supplier, @Nonnull final ObservableValue<Function<? super V, Double>> mapper, @Nonnull final ObservableValue<Predicate<Double>> filter) {
3321 requireNonNull(items, ERROR_ITEMS_NULL);
3322 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3323 requireNonNull(mapper, ERROR_MAPPER_NULL);
3324 requireNonNull(filter, ERROR_FILTER_NULL);
3325 return createDoubleBinding(() -> {
3326 Function<? super V, Double> mapperValue = mapper.getValue();
3327 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3328 Predicate<Double> filterValue = filter.getValue();
3329 requireNonNull(filterValue, ERROR_FILTER_NULL);
3330 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
3331 }, items, mapper, filter);
3332 }
3333
3334 /**
3335 * Creates a string binding with the first value of an observable map after mapping and filtering.
3336 *
3337 * @param items the observable map of items.
3338 * @param defaultValue the value to be returned if there is no value present.
3339 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3340 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3341 *
3342 * @return a string binding
3343 */
3344 @Nonnull
3345 public static <K, V> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final String defaultValue, @Nonnull final Function<? super V, String> mapper, @Nonnull final Predicate<String> filter) {
3346 requireNonNull(items, ERROR_ITEMS_NULL);
3347 requireNonNull(mapper, ERROR_MAPPER_NULL);
3348 requireNonNull(filter, ERROR_FILTER_NULL);
3349 return createStringBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items);
3350 }
3351
3352 /**
3353 * Creates a string binding with the first value of an observable map after mapping and filtering.
3354 *
3355 * @param items the observable map of items.
3356 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3357 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3358 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3359 *
3360 * @return a string binding
3361 */
3362 @Nonnull
3363 public static <K, V> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<String> supplier, @Nonnull final Function<? super V, String> mapper, @Nonnull final Predicate<String> filter) {
3364 requireNonNull(items, ERROR_ITEMS_NULL);
3365 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3366 requireNonNull(mapper, ERROR_MAPPER_NULL);
3367 requireNonNull(filter, ERROR_FILTER_NULL);
3368 return createStringBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElseGet(supplier), items);
3369 }
3370
3371 /**
3372 * Creates a string binding with the first value of an observable map after mapping and filtering.
3373 *
3374 * @param items the observable map of items.
3375 * @param defaultValue the value to be returned if there is no value present.
3376 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3377 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3378 *
3379 * @return a string binding
3380 */
3381 @Nonnull
3382 public static <K, V> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final String defaultValue, @Nonnull final ObservableValue<Function<? super V, String>> mapper, @Nonnull final ObservableValue<Predicate<String>> filter) {
3383 requireNonNull(items, ERROR_ITEMS_NULL);
3384 requireNonNull(mapper, ERROR_MAPPER_NULL);
3385 requireNonNull(filter, ERROR_FILTER_NULL);
3386 return createStringBinding(() -> {
3387 Function<? super V, String> mapperValue = mapper.getValue();
3388 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3389 Predicate<String> filterValue = filter.getValue();
3390 requireNonNull(filterValue, ERROR_FILTER_NULL);
3391 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElse(defaultValue);
3392 }, items, mapper, filter);
3393 }
3394
3395 /**
3396 * Creates a string binding with the first value of an observable map after mapping and filtering.
3397 *
3398 * @param items the observable map of items.
3399 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3400 * @param mapper a non-interfering, stateless function to apply to the each value before filtering.
3401 * @param filter a non-interfering, stateless predicate to apply to the each value after mapping.
3402 *
3403 * @return a string binding
3404 */
3405 @Nonnull
3406 public static <K, V> StringBinding mapToStringThenFilterThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<String> supplier, @Nonnull final ObservableValue<Function<? super V, String>> mapper, @Nonnull final ObservableValue<Predicate<String>> filter) {
3407 requireNonNull(items, ERROR_ITEMS_NULL);
3408 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3409 requireNonNull(mapper, ERROR_MAPPER_NULL);
3410 requireNonNull(filter, ERROR_FILTER_NULL);
3411 return createStringBinding(() -> {
3412 Function<? super V, String> mapperValue = mapper.getValue();
3413 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3414 Predicate<String> filterValue = filter.getValue();
3415 requireNonNull(filterValue, ERROR_FILTER_NULL);
3416 return items.values().stream().map(mapperValue).filter(filterValue).findFirst().orElseGet(supplier);
3417 }, items, mapper, filter);
3418 }
3419
3420 /**
3421 * Creates an object binding with the first element of an observable list after filtering and mapping.
3422 *
3423 * @param items the observable list of items.
3424 * @param defaultValue the value to be returned if there is no value present.
3425 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3426 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3427 *
3428 * @return an object binding
3429 */
3430 @Nonnull
3431 public static <T, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final R defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, R> mapper) {
3432 requireNonNull(items, ERROR_ITEMS_NULL);
3433 requireNonNull(filter, ERROR_FILTER_NULL);
3434 requireNonNull(mapper, ERROR_MAPPER_NULL);
3435 return createObjectBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
3436 }
3437
3438 /**
3439 * Creates an object binding with the first element of an observable list after filtering and mapping.
3440 *
3441 * @param items the observable list of items.
3442 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3443 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3444 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3445 *
3446 * @return an object binding
3447 */
3448 @Nonnull
3449 public static <T, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<R> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, R> mapper) {
3450 requireNonNull(items, ERROR_ITEMS_NULL);
3451 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3452 requireNonNull(filter, ERROR_FILTER_NULL);
3453 requireNonNull(mapper, ERROR_MAPPER_NULL);
3454 return createObjectBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
3455 }
3456
3457 /**
3458 * Creates an object binding with the first element of an observable list after filtering and mapping.
3459 *
3460 * @param items the observable list of items.
3461 * @param defaultValue the value to be returned if there is no value present.
3462 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3463 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3464 *
3465 * @return an object binding
3466 */
3467 @Nonnull
3468 public static <T, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final R defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, R>> mapper) {
3469 requireNonNull(items, ERROR_ITEMS_NULL);
3470 requireNonNull(filter, ERROR_FILTER_NULL);
3471 requireNonNull(mapper, ERROR_MAPPER_NULL);
3472 return createObjectBinding(() -> {
3473 Function<? super T, R> mapperValue = mapper.getValue();
3474 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3475 Predicate<? super T> filterValue = filter.getValue();
3476 requireNonNull(filterValue, ERROR_FILTER_NULL);
3477 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
3478 }, items, mapper, filter);
3479 }
3480
3481 /**
3482 * Creates an object binding with the first element of an observable list after filtering and mapping.
3483 *
3484 * @param items the observable list of items.
3485 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3486 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3487 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3488 *
3489 * @return an object binding
3490 */
3491 @Nonnull
3492 public static <T, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<R> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, R>> mapper) {
3493 requireNonNull(items, ERROR_ITEMS_NULL);
3494 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3495 requireNonNull(filter, ERROR_FILTER_NULL);
3496 requireNonNull(mapper, ERROR_MAPPER_NULL);
3497 return createObjectBinding(() -> {
3498 Function<? super T, R> mapperValue = mapper.getValue();
3499 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3500 Predicate<? super T> filterValue = filter.getValue();
3501 requireNonNull(filterValue, ERROR_FILTER_NULL);
3502 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
3503 }, items, mapper, filter);
3504 }
3505
3506 /**
3507 * Creates a boolean binding with the first element of an observable list after filtering and mapping.
3508 *
3509 * @param items the observable list of items.
3510 * @param defaultValue the value to be returned if there is no value present.
3511 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3512 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3513 *
3514 * @return a boolean binding
3515 */
3516 @Nonnull
3517 public static <T> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Boolean defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Boolean> mapper) {
3518 requireNonNull(items, ERROR_ITEMS_NULL);
3519 requireNonNull(filter, ERROR_FILTER_NULL);
3520 requireNonNull(mapper, ERROR_MAPPER_NULL);
3521 return createBooleanBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
3522 }
3523
3524 /**
3525 * Creates a boolean binding with the first element of an observable list after filtering and mapping.
3526 *
3527 * @param items the observable list of items.
3528 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3529 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3530 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3531 *
3532 * @return a boolean binding
3533 */
3534 @Nonnull
3535 public static <T> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Boolean> mapper) {
3536 requireNonNull(items, ERROR_ITEMS_NULL);
3537 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3538 requireNonNull(filter, ERROR_FILTER_NULL);
3539 requireNonNull(mapper, ERROR_MAPPER_NULL);
3540 return createBooleanBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
3541 }
3542
3543 /**
3544 * Creates a boolean binding with the first element of an observable list after filtering and mapping.
3545 *
3546 * @param items the observable list of items.
3547 * @param defaultValue the value to be returned if there is no value present.
3548 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3549 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3550 *
3551 * @return a boolean binding
3552 */
3553 @Nonnull
3554 public static <T> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Boolean defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Boolean>> mapper) {
3555 requireNonNull(items, ERROR_ITEMS_NULL);
3556 requireNonNull(filter, ERROR_FILTER_NULL);
3557 requireNonNull(mapper, ERROR_MAPPER_NULL);
3558 return createBooleanBinding(() -> {
3559 Function<? super T, Boolean> mapperValue = mapper.getValue();
3560 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3561 Predicate<? super T> filterValue = filter.getValue();
3562 requireNonNull(filterValue, ERROR_FILTER_NULL);
3563 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
3564 }, items, mapper, filter);
3565 }
3566
3567 /**
3568 * Creates a boolean binding with the first element of an observable list after filtering and mapping.
3569 *
3570 * @param items the observable list of items.
3571 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3572 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3573 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3574 *
3575 * @return a boolean binding
3576 */
3577 @Nonnull
3578 public static <T> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Boolean>> mapper) {
3579 requireNonNull(items, ERROR_ITEMS_NULL);
3580 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3581 requireNonNull(filter, ERROR_FILTER_NULL);
3582 requireNonNull(mapper, ERROR_MAPPER_NULL);
3583 return createBooleanBinding(() -> {
3584 Function<? super T, Boolean> mapperValue = mapper.getValue();
3585 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3586 Predicate<? super T> filterValue = filter.getValue();
3587 requireNonNull(filterValue, ERROR_FILTER_NULL);
3588 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
3589 }, items, mapper, filter);
3590 }
3591
3592 /**
3593 * Creates an integer binding with the first element of an observable list after filtering and mapping.
3594 *
3595 * @param items the observable list of items.
3596 * @param defaultValue the value to be returned if there is no value present.
3597 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3598 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3599 *
3600 * @return an integer binding
3601 */
3602 @Nonnull
3603 public static <T> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Integer defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Integer> mapper) {
3604 requireNonNull(items, ERROR_ITEMS_NULL);
3605 requireNonNull(filter, ERROR_FILTER_NULL);
3606 requireNonNull(mapper, ERROR_MAPPER_NULL);
3607 return createIntegerBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
3608 }
3609
3610 /**
3611 * Creates an integer binding with the first element of an observable list after filtering and mapping.
3612 *
3613 * @param items the observable list of items.
3614 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3615 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3616 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3617 *
3618 * @return an integer binding
3619 */
3620 @Nonnull
3621 public static <T> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Integer> mapper) {
3622 requireNonNull(items, ERROR_ITEMS_NULL);
3623 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3624 requireNonNull(filter, ERROR_FILTER_NULL);
3625 requireNonNull(mapper, ERROR_MAPPER_NULL);
3626 return createIntegerBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
3627 }
3628
3629 /**
3630 * Creates an integer binding with the first element of an observable list after filtering and mapping.
3631 *
3632 * @param items the observable list of items.
3633 * @param defaultValue the value to be returned if there is no value present.
3634 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3635 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3636 *
3637 * @return an integer binding
3638 */
3639 @Nonnull
3640 public static <T> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Integer defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Integer>> mapper) {
3641 requireNonNull(items, ERROR_ITEMS_NULL);
3642 requireNonNull(filter, ERROR_FILTER_NULL);
3643 requireNonNull(mapper, ERROR_MAPPER_NULL);
3644 return createIntegerBinding(() -> {
3645 Function<? super T, Integer> mapperValue = mapper.getValue();
3646 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3647 Predicate<? super T> filterValue = filter.getValue();
3648 requireNonNull(filterValue, ERROR_FILTER_NULL);
3649 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
3650 }, items, mapper, filter);
3651 }
3652
3653 /**
3654 * Creates an integer binding with the first element of an observable list after filtering and mapping.
3655 *
3656 * @param items the observable list of items.
3657 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3658 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3659 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3660 *
3661 * @return an integer binding
3662 */
3663 @Nonnull
3664 public static <T> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Integer>> mapper) {
3665 requireNonNull(items, ERROR_ITEMS_NULL);
3666 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3667 requireNonNull(filter, ERROR_FILTER_NULL);
3668 requireNonNull(mapper, ERROR_MAPPER_NULL);
3669 return createIntegerBinding(() -> {
3670 Function<? super T, Integer> mapperValue = mapper.getValue();
3671 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3672 Predicate<? super T> filterValue = filter.getValue();
3673 requireNonNull(filterValue, ERROR_FILTER_NULL);
3674 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
3675 }, items, mapper, filter);
3676 }
3677
3678 /**
3679 * Creates a long binding with the first element of an observable list after filtering and mapping.
3680 *
3681 * @param items the observable list of items.
3682 * @param defaultValue the value to be returned if there is no value present.
3683 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3684 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3685 *
3686 * @return a long binding
3687 */
3688 @Nonnull
3689 public static <T> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Long defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Long> mapper) {
3690 requireNonNull(items, ERROR_ITEMS_NULL);
3691 requireNonNull(filter, ERROR_FILTER_NULL);
3692 requireNonNull(mapper, ERROR_MAPPER_NULL);
3693 return createLongBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
3694 }
3695
3696 /**
3697 * Creates a long binding with the first element of an observable list after filtering and mapping.
3698 *
3699 * @param items the observable list of items.
3700 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3701 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3702 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3703 *
3704 * @return a long binding
3705 */
3706 @Nonnull
3707 public static <T> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Long> mapper) {
3708 requireNonNull(items, ERROR_ITEMS_NULL);
3709 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3710 requireNonNull(filter, ERROR_FILTER_NULL);
3711 requireNonNull(mapper, ERROR_MAPPER_NULL);
3712 return createLongBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
3713 }
3714
3715 /**
3716 * Creates a long binding with the first element of an observable list after filtering and mapping.
3717 *
3718 * @param items the observable list of items.
3719 * @param defaultValue the value to be returned if there is no value present.
3720 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3721 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3722 *
3723 * @return a long binding
3724 */
3725 @Nonnull
3726 public static <T> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Long defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Long>> mapper) {
3727 requireNonNull(items, ERROR_ITEMS_NULL);
3728 requireNonNull(filter, ERROR_FILTER_NULL);
3729 requireNonNull(mapper, ERROR_MAPPER_NULL);
3730 return createLongBinding(() -> {
3731 Function<? super T, Long> mapperValue = mapper.getValue();
3732 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3733 Predicate<? super T> filterValue = filter.getValue();
3734 requireNonNull(filterValue, ERROR_FILTER_NULL);
3735 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
3736 }, items, mapper, filter);
3737 }
3738
3739 /**
3740 * Creates a long binding with the first element of an observable list after filtering and mapping.
3741 *
3742 * @param items the observable list of items.
3743 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3744 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3745 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3746 *
3747 * @return a long binding
3748 */
3749 @Nonnull
3750 public static <T> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Long> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Long>> mapper) {
3751 requireNonNull(items, ERROR_ITEMS_NULL);
3752 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3753 requireNonNull(filter, ERROR_FILTER_NULL);
3754 requireNonNull(mapper, ERROR_MAPPER_NULL);
3755 return createLongBinding(() -> {
3756 Function<? super T, Long> mapperValue = mapper.getValue();
3757 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3758 Predicate<? super T> filterValue = filter.getValue();
3759 requireNonNull(filterValue, ERROR_FILTER_NULL);
3760 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
3761 }, items, mapper, filter);
3762 }
3763
3764 /**
3765 * Creates a float binding with the first element of an observable list after filtering and mapping.
3766 *
3767 * @param items the observable list of items.
3768 * @param defaultValue the value to be returned if there is no value present.
3769 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3770 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3771 *
3772 * @return a float binding
3773 */
3774 @Nonnull
3775 public static <T> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Float defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Float> mapper) {
3776 requireNonNull(items, ERROR_ITEMS_NULL);
3777 requireNonNull(filter, ERROR_FILTER_NULL);
3778 requireNonNull(mapper, ERROR_MAPPER_NULL);
3779 return createFloatBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
3780 }
3781
3782 /**
3783 * Creates a float binding with the first element of an observable list after filtering and mapping.
3784 *
3785 * @param items the observable list of items.
3786 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3787 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3788 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3789 *
3790 * @return a float binding
3791 */
3792 @Nonnull
3793 public static <T> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Float> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Float> mapper) {
3794 requireNonNull(items, ERROR_ITEMS_NULL);
3795 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3796 requireNonNull(filter, ERROR_FILTER_NULL);
3797 requireNonNull(mapper, ERROR_MAPPER_NULL);
3798 return createFloatBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
3799 }
3800
3801 /**
3802 * Creates a float binding with the first element of an observable list after filtering and mapping.
3803 *
3804 * @param items the observable list of items.
3805 * @param defaultValue the value to be returned if there is no value present.
3806 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3807 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3808 *
3809 * @return a float binding
3810 */
3811 @Nonnull
3812 public static <T> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Float defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Float>> mapper) {
3813 requireNonNull(items, ERROR_ITEMS_NULL);
3814 requireNonNull(filter, ERROR_FILTER_NULL);
3815 requireNonNull(mapper, ERROR_MAPPER_NULL);
3816 return createFloatBinding(() -> {
3817 Function<? super T, Float> mapperValue = mapper.getValue();
3818 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3819 Predicate<? super T> filterValue = filter.getValue();
3820 requireNonNull(filterValue, ERROR_FILTER_NULL);
3821 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
3822 }, items, mapper, filter);
3823 }
3824
3825 /**
3826 * Creates a float binding with the first element of an observable list after filtering and mapping.
3827 *
3828 * @param items the observable list of items.
3829 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3830 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3831 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3832 *
3833 * @return a float binding
3834 */
3835 @Nonnull
3836 public static <T> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Float> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Float>> mapper) {
3837 requireNonNull(items, ERROR_ITEMS_NULL);
3838 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3839 requireNonNull(filter, ERROR_FILTER_NULL);
3840 requireNonNull(mapper, ERROR_MAPPER_NULL);
3841 return createFloatBinding(() -> {
3842 Function<? super T, Float> mapperValue = mapper.getValue();
3843 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3844 Predicate<? super T> filterValue = filter.getValue();
3845 requireNonNull(filterValue, ERROR_FILTER_NULL);
3846 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
3847 }, items, mapper, filter);
3848 }
3849
3850 /**
3851 * Creates a double binding with the first element of an observable list after filtering and mapping.
3852 *
3853 * @param items the observable list of items.
3854 * @param defaultValue the value to be returned if there is no value present.
3855 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3856 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3857 *
3858 * @return a double binding
3859 */
3860 @Nonnull
3861 public static <T> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Double defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Double> mapper) {
3862 requireNonNull(items, ERROR_ITEMS_NULL);
3863 requireNonNull(filter, ERROR_FILTER_NULL);
3864 requireNonNull(mapper, ERROR_MAPPER_NULL);
3865 return createDoubleBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
3866 }
3867
3868 /**
3869 * Creates a double binding with the first element of an observable list after filtering and mapping.
3870 *
3871 * @param items the observable list of items.
3872 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3873 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3874 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3875 *
3876 * @return a double binding
3877 */
3878 @Nonnull
3879 public static <T> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Double> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Double> mapper) {
3880 requireNonNull(items, ERROR_ITEMS_NULL);
3881 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3882 requireNonNull(filter, ERROR_FILTER_NULL);
3883 requireNonNull(mapper, ERROR_MAPPER_NULL);
3884 return createDoubleBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
3885 }
3886
3887 /**
3888 * Creates a double binding with the first element of an observable list after filtering and mapping.
3889 *
3890 * @param items the observable list of items.
3891 * @param defaultValue the value to be returned if there is no value present.
3892 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3893 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3894 *
3895 * @return a double binding
3896 */
3897 @Nonnull
3898 public static <T> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Double defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Double>> mapper) {
3899 requireNonNull(items, ERROR_ITEMS_NULL);
3900 requireNonNull(filter, ERROR_FILTER_NULL);
3901 requireNonNull(mapper, ERROR_MAPPER_NULL);
3902 return createDoubleBinding(() -> {
3903 Function<? super T, Double> mapperValue = mapper.getValue();
3904 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3905 Predicate<? super T> filterValue = filter.getValue();
3906 requireNonNull(filterValue, ERROR_FILTER_NULL);
3907 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
3908 }, items, mapper, filter);
3909 }
3910
3911 /**
3912 * Creates a double binding with the first element of an observable list after filtering and mapping.
3913 *
3914 * @param items the observable list of items.
3915 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3916 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3917 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3918 *
3919 * @return a double binding
3920 */
3921 @Nonnull
3922 public static <T> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Double> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Double>> mapper) {
3923 requireNonNull(items, ERROR_ITEMS_NULL);
3924 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3925 requireNonNull(filter, ERROR_FILTER_NULL);
3926 requireNonNull(mapper, ERROR_MAPPER_NULL);
3927 return createDoubleBinding(() -> {
3928 Function<? super T, Double> mapperValue = mapper.getValue();
3929 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3930 Predicate<? super T> filterValue = filter.getValue();
3931 requireNonNull(filterValue, ERROR_FILTER_NULL);
3932 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
3933 }, items, mapper, filter);
3934 }
3935
3936 /**
3937 * Creates a string binding with the first element of an observable list after filtering and mapping.
3938 *
3939 * @param items the observable list of items.
3940 * @param defaultValue the value to be returned if there is no value present.
3941 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3942 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3943 *
3944 * @return a string binding
3945 */
3946 @Nonnull
3947 public static <T> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final String defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, String> mapper) {
3948 requireNonNull(items, ERROR_ITEMS_NULL);
3949 requireNonNull(filter, ERROR_FILTER_NULL);
3950 requireNonNull(mapper, ERROR_MAPPER_NULL);
3951 return createStringBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
3952 }
3953
3954 /**
3955 * Creates a string binding with the first element of an observable list after filtering and mapping.
3956 *
3957 * @param items the observable list of items.
3958 * @param supplier a {@code Supplier} whose result is returned if no value is present.
3959 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3960 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3961 *
3962 * @return a string binding
3963 */
3964 @Nonnull
3965 public static <T> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<String> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, String> mapper) {
3966 requireNonNull(items, ERROR_ITEMS_NULL);
3967 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
3968 requireNonNull(filter, ERROR_FILTER_NULL);
3969 requireNonNull(mapper, ERROR_MAPPER_NULL);
3970 return createStringBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
3971 }
3972
3973 /**
3974 * Creates a string binding with the first element of an observable list after filtering and mapping.
3975 *
3976 * @param items the observable list of items.
3977 * @param defaultValue the value to be returned if there is no value present.
3978 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
3979 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
3980 *
3981 * @return a string binding
3982 */
3983 @Nonnull
3984 public static <T> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final String defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, String>> mapper) {
3985 requireNonNull(items, ERROR_ITEMS_NULL);
3986 requireNonNull(filter, ERROR_FILTER_NULL);
3987 requireNonNull(mapper, ERROR_MAPPER_NULL);
3988 return createStringBinding(() -> {
3989 Function<? super T, String> mapperValue = mapper.getValue();
3990 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
3991 Predicate<? super T> filterValue = filter.getValue();
3992 requireNonNull(filterValue, ERROR_FILTER_NULL);
3993 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
3994 }, items, mapper, filter);
3995 }
3996
3997 /**
3998 * Creates a string binding with the first element of an observable list after filtering and mapping.
3999 *
4000 * @param items the observable list of items.
4001 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4002 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4003 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4004 *
4005 * @return a string binding
4006 */
4007 @Nonnull
4008 public static <T> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<String> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, String>> mapper) {
4009 requireNonNull(items, ERROR_ITEMS_NULL);
4010 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4011 requireNonNull(filter, ERROR_FILTER_NULL);
4012 requireNonNull(mapper, ERROR_MAPPER_NULL);
4013 return createStringBinding(() -> {
4014 Function<? super T, String> mapperValue = mapper.getValue();
4015 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4016 Predicate<? super T> filterValue = filter.getValue();
4017 requireNonNull(filterValue, ERROR_FILTER_NULL);
4018 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4019 }, items, mapper, filter);
4020 }
4021
4022 /**
4023 * Creates an object binding with the first element of an observable set after filtering and mapping.
4024 *
4025 * @param items the observable set of items.
4026 * @param defaultValue the value to be returned if there is no value present.
4027 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4028 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4029 *
4030 * @return an object binding
4031 */
4032 @Nonnull
4033 public static <T, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final R defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, R> mapper) {
4034 requireNonNull(items, ERROR_ITEMS_NULL);
4035 requireNonNull(filter, ERROR_FILTER_NULL);
4036 requireNonNull(mapper, ERROR_MAPPER_NULL);
4037 return createObjectBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4038 }
4039
4040 /**
4041 * Creates an object binding with the first element of an observable set after filtering and mapping.
4042 *
4043 * @param items the observable set of items.
4044 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4045 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4046 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4047 *
4048 * @return an object binding
4049 */
4050 @Nonnull
4051 public static <T, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<R> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, R> mapper) {
4052 requireNonNull(items, ERROR_ITEMS_NULL);
4053 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4054 requireNonNull(filter, ERROR_FILTER_NULL);
4055 requireNonNull(mapper, ERROR_MAPPER_NULL);
4056 return createObjectBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4057 }
4058
4059 /**
4060 * Creates an object binding with the first element of an observable set after filtering and mapping.
4061 *
4062 * @param items the observable set of items.
4063 * @param defaultValue the value to be returned if there is no value present.
4064 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4065 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4066 *
4067 * @return an object binding
4068 */
4069 @Nonnull
4070 public static <T, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final R defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, R>> mapper) {
4071 requireNonNull(items, ERROR_ITEMS_NULL);
4072 requireNonNull(filter, ERROR_FILTER_NULL);
4073 requireNonNull(mapper, ERROR_MAPPER_NULL);
4074 return createObjectBinding(() -> {
4075 Function<? super T, R> mapperValue = mapper.getValue();
4076 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4077 Predicate<? super T> filterValue = filter.getValue();
4078 requireNonNull(filterValue, ERROR_FILTER_NULL);
4079 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4080 }, items, mapper, filter);
4081 }
4082
4083 /**
4084 * Creates an object binding with the first element of an observable set after filtering and mapping.
4085 *
4086 * @param items the observable set of items.
4087 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4088 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4089 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4090 *
4091 * @return an object binding
4092 */
4093 @Nonnull
4094 public static <T, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<R> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, R>> mapper) {
4095 requireNonNull(items, ERROR_ITEMS_NULL);
4096 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4097 requireNonNull(filter, ERROR_FILTER_NULL);
4098 requireNonNull(mapper, ERROR_MAPPER_NULL);
4099 return createObjectBinding(() -> {
4100 Function<? super T, R> mapperValue = mapper.getValue();
4101 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4102 Predicate<? super T> filterValue = filter.getValue();
4103 requireNonNull(filterValue, ERROR_FILTER_NULL);
4104 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4105 }, items, mapper, filter);
4106 }
4107
4108 /**
4109 * Creates a boolean binding with the first element of an observable set after filtering and mapping.
4110 *
4111 * @param items the observable set of items.
4112 * @param defaultValue the value to be returned if there is no value present.
4113 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4114 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4115 *
4116 * @return a boolean binding
4117 */
4118 @Nonnull
4119 public static <T> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Boolean defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Boolean> mapper) {
4120 requireNonNull(items, ERROR_ITEMS_NULL);
4121 requireNonNull(filter, ERROR_FILTER_NULL);
4122 requireNonNull(mapper, ERROR_MAPPER_NULL);
4123 return createBooleanBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4124 }
4125
4126 /**
4127 * Creates a boolean binding with the first element of an observable set after filtering and mapping.
4128 *
4129 * @param items the observable set of items.
4130 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4131 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4132 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4133 *
4134 * @return a boolean binding
4135 */
4136 @Nonnull
4137 public static <T> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Boolean> mapper) {
4138 requireNonNull(items, ERROR_ITEMS_NULL);
4139 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4140 requireNonNull(filter, ERROR_FILTER_NULL);
4141 requireNonNull(mapper, ERROR_MAPPER_NULL);
4142 return createBooleanBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4143 }
4144
4145 /**
4146 * Creates a boolean binding with the first element of an observable set after filtering and mapping.
4147 *
4148 * @param items the observable set of items.
4149 * @param defaultValue the value to be returned if there is no value present.
4150 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4151 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4152 *
4153 * @return a boolean binding
4154 */
4155 @Nonnull
4156 public static <T> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Boolean defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Boolean>> mapper) {
4157 requireNonNull(items, ERROR_ITEMS_NULL);
4158 requireNonNull(filter, ERROR_FILTER_NULL);
4159 requireNonNull(mapper, ERROR_MAPPER_NULL);
4160 return createBooleanBinding(() -> {
4161 Function<? super T, Boolean> mapperValue = mapper.getValue();
4162 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4163 Predicate<? super T> filterValue = filter.getValue();
4164 requireNonNull(filterValue, ERROR_FILTER_NULL);
4165 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4166 }, items, mapper, filter);
4167 }
4168
4169 /**
4170 * Creates a boolean binding with the first element of an observable set after filtering and mapping.
4171 *
4172 * @param items the observable set of items.
4173 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4174 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4175 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4176 *
4177 * @return a boolean binding
4178 */
4179 @Nonnull
4180 public static <T> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Boolean>> mapper) {
4181 requireNonNull(items, ERROR_ITEMS_NULL);
4182 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4183 requireNonNull(filter, ERROR_FILTER_NULL);
4184 requireNonNull(mapper, ERROR_MAPPER_NULL);
4185 return createBooleanBinding(() -> {
4186 Function<? super T, Boolean> mapperValue = mapper.getValue();
4187 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4188 Predicate<? super T> filterValue = filter.getValue();
4189 requireNonNull(filterValue, ERROR_FILTER_NULL);
4190 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4191 }, items, mapper, filter);
4192 }
4193
4194 /**
4195 * Creates an integer binding with the first element of an observable set after filtering and mapping.
4196 *
4197 * @param items the observable set of items.
4198 * @param defaultValue the value to be returned if there is no value present.
4199 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4200 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4201 *
4202 * @return an integer binding
4203 */
4204 @Nonnull
4205 public static <T> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Integer defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Integer> mapper) {
4206 requireNonNull(items, ERROR_ITEMS_NULL);
4207 requireNonNull(filter, ERROR_FILTER_NULL);
4208 requireNonNull(mapper, ERROR_MAPPER_NULL);
4209 return createIntegerBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4210 }
4211
4212 /**
4213 * Creates an integer binding with the first element of an observable set after filtering and mapping.
4214 *
4215 * @param items the observable set of items.
4216 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4217 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4218 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4219 *
4220 * @return an integer binding
4221 */
4222 @Nonnull
4223 public static <T> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Integer> mapper) {
4224 requireNonNull(items, ERROR_ITEMS_NULL);
4225 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4226 requireNonNull(filter, ERROR_FILTER_NULL);
4227 requireNonNull(mapper, ERROR_MAPPER_NULL);
4228 return createIntegerBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4229 }
4230
4231 /**
4232 * Creates an integer binding with the first element of an observable set after filtering and mapping.
4233 *
4234 * @param items the observable set of items.
4235 * @param defaultValue the value to be returned if there is no value present.
4236 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4237 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4238 *
4239 * @return an integer binding
4240 */
4241 @Nonnull
4242 public static <T> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Integer defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Integer>> mapper) {
4243 requireNonNull(items, ERROR_ITEMS_NULL);
4244 requireNonNull(filter, ERROR_FILTER_NULL);
4245 requireNonNull(mapper, ERROR_MAPPER_NULL);
4246 return createIntegerBinding(() -> {
4247 Function<? super T, Integer> mapperValue = mapper.getValue();
4248 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4249 Predicate<? super T> filterValue = filter.getValue();
4250 requireNonNull(filterValue, ERROR_FILTER_NULL);
4251 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4252 }, items, mapper, filter);
4253 }
4254
4255 /**
4256 * Creates an integer binding with the first element of an observable set after filtering and mapping.
4257 *
4258 * @param items the observable set of items.
4259 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4260 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4261 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4262 *
4263 * @return an integer binding
4264 */
4265 @Nonnull
4266 public static <T> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Integer>> mapper) {
4267 requireNonNull(items, ERROR_ITEMS_NULL);
4268 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4269 requireNonNull(filter, ERROR_FILTER_NULL);
4270 requireNonNull(mapper, ERROR_MAPPER_NULL);
4271 return createIntegerBinding(() -> {
4272 Function<? super T, Integer> mapperValue = mapper.getValue();
4273 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4274 Predicate<? super T> filterValue = filter.getValue();
4275 requireNonNull(filterValue, ERROR_FILTER_NULL);
4276 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4277 }, items, mapper, filter);
4278 }
4279
4280 /**
4281 * Creates a long binding with the first element of an observable set after filtering and mapping.
4282 *
4283 * @param items the observable set of items.
4284 * @param defaultValue the value to be returned if there is no value present.
4285 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4286 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4287 *
4288 * @return a long binding
4289 */
4290 @Nonnull
4291 public static <T> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Long defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Long> mapper) {
4292 requireNonNull(items, ERROR_ITEMS_NULL);
4293 requireNonNull(filter, ERROR_FILTER_NULL);
4294 requireNonNull(mapper, ERROR_MAPPER_NULL);
4295 return createLongBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4296 }
4297
4298 /**
4299 * Creates a long binding with the first element of an observable set after filtering and mapping.
4300 *
4301 * @param items the observable set of items.
4302 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4303 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4304 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4305 *
4306 * @return a long binding
4307 */
4308 @Nonnull
4309 public static <T> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Long> mapper) {
4310 requireNonNull(items, ERROR_ITEMS_NULL);
4311 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4312 requireNonNull(filter, ERROR_FILTER_NULL);
4313 requireNonNull(mapper, ERROR_MAPPER_NULL);
4314 return createLongBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4315 }
4316
4317 /**
4318 * Creates a long binding with the first element of an observable set after filtering and mapping.
4319 *
4320 * @param items the observable set of items.
4321 * @param defaultValue the value to be returned if there is no value present.
4322 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4323 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4324 *
4325 * @return a long binding
4326 */
4327 @Nonnull
4328 public static <T> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Long defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Long>> mapper) {
4329 requireNonNull(items, ERROR_ITEMS_NULL);
4330 requireNonNull(filter, ERROR_FILTER_NULL);
4331 requireNonNull(mapper, ERROR_MAPPER_NULL);
4332 return createLongBinding(() -> {
4333 Function<? super T, Long> mapperValue = mapper.getValue();
4334 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4335 Predicate<? super T> filterValue = filter.getValue();
4336 requireNonNull(filterValue, ERROR_FILTER_NULL);
4337 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4338 }, items, mapper, filter);
4339 }
4340
4341 /**
4342 * Creates a long binding with the first element of an observable set after filtering and mapping.
4343 *
4344 * @param items the observable set of items.
4345 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4346 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4347 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4348 *
4349 * @return a long binding
4350 */
4351 @Nonnull
4352 public static <T> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Long> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Long>> mapper) {
4353 requireNonNull(items, ERROR_ITEMS_NULL);
4354 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4355 requireNonNull(filter, ERROR_FILTER_NULL);
4356 requireNonNull(mapper, ERROR_MAPPER_NULL);
4357 return createLongBinding(() -> {
4358 Function<? super T, Long> mapperValue = mapper.getValue();
4359 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4360 Predicate<? super T> filterValue = filter.getValue();
4361 requireNonNull(filterValue, ERROR_FILTER_NULL);
4362 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4363 }, items, mapper, filter);
4364 }
4365
4366 /**
4367 * Creates a float binding with the first element of an observable set after filtering and mapping.
4368 *
4369 * @param items the observable set of items.
4370 * @param defaultValue the value to be returned if there is no value present.
4371 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4372 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4373 *
4374 * @return a float binding
4375 */
4376 @Nonnull
4377 public static <T> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Float defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Float> mapper) {
4378 requireNonNull(items, ERROR_ITEMS_NULL);
4379 requireNonNull(filter, ERROR_FILTER_NULL);
4380 requireNonNull(mapper, ERROR_MAPPER_NULL);
4381 return createFloatBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4382 }
4383
4384 /**
4385 * Creates a float binding with the first element of an observable set after filtering and mapping.
4386 *
4387 * @param items the observable set of items.
4388 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4389 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4390 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4391 *
4392 * @return a float binding
4393 */
4394 @Nonnull
4395 public static <T> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Float> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Float> mapper) {
4396 requireNonNull(items, ERROR_ITEMS_NULL);
4397 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4398 requireNonNull(filter, ERROR_FILTER_NULL);
4399 requireNonNull(mapper, ERROR_MAPPER_NULL);
4400 return createFloatBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4401 }
4402
4403 /**
4404 * Creates a float binding with the first element of an observable set after filtering and mapping.
4405 *
4406 * @param items the observable set of items.
4407 * @param defaultValue the value to be returned if there is no value present.
4408 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4409 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4410 *
4411 * @return a float binding
4412 */
4413 @Nonnull
4414 public static <T> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Float defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Float>> mapper) {
4415 requireNonNull(items, ERROR_ITEMS_NULL);
4416 requireNonNull(filter, ERROR_FILTER_NULL);
4417 requireNonNull(mapper, ERROR_MAPPER_NULL);
4418 return createFloatBinding(() -> {
4419 Function<? super T, Float> mapperValue = mapper.getValue();
4420 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4421 Predicate<? super T> filterValue = filter.getValue();
4422 requireNonNull(filterValue, ERROR_FILTER_NULL);
4423 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4424 }, items, mapper, filter);
4425 }
4426
4427 /**
4428 * Creates a float binding with the first element of an observable set after filtering and mapping.
4429 *
4430 * @param items the observable set of items.
4431 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4432 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4433 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4434 *
4435 * @return a float binding
4436 */
4437 @Nonnull
4438 public static <T> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Float> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Float>> mapper) {
4439 requireNonNull(items, ERROR_ITEMS_NULL);
4440 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4441 requireNonNull(filter, ERROR_FILTER_NULL);
4442 requireNonNull(mapper, ERROR_MAPPER_NULL);
4443 return createFloatBinding(() -> {
4444 Function<? super T, Float> mapperValue = mapper.getValue();
4445 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4446 Predicate<? super T> filterValue = filter.getValue();
4447 requireNonNull(filterValue, ERROR_FILTER_NULL);
4448 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4449 }, items, mapper, filter);
4450 }
4451
4452 /**
4453 * Creates a double binding with the first element of an observable set after filtering and mapping.
4454 *
4455 * @param items the observable set of items.
4456 * @param defaultValue the value to be returned if there is no value present.
4457 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4458 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4459 *
4460 * @return a double binding
4461 */
4462 @Nonnull
4463 public static <T> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Double defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Double> mapper) {
4464 requireNonNull(items, ERROR_ITEMS_NULL);
4465 requireNonNull(filter, ERROR_FILTER_NULL);
4466 requireNonNull(mapper, ERROR_MAPPER_NULL);
4467 return createDoubleBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4468 }
4469
4470 /**
4471 * Creates a double binding with the first element of an observable set after filtering and mapping.
4472 *
4473 * @param items the observable set of items.
4474 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4475 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4476 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4477 *
4478 * @return a double binding
4479 */
4480 @Nonnull
4481 public static <T> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Double> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, Double> mapper) {
4482 requireNonNull(items, ERROR_ITEMS_NULL);
4483 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4484 requireNonNull(filter, ERROR_FILTER_NULL);
4485 requireNonNull(mapper, ERROR_MAPPER_NULL);
4486 return createDoubleBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4487 }
4488
4489 /**
4490 * Creates a double binding with the first element of an observable set after filtering and mapping.
4491 *
4492 * @param items the observable set of items.
4493 * @param defaultValue the value to be returned if there is no value present.
4494 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4495 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4496 *
4497 * @return a double binding
4498 */
4499 @Nonnull
4500 public static <T> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Double defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Double>> mapper) {
4501 requireNonNull(items, ERROR_ITEMS_NULL);
4502 requireNonNull(filter, ERROR_FILTER_NULL);
4503 requireNonNull(mapper, ERROR_MAPPER_NULL);
4504 return createDoubleBinding(() -> {
4505 Function<? super T, Double> mapperValue = mapper.getValue();
4506 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4507 Predicate<? super T> filterValue = filter.getValue();
4508 requireNonNull(filterValue, ERROR_FILTER_NULL);
4509 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4510 }, items, mapper, filter);
4511 }
4512
4513 /**
4514 * Creates a double binding with the first element of an observable set after filtering and mapping.
4515 *
4516 * @param items the observable set of items.
4517 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4518 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4519 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4520 *
4521 * @return a double binding
4522 */
4523 @Nonnull
4524 public static <T> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<Double> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, Double>> mapper) {
4525 requireNonNull(items, ERROR_ITEMS_NULL);
4526 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4527 requireNonNull(filter, ERROR_FILTER_NULL);
4528 requireNonNull(mapper, ERROR_MAPPER_NULL);
4529 return createDoubleBinding(() -> {
4530 Function<? super T, Double> mapperValue = mapper.getValue();
4531 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4532 Predicate<? super T> filterValue = filter.getValue();
4533 requireNonNull(filterValue, ERROR_FILTER_NULL);
4534 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4535 }, items, mapper, filter);
4536 }
4537
4538 /**
4539 * Creates a string binding with the first element of an observable set after filtering and mapping.
4540 *
4541 * @param items the observable set of items.
4542 * @param defaultValue the value to be returned if there is no value present.
4543 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4544 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4545 *
4546 * @return a string binding
4547 */
4548 @Nonnull
4549 public static <T> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final String defaultValue, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, String> mapper) {
4550 requireNonNull(items, ERROR_ITEMS_NULL);
4551 requireNonNull(filter, ERROR_FILTER_NULL);
4552 requireNonNull(mapper, ERROR_MAPPER_NULL);
4553 return createStringBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4554 }
4555
4556 /**
4557 * Creates a string binding with the first element of an observable set after filtering and mapping.
4558 *
4559 * @param items the observable set of items.
4560 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4561 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4562 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4563 *
4564 * @return a string binding
4565 */
4566 @Nonnull
4567 public static <T> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<String> supplier, @Nonnull final Predicate<? super T> filter, @Nonnull final Function<? super T, String> mapper) {
4568 requireNonNull(items, ERROR_ITEMS_NULL);
4569 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4570 requireNonNull(filter, ERROR_FILTER_NULL);
4571 requireNonNull(mapper, ERROR_MAPPER_NULL);
4572 return createStringBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4573 }
4574
4575 /**
4576 * Creates a string binding with the first element of an observable set after filtering and mapping.
4577 *
4578 * @param items the observable set of items.
4579 * @param defaultValue the value to be returned if there is no value present.
4580 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4581 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4582 *
4583 * @return a string binding
4584 */
4585 @Nonnull
4586 public static <T> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final String defaultValue, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, String>> mapper) {
4587 requireNonNull(items, ERROR_ITEMS_NULL);
4588 requireNonNull(filter, ERROR_FILTER_NULL);
4589 requireNonNull(mapper, ERROR_MAPPER_NULL);
4590 return createStringBinding(() -> {
4591 Function<? super T, String> mapperValue = mapper.getValue();
4592 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4593 Predicate<? super T> filterValue = filter.getValue();
4594 requireNonNull(filterValue, ERROR_FILTER_NULL);
4595 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4596 }, items, mapper, filter);
4597 }
4598
4599 /**
4600 * Creates a string binding with the first element of an observable set after filtering and mapping.
4601 *
4602 * @param items the observable set of items.
4603 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4604 * @param filter a non-interfering, stateless predicate to apply to the each element. before mapping.
4605 * @param mapper a non-interfering, stateless function to apply to the each element after filtering.
4606 *
4607 * @return a string binding
4608 */
4609 @Nonnull
4610 public static <T> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableSet<T> items, @Nonnull final Supplier<String> supplier, @Nonnull final ObservableValue<Predicate<? super T>> filter, @Nonnull final ObservableValue<Function<? super T, String>> mapper) {
4611 requireNonNull(items, ERROR_ITEMS_NULL);
4612 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4613 requireNonNull(filter, ERROR_FILTER_NULL);
4614 requireNonNull(mapper, ERROR_MAPPER_NULL);
4615 return createStringBinding(() -> {
4616 Function<? super T, String> mapperValue = mapper.getValue();
4617 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4618 Predicate<? super T> filterValue = filter.getValue();
4619 requireNonNull(filterValue, ERROR_FILTER_NULL);
4620 return items.stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4621 }, items, mapper, filter);
4622 }
4623
4624 /**
4625 * Creates an object binding with the first value of an observable map after filtering and mapping.
4626 *
4627 * @param items the observable map of items.
4628 * @param defaultValue the value to be returned if there is no value present.
4629 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4630 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4631 *
4632 * @return an object binding
4633 */
4634 @Nonnull
4635 public static <K, V, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final R defaultValue, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, R> mapper) {
4636 requireNonNull(items, ERROR_ITEMS_NULL);
4637 requireNonNull(filter, ERROR_FILTER_NULL);
4638 requireNonNull(mapper, ERROR_MAPPER_NULL);
4639 return createObjectBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4640 }
4641
4642 /**
4643 * Creates an object binding with the first value of an observable map after filtering and mapping.
4644 *
4645 * @param items the observable map of items.
4646 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4647 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4648 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4649 *
4650 * @return an object binding
4651 */
4652 @Nonnull
4653 public static <K, V, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<R> supplier, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, R> mapper) {
4654 requireNonNull(items, ERROR_ITEMS_NULL);
4655 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4656 requireNonNull(filter, ERROR_FILTER_NULL);
4657 requireNonNull(mapper, ERROR_MAPPER_NULL);
4658 return createObjectBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4659 }
4660
4661 /**
4662 * Creates an object binding with the first value of an observable map after filtering and mapping.
4663 *
4664 * @param items the observable map of items.
4665 * @param defaultValue the value to be returned if there is no value present.
4666 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4667 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4668 *
4669 * @return an object binding
4670 */
4671 @Nonnull
4672 public static <K, V, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final R defaultValue, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, R>> mapper) {
4673 requireNonNull(items, ERROR_ITEMS_NULL);
4674 requireNonNull(filter, ERROR_FILTER_NULL);
4675 requireNonNull(mapper, ERROR_MAPPER_NULL);
4676 return createObjectBinding(() -> {
4677 Function<? super V, R> mapperValue = mapper.getValue();
4678 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4679 Predicate<? super V> filterValue = filter.getValue();
4680 requireNonNull(filterValue, ERROR_FILTER_NULL);
4681 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4682 }, items, mapper, filter);
4683 }
4684
4685 /**
4686 * Creates an object binding with the first value of an observable map after filtering and mapping.
4687 *
4688 * @param items the observable map of items.
4689 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4690 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4691 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4692 *
4693 * @return an object binding
4694 */
4695 @Nonnull
4696 public static <K, V, R> ObjectBinding<R> filterThenMapThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<R> supplier, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, R>> mapper) {
4697 requireNonNull(items, ERROR_ITEMS_NULL);
4698 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4699 requireNonNull(filter, ERROR_FILTER_NULL);
4700 requireNonNull(mapper, ERROR_MAPPER_NULL);
4701 return createObjectBinding(() -> {
4702 Function<? super V, R> mapperValue = mapper.getValue();
4703 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4704 Predicate<? super V> filterValue = filter.getValue();
4705 requireNonNull(filterValue, ERROR_FILTER_NULL);
4706 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4707 }, items, mapper, filter);
4708 }
4709
4710 /**
4711 * Creates a boolean binding with the first value of an observable map after filtering and mapping.
4712 *
4713 * @param items the observable map of items.
4714 * @param defaultValue the value to be returned if there is no value present.
4715 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4716 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4717 *
4718 * @return a boolean binding
4719 */
4720 @Nonnull
4721 public static <K, V> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Boolean defaultValue, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, Boolean> mapper) {
4722 requireNonNull(items, ERROR_ITEMS_NULL);
4723 requireNonNull(filter, ERROR_FILTER_NULL);
4724 requireNonNull(mapper, ERROR_MAPPER_NULL);
4725 return createBooleanBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4726 }
4727
4728 /**
4729 * Creates a boolean binding with the first value of an observable map after filtering and mapping.
4730 *
4731 * @param items the observable map of items.
4732 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4733 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4734 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4735 *
4736 * @return a boolean binding
4737 */
4738 @Nonnull
4739 public static <K, V> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, Boolean> mapper) {
4740 requireNonNull(items, ERROR_ITEMS_NULL);
4741 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4742 requireNonNull(filter, ERROR_FILTER_NULL);
4743 requireNonNull(mapper, ERROR_MAPPER_NULL);
4744 return createBooleanBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4745 }
4746
4747 /**
4748 * Creates a boolean binding with the first value of an observable map after filtering and mapping.
4749 *
4750 * @param items the observable map of items.
4751 * @param defaultValue the value to be returned if there is no value present.
4752 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4753 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4754 *
4755 * @return a boolean binding
4756 */
4757 @Nonnull
4758 public static <K, V> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Boolean defaultValue, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, Boolean>> mapper) {
4759 requireNonNull(items, ERROR_ITEMS_NULL);
4760 requireNonNull(filter, ERROR_FILTER_NULL);
4761 requireNonNull(mapper, ERROR_MAPPER_NULL);
4762 return createBooleanBinding(() -> {
4763 Function<? super V, Boolean> mapperValue = mapper.getValue();
4764 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4765 Predicate<? super V> filterValue = filter.getValue();
4766 requireNonNull(filterValue, ERROR_FILTER_NULL);
4767 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4768 }, items, mapper, filter);
4769 }
4770
4771 /**
4772 * Creates a boolean binding with the first value of an observable map after filtering and mapping.
4773 *
4774 * @param items the observable map of items.
4775 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4776 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4777 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4778 *
4779 * @return a boolean binding
4780 */
4781 @Nonnull
4782 public static <K, V> BooleanBinding filterThenMapToBooleanThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Boolean> supplier, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, Boolean>> mapper) {
4783 requireNonNull(items, ERROR_ITEMS_NULL);
4784 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4785 requireNonNull(filter, ERROR_FILTER_NULL);
4786 requireNonNull(mapper, ERROR_MAPPER_NULL);
4787 return createBooleanBinding(() -> {
4788 Function<? super V, Boolean> mapperValue = mapper.getValue();
4789 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4790 Predicate<? super V> filterValue = filter.getValue();
4791 requireNonNull(filterValue, ERROR_FILTER_NULL);
4792 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4793 }, items, mapper, filter);
4794 }
4795
4796 /**
4797 * Creates an integer binding with the first value of an observable map after filtering and mapping.
4798 *
4799 * @param items the observable map of items.
4800 * @param defaultValue the value to be returned if there is no value present.
4801 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4802 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4803 *
4804 * @return an integer binding
4805 */
4806 @Nonnull
4807 public static <K, V> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Integer defaultValue, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, Integer> mapper) {
4808 requireNonNull(items, ERROR_ITEMS_NULL);
4809 requireNonNull(filter, ERROR_FILTER_NULL);
4810 requireNonNull(mapper, ERROR_MAPPER_NULL);
4811 return createIntegerBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4812 }
4813
4814 /**
4815 * Creates an integer binding with the first value of an observable map after filtering and mapping.
4816 *
4817 * @param items the observable map of items.
4818 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4819 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4820 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4821 *
4822 * @return an integer binding
4823 */
4824 @Nonnull
4825 public static <K, V> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, Integer> mapper) {
4826 requireNonNull(items, ERROR_ITEMS_NULL);
4827 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4828 requireNonNull(filter, ERROR_FILTER_NULL);
4829 requireNonNull(mapper, ERROR_MAPPER_NULL);
4830 return createIntegerBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4831 }
4832
4833 /**
4834 * Creates an integer binding with the first value of an observable map after filtering and mapping.
4835 *
4836 * @param items the observable map of items.
4837 * @param defaultValue the value to be returned if there is no value present.
4838 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4839 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4840 *
4841 * @return an integer binding
4842 */
4843 @Nonnull
4844 public static <K, V> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Integer defaultValue, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, Integer>> mapper) {
4845 requireNonNull(items, ERROR_ITEMS_NULL);
4846 requireNonNull(filter, ERROR_FILTER_NULL);
4847 requireNonNull(mapper, ERROR_MAPPER_NULL);
4848 return createIntegerBinding(() -> {
4849 Function<? super V, Integer> mapperValue = mapper.getValue();
4850 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4851 Predicate<? super V> filterValue = filter.getValue();
4852 requireNonNull(filterValue, ERROR_FILTER_NULL);
4853 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4854 }, items, mapper, filter);
4855 }
4856
4857 /**
4858 * Creates an integer binding with the first value of an observable map after filtering and mapping.
4859 *
4860 * @param items the observable map of items.
4861 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4862 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4863 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4864 *
4865 * @return an integer binding
4866 */
4867 @Nonnull
4868 public static <K, V> IntegerBinding filterThenMapToIntegerThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Integer> supplier, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, Integer>> mapper) {
4869 requireNonNull(items, ERROR_ITEMS_NULL);
4870 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4871 requireNonNull(filter, ERROR_FILTER_NULL);
4872 requireNonNull(mapper, ERROR_MAPPER_NULL);
4873 return createIntegerBinding(() -> {
4874 Function<? super V, Integer> mapperValue = mapper.getValue();
4875 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4876 Predicate<? super V> filterValue = filter.getValue();
4877 requireNonNull(filterValue, ERROR_FILTER_NULL);
4878 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4879 }, items, mapper, filter);
4880 }
4881
4882 /**
4883 * Creates a long binding with the first value of an observable map after filtering and mapping.
4884 *
4885 * @param items the observable map of items.
4886 * @param defaultValue the value to be returned if there is no value present.
4887 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4888 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4889 *
4890 * @return a long binding
4891 */
4892 @Nonnull
4893 public static <K, V> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Long defaultValue, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, Long> mapper) {
4894 requireNonNull(items, ERROR_ITEMS_NULL);
4895 requireNonNull(filter, ERROR_FILTER_NULL);
4896 requireNonNull(mapper, ERROR_MAPPER_NULL);
4897 return createLongBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4898 }
4899
4900 /**
4901 * Creates a long binding with the first value of an observable map after filtering and mapping.
4902 *
4903 * @param items the observable map of items.
4904 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4905 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4906 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4907 *
4908 * @return a long binding
4909 */
4910 @Nonnull
4911 public static <K, V> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, Long> mapper) {
4912 requireNonNull(items, ERROR_ITEMS_NULL);
4913 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4914 requireNonNull(filter, ERROR_FILTER_NULL);
4915 requireNonNull(mapper, ERROR_MAPPER_NULL);
4916 return createLongBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
4917 }
4918
4919 /**
4920 * Creates a long binding with the first value of an observable map after filtering and mapping.
4921 *
4922 * @param items the observable map of items.
4923 * @param defaultValue the value to be returned if there is no value present.
4924 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4925 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4926 *
4927 * @return a long binding
4928 */
4929 @Nonnull
4930 public static <K, V> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Long defaultValue, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, Long>> mapper) {
4931 requireNonNull(items, ERROR_ITEMS_NULL);
4932 requireNonNull(filter, ERROR_FILTER_NULL);
4933 requireNonNull(mapper, ERROR_MAPPER_NULL);
4934 return createLongBinding(() -> {
4935 Function<? super V, Long> mapperValue = mapper.getValue();
4936 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4937 Predicate<? super V> filterValue = filter.getValue();
4938 requireNonNull(filterValue, ERROR_FILTER_NULL);
4939 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
4940 }, items, mapper, filter);
4941 }
4942
4943 /**
4944 * Creates a long binding with the first value of an observable map after filtering and mapping.
4945 *
4946 * @param items the observable map of items.
4947 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4948 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4949 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4950 *
4951 * @return a long binding
4952 */
4953 @Nonnull
4954 public static <K, V> LongBinding filterThenMapToLongThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Long> supplier, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, Long>> mapper) {
4955 requireNonNull(items, ERROR_ITEMS_NULL);
4956 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
4957 requireNonNull(filter, ERROR_FILTER_NULL);
4958 requireNonNull(mapper, ERROR_MAPPER_NULL);
4959 return createLongBinding(() -> {
4960 Function<? super V, Long> mapperValue = mapper.getValue();
4961 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
4962 Predicate<? super V> filterValue = filter.getValue();
4963 requireNonNull(filterValue, ERROR_FILTER_NULL);
4964 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
4965 }, items, mapper, filter);
4966 }
4967
4968 /**
4969 * Creates a float binding with the first value of an observable map after filtering and mapping.
4970 *
4971 * @param items the observable map of items.
4972 * @param defaultValue the value to be returned if there is no value present.
4973 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4974 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4975 *
4976 * @return a float binding
4977 */
4978 @Nonnull
4979 public static <K, V> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Float defaultValue, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, Float> mapper) {
4980 requireNonNull(items, ERROR_ITEMS_NULL);
4981 requireNonNull(filter, ERROR_FILTER_NULL);
4982 requireNonNull(mapper, ERROR_MAPPER_NULL);
4983 return createFloatBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
4984 }
4985
4986 /**
4987 * Creates a float binding with the first value of an observable map after filtering and mapping.
4988 *
4989 * @param items the observable map of items.
4990 * @param supplier a {@code Supplier} whose result is returned if no value is present.
4991 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
4992 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
4993 *
4994 * @return a float binding
4995 */
4996 @Nonnull
4997 public static <K, V> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Float> supplier, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, Float> mapper) {
4998 requireNonNull(items, ERROR_ITEMS_NULL);
4999 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
5000 requireNonNull(filter, ERROR_FILTER_NULL);
5001 requireNonNull(mapper, ERROR_MAPPER_NULL);
5002 return createFloatBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
5003 }
5004
5005 /**
5006 * Creates a float binding with the first value of an observable map after filtering and mapping.
5007 *
5008 * @param items the observable map of items.
5009 * @param defaultValue the value to be returned if there is no value present.
5010 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
5011 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
5012 *
5013 * @return a float binding
5014 */
5015 @Nonnull
5016 public static <K, V> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Float defaultValue, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, Float>> mapper) {
5017 requireNonNull(items, ERROR_ITEMS_NULL);
5018 requireNonNull(filter, ERROR_FILTER_NULL);
5019 requireNonNull(mapper, ERROR_MAPPER_NULL);
5020 return createFloatBinding(() -> {
5021 Function<? super V, Float> mapperValue = mapper.getValue();
5022 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
5023 Predicate<? super V> filterValue = filter.getValue();
5024 requireNonNull(filterValue, ERROR_FILTER_NULL);
5025 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
5026 }, items, mapper, filter);
5027 }
5028
5029 /**
5030 * Creates a float binding with the first value of an observable map after filtering and mapping.
5031 *
5032 * @param items the observable map of items.
5033 * @param supplier a {@code Supplier} whose result is returned if no value is present.
5034 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
5035 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
5036 *
5037 * @return a float binding
5038 */
5039 @Nonnull
5040 public static <K, V> FloatBinding filterThenMapToFloatThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Float> supplier, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, Float>> mapper) {
5041 requireNonNull(items, ERROR_ITEMS_NULL);
5042 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
5043 requireNonNull(filter, ERROR_FILTER_NULL);
5044 requireNonNull(mapper, ERROR_MAPPER_NULL);
5045 return createFloatBinding(() -> {
5046 Function<? super V, Float> mapperValue = mapper.getValue();
5047 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
5048 Predicate<? super V> filterValue = filter.getValue();
5049 requireNonNull(filterValue, ERROR_FILTER_NULL);
5050 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
5051 }, items, mapper, filter);
5052 }
5053
5054 /**
5055 * Creates a double binding with the first value of an observable map after filtering and mapping.
5056 *
5057 * @param items the observable map of items.
5058 * @param defaultValue the value to be returned if there is no value present.
5059 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
5060 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
5061 *
5062 * @return a double binding
5063 */
5064 @Nonnull
5065 public static <K, V> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Double defaultValue, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, Double> mapper) {
5066 requireNonNull(items, ERROR_ITEMS_NULL);
5067 requireNonNull(filter, ERROR_FILTER_NULL);
5068 requireNonNull(mapper, ERROR_MAPPER_NULL);
5069 return createDoubleBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
5070 }
5071
5072 /**
5073 * Creates a double binding with the first value of an observable map after filtering and mapping.
5074 *
5075 * @param items the observable map of items.
5076 * @param supplier a {@code Supplier} whose result is returned if no value is present.
5077 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
5078 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
5079 *
5080 * @return a double binding
5081 */
5082 @Nonnull
5083 public static <K, V> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Double> supplier, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, Double> mapper) {
5084 requireNonNull(items, ERROR_ITEMS_NULL);
5085 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
5086 requireNonNull(filter, ERROR_FILTER_NULL);
5087 requireNonNull(mapper, ERROR_MAPPER_NULL);
5088 return createDoubleBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
5089 }
5090
5091 /**
5092 * Creates a double binding with the first value of an observable map after filtering and mapping.
5093 *
5094 * @param items the observable map of items.
5095 * @param defaultValue the value to be returned if there is no value present.
5096 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
5097 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
5098 *
5099 * @return a double binding
5100 */
5101 @Nonnull
5102 public static <K, V> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Double defaultValue, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, Double>> mapper) {
5103 requireNonNull(items, ERROR_ITEMS_NULL);
5104 requireNonNull(filter, ERROR_FILTER_NULL);
5105 requireNonNull(mapper, ERROR_MAPPER_NULL);
5106 return createDoubleBinding(() -> {
5107 Function<? super V, Double> mapperValue = mapper.getValue();
5108 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
5109 Predicate<? super V> filterValue = filter.getValue();
5110 requireNonNull(filterValue, ERROR_FILTER_NULL);
5111 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
5112 }, items, mapper, filter);
5113 }
5114
5115 /**
5116 * Creates a double binding with the first value of an observable map after filtering and mapping.
5117 *
5118 * @param items the observable map of items.
5119 * @param supplier a {@code Supplier} whose result is returned if no value is present.
5120 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
5121 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
5122 *
5123 * @return a double binding
5124 */
5125 @Nonnull
5126 public static <K, V> DoubleBinding filterThenMapToDoubleThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<Double> supplier, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, Double>> mapper) {
5127 requireNonNull(items, ERROR_ITEMS_NULL);
5128 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
5129 requireNonNull(filter, ERROR_FILTER_NULL);
5130 requireNonNull(mapper, ERROR_MAPPER_NULL);
5131 return createDoubleBinding(() -> {
5132 Function<? super V, Double> mapperValue = mapper.getValue();
5133 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
5134 Predicate<? super V> filterValue = filter.getValue();
5135 requireNonNull(filterValue, ERROR_FILTER_NULL);
5136 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
5137 }, items, mapper, filter);
5138 }
5139
5140 /**
5141 * Creates a string binding with the first value of an observable map after filtering and mapping.
5142 *
5143 * @param items the observable map of items.
5144 * @param defaultValue the value to be returned if there is no value present.
5145 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
5146 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
5147 *
5148 * @return a string binding
5149 */
5150 @Nonnull
5151 public static <K, V> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final String defaultValue, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, String> mapper) {
5152 requireNonNull(items, ERROR_ITEMS_NULL);
5153 requireNonNull(filter, ERROR_FILTER_NULL);
5154 requireNonNull(mapper, ERROR_MAPPER_NULL);
5155 return createStringBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items);
5156 }
5157
5158 /**
5159 * Creates a string binding with the first value of an observable map after filtering and mapping.
5160 *
5161 * @param items the observable map of items.
5162 * @param supplier a {@code Supplier} whose result is returned if no value is present.
5163 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
5164 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
5165 *
5166 * @return a string binding
5167 */
5168 @Nonnull
5169 public static <K, V> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<String> supplier, @Nonnull final Predicate<? super V> filter, @Nonnull final Function<? super V, String> mapper) {
5170 requireNonNull(items, ERROR_ITEMS_NULL);
5171 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
5172 requireNonNull(filter, ERROR_FILTER_NULL);
5173 requireNonNull(mapper, ERROR_MAPPER_NULL);
5174 return createStringBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items);
5175 }
5176
5177 /**
5178 * Creates a string binding with the first value of an observable map after filtering and mapping.
5179 *
5180 * @param items the observable map of items.
5181 * @param defaultValue the value to be returned if there is no value present.
5182 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
5183 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
5184 *
5185 * @return a string binding
5186 */
5187 @Nonnull
5188 public static <K, V> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final String defaultValue, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, String>> mapper) {
5189 requireNonNull(items, ERROR_ITEMS_NULL);
5190 requireNonNull(filter, ERROR_FILTER_NULL);
5191 requireNonNull(mapper, ERROR_MAPPER_NULL);
5192 return createStringBinding(() -> {
5193 Function<? super V, String> mapperValue = mapper.getValue();
5194 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
5195 Predicate<? super V> filterValue = filter.getValue();
5196 requireNonNull(filterValue, ERROR_FILTER_NULL);
5197 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElse(defaultValue);
5198 }, items, mapper, filter);
5199 }
5200
5201 /**
5202 * Creates a string binding with the first value of an observable map after filtering and mapping.
5203 *
5204 * @param items the observable map of items.
5205 * @param supplier a {@code Supplier} whose result is returned if no value is present.
5206 * @param filter a non-interfering, stateless predicate to apply to the each value before mapping.
5207 * @param mapper a non-interfering, stateless function to apply to the each value after filtering.
5208 *
5209 * @return a string binding
5210 */
5211 @Nonnull
5212 public static <K, V> StringBinding filterThenMapToStringThenFindFirst(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<String> supplier, @Nonnull final ObservableValue<Predicate<? super V>> filter, @Nonnull final ObservableValue<Function<? super V, String>> mapper) {
5213 requireNonNull(items, ERROR_ITEMS_NULL);
5214 requireNonNull(supplier, ERROR_SUPPLIER_NULL);
5215 requireNonNull(filter, ERROR_FILTER_NULL);
5216 requireNonNull(mapper, ERROR_MAPPER_NULL);
5217 return createStringBinding(() -> {
5218 Function<? super V, String> mapperValue = mapper.getValue();
5219 requireNonNull(mapperValue, ERROR_MAPPER_NULL);
5220 Predicate<? super V> filterValue = filter.getValue();
5221 requireNonNull(filterValue, ERROR_FILTER_NULL);
5222 return items.values().stream().filter(filterValue).map(mapperValue).findFirst().orElseGet(supplier);
5223 }, items, mapper, filter);
5224 }
5225 }
|