Package glide.utils

Class Java8Utils


  • public class Java8Utils
    extends java.lang.Object
    Utility methods for Java 8 compatibility. Provides alternatives for Java 9+ APIs.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int compareByteArrays​(byte[] a, byte[] b)
      Compares two byte arrays lexicographically.
      static <T> java.util.List<T> createList()
      Creates an empty list.
      static <T> java.util.List<T> createList​(T... elements)
      Creates a list with elements.
      static <K,​V>
      java.util.Map<K,​V>
      createMap()
      Creates an empty HashMap.
      static <K,​V>
      java.util.Map<K,​V>
      createMap​(K k1, V v1)
      Creates a HashMap with one key-value pair.
      static <K,​V>
      java.util.Map<K,​V>
      createMap​(K k1, V v1, K k2, V v2)
      Creates a HashMap with two key-value pairs.
      static <K,​V>
      java.util.Map<K,​V>
      createMap​(K k1, V v1, K k2, V v2, K k3, V v3)
      Creates a HashMap with three key-value pairs.
      static <K,​V>
      java.util.Map<K,​V>
      createMap​(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
      Creates a HashMap with four key-value pairs.
      static <K,​V>
      java.util.Map<K,​V>
      createMap​(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
      Creates a HashMap with five key-value pairs.
      static <K,​V>
      java.util.Map<K,​V>
      createMap​(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
      Creates a HashMap with six key-value pairs.
      static <K,​V>
      java.util.Map<K,​V>
      createMap​(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
      Creates a HashMap with seven key-value pairs.
      static <T> java.util.Set<T> createSet​(T... elements)
      Creates a HashSet with elements.
      static java.lang.String repeat​(java.lang.String str, int count)
      Repeats a string n times.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • compareByteArrays

        public static int compareByteArrays​(byte[] a,
                                            byte[] b)
        Compares two byte arrays lexicographically.
        Parameters:
        a - the first array to compare
        b - the second array to compare
        Returns:
        the value 0 if the first and second array are equal and contain the same elements in the same order; a value less than 0 if the first array is lexicographically less than the second array; and a value greater than 0 if the first array is lexicographically greater than the second array
      • createMap

        public static <K,​V> java.util.Map<K,​V> createMap()
        Creates an empty HashMap.
        Type Parameters:
        K - the type of keys
        V - the type of values
        Returns:
        an empty HashMap
      • createMap

        public static <K,​V> java.util.Map<K,​V> createMap​(K k1,
                                                                     V v1)
        Creates a HashMap with one key-value pair.
        Type Parameters:
        K - the type of keys
        V - the type of values
        Parameters:
        k1 - the key
        v1 - the value
        Returns:
        a HashMap containing the key-value pair
      • createMap

        public static <K,​V> java.util.Map<K,​V> createMap​(K k1,
                                                                     V v1,
                                                                     K k2,
                                                                     V v2)
        Creates a HashMap with two key-value pairs.
        Type Parameters:
        K - the type of keys
        V - the type of values
        Parameters:
        k1 - the first key
        v1 - the first value
        k2 - the second key
        v2 - the second value
        Returns:
        a HashMap containing the key-value pairs
      • createMap

        public static <K,​V> java.util.Map<K,​V> createMap​(K k1,
                                                                     V v1,
                                                                     K k2,
                                                                     V v2,
                                                                     K k3,
                                                                     V v3)
        Creates a HashMap with three key-value pairs.
        Type Parameters:
        K - the type of keys
        V - the type of values
        Parameters:
        k1 - the first key
        v1 - the first value
        k2 - the second key
        v2 - the second value
        k3 - the third key
        v3 - the third value
        Returns:
        a HashMap containing the key-value pairs
      • createMap

        public static <K,​V> java.util.Map<K,​V> createMap​(K k1,
                                                                     V v1,
                                                                     K k2,
                                                                     V v2,
                                                                     K k3,
                                                                     V v3,
                                                                     K k4,
                                                                     V v4)
        Creates a HashMap with four key-value pairs.
        Type Parameters:
        K - the type of keys
        V - the type of values
        Parameters:
        k1 - the first key
        v1 - the first value
        k2 - the second key
        v2 - the second value
        k3 - the third key
        v3 - the third value
        k4 - the fourth key
        v4 - the fourth value
        Returns:
        a HashMap containing the key-value pairs
      • createMap

        public static <K,​V> java.util.Map<K,​V> createMap​(K k1,
                                                                     V v1,
                                                                     K k2,
                                                                     V v2,
                                                                     K k3,
                                                                     V v3,
                                                                     K k4,
                                                                     V v4,
                                                                     K k5,
                                                                     V v5)
        Creates a HashMap with five key-value pairs.
        Type Parameters:
        K - the type of keys
        V - the type of values
        Parameters:
        k1 - the first key
        v1 - the first value
        k2 - the second key
        v2 - the second value
        k3 - the third key
        v3 - the third value
        k4 - the fourth key
        v4 - the fourth value
        k5 - the fifth key
        v5 - the fifth value
        Returns:
        a HashMap containing the key-value pairs
      • createMap

        public static <K,​V> java.util.Map<K,​V> createMap​(K k1,
                                                                     V v1,
                                                                     K k2,
                                                                     V v2,
                                                                     K k3,
                                                                     V v3,
                                                                     K k4,
                                                                     V v4,
                                                                     K k5,
                                                                     V v5,
                                                                     K k6,
                                                                     V v6)
        Creates a HashMap with six key-value pairs.
        Type Parameters:
        K - the type of keys
        V - the type of values
        Parameters:
        k1 - the first key
        v1 - the first value
        k2 - the second key
        v2 - the second value
        k3 - the third key
        v3 - the third value
        k4 - the fourth key
        v4 - the fourth value
        k5 - the fifth key
        v5 - the fifth value
        k6 - the sixth key
        v6 - the sixth value
        Returns:
        a HashMap containing the key-value pairs
      • createMap

        public static <K,​V> java.util.Map<K,​V> createMap​(K k1,
                                                                     V v1,
                                                                     K k2,
                                                                     V v2,
                                                                     K k3,
                                                                     V v3,
                                                                     K k4,
                                                                     V v4,
                                                                     K k5,
                                                                     V v5,
                                                                     K k6,
                                                                     V v6,
                                                                     K k7,
                                                                     V v7)
        Creates a HashMap with seven key-value pairs.
        Type Parameters:
        K - the type of keys
        V - the type of values
        Parameters:
        k1 - the first key
        v1 - the first value
        k2 - the second key
        v2 - the second value
        k3 - the third key
        v3 - the third value
        k4 - the fourth key
        v4 - the fourth value
        k5 - the fifth key
        v5 - the fifth value
        k6 - the sixth key
        v6 - the sixth value
        k7 - the seventh key
        v7 - the seventh value
        Returns:
        a HashMap containing the key-value pairs
      • createSet

        @SafeVarargs
        public static <T> java.util.Set<T> createSet​(T... elements)
        Creates a HashSet with elements.
        Type Parameters:
        T - the type of elements
        Parameters:
        elements - the elements
        Returns:
        a HashSet containing the elements
      • createList

        public static <T> java.util.List<T> createList()
        Creates an empty list.
        Type Parameters:
        T - the type of elements
        Returns:
        an empty list
      • createList

        @SafeVarargs
        public static <T> java.util.List<T> createList​(T... elements)
        Creates a list with elements.
        Type Parameters:
        T - the type of elements
        Parameters:
        elements - the elements
        Returns:
        a list containing the elements
      • repeat

        public static java.lang.String repeat​(java.lang.String str,
                                              int count)
        Repeats a string n times.
        Parameters:
        str - the string to repeat
        count - the number of times to repeat
        Returns:
        the repeated string
        Throws:
        java.lang.IllegalArgumentException - if count is negative