@Override public boolean hasNext() { return nextVal.isDefined(); }
@Override public boolean isCompleted() { return value.isDefined(); }
@Override public boolean hasNext() { if (nextOption == null) { nextOption = supplier.get(); } return nextOption.isDefined(); }
@Override public boolean isDefinedAt(T value) { return totalFunction.apply(value).isDefined(); }
@Override public boolean containsKey(K key) { return get(key).isDefined(); }
@Override public boolean contains(T element) { return tree.get(element).isDefined(); }
@Override public boolean contains(T element) { return map.get(element).isDefined(); }
/** * Applies an action to this value, if this option is defined, otherwise does nothing. * * @param action An action which can be applied to an optional value * @return this {@code Option} */ @Override default Option<T> peek(Consumer<? super T> action) { Objects.requireNonNull(action, "action is null"); if (isDefined()) { action.accept(get()); } return this; }
private boolean hasDefaultImplementationWithCollector(Class<?> erasedType) { return resolveDefaultCollector(erasedType).isDefined(); }
@SuppressWarnings("unchecked") static <K, V, K2, U extends Map<K2, V>> U mapKeys(Map<K, V> source, U zero, Function<? super K, ? extends K2> keyMapper, BiFunction<? super V, ? super V, ? extends V> valueMerge) { Objects.requireNonNull(zero, "zero is null"); Objects.requireNonNull(keyMapper, "keyMapper is null"); Objects.requireNonNull(valueMerge, "valueMerge is null"); return source.foldLeft(zero, (acc, entry) -> { final K2 k2 = keyMapper.apply(entry._1); final V v2 = entry._2; final Option<V> v1 = acc.get(k2); final V v = v1.isDefined() ? valueMerge.apply(v1.get(), v2) : v2; return (U) acc.put(k2, v); }); }
/** * Creates a {@code Predicate} that tests, if an object is equal to at least one of the specified {@code values} * using {@link Objects#equals(Object, Object)} for comparison. * * <pre>{@code * Predicate<Integer> isIn = isIn(1, 2, 3); * isIn.test(1); // true * isIn.test(0); // false * }</pre> * * @param values an array of values of type T * @param <T> closure over tested object types * @return A new {@code Predicate} * @throws NullPointerException if {@code values} is null */ @SuppressWarnings({ "unchecked", "varargs" }) @SafeVarargs public static <T> Predicate<T> isIn(T... values) { Objects.requireNonNull(values, "values is null"); return obj -> List.of(values).find(value -> Objects.equals(value, obj)).isDefined(); }
/** * A combinator that checks if <strong>at least one</strong> of the given {@code predicates} is satisfies. * * <pre>{@code * Predicate<Integer> isGreaterThanOne = i -> i > 1; * Predicate<Integer> isGreaterThanTwo = i -> i > 2; * anyOf().test(0); // false * anyOf(isGreaterThanOne, isGreaterThanTwo).test(3); // true * anyOf(isGreaterThanOne, isGreaterThanTwo).test(2); // true * anyOf(isGreaterThanOne, isGreaterThanTwo).test(1); // false * }</pre> * * @param predicates An array of predicates * @param <T> closure over tested object types * @return A new {@code Predicate} * @throws NullPointerException if {@code predicates} is null */ @SuppressWarnings({ "unchecked", "varargs" }) @SafeVarargs public static <T> Predicate<T> anyOf(Predicate<T>... predicates) { Objects.requireNonNull(predicates, "predicates is null"); return t -> List.of(predicates).find(pred -> pred.test(t)).isDefined(); }
@Override public boolean hasNext() { while (next.isEmpty() && that.hasNext()) { final T candidate = that.next(); if (predicate.test(candidate)) { next = Option.some(candidate); } } return next.isDefined(); }
@SuppressWarnings("unchecked") static <K, V, M extends Map<K, V>> Tuple2<V, M> computeIfAbsent(M map, K key, Function<? super K, ? extends V> mappingFunction) { Objects.requireNonNull(mappingFunction, "mappingFunction is null"); final Option<V> value = map.get(key); if (value.isDefined()) { return Tuple.of(value.get(), map); } else { final V newValue = mappingFunction.apply(key); final M newMap = (M) map.put(key, newValue); return Tuple.of(newValue, newMap); } }
if (tableName.isDefined() && config.getOrElse("table.schemaName", null) == null) { config = ((Map<String, Object>) config).put("table.schemaName", tableName.get());
@SuppressWarnings("unchecked") static <K, V, M extends Map<K, V>> Tuple2<Option<V>, M> computeIfPresent(M map, K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) { final Option<V> value = map.get(key); if (value.isDefined()) { final V newValue = remappingFunction.apply(key, value.get()); final M newMap = (M) map.put(key, newValue); return Tuple.of(Option.of(newValue), newMap); } else { return Tuple.of(Option.none(), map); } }
@Override public LinkedHashMap<K, V> replace(Tuple2<K, V> currentElement, Tuple2<K, V> newElement) { Objects.requireNonNull(currentElement, "currentElement is null"); Objects.requireNonNull(newElement, "newElement is null"); // We replace the whole element, i.e. key and value have to be present. if (!Objects.equals(currentElement, newElement) && contains(currentElement)) { Queue<Tuple2<K, V>> newList = list; HashMap<K, V> newMap = map; final K currentKey = currentElement._1; final K newKey = newElement._1; // If current key and new key are equal, the element will be automatically replaced, // otherwise we need to remove the pair (newKey, ?) from the list manually. if (!Objects.equals(currentKey, newKey)) { final Option<V> value = newMap.get(newKey); if (value.isDefined()) { newList = newList.remove(Tuple.of(newKey, value.get())); } } newList = newList.replace(currentElement, newElement); newMap = newMap.remove(currentKey).put(newElement); return wrap(newList, newMap); } else { return this; } }
private Option<V> getValueFromCache(K cacheKey){ try { Option<V> result = Option.of(cache.get(cacheKey)); if (result.isDefined()) { onCacheHit(cacheKey); return result; } else { onCacheMiss(cacheKey); return result; } }catch (Exception exception){ LOG.warn("Failed to get a value from Cache {}", getName(), exception); onError(exception); return Option.none(); } }
/** * Associates the specified value with the specified key in this map. * If the map previously contained a mapping for the key, the old value is * replaced by the specified value. * <p> * Note that this method has a worst-case linear complexity. * * @param key key with which the specified value is to be associated * @param value value to be associated with the specified key * @return A new Map containing these elements and that entry. */ @Override public LinkedHashMap<K, V> put(K key, V value) { final Queue<Tuple2<K, V>> newList; final Option<V> currentEntry = get(key); if (currentEntry.isDefined()) { newList = list.replace(Tuple.of(key, currentEntry.get()), Tuple.of(key, value)); } else { newList = list.append(Tuple.of(key, value)); } final HashMap<K, V> newMap = map.put(key, value); return wrap(newList, newMap); }
if (anyColumnSet) { Array<Optional<RowMapper<?>>> mappers = withConfiguredColumnName .map(t -> t._3.isDefined() ? getColumnMapperForDefinedColumn(t._1, t._3.get(), config) : getRowMapper(t._1, config));