/** * {@inheritDoc} */ @Override public boolean putIfAbsent(final char key, final double value) { if (!containsKey(key)) { put(key, value); return true; } return false; }
/** * Creates a hash map from two index-aligned arrays of key-value pairs. Default load factor is used. */ public static CharDoubleHashMap from(final char[] keys, final double[] values) { if (keys.length != values.length) { throw new IllegalArgumentException("Arrays of keys and values must have an identical length."); } final CharDoubleHashMap map = new CharDoubleHashMap(keys.length); for (int i = 0; i < keys.length; i++) { map.put(keys[i], values[i]); } return map; }
/** * {@inheritDoc} */ @Override public int putAll(final Iterable<? extends CharDoubleCursor> iterable) { final int count = this.size(); for (final CharDoubleCursor c : iterable) { put(c.key, c.value); } return this.size() - count; }
/** * If <code>key</code> exists, <code>putValue</code> is inserted into the map, * otherwise any existing value is incremented by <code>additionValue</code>. * * @param key * The key of the value to adjust. * @param putValue * The value to put if <code>key</code> does not exist. * @param incrementValue * The value to add to the existing value if <code>key</code> exists. * @return Returns the current value associated with <code>key</code> (after * changes). */ @SuppressWarnings("cast") @Override public double putOrAdd(final char key, double putValue, final double incrementValue) { if (containsKey(key)) { putValue = get(key); putValue = (double) (((putValue) + (incrementValue))); } put(key, putValue); return putValue; }