Package net.shibboleth.shared.collection
Class CollectionSupport
java.lang.Object
net.shibboleth.shared.collection.CollectionSupport
Support functions for Collection and Map Management.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>arrayAsList(T... a) Creates a mutable List from an array.static <T> List<T>copyToList(Collection<? extends T> coll) Copies a collection to a list with non-null guarantee.static <U,T> Map<U, T> Copies a map to a map with non-null guarantee.static <T> Set<T>copyToSet(Collection<? extends T> coll) Copies a collection to a set with non-null guarantee.static <T> List<T>Gets an empty list with non-null guarantee.static <T,U> Map<T, U> emptyMap()Gets an empty map with non-null guarantee.static <T> Set<T>emptySet()Gets an empty set with non-null guarantee.static <T> List<T>listOf()Gets a zero member list with non-null guarantee.static <T> List<T>listOf(T first) Gets a one member list with non-null guarantee.static <T> List<T>listOf(T... elements) Gets a list with non-null guarantee and a variable number of members.static <T> List<T>listOf(T first, T second) Gets a two member list with non-null guarantee.static <T,A, R> Collector<T, A, NonnullSupplier<R>> nonnullCollector(Collector<T, A, R> collector) Return a collector which collects to aNonnullSupplierwhose content is the value returned by the collector you were given.static <T> Set<T>setOf()Gets a zero member set with non-null guarantee.static <T> Set<T>setOf(T first) Gets a one member set with non-null guarantee.static <T> Set<T>setOf(T... elements) Gets a set with non-null guarantee and a variable number of members.static <T> Set<T>setOf(T first, T second) Gets a two member set with non-null guarantee.static <T> Set<T>singleton(T item) Gets a singleton set with non-null guarantee.static <T> List<T>singletonList(T item) Gets a singleton list with non-null guarantee.static <T,U> Map<T, U> singletonMap(T key, U value) Gets a singleton map with non-null guarantee.static <T> BinaryOperator<T>warningMergeFunction(String what, boolean takeFirst) Build something we can plug in intoCollectors.toMap(java.util.function.Function, java.util.function.Function, BinaryOperator).
-
Field Details
-
log
@Nonnull private static org.slf4j.Logger loglogger.
-
-
Constructor Details
-
CollectionSupport
private CollectionSupport()Constructor.
-
-
Method Details
-
warningMergeFunction
Build something we can plug in intoCollectors.toMap(java.util.function.Function, java.util.function.Function, BinaryOperator).- Type Parameters:
T- the type we'll be looking at- Parameters:
what- What we are building (i.e. IdpUI)takeFirst- do we want the first of the last to win.- Returns:
- an appropriate
BinaryOperator
-
nonnullCollector
public static <T,A, Collector<T,R> A, nonnullCollectorNonnullSupplier<R>> (Collector<T, A, R> collector) Return a collector which collects to aNonnullSupplierwhose content is the value returned by the collector you were given.- Type Parameters:
T- the type of input elements to the reduction operation of the collectorA- the mutable accumulation type of the reduction operation of the collector (often hidden as an implementation detail)R- the result type of the reduction operation of the collector- Parameters:
collector- the collector- Returns:
- the
NonnullSupplier.
-
emptyList
Gets an empty list with non-null guarantee.- Type Parameters:
T- list type- Returns:
- empty list
-
singletonList
Gets a singleton list with non-null guarantee.- Type Parameters:
T- list type- Parameters:
item- the single item- Returns:
- singleton list
-
listOf
Gets a zero member list with non-null guarantee.- Type Parameters:
T- list type- Returns:
- zero member list
-
listOf
Gets a one member list with non-null guarantee.- Type Parameters:
T- list type- Parameters:
first- the first item- Returns:
- a singleton list
-
listOf
@Nonnull @Unmodifiable @NotLive public static <T> List<T> listOf(@Nonnull T first, @Nonnull T second) Gets a two member list with non-null guarantee.- Type Parameters:
T- list type- Parameters:
first- the first itemsecond- the second item- Returns:
- two member list
-
listOf
@SafeVarargs @Nonnull @Unmodifiable @NotLive public static <T> List<T> listOf(@Nonnull T... elements) Gets a list with non-null guarantee and a variable number of members.- Type Parameters:
T- list type- Parameters:
elements- the elements- Returns:
- multi member list
-
copyToList
@Nonnull @Unmodifiable @NotLive public static <T> List<T> copyToList(@Nonnull Collection<? extends T> coll) Copies a collection to a list with non-null guarantee.- Type Parameters:
T- list type- Parameters:
coll- collection to copy- Returns:
- immutable copied list
-
emptySet
Gets an empty set with non-null guarantee.- Type Parameters:
T- set type- Returns:
- empty set
-
singleton
Gets a singleton set with non-null guarantee.- Type Parameters:
T- set type- Parameters:
item- the single item- Returns:
- singleton set
-
setOf
Gets a zero member set with non-null guarantee.- Type Parameters:
T- list type- Returns:
- zero member set
-
setOf
Gets a one member set with non-null guarantee.- Type Parameters:
T- list type- Parameters:
first- the first item- Returns:
- one member set
-
setOf
Gets a two member set with non-null guarantee.- Type Parameters:
T- list type- Parameters:
first- the first itemsecond- the second item- Returns:
- two member set
-
setOf
Gets a set with non-null guarantee and a variable number of members.- Type Parameters:
T- list type- Parameters:
elements- the elements- Returns:
- multi member set
-
copyToSet
@Nonnull @Unmodifiable @NotLive public static <T> Set<T> copyToSet(@Nonnull Collection<? extends T> coll) Copies a collection to a set with non-null guarantee.- Type Parameters:
T- set type- Parameters:
coll- collection to copy- Returns:
- immutable copied set
-
emptyMap
Gets an empty map with non-null guarantee.- Type Parameters:
T- key typeU- value type- Returns:
- empty amp
-
singletonMap
@Nonnull @Unmodifiable @NotLive public static <T,U> Map<T,U> singletonMap(@Nonnull T key, @Nullable U value) Gets a singleton map with non-null guarantee.- Type Parameters:
T- key typeU- value type- Parameters:
key- map keyvalue- map value- Returns:
- singleton amp
-
copyToMap
@Nonnull @Unmodifiable @NotLive public static <U,T> Map<U,T> copyToMap(@Nonnull Map<? extends U, ? extends T> map) Copies a map to a map with non-null guarantee.- Type Parameters:
U- key typeT- value type- Parameters:
map- map to copy- Returns:
- immutable copied map
-
arrayAsList
Creates a mutable List from an array.- Type Parameters:
T- the class of the objects in the array- Parameters:
a- the array by which the list will be backed- Returns:
- a list view of the specified array
- Throws:
NullPointerException- if the specified array isnull
-