Class Utils


  • public final class Utils
    extends Object
    Utility class.
    • Method Detail

      • immutable

        public static <T> List<T> immutable​(List<T> list,
                                            Supplier<List<T>> listSupplier)
        Returns an immutable List.
        Type Parameters:
        T - The type of elements of this list.
        Parameters:
        list - The original list to copy.
        listSupplier - A function which returns a new empty List into which the results will be inserted.
        Returns:
        An immutable list of strings.
      • immutableMap

        public static <K,​V> Map<K,​V> immutableMap​(Map<K,​V> map,
                                                              Supplier<Map<K,​V>> supplier)
        Creates an immutable Map.

        Note: This method uses a reference for the value. If the map value is not a primitive type, such as a list of strings, you may consider using immutable method before creating your immutableMap

        .
        Type Parameters:
        K - Key type of the Map.
        V - Value type of the Map.
        Parameters:
        map - The original map to copy.
        supplier - A function which returns a new empty Map into which the results will be inserted.
        Returns:
        An immutable Map.
      • throwableCauses

        public static List<Throwable> throwableCauses​(Throwable throwable)
        Get the Throwable's causes as a list from a Throwable.
        Parameters:
        throwable - The Throwable to extract the causes from, not null.
        Returns:
        an unmodifiable list containing the cause chain starting with Throwable.