Package one.pkg.tiny.utils
Class Collections
java.lang.Object
one.pkg.tiny.utils.Collections
The Collections class provides utility methods for creating optimized data structures
such as maps, sets, and lists.
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
(@NotNull Map<K, V> map, @NotNull 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 newList
instance with the specified initial size.static <T> List<T>
newArrayList
(@NotNull Iterable<? extends T> elements) Creates a newArrayList
containing the elements from the providedIterable
.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 Iterator<? extends T> elements) Creates a newList
containing all elements from the givenIterator
.static <T> List<T>
newArrayList
(@NotNull T... elements) Creates a new array-backedList
containing the provided elements.Creates and returns a new list to store Boolean values.newBooleanArrayList
(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new list of Booleans with the specified initial capacity.newBooleanArrayList
(boolean... initialValues) Creates a new list of Boolean objects initialized with the provided boolean values.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 newMap
instance with keys of typeK
and boolean values.Creates and returns a new list of Byte elements.newByteArrayList
(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new list to hold Byte elements with the specified initial capacity.newByteArrayList
(byte... initialValues) Creates a new list of Byte objects initialized with the specified byte values.Creates and returns a new list of characters.newCharArrayList
(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates and returns a new list of Characters with the specified initial capacity.newCharArrayList
(char... initialValues) Creates a newList
ofCharacter
elements from the given array of primitivechar
values.Creates and returns a new instance of a list that stores Double values.newDoubleArrayList
(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new list capable of storing double values with the specified initial capacity.newDoubleArrayList
(double... initialValues) Creates a new list of Doubles initialized with the given double 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 typeK
and values of typeDouble
.Creates a new list of Float type.newFloatArrayList
(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new instance of a list to hold float values with the specified initial capacity.newFloatArrayList
(float... initialValues) Creates a new list of Floats containing the provided initial values.Creates a new map with keys of typeK
and values of typeFloat
.newFloatHashMap
(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new map with keys of generic typeK
andfloat
values.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.static <T> Set<T>
newHashSet
(@NotNull T... elements) Creates a new HashSet containing the provided elements.Creates and returns a new instance of a list that stores integers.newIntArrayList
(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new list of integers with the specified initial capacity.newIntArrayList
(int... initialValues) Creates a new list of integers initialized with the given values.Creates a new hash map that maps keys of typeK
to 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.static <K,
V> Map<K, V> Creates and returns a new instance of a LinkedHashMap.static <K,
V> Map<K, V> newLinkedHashMap
(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new LinkedHashMap with the specified initial capacity.static <K,
V> Map<K, V> newLinkedHashMap
(@NotNull Map<K, V> map) Creates a new LinkedHashMap or a fastutil Object2ObjectLinkedOpenHashMap based on the specified map.Creates a new list of Long type.newLongArrayList
(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new instance of a list that can hold Long objects with the specified initial capacity.newLongArrayList
(long... initialValues) Creates a new List of Longs initialized with the given long values.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 typeK
and values of typeLong
.Creates and returns a new instance of a list that can store Short objects.newShortArrayList
(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new list of Short objects with the specified initial capacity.newShortArrayList
(short... initialValues) Creates a new List of Short values, optionally initializing it with the provided short values.static <T> Set<T>
newTreeSet
(@NotNull 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 unmodifiableSet
that 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 typeK
to integer values.- Type Parameters:
K
- the type of keys maintained by this map- Returns:
- a new map that maps keys of type
K
to 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.- 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.- 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 typeK
and values of typeLong
.- 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 typeK
and values of typeFloat
.- Type Parameters:
K
- the type of keys in the map- Returns:
- a new map capable of storing keys of type
K
and 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 typeK
andfloat
values.- 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.- 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 typeK
and values of typeDouble
.- 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.- 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 newMap
instance with keys of typeK
and boolean values.- Parameters:
initialCapacity
- the initial capacity of the map; must be a non-negative integer.- Returns:
- a new
Map
instance with the specified initial capacity.
-
newHashMap
Creates and returns a new hash map with default settings.- 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.- 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
-
newLinkedHashMap
Creates and returns a new instance of a LinkedHashMap.- Type Parameters:
K
- the type of keys maintained by the mapV
- the type of values stored in the map- Returns:
- a new instance of a map, either LinkedHashMap or Object2ObjectLinkedOpenHashMap
-
newLinkedHashMap
Creates a new LinkedHashMap or a fastutil Object2ObjectLinkedOpenHashMap based on the specified map.- Parameters:
map
- the input map whose entries are to be copied to the newly created map; must not be null- Returns:
- a new map containing the entries from the given map, maintaining insertion order
-
newLinkedHashMap
public static <K,V> Map<K,V> newLinkedHashMap(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new LinkedHashMap with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the map, must be non-negative and within the valid range.- Returns:
- a new instance of a map implementing LinkedHashMap with the specified initial capacity.
-
newHashSet
Creates a new empty HashSet instance.- Type Parameters:
T
- the type of elements maintained by the set.- Returns:
- a new empty
Set
instance.
-
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
-
newHashSet
Creates a new HashSet containing the provided elements.- Parameters:
elements
- the elements to be added to the new HashSet; must not be null- Returns:
- a new HashSet containing the specified elements
-
newUnmodifiableHashSet
Creates a new unmodifiable empty set.- 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 unmodifiableSet
that 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.
-
newTreeSet
Creates a new TreeSet with the elements provided in the specified collection. Depending on the context, either aTreeSet
or aObjectAVLTreeSet
from 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.- 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.- 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
-
newIntArrayList
Creates and returns a new instance of a list that stores integers.- Returns:
- a new list instance for storing integers, either an IntArrayList or an ArrayList based on the 'fastutil' flag.
-
newIntArrayList
Creates a new list of integers initialized with the given values.- Parameters:
initialValues
- the integer values to initialize the list with- Returns:
- a new list of integers containing the provided initial values
-
newIntArrayList
public static List<Integer> newIntArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new list of integers with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the list, must be non-negative- Returns:
- a new instance of a list of integers with the specified initial capacity
-
newLongArrayList
Creates a new list of Long type.- Returns:
- a new list of Long elements, using a specific implementation based on the configuration.
-
newLongArrayList
Creates a new List of Longs initialized with the given long values.- Parameters:
initialValues
- an optional list of long values to initialize the list with- Returns:
- a new List of Longs containing the given initial values
-
newLongArrayList
public static List<Long> newLongArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new instance of a list that can hold Long objects with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the list. Must be a non-negative integer value.- Returns:
- a List of Long objects with the specified initial capacity.
-
newFloatArrayList
Creates a new list of Float type.- Returns:
- a new list of Float type, using the specified implementation based on the 'fastutil' flag.
-
newFloatArrayList
Creates a new list of Floats containing the provided initial values.- Parameters:
initialValues
- an array of float values to initialize the list with- Returns:
- a List of Float containing the provided initial values
-
newFloatArrayList
public static List<Float> newFloatArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new instance of a list to hold float values with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the list. Must be a non-negative integer.- Returns:
- a list capable of storing float values, utilizing either a FastUtil implementation or a standard ArrayList based on the configuration.
-
newDoubleArrayList
Creates and returns a new instance of a list that stores Double values.- Returns:
- a new list for storing Double values, either a FastUtil `DoubleArrayList` or a Java `ArrayList`
-
newDoubleArrayList
Creates a new list of Doubles initialized with the given double values.- Parameters:
initialValues
- an array of double values to initialize the list- Returns:
- a new list containing the given double values
-
newDoubleArrayList
public static List<Double> newDoubleArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new list capable of storing double values with the specified initial capacity.- Parameters:
initialCapacity
- the initial size of the list, must be a non-negative integer.- Returns:
- a new instance of a list that can contain double values, using FastUtil's implementation if available, otherwise a standard ArrayList.
-
newBooleanArrayList
Creates and returns a new list to store Boolean values.- Returns:
- a new list instance for storing Boolean values, either a FastUtil BooleanArrayList or a standard ArrayList, depending on the fastutil flag.
-
newBooleanArrayList
Creates a new list of Boolean objects initialized with the provided boolean values.- Parameters:
initialValues
- the initial boolean values to populate the list with- Returns:
- a list of Boolean objects containing the specified initial values
-
newBooleanArrayList
public static List<Boolean> newBooleanArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new list of Booleans with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the list; must be non-negative.- Returns:
- a new instance of a list of Booleans with the specified initial capacity.
-
newByteArrayList
Creates and returns a new list of Byte elements. -
newByteArrayList
Creates a new list of Byte objects initialized with the specified byte values.- Parameters:
initialValues
- the initial byte values to populate the list- Returns:
- a new List of Byte objects containing the specified values
-
newByteArrayList
public static List<Byte> newByteArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new list to hold Byte elements with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the list, must be between 0 and Integer.MAX_VALUE inclusive- Returns:
- a new list capable of holding Byte elements with the specified initial capacity
-
newShortArrayList
Creates and returns a new instance of a list that can store Short objects.- Returns:
- A new list for storing Short objects, either a fastutil ShortArrayList or a standard ArrayList.
-
newShortArrayList
Creates a new List of Short values, optionally initializing it with the provided short values.- Parameters:
initialValues
- an optional array of short values to initialize the list with- Returns:
- a List containing the initial short values, or an empty list if no values are provided
-
newShortArrayList
public static List<Short> newShortArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates a new list of Short objects with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the list; must be a non-negative value.- Returns:
- a new List of Short objects with the specified initial capacity.
-
newCharArrayList
Creates and returns a new list of characters.- Returns:
- a new list of characters, either a `CharArrayList` or an `ArrayList` depending on the `fastutil` flag.
-
newCharArrayList
Creates a newList
ofCharacter
elements from the given array of primitivechar
values.- Parameters:
initialValues
- an array of primitivechar
values to initialize the list with- Returns:
- a new
List
containing the providedchar
values asCharacter
objects
-
newCharArrayList
public static List<Character> newCharArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int initialCapacity) Creates and returns a new list of Characters with the specified initial capacity.- Parameters:
initialCapacity
- the initial capacity of the list, must be a non-negative integer.- Returns:
- a new list of Characters with the specified initial capacity.
-
newArrayList
public static <T> List<T> newArrayList(@org.jetbrains.annotations.Range(from=0L, to=2147483647L) int size) Creates a newList
instance with the specified initial size.- 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-backedList
containing the provided elements.- 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
List
containing 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
-
newArrayList
Creates a newArrayList
containing the elements from the providedIterable
. If theIterable
is aCollection
, it leverages its properties to create the list more efficiently.- Type Parameters:
T
- the type of elements in the list- Parameters:
elements
- theIterable
whose elements are to be placed into the new list; must not be null- Returns:
- a new
ArrayList
containing the elements from the providedIterable
-
newArrayList
Creates a newList
containing all elements from the givenIterator
.- Type Parameters:
T
- the type of elements in the list- Parameters:
elements
- anIterator
containing elements to be added to the list- Returns:
- a new
List
containing all the elements from the givenIterator
-
entryForEach
public static <K,V> void entryForEach(@NotNull @NotNull Map<K, V> map, @NotNull @NotNull Consumer<? super Map.Entry<K, V>> consumer) Iterates over each entry in the provided map and applies the given consumer action to each entry.- 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
public static <K,V> boolean removeIf(@NotNull @NotNull Map<K, V> map, @NotNull @NotNull Predicate<? super Map.Entry<K, V>> filter) Removes all entries from the specified map that satisfy the provided predicate.- 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:
true
if any entries were removed from the map, otherwisefalse
-