Package megamek.common.util
Class CollectionUtil
java.lang.Object
megamek.common.util.CollectionUtil
Some utility methods for Collections.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TanyOneElement(Collection<T> collection) static <T> Counter<T> \ Returns a hashmap that has the number of occurrence of each element on the liststatic <T> TtheElement(Collection<T> collection) Returns the only element of the collection.static <T> List<T> Returns a list that is the concatenation of the provided lists.
-
Method Details
-
union
Returns a list that is the concatenation of the provided lists. Does NOT do anything else (e.g. remove duplicate entries). -
counter
\ Returns a hashmap that has the number of occurrence of each element on the list- Parameters:
listOfElements- List of elements to count.- Returns:
- Map with the count of each element in the list.
-
anyOneElement
- Returns:
- One element (not randomly chosen) of the collection or the element if it has only one.
- Throws:
NoSuchElementException- if the collection is empty.
-
theElement
Returns the only element of the collection. Throws an IllegalArgument exception if the collection size is greater than 1. Throws a NoSuchElement exception if it is empty.
-