/** * Composes the given bi-function ({@code f(a,b)}) with a function checking the type of the output: * {@code checkType(f(a,b))}. So the output of the given function is checked to verify that it uses a valid type. * * @param function the function * @return the composition */ private BiFunction<? super K, ? super V, ? extends V> typeChecked(BiFunction<? super K, ? super V, ? extends V> function) { return (k, v) -> { checkType(k); V output = function.apply(k, v); if (output != null) { checkType(output); } return output; }; }
/** * Composes the given function ({@code f(a)}) with a function checking the type of the output. So the output of the * given function is checked to verify that is uses a valid type. * * @param function the function * @return the composition */ private Function<? super K, ? extends V> typeChecked(Function<? super K, ? extends V> function) { return k -> { checkType(k); V output = function.apply(k); if (output != null) { checkType(output); } return output; }; }
@Override public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) { checkType(key); checkType(value); return map.merge(key, value, (k, v) -> { // No need to check the key, already check above. V output = remappingFunction.apply(k, v); if (output != null) { checkType(output); } return output; }); }
@Override public V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) { checkType(key); checkType(value); return map.merge(key, value, (k, v) -> { // No need to check the key, already check above. V output = remappingFunction.apply(k, v); if (output != null) { checkType(output); } return output; }); }
/** * Composes the given bi-function ({@code f(a,b)}) with a function checking the type of the output: * {@code checkType(f(a,b))}. So the output of the given function is checked to verify that it uses a valid type. * * @param function the function * @return the composition */ private BiFunction<? super K, ? super V, ? extends V> typeChecked(BiFunction<? super K, ? super V, ? extends V> function) { return (k, v) -> { checkType(k); V output = function.apply(k, v); if (output != null) { checkType(output); } return output; }; }
/** * Composes the given function ({@code f(a)}) with a function checking the type of the output. So the output of the * given function is checked to verify that is uses a valid type. * * @param function the function * @return the composition */ private Function<? super K, ? extends V> typeChecked(Function<? super K, ? extends V> function) { return k -> { checkType(k); V output = function.apply(k); if (output != null) { checkType(output); } return output; }; }