/** * {@inheritDoc} */ @Override public boolean putIfAbsent(final char key, final char 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 CharCharHashMap from(final char[] keys, final char[] values) { if (keys.length != values.length) { throw new IllegalArgumentException("Arrays of keys and values must have an identical length."); } final CharCharHashMap map = new CharCharHashMap(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 CharCharCursor> iterable) { final int count = this.size(); for (final CharCharCursor 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 char putOrAdd(final char key, char putValue, final char incrementValue) { if (containsKey(key)) { putValue = get(key); putValue = (char) (((putValue) + (incrementValue))); } put(key, putValue); return putValue; }