java.lang.Object
ushiosan.jvm_utilities.lang.collection.Collections

public final class Collections extends Object
Class that has helper methods for data containers like Map, List, Set, Stack and Vector
  • Method Details

    • listOf

      @SafeVarargs @Contract(pure=true) public static <T> @Unmodifiable List<T> listOf(T @NotNull ... elements)
      Create an immutable list with all given elements.
      Type Parameters:
      T - list generic type
      Parameters:
      elements - the elements to insert
      Returns:
      an immutable list with all elements
    • listOf

      public static <T> @Unmodifiable List<T> listOf(@NotNull @NotNull Collection<T> base)
      Create an immutable list with all given elements.
      Type Parameters:
      T - list generic type
      Parameters:
      base - the base collection content
      Returns:
      an immutable list with all elements
    • listOf

      @NotNull public static <T> @Unmodifiable @NotNull List<T> listOf(@NotNull @NotNull Iterator<T> iterator)
      Create an immutable list with all given elements.
      Type Parameters:
      T - list generic type
      Parameters:
      iterator - the base collection content
      Returns:
      an immutable list with all elements
    • mutableListOf

      @SafeVarargs @Contract("_ -> new") @NotNull public static <T> @NotNull List<T> mutableListOf(T @NotNull ... elements)
      Create a mutable list with all given elements.
      Type Parameters:
      T - list generic type
      Parameters:
      elements - the elements to insert
      Returns:
      a mutable list with all elements
    • mutableListOf

      @NotNull public static <T> @NotNull List<T> mutableListOf(@NotNull @NotNull Collection<T> base)
      Create a mutable list with all given elements.
      Type Parameters:
      T - list generic type
      Parameters:
      base - the base collection content
      Returns:
      a mutable list with all elements
    • mutableListOf

      @NotNull public static <T> @NotNull List<T> mutableListOf(@NotNull @NotNull Iterator<T> iterator)
      Create a mutable list with all given elements.
      Type Parameters:
      T - list generic type
      Parameters:
      iterator - the base collection content
      Returns:
      a mutable list with all elements
    • linkedListOf

      @SafeVarargs @NotNull public static <T> @NotNull List<T> linkedListOf(T @NotNull ... elements)
      Create a linked list with all given elements.
      Type Parameters:
      T - generic type list
      Parameters:
      elements - the elements to insert
      Returns:
      a linked list with all elements
    • linkedListOf

      @NotNull public static <T> @NotNull List<T> linkedListOf(@NotNull @NotNull Collection<T> base)
      Create a linked list with all given elements.
      Type Parameters:
      T - list generic type
      Parameters:
      base - the base collection content
      Returns:
      a linked list with all elements
    • searchListIndex

      @NotNull public static <T> @NotNull List<Integer> searchListIndex(@NotNull @NotNull List<T> base, @NotNull T search)
      Returns all indices where the searched element is found
      Type Parameters:
      T - generic object type
      Parameters:
      base - the base list
      search - the object to search
      Returns:
      all indices where the searched object is found
    • stackOf

      @SafeVarargs @NotNull public static <T> @NotNull Stack<T> stackOf(T @NotNull ... elements)
      Create a stack with all given elements.
      Type Parameters:
      T - generic type list
      Parameters:
      elements - the elements to insert
      Returns:
      a stack with all elements
    • stackOf

      @NotNull public static <T> @NotNull Stack<T> stackOf(@NotNull @NotNull Collection<T> base)
      Create a stack with all given elements.
      Type Parameters:
      T - list generic type
      Parameters:
      base - the base collection content
      Returns:
      a stack with all elements
    • vectorOf

      @SafeVarargs @NotNull public static <T> @NotNull Vector<T> vectorOf(T @NotNull ... elements)
      Create a vector with all given elements.
      Type Parameters:
      T - generic type list
      Parameters:
      elements - the elements to insert
      Returns:
      a vector with all elements
    • vectorOf

      @NotNull public static <T> @NotNull Vector<T> vectorOf(@NotNull @NotNull Collection<T> base)
      Create a vector with all given elements.
      Type Parameters:
      T - list generic type
      Parameters:
      base - the base collection content
      Returns:
      a vector with all elements
    • setOf

      @SafeVarargs @NotNull public static <T> @Unmodifiable @NotNull Set<T> setOf(T @NotNull ... elements)
      Create a set with all given elements.
      Type Parameters:
      T - generic type set
      Parameters:
      elements - the elements to insert
      Returns:
      a set with all elements
    • setOf

      @NotNull public static <T> @Unmodifiable @NotNull Set<T> setOf(@NotNull @NotNull Collection<T> base)
      Create a set with all given elements.
      Type Parameters:
      T - generic type set
      Parameters:
      base - the base collection content
      Returns:
      a set with all elements
    • mutableSetOf

      @SafeVarargs @NotNull public static <T> @NotNull Set<T> mutableSetOf(T @NotNull ... elements)
      Create a mutable set with all given elements.
      Type Parameters:
      T - generic type set
      Parameters:
      elements - the elements to insert
      Returns:
      a set with all elements
    • mutableSetOf

      @NotNull public static <T> @NotNull Set<T> mutableSetOf(@NotNull @NotNull Collection<T> base)
      Create a mutable set with all given elements.
      Type Parameters:
      T - generic type set
      Parameters:
      base - the base collection content
      Returns:
      a set with all elements
    • linkedSetOf

      @SafeVarargs @NotNull public static <T> @NotNull Set<T> linkedSetOf(T @NotNull ... elements)
      Create a linked set with all given elements.
      Type Parameters:
      T - generic type set
      Parameters:
      elements - the elements to insert
      Returns:
      a linked set with all elements
    • linkedSetOf

      @NotNull public static <T> @NotNull Set<T> linkedSetOf(@NotNull @NotNull Collection<T> base)
      Create a linked set with all given elements.
      Type Parameters:
      T - generic type set
      Parameters:
      base - the base collection content
      Returns:
      a linked set with all elements
    • treeSetOf

      @SafeVarargs @NotNull public static <T> @NotNull Set<T> treeSetOf(@Nullable @Nullable Comparator<T> comparator, T @NotNull ... elements)
      Create a tree set with all given elements.
      Type Parameters:
      T - generic type set
      Parameters:
      comparator - the set comparator (used to sort the elements)
      elements - the elements to insert
      Returns:
      a tree set with all elements
    • treeSetOf

      @SafeVarargs @NotNull public static <T> @NotNull Set<T> treeSetOf(T @NotNull ... elements)
      Create a tree set with all given elements.
      Type Parameters:
      T - generic type set
      Parameters:
      elements - the elements to insert
      Returns:
      a linked set with all elements
    • treeSetOf

      @NotNull public static <T> @NotNull Set<T> treeSetOf(@Nullable @Nullable Comparator<T> comparator, @NotNull @NotNull Collection<T> base)
      Create a linked set with all given elements.
      Type Parameters:
      T - generic type set
      Parameters:
      comparator - sort comparator instance
      base - the base collection content
      Returns:
      a linked set with all elements
    • enumSetOf

      @NotNull public static <T extends Enum<T>> @NotNull Set<T> enumSetOf(@NotNull @NotNull Class<T> cls)
      Create an enum set with all enum elements.
      Type Parameters:
      T - generic enum type
      Parameters:
      cls - the enum class to check
      Returns:
      an enum set with all enum elements
    • mapOf

      @NotNull public static <K, V> @Unmodifiable @NotNull Map<K,V> mapOf()
      Create a read-only empty map.
      Type Parameters:
      K - key entry type
      V - value entry type
      Returns:
      a read-only map with all content
    • mapOf

      @SafeVarargs @NotNull public static <K, V> @Unmodifiable @NotNull Map<K,V> mapOf(Map.Entry<K,V> @NotNull ... entries)
      Create a read-only map with all the given elements.
      Type Parameters:
      K - key entry type
      V - value entry type
      Parameters:
      entries - the elements to insert
      Returns:
      a read-only map with all content
    • mapOf

      @SafeVarargs @NotNull public static <K, V> @Unmodifiable @NotNull Map<K,V> mapOf(Pair<K,V> @NotNull ... pairs)
      Create a read-only map with all the given elements.
      Type Parameters:
      K - key entry type
      V - value entry type
      Parameters:
      pairs - the elements to insert
      Returns:
      a read-only map with all content
    • mutableMapOf

      @NotNull public static <K, V> @NotNull Map<K,V> mutableMapOf()
      Create a mutable map with all the given elements.
      Type Parameters:
      K - key entry type
      V - value entry type
      Returns:
      a mutable map with all content
    • mutableMapOf

      @SafeVarargs @NotNull public static <K, V> @NotNull Map<K,V> mutableMapOf(Map.Entry<K,V> @NotNull ... entries)
      Create a mutable map with all the given elements.
      Type Parameters:
      K - key entry type
      V - value entry type
      Parameters:
      entries - the elements to insert
      Returns:
      a mutable map with all content
    • mutableMapOf

      @SafeVarargs @NotNull public static <K, V> @NotNull Map<K,V> mutableMapOf(Pair<K,V> @NotNull ... pairs)
      Create a mutable map with all the given elements.
      Type Parameters:
      K - key entry type
      V - value entry type
      Parameters:
      pairs - the elements to insert
      Returns:
      a mutable map with all content
    • weakMapOf

      @SafeVarargs @NotNull public static <K, V> @NotNull Map<K,V> weakMapOf(Map.Entry<K,V> @NotNull ... entries)
      Create a weak-reference map with all the given elements.
      Type Parameters:
      K - key entry type
      V - value entry type
      Parameters:
      entries - the elements to insert
      Returns:
      a weak map with all content
    • weakMapOf

      @SafeVarargs @NotNull public static <K, V> @NotNull Map<K,V> weakMapOf(Pair<K,V> @NotNull ... pairs)
      Create a weak-reference map with all the given elements.
      Type Parameters:
      K - key entry type
      V - value entry type
      Parameters:
      pairs - the elements to insert
      Returns:
      a weak map with all content
    • linkedMapOf

      @SafeVarargs @NotNull public static <K, V> @NotNull Map<K,V> linkedMapOf(Map.Entry<K,V> @NotNull ... entries)
      Create a linked map with all the given elements.
      Type Parameters:
      K - key entry type
      V - value entry type
      Parameters:
      entries - the elements to insert
      Returns:
      a linked map with all content
    • linkedMapOf

      @SafeVarargs @NotNull public static <K, V> @NotNull Map<K,V> linkedMapOf(Pair<K,V> @NotNull ... pairs)
      Create a linked map with all the given elements.
      Type Parameters:
      K - key entry type
      V - value entry type
      Parameters:
      pairs - the elements to insert
      Returns:
      a linked map with all content
    • entryOf

      public static <K, V> @Unmodifiable @NotNull Map.Entry<K,V> entryOf(K key, V value)
      Instantiate Map.Entry to more easily generate data maps.
      Type Parameters:
      K - entry key type
      V - entry value type
      Parameters:
      key - entry key
      value - entry value
      Returns:
      a read-only configured entry
    • mutableEntryOf

      public static <K, V> @NotNull Map.Entry<K,V> mutableEntryOf(K key, V value)
      Instantiate Map.Entry to more easily generate data maps.
      Type Parameters:
      K - entry key type
      V - entry value type
      Parameters:
      key - entry key
      value - entry value
      Returns:
      a mutable configured entry
    • combine

      @SafeVarargs @NotNull public static <T> @NotNull Collection<T> combine(boolean excludeDuplicates, List<T> @NotNull ... lts)
      Combine different lists into a single collection
      Type Parameters:
      T - generic collection type
      Parameters:
      excludeDuplicates - remove all duplicate items
      lts - the lists you want to merge
      Returns:
      returns a single collection with all the elements of the passed lists
    • combine

      @SafeVarargs @NotNull public static <T> @NotNull Collection<T> combine(List<T> @NotNull ... lts)
      Combine different lists into a single collection
      Type Parameters:
      T - generic collection type
      Parameters:
      lts - the lists you want to merge
      Returns:
      returns a single collection with all the elements of the passed lists
    • combine

      @SafeVarargs @NotNull public static <T> @NotNull Set<T> combine(Set<T> @NotNull ... sets)
      Combine different sets into a single collection
      Type Parameters:
      T - generic collection type
      Parameters:
      sets - the sets you want to merge
      Returns:
      returns a single collection with all the elements of the passed sets