Class CollectionUtil

java.lang.Object
megamek.common.util.CollectionUtil

public final class CollectionUtil extends Object
Some utility methods for Collections.
  • Method Details

    • union

      public static <T> List<T> union(List<T> c1, List<T> c2)
      Returns a list that is the concatenation of the provided lists. Does NOT do anything else (e.g. remove duplicate entries).
    • counter

      public static <T> Counter<T> counter(List<T> listOfElements)
      \ 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

      public static <T> T anyOneElement(Collection<T> collection)
      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

      public static <T> T theElement(Collection<T> collection)
      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.