Class CollectionUtil

java.lang.Object
kr.toxicity.model.api.util.CollectionUtil

@Internal public final class CollectionUtil extends Object
Collection util
  • Method Details

    • newAddressingMap

      @NotNull public static <K,V> @NotNull it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<K,V> newAddressingMap()
      Creates a new addressing hash map.
      Type Parameters:
      K - key type
      V - value type
      Returns:
      new addressing map
      Since:
      2.2.1
    • newSequencedChainingMap

      @NotNull public static <K,V> @NotNull SequencedMap<K,V> newSequencedChainingMap()
      Creates a new sequenced chaining hash map.
      Type Parameters:
      K - key type
      V - value type
      Returns:
      new linked hash map
      Since:
      2.2.1
    • newSequencedAddressingMap

      @NotNull public static <K,V> @NotNull it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<K,V> newSequencedAddressingMap()
      Creates a new sequenced addressing hash map.
      Type Parameters:
      K - key type
      V - value type
      Returns:
      new sequenced addressing map
      Since:
      2.2.1
    • newChainingMap

      @NotNull public static <K,V> @NotNull Map<K,V> newChainingMap(int capacity)
      Creates a new chaining hash map.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      capacity - the initial capacity
      Returns:
      new hash map
      Since:
      2.2.1
    • newAddressingMap

      @NotNull public static <K,V> @NotNull it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<K,V> newAddressingMap(int capacity)
      Creates a new addressing hash map.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      capacity - the initial capacity
      Returns:
      new addressing map
      Since:
      2.2.1
    • newSequencedChainingMap

      @NotNull public static <K,V> @NotNull SequencedMap<K,V> newSequencedChainingMap(int capacity)
      Creates a new sequenced chaining hash map.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      capacity - the initial capacity
      Returns:
      new linked hash map
      Since:
      2.2.1
    • newSequencedAddressingMap

      @NotNull public static <K,V> @NotNull it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<K,V> newSequencedAddressingMap(int capacity)
      Creates a new sequenced addressing hash map.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      capacity - the initial capacity
      Returns:
      new sequenced addressing map
      Since:
      2.2.1
    • filterIsInstance

      @NotNull public static <E,R> @NotNull Stream<R> filterIsInstance(@NotNull @NotNull Collection<E> collection, @NotNull @NotNull Class<R> rClass)
      Filters stream by some instance
      Type Parameters:
      E - element
      R - return value
      Parameters:
      collection - collection
      rClass - class of instance
      Returns:
      filtered stream
    • mapToList

      @NotNull public static <E,R> @NotNull @Unmodifiable List<R> mapToList(@NotNull @NotNull Collection<E> collection, @NotNull @NotNull Function<E,R> mapper)
      Maps stream to list
      Type Parameters:
      E - element
      R - return value
      Parameters:
      collection - collection
      mapper - mapper
      Returns:
      unmodifiable list
    • mapToList

      @NotNull public static <E,R> @NotNull @Unmodifiable List<R> mapToList(@NotNull @NotNull Stream<E> stream, @NotNull @NotNull Function<E,R> mapper)
      Maps stream to list
      Type Parameters:
      E - element
      R - return value
      Parameters:
      stream - stream
      mapper - mapper
      Returns:
      unmodifiable list
    • mapToSet

      @NotNull public static <E,R> @NotNull @Unmodifiable Set<R> mapToSet(@NotNull @NotNull Collection<E> collection, @NotNull @NotNull Function<E,R> mapper)
      Maps stream to set
      Type Parameters:
      E - element
      R - return value
      Parameters:
      collection - collection
      mapper - mapper
      Returns:
      unmodifiable set
    • mapToSet

      @NotNull public static <E,R> @NotNull @Unmodifiable Set<R> mapToSet(@NotNull @NotNull Stream<E> stream, @NotNull @NotNull Function<E,R> mapper)
      Maps stream to set
      Type Parameters:
      E - element
      R - return value
      Parameters:
      stream - stream
      mapper - mapper
      Returns:
      unmodifiable set
    • mapToJson

      @NotNull public static <E, R extends com.google.gson.JsonElement> @NotNull com.google.gson.JsonArray mapToJson(@NotNull @NotNull Collection<E> collection, @NotNull @NotNull Function<E,R> mapper)
      Maps stream to JSON
      Type Parameters:
      E - element
      R - return value
      Parameters:
      collection - collection
      mapper - mapper
      Returns:
      JSON array
    • mapToJson

      @NotNull public static <E, R extends com.google.gson.JsonElement> @NotNull com.google.gson.JsonArray mapToJson(@NotNull @NotNull Stream<E> stream, @NotNull @NotNull Function<E,R> mapper)
      Maps stream to JSON
      Type Parameters:
      E - element
      R - return value
      Parameters:
      stream - stream
      mapper - mapper
      Returns:
      JSON array
    • mapToJson

      @NotNull public static <E, R extends com.google.gson.JsonElement> @NotNull com.google.gson.JsonArray mapToJson(int capacity, @NotNull @NotNull Stream<E> stream, @NotNull @NotNull Function<E,R> mapper)
      Maps stream to JSON
      Type Parameters:
      E - element
      R - return value
      Parameters:
      capacity - initial capacity
      stream - stream
      mapper - mapper
      Returns:
      JSON array
    • filterIsInstance

      @NotNull public static <E,R> @NotNull Stream<R> filterIsInstance(@NotNull @NotNull Stream<E> stream, @NotNull @NotNull Class<R> rClass)
      Filters stream by some instance
      Type Parameters:
      E - element
      R - return value
      Parameters:
      stream - stream
      rClass - class of instance
      Returns:
      filtered stream
    • group

      @NotNull public static <K,E> @NotNull @Unmodifiable Map<K,List<E>> group(@NotNull @NotNull Stream<E> stream, @NotNull @NotNull Function<E,K> keyMapper)
      Groups stream by some key
      Type Parameters:
      K - key
      E - element
      Parameters:
      stream - stream
      keyMapper - key mapper
      Returns:
      unmodifiable grouped map
    • mapIndexed

      @NotNull public static <K,V,R> @NotNull Stream<R> mapIndexed(@NotNull @NotNull Map<K,V> map, @NotNull @NotNull CollectionUtil.IndexedFunction<Map.Entry<K,V>, R> function)
      Maps some collection with map index
      Type Parameters:
      K - key
      V - value
      R - return value
      Parameters:
      map - map
      function - mapper
      Returns:
      mapped stream
    • mapIndexed

      @NotNull public static <E,R> @NotNull Stream<R> mapIndexed(@NotNull @NotNull Collection<E> collection, @NotNull @NotNull CollectionUtil.IndexedFunction<E,R> function)
      Maps some collection with map index
      Type Parameters:
      E - element
      R - return value
      Parameters:
      collection - collection
      function - mapper
      Returns:
      mapped stream
    • mapIndexed

      @NotNull public static <E,R> @NotNull Stream<R> mapIndexed(@NotNull @NotNull Stream<E> stream, @NotNull @NotNull CollectionUtil.IndexedFunction<E,R> function)
      Maps some collection with map index
      Type Parameters:
      E - element
      R - return value
      Parameters:
      stream - stream
      function - mapper
      Returns:
      mapped stream
    • mapFloat

      @NotNull public static <E, T extends it.unimi.dsi.fastutil.floats.FloatCollection> T mapFloat(@NotNull @NotNull Stream<E> stream, @NotNull @NotNull CollectionUtil.FloatFunction<E> mapper, @NotNull @NotNull Supplier<T> creator)
      Maps some stream to a float collection
      Type Parameters:
      E - element
      T - type
      Parameters:
      stream - stream
      mapper - mapper
      creator - float collection creator
      Returns:
      float collection
    • mapValue

      @NotNull public static <K,V,R> @NotNull @Unmodifiable Map<K,R> mapValue(@NotNull @NotNull Map<K,V> original, @NotNull @NotNull Function<V,R> mapper)
      Map some map's value.
      Type Parameters:
      K - key
      V - value
      R - new value
      Parameters:
      original - original map
      mapper - value mapper
      Returns:
      unmodifiable map
    • filterWithWarning

      @NotNull public static <T> @NotNull Predicate<T> filterWithWarning(@NotNull @NotNull Predicate<T> predicate, @NotNull @NotNull Function<T,String> lazyLogFunction)
      Gets filter with warning if not matched
      Type Parameters:
      T - type
      Parameters:
      predicate - delegated predicate
      lazyLogFunction - log function
      Returns:
      predicate
    • associate

      @NotNull public static <E,K,V> @NotNull @Unmodifiable Map<K,V> associate(@NotNull @NotNull Collection<E> collection, @NotNull @NotNull Function<E,K> keyMapper, @NotNull @NotNull Function<E,V> valueMapper)
      Associates collection to map
      Type Parameters:
      E - element
      K - key
      V - value
      Parameters:
      collection - collection
      keyMapper - key mapper
      valueMapper - value mapper
      Returns:
      unmodifiable map
    • associate

      @NotNull public static <E,K> @NotNull @Unmodifiable Map<K,E> associate(@NotNull @NotNull Collection<E> collection, @NotNull @NotNull Function<E,K> keyMapper)
      Associates stream to map
      Type Parameters:
      E - element
      K - key
      Parameters:
      collection - collection
      keyMapper - key mapper
      Returns:
      unmodifiable map
    • associate

      @NotNull public static <E,K> @NotNull @Unmodifiable Map<K,E> associate(@NotNull E[] array, @NotNull @NotNull Function<E,K> keyMapper)
      Associates stream to map
      Type Parameters:
      E - element
      K - key
      Parameters:
      array - array
      keyMapper - key mapper
      Returns:
      unmodifiable map
    • associate

      @NotNull public static <E,K> @NotNull @Unmodifiable Map<K,E> associate(@NotNull @NotNull Stream<E> stream, @NotNull @NotNull Function<E,K> keyMapper)
      Associates stream to map
      Type Parameters:
      E - element
      K - key
      Parameters:
      stream - stream
      keyMapper - key mapper
      Returns:
      unmodifiable map
    • associate

      @NotNull public static <E,K,V> @NotNull @Unmodifiable Map<K,V> associate(@NotNull @NotNull Stream<E> stream, @NotNull @NotNull Function<E,K> keyMapper, @NotNull @NotNull Function<E,V> valueMapper)
      Associates stream to map
      Type Parameters:
      E - element
      K - key
      V - value
      Parameters:
      stream - stream
      keyMapper - key mapper
      valueMapper - value mapper
      Returns:
      unmodifiable map
    • associateSequenced

      @NotNull public static <E,K> @NotNull @Unmodifiable SequencedMap<K,E> associateSequenced(@NotNull @NotNull Collection<E> collection, @NotNull @NotNull Function<E,K> keyMapper)
      Associates stream to sequenced map
      Type Parameters:
      E - element
      K - key
      Parameters:
      collection - collection
      keyMapper - key mapper
      Returns:
      unmodifiable sequenced map
    • associateSequenced

      @NotNull public static <E,K,V> @NotNull @Unmodifiable SequencedMap<K,V> associateSequenced(@NotNull @NotNull Collection<E> collection, @NotNull @NotNull Function<E,K> keyMapper, @NotNull @NotNull Function<E,V> valueMapper)
      Associates collection to sequenced map
      Type Parameters:
      E - element
      K - key
      V - value
      Parameters:
      collection - collection
      keyMapper - key mapper
      valueMapper - value mapper
      Returns:
      unmodifiable sequenced map
    • associateSequenced

      @NotNull public static <E,K> @NotNull @Unmodifiable SequencedMap<K,E> associateSequenced(@NotNull E[] array, @NotNull @NotNull Function<E,K> keyMapper)
      Associates stream to sequenced map
      Type Parameters:
      E - element
      K - key
      Parameters:
      array - array
      keyMapper - key mapper
      Returns:
      unmodifiable sequenced map
    • associateSequenced

      @NotNull public static <E,K,V> @NotNull @Unmodifiable SequencedMap<K,V> associateSequenced(@NotNull E[] array, @NotNull @NotNull Function<E,K> keyMapper, @NotNull @NotNull Function<E,V> valueMapper)
      Associates collection to sequenced map
      Type Parameters:
      E - element
      K - key
      V - value
      Parameters:
      array - array
      keyMapper - key mapper
      valueMapper - value mapper
      Returns:
      unmodifiable sequenced map
    • associateSequenced

      @NotNull public static <E,K> @NotNull @Unmodifiable SequencedMap<K,E> associateSequenced(int capacity, @NotNull @NotNull Stream<E> stream, @NotNull @NotNull Function<E,K> keyMapper)
      Associates stream to sequenced map
      Type Parameters:
      E - element
      K - key
      Parameters:
      capacity - the initial capacity
      stream - stream
      keyMapper - key mapper
      Returns:
      unmodifiable sequenced map
    • associateSequenced

      @NotNull public static <E,K,V> @NotNull @Unmodifiable SequencedMap<K,V> associateSequenced(int capacity, @NotNull @NotNull Stream<E> stream, @NotNull @NotNull Function<E,K> keyMapper, @NotNull @NotNull Function<E,V> valueMapper)
      Associates stream to sequenced map
      Type Parameters:
      E - element
      K - key
      V - value
      Parameters:
      capacity - the initial capacity
      stream - stream
      keyMapper - key mapper
      valueMapper - value mapper
      Returns:
      unmodifiable sequenced map