/** * Replaces the entry for the specified key only if it is currently mapped to * some value. * * @param key * key with which the specified value is associated. * @param value * value to be associated with the specified key. * * @return the previous value associated with the specified key, or the * {@linkplain #defaultReturnValue() default return value} if there was * no mapping for the key. * * @see java.util.Map#replace(Object, Object) * @since 8.0.0 */ default V replace(final short key, final V value) { return containsKey(key) ? put(key, value) : defaultReturnValue(); } /**
/** * Returns the value to which the specified key is mapped, or the * {@code defaultValue} if this map contains no mapping for the key. * * @param key * the key. * @param defaultValue * the default mapping of the key. * * @return the value to which the specified key is mapped, or the * {@code defaultValue} if this map contains no mapping for the key. * * @see java.util.Map#getOrDefault(Object, Object) * @since 8.0.0 */ default V getOrDefault(final short key, final V defaultValue) { final V v; return ((v = get(key)) != defaultReturnValue() || containsKey(key)) ? v : defaultValue; } /**
/** * Removes the entry for the specified key only if it is currently mapped to the * specified value. * * @param key * key with which the specified value is associated. * @param value * value expected to be associated with the specified key. * * @return {@code true} if the value was removed. * * @see java.util.Map#remove(Object, Object) * @since 8.0.0 */ default boolean remove(final short key, final Object value) { final V curValue = get(key); if (!java.util.Objects.equals(curValue, value) || (curValue == defaultReturnValue() && !containsKey(key))) return false; remove(key); return true; } /**
java.util.Objects.requireNonNull(mappingFunction); final V v = get(key); if (v != defaultReturnValue() || containsKey(key)) return v; V newValue = mappingFunction.apply(key);
/** * Replaces the entry for the specified key only if currently mapped to the * specified value. * * @param key * key with which the specified value is associated. * @param oldValue * value expected to be associated with the specified key. * @param newValue * value to be associated with the specified key. * * @return {@code true} if the value was replaced. * * @see java.util.Map#replace(Object, Object, Object) * @since 8.0.0 */ default boolean replace(final short key, final V oldValue, final V newValue) { final V curValue = get(key); if (!java.util.Objects.equals(curValue, oldValue) || (curValue == defaultReturnValue() && !containsKey(key))) return false; put(key, newValue); return true; } /**
/** * If the value for the specified key is present, attempts to compute a new * mapping given the key and its current mapped value. * * @param key * key with which the specified value is to be associated. * @param remappingFunction * the function to compute a value. * * @return the new value associated with the specified key, or the * {@linkplain #defaultReturnValue() default return value} if none. * * @see java.util.Map#computeIfPresent(Object, java.util.function.BiFunction) * @since 8.0.0 */ default V computeIfPresent(final short key, final java.util.function.BiFunction<? super Short, ? super V, ? extends V> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final V oldValue = get(key), drv = defaultReturnValue(); if (oldValue == drv && !containsKey(key)) return drv; final V newValue = remappingFunction.apply(Short.valueOf(key), (oldValue)); if (newValue == null) { remove(key); return drv; } put(key, newValue); return newValue; } /**
final java.util.function.BiFunction<? super Short, ? super V, ? extends V> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final V oldValue = get(key), drv = defaultReturnValue(); final boolean contained = oldValue != drv || containsKey(key); final V newValue = remappingFunction.apply(Short.valueOf(key), contained ? (oldValue) : null);
java.util.Objects.requireNonNull(remappingFunction); java.util.Objects.requireNonNull(value); final V oldValue = get(key), drv = defaultReturnValue(); final V newValue; if (oldValue != drv || containsKey(key)) {
/** * If the specified key is not already associated with a value, associates it * with the given value and returns the {@linkplain #defaultReturnValue() * default return value}, else returns the current value. * * @param key * key with which the specified value is to be associated. * @param value * value to be associated with the specified key. * * @return the previous value associated with the specified key, or the * {@linkplain #defaultReturnValue() default return value} if there was * no mapping for the key. * * @see java.util.Map#putIfAbsent(Object, Object) * @since 8.0.0 */ default V putIfAbsent(final short key, final V value) { final V v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v; put(key, value); return drv; } /**
final V v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v;