Package org.bsc.langgraph4j.utils
Class CollectionsUtils
java.lang.Object
org.bsc.langgraph4j.utils.CollectionsUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> Map.Entry <K, V> entryOf(K key, V value) create an entry that accept null valuestatic <T> Optional<T> Returns the value at the specified position from the end of the list, if present.static <T> Optional<T> Returns the last value in the list, if present.static <T> List<T> Deprecated, for removal: This API element is subject to removal in a future version.static <T> List<T> listOf(T... objects) Creates a list containing the provided elements.static <K,V> Map <K, V> mapOf()Creates an empty map.static <K,V> Map <K, V> mapOf(K k1, V v1) Creates a map containing a single key-value pair.static <K,V> Map <K, V> mapOf(K k1, V v1, K k2, V v2) Creates a map containing two key-value pairs.static <K,V> Map <K, V> mapOf(K k1, V v1, K k2, V v2, K k3, V v3) Creates a map containing three key-value pairs.static <K,V> Map <K, V> mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) Creates a map containing three key-value pairs.static <K,V> Map <K, V> mapOf(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) Creates a map containing three key-value pairs.static <K,V> Map <K, V> Merges two maps into a new map, doesn't accept duplicates.static <K,V> Map <K, V> mergeMap(Map<K, V> map1, Map<K, V> map2, BinaryOperator<V> mergeFunction) Merges two maps into a new map, resolving key collisions using the specified merge function.static StringtoString(Collection<?> collection) static String
-
Constructor Details
-
CollectionsUtils
public CollectionsUtils()
-
-
Method Details
-
toString
-
toString
-
lastOf
-
lastMinus
Returns the value at the specified position from the end of the list, if present.- Parameters:
n- the position from the end of the list- Returns:
- an Optional containing the value at the specified position if present, otherwise an empty Optional
-
mergeMap
Merges two maps into a new map, doesn't accept duplicates.- Type Parameters:
K- the type of the keys in the mapsV- the type of the values in the maps- Parameters:
map1- the first mapmap2- the second map- Returns:
- a new map containing all entries from both maps, collisions result in error
- Throws:
NullPointerException- if both maps are null
-
mergeMap
public static <K,V> Map<K,V> mergeMap(Map<K, V> map1, Map<K, V> map2, BinaryOperator<V> mergeFunction) Merges two maps into a new map, resolving key collisions using the specified merge function.- Type Parameters:
K- the type of the keys in the mapsV- the type of the values in the maps- Parameters:
map1- the first mapmap2- the second mapmergeFunction- the function used to resolve collisions between values associated with the same key- Returns:
- a new map containing all entries from both maps, with collisions resolved by the merge function
- Throws:
NullPointerException- if both maps are null
-
entryOf
create an entry that accept null value- Parameters:
key- – the key represented by this entryvalue- – the value represented by this entry- Returns:
- new entry
Type parameters:
– the type of the key – the type of the value
-
listOf
Deprecated, for removal: This API element is subject to removal in a future version. -
listOf
Creates a list containing the provided elements. It allows null values.- Type Parameters:
T- the type of the elements- Parameters:
objects- the elements to be included in the list- Returns:
- a list containing the provided elements
-
mapOf
Creates an empty map. It allows null values.- Type Parameters:
K- the type of the keysV- the type of the values- Returns:
- an empty map
-
mapOf
Creates a map containing a single key-value pair. It allows null values.- Type Parameters:
K- the type of the keyV- the type of the value- Parameters:
k1- the keyv1- the value- Returns:
- an unmodifiable map containing the provided key-value pair
-
mapOf
Creates a map containing two key-value pairs. It allows null values.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
k1- the first keyv1- the first valuek2- the second keyv2- the second value- Returns:
- an unmodifiable map containing the provided key-value pairs
-
mapOf
Creates a map containing three key-value pairs. It allows null values.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
k1- the first keyv1- the first valuek2- the second keyv2- the second valuek3- the third keyv3- the third value- Returns:
- an unmodifiable map containing the provided key-value pairs
-
mapOf
Creates a map containing three key-value pairs. It allows null values.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
k1- the first keyv1- the first valuek2- the second keyv2- the second valuek3- the third keyv3- the third valuek4- the fourth keyv4- the fourth value@- Returns:
- an unmodifiable map containing the provided key-value pairs
-
mapOf
Creates a map containing three key-value pairs. It allows null values.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
k1- the first keyv1- the first valuek2- the second keyv2- the second valuek3- the third keyv3- the third valuek4- the fourth keyv4- the fourth value@k5- the fifth keyv5- the fifth value@- Returns:
- an unmodifiable map containing the provided key-value pairs
-