Package com.linkedin.venice.utils
Class CollectionUtils
- java.lang.Object
-
- com.linkedin.venice.utils.CollectionUtils
-
public class CollectionUtils extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CollectionUtils.MapBuilder<K,V>
-
Constructor Summary
Constructors Constructor Description CollectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<java.lang.Float>
asUnmodifiableList(float[] array)
static java.util.Map<java.lang.String,java.lang.String>
convertCharSequenceMapToStringMap(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> charSequenceMap)
static java.util.Map<java.lang.CharSequence,java.lang.CharSequence>
convertStringMapToCharSequenceMap(java.util.Map<java.lang.String,java.lang.String> stringMap)
static java.util.Map<java.lang.CharSequence,java.lang.CharSequence>
getCharSequenceMapFromStringMap(java.util.Map<java.lang.String,java.lang.String> stringStringMap)
static java.util.Map<java.lang.String,java.lang.CharSequence>
getStringKeyCharSequenceValueMapFromStringMap(java.util.Map<java.lang.String,java.lang.String> stringMap)
static java.util.Map<java.lang.String,java.lang.String>
getStringMapFromCharSequenceMap(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> charSequenceMap)
static <T> boolean
listEquals(java.util.List<T> list1, java.util.List<T> list2)
A manual implementation of list equality.static <K,V>
CollectionUtils.MapBuilder<K,V>mapBuilder()
static <T> java.util.List<T>
reversed(java.util.Collection<T> collection)
A reversed copy of the given collectionstatic <T> java.util.Set<T>
setOf(java.util.Collection<T> values)
static <T> java.util.Set<T>
setOf(T value)
static <T> java.util.Set<T>
setOf(T... values)
static <K,V>
java.util.Map<K,V>substituteEmptyMap(java.util.Map<K,V> map)
This function can be useful when we want: - To ensure a map is not null.
-
-
-
Method Detail
-
listEquals
public static <T> boolean listEquals(java.util.List<T> list1, java.util.List<T> list2)
A manual implementation of list equality. This is (unfortunately) useful with Avro lists since they do not work reliably. There are cases where aList
coming out of an Avro record will be implemented as aGenericData.Array
and other times it will be a javaArrayList
. When this happens, the equality check fails...- Returns:
- true if both lists have the same items in the same order
-
asUnmodifiableList
public static java.util.List<java.lang.Float> asUnmodifiableList(float[] array)
-
reversed
public static <T> java.util.List<T> reversed(java.util.Collection<T> collection)
A reversed copy of the given collection- Type Parameters:
T
- The type of the items in the list- Parameters:
collection
- The collection to reverse- Returns:
- The list, reversed
-
getCharSequenceMapFromStringMap
public static java.util.Map<java.lang.CharSequence,java.lang.CharSequence> getCharSequenceMapFromStringMap(java.util.Map<java.lang.String,java.lang.String> stringStringMap)
-
getStringKeyCharSequenceValueMapFromStringMap
public static java.util.Map<java.lang.String,java.lang.CharSequence> getStringKeyCharSequenceValueMapFromStringMap(java.util.Map<java.lang.String,java.lang.String> stringMap)
-
getStringMapFromCharSequenceMap
public static java.util.Map<java.lang.String,java.lang.String> getStringMapFromCharSequenceMap(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> charSequenceMap)
-
convertStringMapToCharSequenceMap
public static java.util.Map<java.lang.CharSequence,java.lang.CharSequence> convertStringMapToCharSequenceMap(java.util.Map<java.lang.String,java.lang.String> stringMap)
-
convertCharSequenceMapToStringMap
public static java.util.Map<java.lang.String,java.lang.String> convertCharSequenceMapToStringMap(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> charSequenceMap)
-
substituteEmptyMap
public static <K,V> java.util.Map<K,V> substituteEmptyMap(java.util.Map<K,V> map)
This function can be useful when we want: - To ensure a map is not null. - To avoid hanging on to many references of empty maps (as opposed to the singletonCollections.EMPTY_MAP
).- Parameters:
map
- to be returned if populated, or substituted if null or empty- Returns:
- a non-null map with the same content (though not necessarily the same identity) as the input map
-
mapBuilder
public static <K,V> CollectionUtils.MapBuilder<K,V> mapBuilder()
-
setOf
public static <T> java.util.Set<T> setOf(T value)
-
setOf
@SafeVarargs public static <T> java.util.Set<T> setOf(T... values)
-
setOf
public static <T> java.util.Set<T> setOf(java.util.Collection<T> values)
-
-