public DoubleToIdMap() { _valueToIdMap = new Double2IntOpenHashMap(); _valueToIdMap.defaultReturnValue(INVALID_KEY); _idToValueMap = new DoubleArrayList(); }
/** * 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 int replace(final double key, final int 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 int getOrDefault(final double key, final int defaultValue) { final int v; return ((v = get(key)) != defaultReturnValue() || containsKey(key)) ? v : defaultValue; } /**
final java.util.function.BiFunction<? super Double, ? super Integer, ? extends Integer> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int oldValue = get(key), drv = defaultReturnValue(); if (oldValue == drv && !containsKey(key)) return drv;
final java.util.function.BiFunction<? super Double, ? super Integer, ? extends Integer> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int oldValue = get(key), drv = defaultReturnValue(); final boolean contained = oldValue != drv || containsKey(key); final Integer newValue = remappingFunction.apply(Double.valueOf(key),
final java.util.function.BiFunction<? super Integer, ? super Integer, ? extends Integer> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int oldValue = get(key), drv = defaultReturnValue(); final int newValue; if (oldValue != drv || containsKey(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 double key, final int oldValue, final int newValue) { final int curValue = get(key); if (!((curValue) == (oldValue)) || (curValue == defaultReturnValue() && !containsKey(key))) return false; put(key, newValue); return true; } /**
/** * 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 double key, final int value) { final int curValue = get(key); if (!((curValue) == (value)) || (curValue == defaultReturnValue() && !containsKey(key))) return false; remove(key); return true; } /**
final java.util.function.DoubleFunction<? extends Integer> mappingFunction) { java.util.Objects.requireNonNull(mappingFunction); final int v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v;
/** * 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 int putIfAbsent(final double key, final int value) { final int v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v; put(key, value); return drv; } /**
java.util.Objects.requireNonNull(mappingFunction); final int v = get(key); if (v != defaultReturnValue() || containsKey(key)) return v; int newValue = mappingFunction.applyAsInt(key);
final int v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v;