Package org.jboss.remoting3._private
Class IntIndexHashMap<V>
- java.lang.Object
-
- java.util.AbstractCollection<V>
-
- org.jboss.remoting3._private.IntIndexHashMap<V>
-
- Type Parameters:
V
- the value type
- All Implemented Interfaces:
Iterable<V>
,Collection<V>
,ToIntFunction<V>
,IntIndexMap<V>
public final class IntIndexHashMap<V> extends AbstractCollection<V> implements IntIndexMap<V>
Lock-free concurrent integer-indexed hash map.- Author:
- David M. Lloyd
-
-
Constructor Summary
Constructors Constructor Description IntIndexHashMap(ToIntFunction<? super V> indexer)
Construct a new instance.IntIndexHashMap(ToIntFunction<? super V> indexer, float loadFactor)
Construct a new instance.IntIndexHashMap(ToIntFunction<? super V> indexer, int initialCapacity)
Construct a new instance.IntIndexHashMap(ToIntFunction<? super V> indexer, int initialCapacity, float loadFactor)
Construct a new instance.IntIndexHashMap(ToIntFunction<? super V> indexer, Equaller<? super V> valueEqualler)
Construct a new instance.IntIndexHashMap(ToIntFunction<? super V> indexer, Equaller<? super V> valueEqualler, int initialCapacity, float loadFactor)
Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(V v)
int
applyAsInt(V argument)
void
clear()
V
computeIfAbsent(int index, IntFunction<V> producer)
Compute a map value if no mapping exists.boolean
contains(Object o)
boolean
containsKey(int index)
Determine whether the given index is contained in the map.V
get(int index)
Get the value for the given index.Iterator<V>
iterator()
V
put(V value)
Put a value into the map, replacing and returning any existing mapping.V
putIfAbsent(V value)
Put a value into the map if there is not already an existing mapping for it.boolean
remove(Object value)
V
removeKey(int index)
Remove and return a value for the given index.V
replace(V value)
Put a value into the map only if there is an existing mapping for it.boolean
replace(V oldValue, V newValue)
Replace an old value with a new value.int
size()
Object[]
toArray()
<T> T[]
toArray(T[] a)
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, removeAll, retainAll, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray
-
-
-
-
Constructor Detail
-
IntIndexHashMap
public IntIndexHashMap(ToIntFunction<? super V> indexer, Equaller<? super V> valueEqualler, int initialCapacity, float loadFactor)
Construct a new instance.- Parameters:
indexer
- the key indexervalueEqualler
- the value equallerinitialCapacity
- the initial capacityloadFactor
- the load factor
-
IntIndexHashMap
public IntIndexHashMap(ToIntFunction<? super V> indexer, Equaller<? super V> valueEqualler)
Construct a new instance.- Parameters:
indexer
- the key indexervalueEqualler
- the value equaller
-
IntIndexHashMap
public IntIndexHashMap(ToIntFunction<? super V> indexer, int initialCapacity, float loadFactor)
Construct a new instance.- Parameters:
indexer
- the key indexerinitialCapacity
- the initial capacityloadFactor
- the load factor
-
IntIndexHashMap
public IntIndexHashMap(ToIntFunction<? super V> indexer, float loadFactor)
Construct a new instance.- Parameters:
indexer
- the key indexerloadFactor
- the load factor
-
IntIndexHashMap
public IntIndexHashMap(ToIntFunction<? super V> indexer, int initialCapacity)
Construct a new instance.- Parameters:
indexer
- the key indexerinitialCapacity
- the initial capacity
-
IntIndexHashMap
public IntIndexHashMap(ToIntFunction<? super V> indexer)
Construct a new instance.- Parameters:
indexer
- the key indexer
-
-
Method Detail
-
putIfAbsent
public V putIfAbsent(V value)
Description copied from interface:IntIndexMap
Put a value into the map if there is not already an existing mapping for it.- Specified by:
putIfAbsent
in interfaceIntIndexMap<V>
- Parameters:
value
- the value to add- Returns:
- the existing value, if any, or
null
if the existing value wasnull
or the value was added successfully
-
computeIfAbsent
public V computeIfAbsent(int index, IntFunction<V> producer)
Description copied from interface:IntIndexMap
Compute a map value if no mapping exists.- Specified by:
computeIfAbsent
in interfaceIntIndexMap<V>
- Parameters:
index
- the keyproducer
- the producer which creates a new value- Returns:
- the existing or new value
-
removeKey
public V removeKey(int index)
Description copied from interface:IntIndexMap
Remove and return a value for the given index.- Specified by:
removeKey
in interfaceIntIndexMap<V>
- Parameters:
index
- the index- Returns:
- the value
-
remove
public boolean remove(Object value)
- Specified by:
remove
in interfaceCollection<V>
- Specified by:
remove
in interfaceIntIndexMap<V>
- Overrides:
remove
in classAbstractCollection<V>
-
containsKey
public boolean containsKey(int index)
Description copied from interface:IntIndexMap
Determine whether the given index is contained in the map.- Specified by:
containsKey
in interfaceIntIndexMap<V>
- Parameters:
index
- the index- Returns:
true
if it is contained in the map
-
get
public V get(int index)
Description copied from interface:IntIndexMap
Get the value for the given index.- Specified by:
get
in interfaceIntIndexMap<V>
- Parameters:
index
- the index- Returns:
- the corresponding value
-
put
public V put(V value)
Description copied from interface:IntIndexMap
Put a value into the map, replacing and returning any existing mapping.- Specified by:
put
in interfaceIntIndexMap<V>
- Parameters:
value
- the value to add- Returns:
- the old value, or
null
if the old value wasnull
or was not present
-
replace
public V replace(V value)
Description copied from interface:IntIndexMap
Put a value into the map only if there is an existing mapping for it.- Specified by:
replace
in interfaceIntIndexMap<V>
- Parameters:
value
- the value to store- Returns:
- the previous value (may be
null
) ornull
if there was no mapping to replace
-
replace
public boolean replace(V oldValue, V newValue)
Description copied from interface:IntIndexMap
Replace an old value with a new value.- Specified by:
replace
in interfaceIntIndexMap<V>
- Parameters:
oldValue
- the value to replacenewValue
- the value to replace with- Returns:
true
if the replacement succeeded, orfalse
if the old value was not present in the map
-
applyAsInt
public int applyAsInt(V argument)
- Specified by:
applyAsInt
in interfaceToIntFunction<V>
-
add
public boolean add(V v)
- Specified by:
add
in interfaceCollection<V>
- Overrides:
add
in classAbstractCollection<V>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfaceCollection<V>
- Overrides:
toArray
in classAbstractCollection<V>
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<V>
- Overrides:
toArray
in classAbstractCollection<V>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<V>
- Overrides:
contains
in classAbstractCollection<V>
-
iterator
public Iterator<V> iterator()
- Specified by:
iterator
in interfaceCollection<V>
- Specified by:
iterator
in interfaceIterable<V>
- Specified by:
iterator
in classAbstractCollection<V>
-
size
public int size()
- Specified by:
size
in interfaceCollection<V>
- Specified by:
size
in classAbstractCollection<V>
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<V>
- Overrides:
clear
in classAbstractCollection<V>
-
-