Class Util


  • public final class Util
    extends Object
    Misc. utilities.
    • Field Detail

      • LINE_SEPARATOR

        public static final String LINE_SEPARATOR
        The line separator for the current system
      • FILE_SEPARATOR

        public static final String FILE_SEPARATOR
        The file separator for the current system
      • PATH_SEPARATOR

        public static final String PATH_SEPARATOR
        The path separator for the current system
    • Method Detail

      • nullOrEmpty

        public static boolean nullOrEmpty​(String... strings)
        Parameters:
        strings - the strings to check
        Returns:
        true if one of the given strings is null or empty or if no arguments are provided, false otherwise
      • notNull

        public static boolean notNull​(Object... objects)
        Checks if any of the given objects is null
        Parameters:
        objects - the objects to check
        Returns:
        true if none of the given objects is null
      • map

        public static <K,​V> LinkedHashMap<K,​List<V>> map​(Collection<V> values,
                                                                     Function<V,​K> keyProvider)
        Maps the given values according to the keys provided by the given key provider, keeping the iteration order of the given collection. class Person { String name; Integer age; ... } List&#60;Person&#62; persons = ...; Function<Person, Integer> ageKeyProvider = new Function&#60;Person, Integer&#62;() { public Integer apply(Person person) { return person.getAge(); } }; Map&#60;Integer, List&#60;Person&#62;&#62; personsByAge = Util.map(persons, ageKeyProvider);
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        values - the values to map
        keyProvider - the object providing keys for values
        Returns:
        a LinkedHashMap with the values mapped to their respective key values, respecting the iteration order of the given collection
      • onClasspath

        public static boolean onClasspath​(String className)
        Parameters:
        className - the name of the class to search for
        Returns:
        true if the given class is found on the classpath
      • nullOrEmpty

        public static boolean nullOrEmpty​(Map... maps)
        Parameters:
        maps - the maps to check
        Returns:
        true if one of the given maps is null or empty or if no arguments are provided, false otherwise
      • nullOrEmpty

        public static boolean nullOrEmpty​(Map map)
        Parameters:
        map - the map to check
        Returns:
        true if the given map is null or empty, false otherwise
      • nullOrEmpty

        public static boolean nullOrEmpty​(Collection... collections)
        Parameters:
        collections - the collections to check
        Returns:
        true if one of the given collections is null or empty or if no arguments are provided, false otherwise
      • nullOrEmpty

        public static boolean nullOrEmpty​(Collection collection)
        Parameters:
        collection - the collection to check
        Returns:
        true if the given collection is null or empty, false otherwise
      • rejectNullOrEmpty

        public static String rejectNullOrEmpty​(String value,
                                               String valueName)
        Throws an IllegalArgumentException if the given string value is null or empty
        Parameters:
        value - the string value
        valueName - the name of the value to include in the error message
        Returns:
        the string value
      • roundDouble

        public static double roundDouble​(double d,
                                         int places)
        Rounds the given double to places decimal places
        Parameters:
        d - the double to round
        places - the number of decimal places
        Returns:
        the rounded value
      • getSystemProperties

        public static String getSystemProperties()
        Returns:
        a String containing all system properties, one per line
      • getSystemProperties

        public static String getSystemProperties​(Util.PropertyWriter propertyWriter)
        Returns a String containing all system properties, written by the given Util.PropertyWriter.
        Parameters:
        propertyWriter - for specific property formatting or exclusions
        Returns:
        a String containing all system properties, one per line
      • getSetMethod

        public static Method getSetMethod​(Class valueType,
                                          String property,
                                          Object valueOwner)
                                   throws NoSuchMethodException
        Returns the Method representing the setter for the given property in the given class.
        Parameters:
        valueType - the class of the value for the given property
        property - the name of the property for which to retrieve the set method
        valueOwner - an instance
        Returns:
        the method used to set the value of the linked property
        Throws:
        NoSuchMethodException - if the method does not exist in the owner class
      • getSetMethod

        public static Method getSetMethod​(Class valueType,
                                          String property,
                                          Class ownerClass)
                                   throws NoSuchMethodException
        Returns the Method representing the setter for the given property in the given class.
        Parameters:
        valueType - the class of the value for the given property
        property - the name of the property for which to retrieve the set method
        ownerClass - the class
        Returns:
        the method used to set the value of the linked property
        Throws:
        NoSuchMethodException - if the method does not exist in the owner class
      • getGetMethod

        public static Method getGetMethod​(Class valueType,
                                          String property,
                                          Object valueOwner)
                                   throws NoSuchMethodException
        Returns the Method representing the getter for the given property in the given class.
        Parameters:
        valueType - the class of the value for the given property
        property - the name of the property for which to retrieve the get method
        valueOwner - an instance
        Returns:
        the method used to get the value of the linked property
        Throws:
        NoSuchMethodException - if the method does not exist in the owner class
      • getGetMethod

        public static Method getGetMethod​(Class valueType,
                                          String property,
                                          Class ownerClass)
                                   throws NoSuchMethodException
        Returns the Method representing the getter for the given property in the given class.
        Parameters:
        valueType - the class of the value for the given property
        property - the name of the property for which to retrieve the get method
        ownerClass - the class
        Returns:
        the method used to get the value of the linked property
        Throws:
        NoSuchMethodException - if the method does not exist in the owner class