/** * Construct an empty map */ public BiInt2ObjectMap() { map = new Long2ObjectHashMap<V>(); }
/** * Get the total capacity for the map to which the load factor with be a fraction of. * * @return the total capacity for the map. */ public int capacity() { return map.capacity(); }
@Override public V get(final Object key) { return get(((Long) key).longValue()); }
builderBySessionIdMap.put(message.getCorrelationId(), builder); builder.append(message.buffer(), 0, message.getFrameLength()); } else { BufferBuilder builder = builderBySessionIdMap.get(message.getCorrelationId()); if (builder.position() == 0) { throw new IllegalStateException(); builderBySessionIdMap.remove(message.getCorrelationId());
/** * Get a value for a given key, or if it does ot exist then default the value via a {@link LongFunction} * and put it in the map. * * @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 long key, final LongFunction<? extends V> mappingFunction) { checkNotNull(mappingFunction, "mappingFunction cannot be null"); V value = get(key); if (value == null) { value = mappingFunction.apply(key); if (value != null) { put(key, value); } } return value; }
/** * Iterate over the values in the map * * @param consumer to apply to each value in the map */ public void forEach(final Consumer<V> consumer) { for (Map.Entry<Long, V> entry : map.entrySet()) { consumer.accept(entry.getValue()); } }
@Override public V put(final Long key, final V value) { return put(key.longValue(), value); }
@Override public boolean containsKey(final Object key) { checkNotNull(key, "Null keys are not permitted"); return containsKey(((Long) key).longValue()); }
/** * Get the load factor beyond which the map will increase size. * * @return load factor for when the map should increase size. */ public double loadFactor() { return map.loadFactor(); }
/** * Is map empty or not. * * @return boolean indicating empty map or not */ public boolean isEmpty() { return map.isEmpty(); }
/** * Overloaded version of {@link Map#remove(Object)} that takes a primitive long key. * * @param key for indexing the {@link Map} * @return the value if found otherwise null */ @SuppressWarnings("unchecked") public V remove(final long key) { int index = longHash(key, mask); Object value; while (null != (value = values[index])) { if (key == keys[index]) { values[index] = null; --size; compactChain(index); return (V) value; } index = ++index & mask; } return null; }
/** * Overloaded version of {@link Map#put(Object, Object)} that takes a primitive long key. * * @param key for indexing the {@link Map} * @param value to be inserted in the {@link Map} * @return the previous value if found otherwise null */ @SuppressWarnings("unchecked") public V put(final long key, final V value) { checkNotNull(value, "Value cannot be null"); V oldValue = null; int index = longHash(key, mask); while (null != values[index]) { if (key == keys[index]) { oldValue = (V) values[index]; break; } index = ++index & mask; } if (null == oldValue) { ++size; keys[index] = key; } values[index] = value; if (size > resizeThreshold) { increaseCapacity(); } return oldValue; }
builderBySessionIdMap.put(message.getCorrelationId(), builder); builder.append(message.buffer(), 0, message.getFrameLength()); } else { BufferBuilder builder = builderBySessionIdMap.get(message.getCorrelationId()); if (builder.position() == 0) { throw new IllegalStateException(); builderBySessionIdMap.remove(message.getCorrelationId());
/** * Get a value for a given key, or if it does ot exist then default the value via a {@link LongFunction} * and put it in the map. * * @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 long key, final LongFunction<? extends V> mappingFunction) { checkNotNull(mappingFunction, "mappingFunction cannot be null"); V value = get(key); if (value == null) { value = mappingFunction.apply(key); if (value != null) { put(key, value); } } return value; }
/** * Iterate over the values in the map * * @param consumer to apply to each value in the map */ public void forEach(final Consumer<V> consumer) { for (Map.Entry<Long, V> entry : map.entrySet()) { consumer.accept(entry.getValue()); } }
@Override public V put(final Long key, final V value) { return put(key.longValue(), value); }
@Override public boolean containsKey(final Object key) { checkNotNull(key, "Null keys are not permitted"); return containsKey(((Long) key).longValue()); }
/** * Get the load factor beyond which the map will increase size. * * @return load factor for when the map should increase size. */ public double loadFactor() { return map.loadFactor(); }
/** * Is map empty or not. * * @return boolean indicating empty map or not */ public boolean isEmpty() { return map.isEmpty(); }
/** * Overloaded version of {@link Map#remove(Object)} that takes a primitive long key. * * @param key for indexing the {@link Map} * @return the value if found otherwise null */ @SuppressWarnings("unchecked") public V remove(final long key) { int index = longHash(key, mask); Object value; while (null != (value = values[index])) { if (key == keys[index]) { values[index] = null; --size; compactChain(index); return (V) value; } index = ++index & mask; } return null; }