@SuppressWarnings("unchecked") private int getKeyForValue(double value) { Double2IntMap map = (Double2IntMap) _groupKeyMap; int groupId = map.get(value); if (groupId == INVALID_ID) { if (_numGroups < _globalGroupIdUpperBound) { groupId = _numGroups; map.put(value, _numGroups++); } } return groupId; }
@Override public int put(double value) { int id = _valueToIdMap.get(value); if (id == INVALID_KEY) { id = _idToValueMap.size(); _valueToIdMap.put(value, id); _idToValueMap.add(value); } return id; }
@Override public boolean contains(final Object o) { if (!(o instanceof Map.Entry)) return false; if (o instanceof Double2IntMap.Entry) { final Double2IntMap.Entry e = (Double2IntMap.Entry) o; final double k = e.getDoubleKey(); return map.containsKey(k) && ((map.get(k)) == (e.getIntValue())); } final Map.Entry<?, ?> e = (Map.Entry<?, ?>) o; final Object key = e.getKey(); if (key == null || !(key instanceof Double)) return false; final double k = ((Double) (key)).doubleValue(); final Object value = e.getValue(); if (value == null || !(value instanceof Integer)) return false; return map.containsKey(k) && ((map.get(k)) == (((Integer) (value)).intValue())); }
/** * 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 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)) {
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),
/** * 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; } /**
final int v = get(key); if (v != defaultReturnValue() || containsKey(key)) return v;
final int v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v;