Package org.opendaylight.yangtools.util
Class CollectionWrappers
- java.lang.Object
-
- org.opendaylight.yangtools.util.CollectionWrappers
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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 Detail
-
wrapAsList
public static <E> List<E> wrapAsList(Collection<E> collection)
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.- Parameters:
collection
- Collection to be wrapped- Returns:
- An effectively-immutable wrapper of the collection.
- Throws:
NullPointerException
- if collection is null
-
wrapAsSet
public static <E> Set<E> wrapAsSet(Collection<E> collection)
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.- 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
-
-