Package org.opendaylight.yangtools.util
Class CollectionWrappers
java.lang.Object
org.opendaylight.yangtools.util.CollectionWrappers
- Author:
- Robert Varga
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> List
<E> wrapAsList
(Collection<E> collection) Wrap the specifiedCollection
as aList
.static <E> Set
<E> wrapAsSet
(Collection<E> collection) Wrap the specifiedCollection
as aSet
.
-
Method Details
-
wrapAsList
Wrap the specifiedCollection
as aList
. If the collection is already a List, it is wrapped in aCollections.unmodifiableList(List)
to prevent mutability leaking. If the collection is determined to be empty, an empty list is returned instead. If the collection is a known-immutable implementation of List interface, it is returned unwrapped. Backing collection is required to be effectively immutable. If this requirement is violated, the returned object may behave in unpredictable ways.- Type Parameters:
E
- the type of elements in the collection- Parameters:
collection
- Collection to be wrapped- Returns:
- An effectively-immutable wrapper of the collection.
- Throws:
NullPointerException
- if collection is null
-
wrapAsSet
Wrap the specifiedCollection
as aSet
. If the collection is already a Set, it is wrapped in aCollections.unmodifiableSet(Set)
to prevent mutability leaking. If the collection is determined to be empty, an empty set is returned instead. If the collection is a known-immutable implementation of Set interface, it is returned unwrapped. The collection is checked for duplicates at instantiation time, such that it effectively implements the Set contract. Backing collection is required to be effectively immutable. If this requirement is violated, the returned object may behave in unpredictable ways.- Type Parameters:
E
- the type of elements in the collection- Parameters:
collection
- Collection to be wrapped- Returns:
- An effectively-immutable wrapper of the collection.
- Throws:
NullPointerException
- if collection is null or any of its elements is nullIllegalArgumentException
- if the collection's contents do not conform to the Set contract
-