Class CollectionUtil

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

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

    • 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
    • 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(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
    • 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
    • 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> @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 @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