Class Collections

java.lang.Object
me.despical.commons.util.Collections

public class Collections extends Object
Author:
Despical

Created at 4.04.2021

  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> boolean
    addAll(Collection<T> collection, T... elements)
    Adds all the elements in the specified collection to this collection (optional operation).
    static boolean
    contains(Object objectToFind, Object... array)
    Checks if the object is in the given array.
    static <K, V> List<Map.Entry<K,V>>
    Returns an immutable list containing an arbitrary number of elements.
    static <T> List<T>
    Returns an immutable list containing elements of given set.
    static <T> List<T>
    Returns an immutable list containing an arbitrary number of elements.
    static <K, V> Map<K,V>
    Returns an immutable map containing an arbitrary number of elements.
    static <K, V> Map<K,V>
    immutableMapOf(K a, V b)
    Returns an immutable map containing one element.
    static <T> Set<T>
    Returns an immutable set containing an arbitrary number of elements.
    static <K, V> List<Map.Entry<K,V>>
    listFromMap(Map<K,V> a)
    Returns a mutable list containing entry set elements of given map.
    static <T> List<T>
    Returns a mutable list containing elements of given set.
    static <T> List<T>
    listOf(T... a)
    Returns a mutable list containing an arbitrary number of elements.
    static <K, V> Map.Entry<K,V>
    mapEntry(K a, V b)
    Returns a Map.Entry containing the given key and value.
    static <K, V> Map<K,V>
    mapOf(Map.Entry<K,V>... a)
    Returns a mutable map containing an arbitrary number of elements.
    static <K, V> Map<K,V>
    mapOf(K a, V b)
    Returns an mutable map containing one element.
    static <T> Set<T>
    setOf(T... a)
    Returns a mutable set containing an arbitrary number of elements.
    static <T> Stream<T>
    streamOf(T... a)
    Returns a sequential ordered stream whose elements are the specified values.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • listOf

      @SafeVarargs public static <T> List<T> listOf(T... a)
      Returns a mutable list containing an arbitrary number of elements.
      Type Parameters:
      T - Type of given parameters.
      Parameters:
      a - Array of given parameters.
      Returns:
      mutable list containing an arbitrary number of elements.
    • immutableListOf

      @SafeVarargs public static <T> List<T> immutableListOf(T... a)
      Returns an immutable list containing an arbitrary number of elements.
      Type Parameters:
      T - Type of given parameters.
      Parameters:
      a - Array of given parameters.
      Returns:
      immutable list containing an arbitrary number of elements.
    • listFromSet

      public static <T> List<T> listFromSet(Set<T> a)
      Returns a mutable list containing elements of given set.
      Type Parameters:
      T - Type of given set.
      Parameters:
      a - Set to be converted to list.
      Returns:
      mutable list containing elements of given set.
    • immutableListFromSet

      public static <T> List<T> immutableListFromSet(Set<T> a)
      Returns an immutable list containing elements of given set.
      Type Parameters:
      T - Type of given set.
      Parameters:
      a - Set to be converted to list.
      Returns:
      immutable list containing elements of given set.
    • listFromMap

      public static <K, V> List<Map.Entry<K,V>> listFromMap(Map<K,V> a)
      Returns a mutable list containing entry set elements of given map.
      Type Parameters:
      K - Type of entry.
      V - Value of entry.
      Parameters:
      a - Map to be converted to list.
      Returns:
      mutable list containing entry set elements of given map.
    • immutableListFromMap

      public static <K, V> List<Map.Entry<K,V>> immutableListFromMap(Map<K,V> a)
      Returns an immutable list containing an arbitrary number of elements.
      Type Parameters:
      K - Type of entry.
      V - Value of entry.
      Parameters:
      a - Map to be converted to list.
      Returns:
      immutable list containing entry set elements of given map.
    • setOf

      @SafeVarargs public static <T> Set<T> setOf(T... a)
      Returns a mutable set containing an arbitrary number of elements.
      Type Parameters:
      T - Type of given parameters.
      Parameters:
      a - Array of given parameters.
      Returns:
      mutable set containing an arbitrary number of elements.
    • immutableSetOf

      @SafeVarargs public static <T> Set<T> immutableSetOf(T... a)
      Returns an immutable set containing an arbitrary number of elements.
      Type Parameters:
      T - Type of given parameters.
      Parameters:
      a - Array of given parameters.
      Returns:
      immutable set containing an arbitrary number of elements.
    • mapEntry

      public static <K, V> Map.Entry<K,V> mapEntry(K a, V b)
      Returns a Map.Entry containing the given key and value.
      Type Parameters:
      K - new key type to be stored in this entry.
      V - new value type to be stored in this entry.
      Parameters:
      a - new key to be stored in this entry.
      b - new value to be stored in this entry.
      Returns:
      new Map.Entry containing the given key and value.
    • mapOf

      @SafeVarargs public static <K, V> Map<K,V> mapOf(Map.Entry<K,V>... a)
      Returns a mutable map containing an arbitrary number of elements.
      Type Parameters:
      K - key type to be stored in this map.
      V - value type to be stored in this map.
      Parameters:
      a - Array of given entries to be stored in this map.
      Returns:
      Returns a mutable map containing an arbitrary number of elements.
    • mapOf

      public static <K, V> Map<K,V> mapOf(K a, V b)
      Returns an mutable map containing one element.
      Type Parameters:
      K - key type to be stored in this map.
      V - value type to be stored in this map.
      Parameters:
      a - key to be stored in this map.
      b - value to be stored in this map.
      Returns:
      Returns an mutable map containing one element.
    • immutableMapOf

      public static <K, V> Map<K,V> immutableMapOf(K a, V b)
      Returns an immutable map containing one element.
      Type Parameters:
      K - key type to be stored in this map.
      V - value type to be stored in this map.
      Parameters:
      a - key to be stored in this map.
      b - value to be stored in this map.
      Returns:
      Returns an immutable map containing one element.
    • immutableMapOf

      @SafeVarargs public static <K, V> Map<K,V> immutableMapOf(Map.Entry<K,V>... a)
      Returns an immutable map containing an arbitrary number of elements.
      Type Parameters:
      K - key type to be stored in this map.
      V - value type to be stored in this map.
      Parameters:
      a - Array of given entries to be stored in this map.
      Returns:
      immutable map containing an arbitrary number of elements.
    • streamOf

      @SafeVarargs public static <T> Stream<T> streamOf(T... a)
      Returns a sequential ordered stream whose elements are the specified values.
      Type Parameters:
      T - the type of stream elements
      Parameters:
      a - the elements of the new stream
      Returns:
      the new stream
    • contains

      public static boolean contains(Object objectToFind, Object... array)
      Checks if the object is in the given array.

      The method returns false if a null array is passed in.

      Parameters:
      objectToFind - the object to find
      array - the array to search through
      Returns:
      true if the array contains the object
    • addAll

      @SafeVarargs public static <T> boolean addAll(Collection<T> collection, T... elements)
      Adds all the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)
      Parameters:
      collection - containing elements to be added to this collection
      Returns:
      true if this collection changed as a result of the call
      Throws:
      UnsupportedOperationException - if the addAll operation is not supported by this collection
      ClassCastException - if the class of an element of the specified collection prevents it from being added to this collection
      NullPointerException - if the specified collection contains a null element and this collection does not permit null elements, or if the specified collection is null
      IllegalArgumentException - if some property of an element of the specified collection prevents it from being added to this collection
      IllegalStateException - if not all the elements can be added at this time due to insertion restrictions