Package com.yahoo.collections
Class CollectionUtil
java.lang.Object
com.yahoo.collections.CollectionUtil
Utilities for java collections
- Author:
- Tony Vaagenes, gjoranv
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
equalContentsIgnoreOrder
(Collection<?> c1, Collection<?> c2) Returns true if the contents of the two given collections are equal, ignoring order.static <T> Collection<T>
filter
(Collection<?> collection, Class<T> lowerBound) Returns the subset of elements from the given collection that can be cast to the reference type, defined by the given Class object.static <T> T
first
(Collection<T> collection) Returns the first element in a collection according to iteration order.static <T> Optional<T>
firstMatching
(T[] array, Predicate<? super T> predicate) static String
mkString
(Collection<?> collection, String sep) Returns a String containing the string representation of all elements from the given collection, separated by the separator string.static <T> String
mkString
(Collection<T> collection, String start, String sep, String end) Returns a String containing the string representation of all elements from the given collection, using a start string, separator strings, and an end string.static <T> Set<T>
symmetricDifference
(Collection<? extends T> c1, Collection<? extends T> c2) Returns the symmetric difference between two collections, i.e.
-
Constructor Details
-
CollectionUtil
public CollectionUtil()
-
-
Method Details
-
mkString
Returns a String containing the string representation of all elements from the given collection, separated by the separator string.- Parameters:
collection
- The collectionsep
- The separator string- Returns:
- A string: elem(0) + sep + ... + elem(N)
-
mkString
Returns a String containing the string representation of all elements from the given collection, using a start string, separator strings, and an end string.- Type Parameters:
T
- The element type- Parameters:
collection
- The collectionstart
- The start stringsep
- The separator stringend
- The end string- Returns:
- A string: start + elem(0) + sep + ... + elem(N) + end
-
equalContentsIgnoreOrder
Returns true if the contents of the two given collections are equal, ignoring order. -
symmetricDifference
public static <T> Set<T> symmetricDifference(Collection<? extends T> c1, Collection<? extends T> c2) Returns the symmetric difference between two collections, i.e. the set of elements that occur in exactly one of the collections. -
filter
Returns the subset of elements from the given collection that can be cast to the reference type, defined by the given Class object. -
first
Returns the first element in a collection according to iteration order. Returns null if the collection is empty. -
firstMatching
-