Package edu.wpi.first.units.collections
Class LongToObjectHashMap<V>
java.lang.Object
edu.wpi.first.units.collections.LongToObjectHashMap<V>
- Type Parameters:
V
- the type of the values stored in the map
public class LongToObjectHashMap<V> extends Object
A variant on
java.util.HashMap<K, V>
that uses primitive long ints for map keys instead
of autoboxed Long objects like would be used for a Map<Long, V>
.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
LongToObjectHashMap.IteratorFunction<V>
Interface for map iterator function. -
Constructor Summary
Constructors Constructor Description LongToObjectHashMap()
Default constructor. -
Method Summary
Modifier and Type Method Description void
clear()
Clears and removes all entries from the map.boolean
containsKey(long key)
Checks if a key is contained in the map.void
forEach(LongToObjectHashMap.IteratorFunction<? super V> function)
Iterates over every key-value pair in the map and passes them to the given function.V
get(long key)
Gets the value associated with the given key.boolean
isEmpty()
Checks if the map contains any entries.ReadOnlyPrimitiveLongSet
keySet()
Gets the keys contained in the map.V
put(long key, V value)
Puts a valuevalue
corresponding to keykey
in the map.V
remove(long key)
Removes the value associated with the given key and returns it.int
size()
Gets the number of key-value pairs currently contained in the map.Collection<V>
values()
Gets the values contained in the map.
-
Constructor Details
-
LongToObjectHashMap
public LongToObjectHashMap()Default constructor.
-
-
Method Details
-
put
Puts a valuevalue
corresponding to keykey
in the map.- Parameters:
key
- the associated keyvalue
- the value to insert- Returns:
- the previous value that was mapped to the key, or null if no such value existed
-
get
Gets the value associated with the given key.- Parameters:
key
- the key to retrieve the value for- Returns:
- the value mapped to the key, or null if the key is not in the map
-
remove
Removes the value associated with the given key and returns it.- Parameters:
key
- the key to remove- Returns:
- the value corresponding to the key, or null if the key is not in the map
-
containsKey
Checks if a key is contained in the map.- Parameters:
key
- the key to check- Returns:
- true if the key has an associated value, false if not
-
clear
Clears and removes all entries from the map. -
size
Gets the number of key-value pairs currently contained in the map.- Returns:
- the current size of the map
-
isEmpty
Checks if the map contains any entries.- Returns:
- true if at least one entry is present, false otherwise
-
keySet
Gets the keys contained in the map. Ordering is not guaranteed. The returned set is read-only and immutable. This uses a custom class for primitive long values to avoid unnecessary autoboxing tojava.lang.Long
.- Returns:
- a read-only set of keys
-
values
Gets the values contained in the map. Ordering is not guaranteed. The returned collection is read-only and immutable.- Returns:
- a read-only collection of values
-
forEach
Iterates over every key-value pair in the map and passes them to the given function.- Parameters:
function
- the function to apply to every key-value pair.
-