Class CollectionUtils

java.lang.Object
co.crystaldev.alpinecore.util.CollectionUtils

public final class CollectionUtils extends Object
Utility for instantiating commonly used Collections with concise and clean syntax.
Since:
0.1.1
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> @NotNull LinkedList<T>
    linkedList(@NotNull T... items)
    Creates a new ordered list with the specified objects.
    static <K, V> @NotNull LinkedHashMap<K,V>
    linkedMap(K firstKey, V firstValue, @NotNull Object... items)
    Creates a new ordered map with the specified objects.
    static <T> @NotNull LinkedHashSet<T>
    linkedSet(@NotNull T... items)
    Creates a new ordered list with the specified objects.
    static <T> @NotNull List<T>
    list(@NotNull T... items)
    Creates a new list with the specified objects.
    static <K, V> @NotNull Map<K,V>
    map(K firstKey, V firstValue, @NotNull Object... items)
    Creates a new map with the specified objects.
    static <T> @NotNull Set<T>
    set(@NotNull T... items)
    Creates a new set with the specified objects.

    Methods inherited from class java.lang.Object

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

    • CollectionUtils

      public CollectionUtils()
  • Method Details

    • list

      @SafeVarargs @NotNull @Contract("null -> fail") public static <T> @NotNull List<T> list(@NotNull @NotNull T... items)
      Creates a new list with the specified objects.

      This method makes no assertion as to the ordering of the list. For an ordered list, use linkedList(Object[]).

      Type Parameters:
      T - the type of the elements in the list
      Parameters:
      items - the objects to add to the list
      Returns:
      the list
      See Also:
    • linkedList

      @SafeVarargs @NotNull @Contract("null -> fail") public static <T> @NotNull LinkedList<T> linkedList(@NotNull @NotNull T... items)
      Creates a new ordered list with the specified objects.
      Type Parameters:
      T - the type of the elements in the list
      Parameters:
      items - the objects to add to the list
      Returns:
      the list
      See Also:
    • set

      @SafeVarargs @NotNull @Contract("null -> fail") public static <T> @NotNull Set<T> set(@NotNull @NotNull T... items)
      Creates a new set with the specified objects.

      This method makes no assertion as to the ordering of the list. For an ordered list, use linkedSet(Object[]).

      Type Parameters:
      T - the type of the elements in the set
      Parameters:
      items - the objects to add to the set
      Returns:
      the set
      See Also:
    • linkedSet

      @SafeVarargs @NotNull @Contract("null -> fail") public static <T> @NotNull LinkedHashSet<T> linkedSet(@NotNull @NotNull T... items)
      Creates a new ordered list with the specified objects.
      Type Parameters:
      T - the type of the elements in the set
      Parameters:
      items - the objects to add to the set
      Returns:
      the set
      See Also:
    • map

      @NotNull public static <K, V> @NotNull Map<K,V> map(@NotNull K firstKey, @NotNull V firstValue, @NotNull @NotNull Object... items)
      Creates a new map with the specified objects.

      This method makes no assertion as to the ordering of the map. For an ordered map, use linkedMap(Object, Object, Object...).

      Varargs should be specified by alternating keys and values.

      If the number of varargs is odd, the method will quietly ignore them.

      Type Parameters:
      K - the type of the keys in the map
      V - the type of the values in the map
      Parameters:
      items - the keys and values to add to the map
      Returns:
      the map
      See Also:
    • linkedMap

      @NotNull public static <K, V> @NotNull LinkedHashMap<K,V> linkedMap(@NotNull K firstKey, @NotNull V firstValue, @NotNull @NotNull Object... items)
      Creates a new ordered map with the specified objects.

      Varargs should be specified by alternating keys and values.

      If the number of varargs is odd, the method will quietly ignore them.

      Type Parameters:
      K - the type of the keys in the map
      V - the type of the values in the map
      Parameters:
      items - the keys and values to add to the map
      Returns:
      the map
      See Also: