/** * Overloaded version of {@link Map#get(Object)} that takes a primitive int key. * * @param key for indexing the {@link Map} * @return the value if found otherwise null */ public V get(final int key) { return unmapNullValue(getMapped(key)); }
/** * Primitive specialised version of {@link #replace(Object, Object, Object)} * * @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 */ public boolean replace(final int key, final V oldValue, final V newValue) { final Object curValue = get(key); if (curValue == null || !Objects.equals(unmapNullValue(curValue), oldValue)) { return false; } put(key, newValue); return true; }
/** * Get a value for a given key, or if it does not exist then default the value via a * {@link java.util.function.IntFunction} and put it in the map. * <p> * Primitive specialized version of {@link java.util.Map#computeIfAbsent}. * * @param key to search on. * @param mappingFunction to provide a value if the get returns null. * @return the value if found otherwise the default. */ public V computeIfAbsent(final int key, final IntFunction<? extends V> mappingFunction) { V value = getMapped(key); if (value == null) { value = mappingFunction.apply(key); if (value != null) { put(key, value); } } else { value = unmapNullValue(value); } return value; }
/** * {@inheritDoc} */ public String toString() { if (isEmpty()) { return "{}"; } final EntryIterator entryIterator = new EntryIterator(); entryIterator.reset(); final StringBuilder sb = new StringBuilder().append('{'); while (true) { entryIterator.next(); sb.append(entryIterator.getIntKey()).append('=').append(unmapNullValue(entryIterator.getValue())); if (!entryIterator.hasNext()) { return sb.append('}').toString(); } sb.append(',').append(' '); } }
return unmapNullValue(oldValue);
/** * Overloaded version of {@link Map#remove(Object)} that takes a primitive int key. * * @param key for indexing the {@link Map} * @return the value if found otherwise null */ public V remove(final int key) { @DoNotSub final int mask = values.length - 1; @DoNotSub int index = Hashing.hash(key, mask); Object value; while (null != (value = values[index])) { if (key == keys[index]) { values[index] = null; --size; compactChain(index); break; } index = ++index & mask; } return unmapNullValue(value); }
/** * Overloaded version of {@link Map#get(Object)} that takes a primitive int key. * * @param key for indexing the {@link Map} * @return the value if found otherwise null */ public V get(final int key) { return unmapNullValue(getMapped(key)); }
/** * Primitive specialised version of {@link #replace(Object, Object, Object)} * * @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 */ public boolean replace(final int key, final V oldValue, final V newValue) { final Object curValue = get(key); if (curValue == null || !Objects.equals(unmapNullValue(curValue), oldValue)) { return false; } put(key, newValue); return true; }
/** * Get a value for a given key, or if it does not exist then default the value via a * {@link java.util.function.IntFunction} and put it in the map. * <p> * Primitive specialized version of {@link java.util.Map#computeIfAbsent}. * * @param key to search on. * @param mappingFunction to provide a value if the get returns null. * @return the value if found otherwise the default. */ public V computeIfAbsent(final int key, final IntFunction<? extends V> mappingFunction) { V value = getMapped(key); if (value == null) { value = mappingFunction.apply(key); if (value != null) { put(key, value); } } else { value = unmapNullValue(value); } return value; }
/** * {@inheritDoc} */ public String toString() { if (isEmpty()) { return "{}"; } final EntryIterator entryIterator = new EntryIterator(); entryIterator.reset(); final StringBuilder sb = new StringBuilder().append('{'); while (true) { entryIterator.next(); sb.append(entryIterator.getIntKey()).append('=').append(unmapNullValue(entryIterator.getValue())); if (!entryIterator.hasNext()) { return sb.append('}').toString(); } sb.append(',').append(' '); } }
return unmapNullValue(oldValue);
/** * Overloaded version of {@link Map#remove(Object)} that takes a primitive int key. * * @param key for indexing the {@link Map} * @return the value if found otherwise null */ public V remove(final int key) { @DoNotSub final int mask = values.length - 1; @DoNotSub int index = Hashing.hash(key, mask); Object value; while (null != (value = values[index])) { if (key == keys[index]) { values[index] = null; --size; compactChain(index); break; } index = ++index & mask; } return unmapNullValue(value); }