Package it.unimi.dsi.fastutil.objects
Class Object2ObjectMaps
java.lang.Object
it.unimi.dsi.fastutil.objects.Object2ObjectMaps
public final class Object2ObjectMaps
extends java.lang.Object
A class providing static methods and objects that do useful things with type-specific maps.
- See Also:
Collections
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classObject2ObjectMaps.EmptyMap<K,V>An immutable class representing an empty type-specific map.static classObject2ObjectMaps.Singleton<K,V>An immutable class representing a type-specific singleton map.static classObject2ObjectMaps.SynchronizedMap<K,V>A synchronized wrapper class for maps.static classObject2ObjectMaps.UnmodifiableMap<K,V>An unmodifiable wrapper class for maps. -
Field Summary
Fields Modifier and Type Field Description static Object2ObjectMaps.EmptyMapEMPTY_MAPAn empty type-specific map (immutable). -
Method Summary
Modifier and Type Method Description static <K, V> Object2ObjectMap<K,V>emptyMap()Returns an empty map (immutable).static <K, V> voidfastForEach(Object2ObjectMap<K,V> map, java.util.function.Consumer<? super Object2ObjectMap.Entry<K,V>> consumer)Iterates quickly, if possible, on the entry set of the providedmap.static <K, V> ObjectIterable<Object2ObjectMap.Entry<K,V>>fastIterable(Object2ObjectMap<K,V> map)Returns an iterable yielding an iterator that will be fast, if possible, on the entry set of the providedmap.static <K, V> ObjectIterator<Object2ObjectMap.Entry<K,V>>fastIterator(Object2ObjectMap<K,V> map)Returns an iterator that will be fast, if possible, on the entry set of the providedmap.static <K, V> Object2ObjectMap<K,V>singleton(K key, V value)Returns a type-specific immutable map containing only the specified pair.static <K, V> Object2ObjectMap<K,V>synchronize(Object2ObjectMap<K,V> m)Returns a synchronized type-specific map backed by the given type-specific map.static <K, V> Object2ObjectMap<K,V>synchronize(Object2ObjectMap<K,V> m, java.lang.Object sync)Returns a synchronized type-specific map backed by the given type-specific map, using an assigned object to synchronize.static <K, V> Object2ObjectMap<K,V>unmodifiable(Object2ObjectMap<? extends K,? extends V> m)Returns an unmodifiable type-specific map backed by the given type-specific map.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
EMPTY_MAP
An empty type-specific map (immutable). It is serializable and cloneable.
-
-
Method Details
-
fastIterator
public static <K, V> ObjectIterator<Object2ObjectMap.Entry<K,V>> fastIterator(Object2ObjectMap<K,V> map)Returns an iterator that will be fast, if possible, on the entry set of the providedmap.- Parameters:
map- a map from which we will try to extract a (fast) iterator on the entry set.- Returns:
- an iterator on the entry set of the given map that will be fast, if possible.
- Since:
- 8.0.0
-
fastForEach
public static <K, V> void fastForEach(Object2ObjectMap<K,V> map, java.util.function.Consumer<? super Object2ObjectMap.Entry<K,V>> consumer)Iterates quickly, if possible, on the entry set of the providedmap.- Parameters:
map- a map on which we will try to iterate quickly.consumer- the consumer that will be passed toObject2ObjectMap.FastEntrySet.fastForEach(Consumer), if possible, or toIterable.forEach(Consumer).- Since:
- 8.1.0
-
fastIterable
public static <K, V> ObjectIterable<Object2ObjectMap.Entry<K,V>> fastIterable(Object2ObjectMap<K,V> map)Returns an iterable yielding an iterator that will be fast, if possible, on the entry set of the providedmap.- Parameters:
map- a map from which we will try to extract an iterable yielding a (fast) iterator on the entry set.- Returns:
- an iterable yielding an iterator on the entry set of the given map that will be fast, if possible.
- Since:
- 8.0.0
-
emptyMap
Returns an empty map (immutable). It is serializable and cloneable.This method provides a typesafe access to
EMPTY_MAP.- Returns:
- an empty map (immutable).
-
singleton
Returns a type-specific immutable map containing only the specified pair. The returned map is serializable and cloneable.Note that albeit the returned map is immutable, its default return value may be changed.
- Parameters:
key- the only key of the returned map.value- the only value of the returned map.- Returns:
- a type-specific immutable map containing just the pair
<key,value>.
-
synchronize
Returns a synchronized type-specific map backed by the given type-specific map.- Parameters:
m- the map to be wrapped in a synchronized map.- Returns:
- a synchronized view of the specified map.
- See Also:
Collections.synchronizedMap(Map)
-
synchronize
public static <K, V> Object2ObjectMap<K,V> synchronize(Object2ObjectMap<K,V> m, java.lang.Object sync)Returns a synchronized type-specific map backed by the given type-specific map, using an assigned object to synchronize.- Parameters:
m- the map to be wrapped in a synchronized map.sync- an object that will be used to synchronize the access to the map.- Returns:
- a synchronized view of the specified map.
- See Also:
Collections.synchronizedMap(Map)
-
unmodifiable
public static <K, V> Object2ObjectMap<K,V> unmodifiable(Object2ObjectMap<? extends K,? extends V> m)Returns an unmodifiable type-specific map backed by the given type-specific map.- Parameters:
m- the map to be wrapped in an unmodifiable map.- Returns:
- an unmodifiable view of the specified map.
- See Also:
Collections.unmodifiableMap(Map)
-