Class Utils

java.lang.Object
io.activej.common.Utils

@Internal public class Utils extends Object
Utility helper methods for internal use
  • Field Details

    • TO_STRING_LIMIT

      public static final int TO_STRING_LIMIT
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • get

      public static <T> T get(Supplier<T> supplier)
    • nonNullElse

      public static <T> T nonNullElse(@Nullable T value1, T defaultValue)
    • nonNullElseGet

      public static <T> T nonNullElseGet(@Nullable T value, Supplier<? extends T> defaultValue)
    • nonNullElseEmpty

      public static String nonNullElseEmpty(@Nullable @Nullable String value)
    • nonNullElseEmpty

      public static <T> Set<T> nonNullElseEmpty(@Nullable @Nullable Set<T> set)
    • nonNullElseEmpty

      public static <T> List<T> nonNullElseEmpty(@Nullable @Nullable List<T> list)
    • nonNullElseEmpty

      public static <K, V> Map<K,V> nonNullElseEmpty(@Nullable @Nullable Map<K,V> map)
    • nonNullOrException

      @NotNull public static <T, E extends Throwable> T nonNullOrException(@Nullable T value, Supplier<@NotNull E> exceptionSupplier) throws E
      Throws:
      E extends Throwable
    • nullify

      @Contract("_, _ -> null") @Nullable public static <V> V nullify(@Nullable V value, @NotNull @NotNull Runnable action)
    • nullify

      @Contract("_, _ -> null") @Nullable public static <V> V nullify(@Nullable V value, @NotNull @NotNull Consumer<? super V> action)
    • nullify

      @Contract("_, _, _ -> null") @Nullable public static <V, A> V nullify(@Nullable V value, @NotNull @NotNull BiConsumer<? super V,A> action, A actionArg)
    • arraysEquals

      public static boolean arraysEquals(byte[] array1, int pos1, int len1, byte[] array2, int pos2, int len2)
    • concat

      public static <D> List<D> concat(List<? extends D> list1, List<? extends D> list2)
      Concatenates two lists into one

      No guarantee on a mutability of a resulting list is made, so list should be considered unmodifiable

      If any of concatenated lists is modified, the behaviour of a concatenated list is undefined

    • setOf

      public static <T> Set<T> setOf(T item)
      Returns a Set of a provided element
      See Also:
    • setOf

      @SafeVarargs public static <T> Set<T> setOf(T... items)
      Returns a Set of provided elements

      No guarantee on a mutability of a resulting set is made, so set should be considered unmodifiable

      This is a simple alternative to Java 9's Set#of method

    • difference

      public static <T> Set<T> difference(Set<? extends T> a, Set<? extends T> b)
      Returns a difference of two sets

      No guarantee on a mutability of a resulting set is made, so set should be considered unmodifiable

      If any of provided sets is modified, the behaviour of a resulting set is undefined

    • intersection

      public static <T> Set<T> intersection(Set<? extends T> a, Set<? extends T> b)
      Returns an intersection of two sets

      No guarantee on a mutability of a resulting set is made, so set should be considered unmodifiable

      If any of provided sets is modified, the behaviour of a resulting set is undefined

    • hasIntersection

      public static <T> boolean hasIntersection(Set<? extends T> a, Set<? extends T> b)
    • union

      public static <T> Set<T> union(Set<? extends T> a, Set<? extends T> b)
      Returns a union of two sets

      No guarantee on a mutability of a resulting set is made, so set should be considered unmodifiable

      If any of provided sets is modified, the behaviour of a resulting set is undefined

    • first

      public static <T> T first(List<? extends T> list)
    • first

      public static <T> T first(Iterable<? extends T> iterable)
    • last

      public static <T> T last(List<? extends T> list)
    • last

      public static <T> T last(Iterable<? extends T> iterable)
    • listOf

      public static <T> List<T> listOf()
      Returns an empty List
      See Also:
    • listOf

      public static <T> List<T> listOf(T value)
      Returns a List of a provided element
      See Also:
    • listOf

      public static <T> List<T> listOf(T... items)
      Returns a List of provided elements

      No guarantee on a mutability of a resulting list is made, so list should be considered unmodifiable

      This is a simple alternative to Java 9's List#of method

    • iteratorOf

      public static <T> Iterator<T> iteratorOf()
    • iteratorOf

      public static <T> Iterator<T> iteratorOf(T item)
    • iteratorOf

      public static <T> Iterator<T> iteratorOf(T item1, T item2)
    • iteratorOf

      @SafeVarargs public static <T> Iterator<T> iteratorOf(T... items)
    • transformIterator

      public static <T, R> Iterator<R> transformIterator(Iterator<? extends T> iterator, Function<? super T,? extends R> fn)
    • concat

      public static <T> Iterator<T> concat(Iterator<? extends T> iterator1, Iterator<? extends T> iterator2)
    • append

      public static <T> Iterator<T> append(Iterator<? extends T> iterator, T value)
    • prepend

      public static <T> Iterator<T> prepend(T value, Iterator<? extends T> iterator)
    • mapOf

      public static <K, V> Map<K,V> mapOf()
      Returns an empty Map

      No guarantee on a mutability of a resulting map is made, so map should be considered unmodifiable

      This is a simple alternative to Java 9's Map#of method

    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1)
      Returns a Map of provided key and value

      No guarantee on a mutability of a resulting map is made, so map should be considered unmodifiable

      This is a simple alternative to Java 9's Map#of method

    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1, K key2, V value2)
      Returns a Map of provided keys and values

      No guarantee on a mutability of a resulting map is made, so map should be considered unmodifiable

      This is a simple alternative to Java 9's Map#of method

    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3)
      Returns a Map of provided keys and values

      No guarantee on a mutability of a resulting map is made, so map should be considered unmodifiable

      This is a simple alternative to Java 9's Map#of method

    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
      Returns a Map of provided keys and values

      No guarantee on a mutability of a resulting map is made, so map should be considered unmodifiable

      This is a simple alternative to Java 9's Map#of method

    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5)
      Returns a Map of provided keys and values

      No guarantee on a mutability of a resulting map is made, so map should be considered unmodifiable

      This is a simple alternative to Java 9's Map#of method

    • mapOf

      public static <K, V> Map<K,V> mapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5, K key6, V value6)
      Returns a Map of provided keys and values

      No guarantee on a mutability of a resulting map is made, so map should be considered unmodifiable

      This is a simple alternative to Java 9's Map#of method

    • isBijection

      public static boolean isBijection(Map<?,?> map)
    • iterate

      public static <T> Stream<T> iterate(@NotNull @NotNull Supplier<? extends T> supplier, @NotNull @NotNull Predicate<? super T> hasNext)
    • iterate

      public static <T> Stream<T> iterate(T seed, @NotNull @NotNull Predicate<? super T> hasNext, @NotNull @NotNull UnaryOperator<T> f)
    • noMergeFunction

      public static <T> BinaryOperator<T> noMergeFunction()
    • keysToMap

      public static <K, V> Map<K,V> keysToMap(Stream<? extends K> stream, Function<? super K,? extends V> fn)
    • entriesToMap

      public static <K, V> Map<K,V> entriesToMap(Stream<? extends Map.Entry<? extends K,? extends V>> stream)
    • entriesToMap

      public static <K, V, R> Map<K,R> entriesToMap(Stream<? extends Map.Entry<? extends K,? extends V>> stream, Function<? super V,? extends R> fn)
    • transformMap

      public static <K, V, R> Map<K,R> transformMap(Map<? extends K,? extends V> map, Function<? super V,? extends R> function)
    • toString

      public static <T> String toString(Collection<? extends T> collection)
    • toString

      public static <K, V> String toString(Map<? extends K,? extends V> map)
    • toString

      public static <T> String toString(Collection<? extends T> collection, int limit)
    • toString

      public static <K, V> String toString(Map<? extends K,? extends V> map, int limit)