Class CollectionHelpers

java.lang.Object
org.cyclops.cyclopscore.helper.CollectionHelpers

public final class CollectionHelpers extends Object
Helper methods for collections.
  • Constructor Details

    • CollectionHelpers

      public CollectionHelpers()
  • Method Details

    • addToMapList

      public static <K, V> void addToMapList(Map<K,List<V>> map, K key, V value)
      Add the given key value pair in a map structure where multiple values for a key can exist. This will take care of making a new list into the map when one did not exist before.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      map - The map.
      key - The key.
      value - The value.
    • addToMapSet

      public static <K, V> void addToMapSet(Map<K,Set<V>> map, K key, V value)
      Add the given key value pair in a map structure where multiple values for a key can exist. This will take care of making a new set into the map when one did not exist before.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      map - The map.
      key - The key.
      value - The value.
    • compareCollection

      public static <T extends Comparable<T>> int compareCollection(Collection<? super T> a, Collection<? super T> b)
      Compare two collections with comparable elements.
      Type Parameters:
      T - The type of the elements.
      Parameters:
      a - A first collection.
      b - A second collection.
      Returns:
      The comparator value.
    • compareCollection

      public static <T> int compareCollection(Collection<? super T> a, Collection<? super T> b, Comparator<T> comparator)
      Compare two collections with a custom comparator.
      Type Parameters:
      T - The type of the elements.
      Parameters:
      a - A first collection.
      b - A second collection.
      comparator - The element comparator.
      Returns:
      The comparator value.