Class Collections
It dynamically determines whether to use the optimized implementations from the FastUtil library or standard Java collections based on the availability of FastUtil classes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> void entryForEach(Map<K, V> map, Consumer<? super Map.Entry<K, V>> consumer) Iterates over each entry in the provided map and applies the given consumer action to each entry.static <T> List<T>Creates a new empty list instance.static <T> List<T>newArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int size) Creates a newListinstance with the specified initial size.static <T> List<T>newArrayList(@NotNull Collection<? extends T> elements) Creates a new list containing the elements from the specified collection.static <T> List<T>newArrayList(@NotNull T... elements) Creates a new array-backedListcontaining the provided elements.Creates and returns a new Map instance where the values are of type Boolean.newBooleanHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a newMapinstance with keys of typeKand boolean values.Creates a new map with generic keys and double values.newDoubleHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new hash map with keys of typeKand values of typeDouble.Creates a new map with keys of typeKand values of typeFloat.newFloatHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new map with keys of generic typeKandfloatvalues.static <K,V> Map<K, V> Creates and returns a new hash map with default settings.static <K,V> Map<K, V> newHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new hash map with the specified initial capacity.static <K,V> Map<K, V> newHashMap(@NotNull Map<K, V> map) Creates a new HashMap instance and populates it with the entries from the provided map.static <T> Set<T>Creates a new empty HashSet instance.static <T> Set<T>newHashSet(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new hash set with the specified initial capacity.Creates a new hash map that maps keys of typeKto integer values.newIntHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new hash map where keys are of type K and values are of type Integer.Creates and returns a new map instance where the keys are of generic type K, and the values are of type Long.newLongHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new hash map with keys of typeKand values of typeLong.static <T> Set<T>newTreeSet(Collection<? extends T> c) Creates a new TreeSet with the elements provided in the specified collection.static <T> Set<T>newTreeSetRB(@NotNull Collection<? extends T> c) Creates a new TreeSet instance with the elements provided in the specified collection.static <T> Set<T>Creates a new unmodifiable empty set.static <T> Set<T>newUnmodifiableHashSet(@NotNull Set<T> set) Creates a new unmodifiable hash set containing the elements of the provided set.static <T> Set<T>newUnmodifiableHashSet(@NotNull T... elements) Creates a new unmodifiableSetthat contains the specified elements.static <T> List<T>Creates a new unmodifiable list.static <T> List<T>newUnmodifiableList(@NotNull List<T> list) Creates a new unmodifiable list from the provided list.static <T> List<T>newUnmodifiableList(@NotNull T... elements) Creates a new unmodifiable list containing the specified elements.static <K,V> boolean Removes all entries from the specified map that satisfy the provided predicate.
-
Constructor Details
-
Collections
public Collections()
-
-
Method Details
-
newIntHashMap
Creates a new hash map that maps keys of typeKto integer values.Depending on the configuration, the implementation may use either
Object2IntOpenHashMapfrom fastutil orHashMapfrom Java's standard library.- Type Parameters:
K- the type of keys maintained by this map- Returns:
- a new map that maps keys of type
Kto integers
-
newIntHashMap
public static <K> Map<K,Integer> newIntHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new hash map where keys are of type K and values are of type Integer.Depending on the underlying configuration, this method may create either a HashMap instance or a fastutil Object2IntOpenHashMap instance.
- Parameters:
initialCapacity- the initial capacity of the hash map. Must be a non-negative integer.- Returns:
- a new map instance with keys of type K and values of type Integer.
-
newLongHashMap
Creates and returns a new map instance where the keys are of generic type K, and the values are of type Long.The specific implementation of the map depends on the runtime evaluation of the `fastutil` flag.
If `fastutil` is true, the map will be an instance of `it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap`.
Otherwise, it will fall back to a standard Java `HashMap`.
- Type Parameters:
K- the type of keys maintained by the map- Returns:
- a newly created map with generic key type K and Long values
-
newLongHashMap
public static <K> Map<K,Long> newLongHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new hash map with keys of typeKand values of typeLong.Optionally utilizes a specialized implementation for performance optimization if the
fastutilflag is enabled.- Type Parameters:
K- the type of keys to be used in the map- Parameters:
initialCapacity- the initial capacity of the hash map; must be greater than or equal to 0- Returns:
- a new hash map instance with the specified initial capacity, either using a specialized
implementation or a standard
HashMap
-
newFloatHashMap
Creates a new map with keys of typeKand values of typeFloat.This method returns an instance of either
Object2FloatOpenHashMaporHashMap, based on the runtime environment configuration. It is designed to optimize performance when handling float values as map entries.- Type Parameters:
K- the type of keys in the map- Returns:
- a new map capable of storing keys of type
Kand values of typeFloat
-
newFloatHashMap
public static <K> Map<K,Float> newFloatHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new map with keys of generic typeKandfloatvalues.The initial capacity of the map is specified by the provided parameter.
This method switches between using a FastUtil implementation or a standard Java HashMap depending on the underlying configuration.
- Type Parameters:
K- the type of keys maintained by the map- Parameters:
initialCapacity- the initial capacity of the map; must be non-negative- Returns:
- a new map instance with the respective initial capacity
-
newDoubleHashMap
Creates a new map with generic keys and double values.If the `fastutil` flag is true, an instance of `Object2DoubleOpenHashMap` from the FastUtil library is returned. Otherwise, a standard Java `HashMap` is created.
- Type Parameters:
K- the type of keys maintained by this map- Returns:
- a new map with keys of type K and values of type Double
-
newDoubleHashMap
public static <K> Map<K,Double> newDoubleHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new hash map with keys of typeKand values of typeDouble.The map's initial capacity is specified by the parameter.
Depending on the internal configuration, it either creates an instance of
Object2DoubleOpenHashMapfrom the FastUtil library or a standardHashMap.- Parameters:
initialCapacity- the initial capacity of the map. Must be a non-negative integer.- Returns:
- a new map of type
Map<K, Double>with the specified initial capacity.
-
newBooleanHashMap
Creates and returns a new Map instance where the values are of type Boolean.The type of Map implementation used depends on the value of the `fastutil` field:
- If `fastutil` is true, an instance of `it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap` is returned.
- If `fastutil` is false, a standard `HashMap` is returned.
- Type Parameters:
K- the type of the keys in the map- Returns:
- a new Map instance with Boolean values
-
newBooleanHashMap
public static <K> Map<K,Boolean> newBooleanHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a newMapinstance with keys of typeKand boolean values.Allows specifying the initial capacity for the map to optimize performance.
If the `fastutil` flag is enabled, it uses a `Object2BooleanOpenHashMap` from the fastutil library; otherwise, it defaults to using a standard
HashMap.- Parameters:
initialCapacity- the initial capacity of the map; must be a non-negative integer.- Returns:
- a new
Mapinstance with the specified initial capacity.
-
newHashMap
Creates and returns a new hash map with default settings.The implementation of the hash map may vary based on internal configuration.
- Type Parameters:
K- the type of keys maintained by this mapV- the type of mapped values- Returns:
- a new instance of a hash map
-
newHashMap
public static <K,V> Map<K,V> newHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new hash map with the specified initial capacity.- Parameters:
initialCapacity- the initial capacity of the hash map; must be a non-negative integer- Returns:
- a new instance of a hash map with the given initial capacity
-
newHashMap
Creates a new HashMap instance and populates it with the entries from the provided map.Depending on the configuration, it will use either a standard HashMap or a fastutil-specific Object2ObjectOpenHashMap implementation.
- Parameters:
map- the map whose entries are to be added to the newly created map; must not be null- Returns:
- a new map containing all entries from the provided map
-
newHashSet
Creates a new empty HashSet instance.Depending on the configuration, this method returns either an instance of
it.unimi.dsi.fastutil.objects.ObjectOpenHashSetif the fastutil optimization is enabled, or a standardjava.util.HashSetotherwise.- Type Parameters:
T- the type of elements maintained by the set.- Returns:
- a new empty
Setinstance.
-
newUnmodifiableHashSet
Creates a new unmodifiable empty set. The implementation of the set may vary depending on the internal configuration.- Type Parameters:
T- the type of elements that the set can hold- Returns:
- a new unmodifiable empty set
-
newUnmodifiableHashSet
Creates a new unmodifiable hash set containing the elements of the provided set.- Parameters:
set- the input set whose elements will be included in the new unmodifiable set; must not be null- Returns:
- an unmodifiable set containing the elements of the input set
-
newUnmodifiableHashSet
Creates a new unmodifiableSetthat contains the specified elements.- Parameters:
elements- the elements to be included in the set; cannot be null.- Returns:
- an unmodifiable set containing the specified elements.
-
newHashSet
public static <T> Set<T> newHashSet(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new hash set with the specified initial capacity.- Parameters:
initialCapacity- the initial capacity of the hash set; must be non-negative- Returns:
- a newly created hash set instance with the specified initial capacity
-
newTreeSet
Creates a new TreeSet with the elements provided in the specified collection. Depending on the context, either aTreeSetor aObjectAVLTreeSetfrom the fastutil library will be created and returned.- Type Parameters:
T- the type of elements maintained by the set- Parameters:
c- the collection whose elements are to be placed into the new set- Returns:
- a newly created TreeSet containing the elements from the provided collection
-
newTreeSetRB
Creates a new TreeSet instance with the elements provided in the specified collection. Depending on the configuration, it uses either a fastutil ObjectRBTreeSet or a standard TreeSet.- Type Parameters:
T- the type of elements maintained by the set- Parameters:
c- the collection whose elements are to be placed into the new set; must not be null- Returns:
- a newly created TreeSet containing all elements of the specified collection
-
newArrayList
Creates a new empty list instance. The implementation type of the list returned depends on the runtime configuration.- Type Parameters:
T- The type of elements that the list will hold.- Returns:
- A new instance of an empty
List.
-
newUnmodifiableList
Creates a new unmodifiable list. The implementation used for the unmodifiable list depends on whether the `fastutil` flag is enabled. If `fastutil` is true, it uses the `ObjectList.of()` from the FastUtil library. Otherwise, it uses `Collections.unmodifiableList` wrapping an empty `ArrayList`.- Type Parameters:
T- the type of elements in the list- Returns:
- a new unmodifiable list instance
-
newUnmodifiableList
Creates a new unmodifiable list from the provided list. The method ensures that the returned list is immutable and changes to the original list will not reflect in the new unmodifiable list.- Parameters:
list- the list from which the unmodifiable list is to be created; must not be null- Returns:
- an unmodifiable list containing the same elements as the provided list
-
newUnmodifiableList
Creates a new unmodifiable list containing the specified elements.- Type Parameters:
T- the type of elements in the list- Parameters:
elements- the elements to include in the unmodifiable list; must not be null- Returns:
- an unmodifiable list containing the provided elements
-
newArrayList
public static <T> List<T> newArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int size) Creates a newListinstance with the specified initial size. Depending on the configuration, it uses either a fastutil-backed implementation or a standardArrayList.- Type Parameters:
T- The type of elements the list will contain.- Parameters:
size- The initial size of the list. Must be greater than or equal to 0.- Returns:
- A new list instance with the specified size.
-
newArrayList
Creates a new array-backedListcontaining the provided elements. The returned list may be an instance of a more specialized implementation depending on the runtime configuration.- Type Parameters:
T- the type of elements in the list- Parameters:
elements- the elements to include in the new list; must not be null- Returns:
- a new
Listcontaining the specified elements
-
newArrayList
Creates a new list containing the elements from the specified collection.- Parameters:
elements- the collection whose elements are to be placed into the new list, must not be null- Returns:
- a new list containing the elements from the specified collection
-
entryForEach
Iterates over each entry in the provided map and applies the given consumer action to each entry. If the map is an instance of a fastutil Object2ObjectOpenHashMap, it uses optimized iteration, otherwise defaults to standard map entry iteration.- Type Parameters:
K- the type of keys maintained by the mapV- the type of mapped values- Parameters:
map- the map whose entries are to be processedconsumer- the action to be performed for each map entry
-
removeIf
Removes all entries from the specified map that satisfy the provided predicate. If the map is an instance ofObject2ObjectOpenHashMapfrom FastUtil, it utilizes the optimized removal method for that implementation; otherwise, it defaults to the standard Java map implementation.- Parameters:
map- the map from which entries are to be removed based on the given predicatefilter- the predicate that tests each entry; entries that satisfy this predicate are removed- Returns:
trueif any entries were removed from the map, otherwisefalse
-