/** * Converts a long object observable value into a long binding. * * @param observable the observable to be converted. * * @return a long binding. */ @Nonnull public static LongBinding mapToLong(@Nonnull final ObservableObjectValue<Long> observable) { requireNonNull(observable, ERROR_OBSERVABLE_NULL); return createLongBinding(observable::get, observable); }
/** * Creates a long binding with the first value of an observable map after filtering. * * @param items the observable map 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 value * * @return a long binding */ @Nonnull public static <K> LongBinding filterThenFindFirstLong(@Nonnull final ObservableMap<K, Long> items, @Nonnull final Long defaultValue, @Nonnull final Predicate<? super Long> filter) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(filter, ERROR_FILTER_NULL); return createLongBinding(() -> items.values().stream().filter(filter).findFirst().orElse(defaultValue), items); }
/** * Creates a long binding with the first element of an observable list after filtering. * * @param items the observable list 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 long binding */ @Nonnull public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableList<Long> items, @Nonnull final Long defaultValue, @Nonnull final Predicate<? super Long> filter) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(filter, ERROR_FILTER_NULL); return createLongBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items); }
/** * Creates a long binding with the first value of an observable map after filtering and mapping. * * @param items the observable map 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 value before mapping. * @param mapper a non-interfering, stateless function to apply to the each value after filtering. * * @return a long binding */ @Nonnull 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) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(filter, ERROR_FILTER_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createLongBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items); }
/** * Creates a long binding with the first element of an observable set after filtering. * * @param items the observable set of items. * @param supplier a {@code Supplier} whose result is returned if no value is present. * @param filter a non-interfering, stateless predicate to apply to the each element. * * @return a long binding */ @Nonnull public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableSet<Long> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Predicate<? super Long> filter) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(supplier, ERROR_SUPPLIER_NULL); requireNonNull(filter, ERROR_FILTER_NULL); return createLongBinding(() -> items.stream().filter(filter).findFirst().orElseGet(supplier), items); }
/** * Converts an observable into a long binding. * * @param observable the observable to be converted. * @param mapper a non-interfering, stateless function to apply to the observable value. * * @return a long binding. * * @since 2.11.0 */ @Nonnull public static <T> LongBinding mapAsLong(@Nonnull final ObservableValue<T> observable, @Nonnull final Function<T, Long> mapper) { requireNonNull(observable, ERROR_OBSERVABLE_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createLongBinding(() -> mapper.apply(observable.getValue()), observable); }
/** * Creates a long binding with the first value of an observable map after filtering and mapping. * * @param items the observable map of items. * @param supplier a {@code Supplier} whose result is returned if no value is present. * @param filter a non-interfering, stateless predicate to apply to the each value before mapping. * @param mapper a non-interfering, stateless function to apply to the each value after filtering. * * @return a long binding */ @Nonnull 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) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(supplier, ERROR_SUPPLIER_NULL); requireNonNull(filter, ERROR_FILTER_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createLongBinding(() -> items.values().stream().filter(filter).map(mapper).findFirst().orElseGet(supplier), items); }
/** * Returns a long binding whose value is the reduction of all values in the map. The mapper function is applied to the reduced value. * * @param items the observable map. * @param supplier a {@code Supplier} whose result is returned if no value is present. * @param reducer an associative, non-interfering, stateless function for combining two values. * @param mapper a non-interfering, stateless function to apply to the reduced value. * * @return a long binding */ @Nonnull public static <K, V> LongBinding reduceThenMapToLong(@Nonnull final ObservableMap<K, V> items, @Nonnull final Supplier<V> supplier, @Nonnull final BinaryOperator<V> reducer, @Nonnull final Function<? super V, Long> mapper) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(reducer, ERROR_REDUCER_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); requireNonNull(supplier, ERROR_SUPPLIER_NULL); return createLongBinding(() -> mapper.apply(items.values().stream().reduce(reducer).orElseGet(supplier)), items); }
/** * Returns a long binding whose value is the reduction of all elements in the list. The mapper function is applied to each element before reduction. * * @param items the observable list of elements. * @param supplier a {@code Supplier} whose result is returned if no value is present. * @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 long binding */ @Nonnull public static <T> LongBinding mapToLongThenReduce(@Nonnull final ObservableList<T> items, @Nonnull final Supplier<Long> supplier, @Nonnull final Function<? super T, Long> mapper, @Nonnull final BinaryOperator<Long> reducer) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(reducer, ERROR_REDUCER_NULL); requireNonNull(supplier, ERROR_SUPPLIER_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createLongBinding(() -> items.stream().map(mapper).reduce(reducer).orElseGet(supplier), items); }
/** * Creates a long 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 long binding */ @Nonnull public static LongBinding filterThenFindFirstLong(@Nonnull final ObservableSet<Long> items, @Nonnull final Long defaultValue, @Nonnull final Predicate<? super Long> filter) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(filter, ERROR_FILTER_NULL); return createLongBinding(() -> items.stream().filter(filter).findFirst().orElse(defaultValue), items); }
/** * Creates a long binding with the first element of an observable set after filtering and mapping. * * @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. before mapping. * @param mapper a non-interfering, stateless function to apply to the each element after filtering. * * @return a long binding */ @Nonnull 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) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(filter, ERROR_FILTER_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createLongBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items); }
/** * Creates a long binding containing the value of the mapper function applied to the source observable. * * @param observable the source observable. * @param mapper a non-interfering, stateless function to apply to the reduced value. * @param supplier a {@code Supplier} whose result is returned if no value is present. * * @return a long binding. */ @Nonnull public static LongBinding mapLong(@Nonnull final ObservableValue<Long> observable, @Nonnull final Function<Long, Long> mapper, @Nonnull final Supplier<Long> supplier) { requireNonNull(observable, ERROR_OBSERVABLE_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); requireNonNull(supplier, ERROR_SUPPLIER_NULL); return createLongBinding(() -> { Long sourceValue = observable.getValue(); return sourceValue == null ? supplier.get() : mapper.apply(sourceValue); }, observable); }
/** * Creates a long binding with the first element of an observable set after mapping and filtering. * * @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 before filtering. * @param filter a non-interfering, stateless predicate to apply to the each element. after mapping. * * @return a long binding */ @Nonnull 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) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); requireNonNull(filter, ERROR_FILTER_NULL); return createLongBinding(() -> items.stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items); }
/** * Creates a long binding with the first value of an observable map after mapping and filtering. * * @param items the observable map 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 value before filtering. * @param filter a non-interfering, stateless predicate to apply to the each value after mapping. * * @return a long binding */ @Nonnull 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) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); requireNonNull(filter, ERROR_FILTER_NULL); return createLongBinding(() -> items.values().stream().map(mapper).filter(filter).findFirst().orElse(defaultValue), items); }
/** * Creates a long binding with the first element of an observable list after filtering and mapping. * * @param items the observable list 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. before mapping. * @param mapper a non-interfering, stateless function to apply to the each element after filtering. * * @return a long binding */ @Nonnull 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) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(filter, ERROR_FILTER_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createLongBinding(() -> items.stream().filter(filter).map(mapper).findFirst().orElse(defaultValue), items); }
/** * Returns a long binding whose value is the reduction of all values in the map. The mapper function is applied to the reduced value. * * @param items the observable map. * @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. * @param mapper a non-interfering, stateless function to apply to the reduced value. * * @return a long binding */ @Nonnull public static <K, V> LongBinding reduceThenMapToLong(@Nonnull final ObservableMap<K, V> items, @Nullable final V defaultValue, @Nonnull final BinaryOperator<V> reducer, @Nonnull final Function<? super V, Long> mapper) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(reducer, ERROR_REDUCER_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createLongBinding(() -> mapper.apply(items.values().stream().reduce(reducer).orElse(defaultValue)), items); }
/** * Returns a long binding whose value is the reduction of all elements in the list. The mapper function is applied to the reduced value. * * @param items the observable list 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. * @param mapper a non-interfering, stateless function to apply to the reduced value. * * @return a long binding */ @Nonnull public static <T> LongBinding reduceThenMapToLong(@Nonnull final ObservableList<T> items, @Nullable final T defaultValue, @Nonnull final BinaryOperator<T> reducer, @Nonnull final Function<? super T, Long> mapper) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(reducer, ERROR_REDUCER_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createLongBinding(() -> mapper.apply(items.stream().reduce(reducer).orElse(defaultValue)), items); }
/** * Returns a long binding whose value is the reduction of all values in the map. The mapper function is applied to each value before reduction. * * @param items the observable map. * @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 value. * @param reducer an associative, non-interfering, stateless function for combining two values. * * @return a long binding */ @Nonnull public static <K, V> LongBinding mapToLongThenReduce(@Nonnull final ObservableMap<K, V> items, @Nullable final Long defaultValue, @Nonnull final Function<? super V, Long> mapper, @Nonnull final BinaryOperator<Long> reducer) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(reducer, ERROR_REDUCER_NULL); requireNonNull(mapper, ERROR_MAPPER_NULL); return createLongBinding(() -> items.values().stream().map(mapper).reduce(reducer).orElse(defaultValue), items); }
/** * Returns a long 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 long binding */ @Nonnull public static <T> LongBinding mapToLongThenReduce(@Nonnull final ObservableSet<T> items, @Nullable final Long defaultValue, @Nonnull final Function<? super T, Long> mapper, @Nonnull final BinaryOperator<Long> reducer) { requireNonNull(items, ERROR_ITEMS_NULL); requireNonNull(reducer, ERROR_REDUCER_NULL); return createLongBinding(() -> items.stream().map(mapper).reduce(reducer).orElse(defaultValue), items); }
/** * creates a LongBinding from three Integer properties. * @param intProperty0 * @param intProperty1 * @param intProperty2 */ public static LongBinding createLongBinding(@Nonnull ReadOnlyProperty<Integer> intProperty0, @Nonnull ReadOnlyProperty<Integer> intProperty1, @Nonnull ReadOnlyProperty<Integer> intProperty2) { return Bindings.createLongBinding(() -> { Integer byte0 = intProperty0.getValue() & 0xffffff; Integer byte1 = intProperty1.getValue() & 0xffff; Integer byte2 = intProperty2.getValue() & 0xff; return (long) (byte2 + byte1 * 256 + byte0 * 256 * 256); }, intProperty0, intProperty1, intProperty2); }