@Nonnull @Override protected Stream createStream() { return ((ObservableSet) observable).stream(); } }
/** * Creates a number binding that contains the sum of the items of the given observable set. * * @param items the observable set of items. * * @return a number binding. */ @Nonnull public static NumberBinding sumOfSet(@Nonnull final ObservableSet<? extends Number> items) { requireNonNull(items, ERROR_ITEMS_NULL); return createDoubleBinding(() -> items.stream().mapToDouble(Number::doubleValue).sum(), items); }
/** * Creates a float binding with the first element of an observable set after filtering. * * @param items the observable set of items. * @param defaultValue the value to be returned if there is no value present. * @param filter a non-interfering, stateless predicate to apply to the each element. * * @return a float binding */ @Nonnull public static FloatBinding filterThenFindFirstFloat(@Nonnull final ObservableSet<Float> items, @Nonnull final Float defaultValue, @Nonnull final Predicate<? super Float> filter) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(filter, ERROR_FILTER_NULL); return createFloatBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items); }
/** * Returns an object binding whose value is the reduction of all elements in the set. * * @param items the observable set of elements. * @param defaultValue the value to be returned if there is no value present, may be null. * @param reducer an associative, non-interfering, stateless function for combining two values. * * @return an object binding */ @Nonnull public static <T> ObjectBinding<T> reduce(@Nonnull final ObservableSet<T> items, @Nullable final T defaultValue, @Nonnull final BinaryOperator<T> reducer) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(reducer, ERROR_REDUCER_NULL); return createObjectBinding(() -> items.stream().reduce(reducer).orElse(defaultValue), items); }
/** * Creates a number binding that contains the sum of the items of the given observable set. * * @param items the observable set of items. * @param mapper a non-interfering, stateless function to apply to the each element. * * @return a number binding. */ @Nonnull public static <T> NumberBinding sumOfSet(@Nonnull final ObservableSet<T> items, @Nonnull final ToDoubleFunction<? super T> mapper) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createDoubleBinding(() -> items.stream().mapToDouble(mapper).sum(), items); }
/** * Creates a boolean binding based on a <tt>noneMatch</tt> predicate applied to the items. * * @param items the observable set of items. * @param predicate a non-interfering, stateless predicate to apply to the each element. * * @return a boolean binding */ @Nonnull public static <T> BooleanBinding noneMatch(@Nonnull final ObservableSet<T> items, @Nonnull final Predicate<? super T> predicate) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(predicate, ERROR_PREDICATE_NULL); return createBooleanBinding(() -> items.stream().noneMatch(predicate), items); }
/** * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items. * * @param items the observable set of items. * @param predicate a non-interfering, stateless predicate to apply to the each element. * * @return a boolean binding */ @Nonnull public static <T> BooleanBinding allMatch(@Nonnull final ObservableSet<T> items, @Nonnull final Predicate<? super T> predicate) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(predicate, ERROR_PREDICATE_NULL); return createBooleanBinding(() -> items.stream().allMatch(predicate), items); }
/** * Returns a boolean binding whose value is the reduction of all elements in the set. The mapper function is applied to each element before reduction. * * @param items the observable set of elements. * @param defaultValue the value to be returned if there is no value present, may be null. * @param mapper a non-interfering, stateless function to apply to each element. * @param reducer an associative, non-interfering, stateless function for combining two values. * * @return a boolean binding */ @Nonnull public static <T> BooleanBinding mapToBooleanThenReduce(@Nonnull final ObservableSet<T> items, @Nullable final Boolean defaultValue, @Nonnull final Function<? super T, Boolean> mapper, @Nonnull final BinaryOperator<Boolean> reducer) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(reducer, ERROR_REDUCER_NULL); return createBooleanBinding(() -> items.stream().map(mapper).reduce(reducer).orElse(defaultValue), items); }
/** * Returns a double binding whose value is the reduction of all elements in the set. The mapper function is applied to each element before reduction. * * @param items the observable set of elements. * @param defaultValue the value to be returned if there is no value present, may be null. * @param mapper a non-interfering, stateless function to apply to each element. * @param reducer an associative, non-interfering, stateless function for combining two values. * * @return a double binding */ @Nonnull public static <T> DoubleBinding mapToDoubleThenReduce(@Nonnull final ObservableSet<T> items, @Nullable final Double defaultValue, @Nonnull final Function<? super T, Double> mapper, @Nonnull final BinaryOperator<Double> reducer) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(reducer, ERROR_REDUCER_NULL); return createDoubleBinding(() -> items.stream().map(mapper).reduce(reducer).orElse(defaultValue), items); }
/** * Returns a string binding whose value is the reduction of all elements in the set. The mapper function is applied to each element before reduction. * * @param items the observable set of elements. * @param defaultValue the value to be returned if there is no value present, may be null. * @param mapper a non-interfering, stateless function to apply to each element. * @param reducer an associative, non-interfering, stateless function for combining two values. * * @return a string binding */ @Nonnull public static <T> StringBinding mapToStringThenReduce(@Nonnull final ObservableSet<T> items, @Nullable final String defaultValue, @Nonnull final Function<? super T, String> mapper, @Nonnull final BinaryOperator<String> reducer) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(reducer, ERROR_REDUCER_NULL); return createStringBinding(() -> items.stream().map(mapper).reduce(reducer).orElse(defaultValue), items); }
/** * Creates a boolean binding based on a <tt>allMatch</tt> predicate applied to the items. * * @param items the observable set of items. * @param mapper a non-interfering, stateless function to apply to the each value before matching. * @param predicate a non-interfering, stateless predicate to apply to the each element. * * @return a boolean binding */ @Nonnull public static <T, R> BooleanBinding allMatch(@Nonnull final ObservableSet<T> items, @Nonnull final Function<? super T, R> mapper, @Nonnull final Predicate<? super R> predicate) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); requireNonNull(predicate, ERROR_PREDICATE_NULL); return createBooleanBinding(() -> items.stream().map(mapper).allMatch(predicate), items); }
/** * Creates a double binding with the first element of an observable set after filtering. * * @param items the observable set of items. * @param defaultValue the value to be returned if there is no value present. * @param filter a non-interfering, stateless predicate to apply to the each element. * * @return a double binding */ @Nonnull public static DoubleBinding filterThenFindFirstDouble(@Nonnull final ObservableSet<Double> items, @Nonnull final Double defaultValue, @Nonnull final Predicate<? super Double> filter) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(filter, ERROR_FILTER_NULL); return createDoubleBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items); }
/** * Creates a string binding with the first element of an observable set after filtering. * * @param items the observable set of items. * @param defaultValue the value to be returned if there is no value present. * @param filter a non-interfering, stateless predicate to apply to the each element. * * @return a string binding */ @Nonnull public static StringBinding filterThenFindFirstString(@Nonnull final ObservableSet<String> items, @Nonnull final String defaultValue, @Nonnull final Predicate<? super String> filter) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(filter, ERROR_FILTER_NULL); return createStringBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items); }
public String getDefaultEditorAreaId() { return dockingAreaDescriptors.stream() .filter(dockingAreaDescriptor -> dockingAreaDescriptor.getKind() == DockingAreaKind.EDITOR) .filter(dockingAreaDescriptor -> !dockingAreaDescriptor.isAdHoc()) .map(DockingAreaDescriptor::getId) .findFirst() .orElse(null); }
/** * Creates a number binding that computes the average value amongst elements. * * @param items the observable set of items. * @param defaultValue the value to be returned if there is no value present. * * @return a number binding */ @Nonnull public static NumberBinding averageInSet(@Nonnull final ObservableSet<? extends Number> items, @Nonnull final Number defaultValue) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(defaultValue, ERROR_DEFAULT_VALUE_NULL); return createDoubleBinding(() -> items.stream().mapToDouble(Number::doubleValue).average().orElse(defaultValue.doubleValue()), items); }
/** * Creates a number binding that computes the minimum value amongst elements. * * @param items the observable set of items. * @param defaultValue the value to be returned if there is no value present. * @param mapper a non-interfering, stateless function to apply to the each element. * * @return a number binding */ @Nonnull public static <T> NumberBinding minInSet(@Nonnull final ObservableSet<T> items, @Nonnull final Number defaultValue, @Nonnull final ToDoubleFunction<? super T> mapper) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(defaultValue, ERROR_DEFAULT_VALUE_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createDoubleBinding(() -> items.stream().mapToDouble(mapper).min().orElse(defaultValue.doubleValue()), items); }
/** * Creates a number binding that computes the maximum value amongst elements. * * @param items the observable set of items. * @param defaultValue the value to be returned if there is no value present. * * @return a number binding */ @Nonnull public static NumberBinding maxInSet(@Nonnull final ObservableSet<? extends Number> items, @Nonnull final Number defaultValue) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(defaultValue, ERROR_DEFAULT_VALUE_NULL); return createDoubleBinding(() -> items.stream().mapToDouble(Number::doubleValue).max().orElse(defaultValue.doubleValue()), items); }
/** * Creates a number binding that computes the minimum value amongst elements. * * @param items the observable set of items. * @param defaultValue the value to be returned if there is no value present. * * @return a number binding */ @Nonnull public static NumberBinding minInSet(@Nonnull final ObservableSet<? extends Number> items, @Nonnull final Number defaultValue) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(defaultValue, ERROR_DEFAULT_VALUE_NULL); return createDoubleBinding(() -> items.stream().mapToDouble(Number::doubleValue).min().orElse(defaultValue.doubleValue()), items); }
/** * Creates a number binding that computes the average value amongst elements. * * @param items the observable set of items. * @param supplier a {@code Supplier} whose result is returned if no value is present. * * @return a number binding */ @Nonnull public static NumberBinding averageInSet(@Nonnull final ObservableSet<? extends Number> items, @Nonnull final Supplier<? extends Number> supplier) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(supplier, ERROR_SUPPLIER_NULL); return createDoubleBinding(() -> items.stream().mapToDouble(Number::doubleValue).average().orElseGet(resolveDoubleSupplier(supplier)), items); }
/** * Creates a number binding that computes the maximum value amongst elements. * * @param items the observable set of items. * @param supplier a {@code Supplier} whose result is returned if no value is present. * * @return a number binding */ @Nonnull public static NumberBinding maxInSet(@Nonnull final ObservableSet<? extends Number> items, @Nonnull final Supplier<? extends Number> supplier) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(supplier, ERROR_SUPPLIER_NULL); return createDoubleBinding(() -> items.stream().mapToDouble(Number::doubleValue).max().orElseGet(resolveDoubleSupplier(supplier)), items); }