Class OkkamStrings


  • public class OkkamStrings
    extends Object
    • Method Detail

      • isEmptyOrNull

        public static boolean isEmptyOrNull​(String string,
                                            boolean trim)
        Check if the string is null or empty.
        Parameters:
        string - The input string
        trim - true to trim the input string (when not null)
        Returns:
        The check result
      • isEmptyAndNotNull

        public static boolean isEmptyAndNotNull​(String string,
                                                boolean trim)
        Check if the string is empty and not null.
        Parameters:
        string - The input string
        trim - true to trim the input string (when not null)
        Returns:
        The check result
      • noOneIsEmptyOrNull

        public static boolean noOneIsEmptyOrNull​(boolean trim,
                                                 String... strings)
        Check if the strings are not empty and not blank.
        Parameters:
        trim - true to trim the strings (when not empty)
        strings - The input strings
        Returns:
        The check result
      • isOneOf

        public static boolean isOneOf​(String string,
                                      boolean trim,
                                      String... ors)
        Check if the string is one of the specified values. String could also be null, in this case the method will return true if there's a null element in the passed array.
        Parameters:
        string - The input string
        trim - true to trim the strings to check for equality
        ors - The values to check
        Returns:
        A boolean value depending on the result
      • trimIfNecessary

        public static String trimIfNecessary​(boolean trim,
                                             String src)
        Returns the trimmed string when not null and necessary (i.e. trim is true).
        Parameters:
        trim - true to trim the passed string
        src - the string to trim (maybe)
        Returns:
        the trimmed string (if necessary). Return null if src is null.
      • appendAll

        @SafeVarargs
        public static <T> StringBuilder appendAll​(StringBuilder sb,
                                                  T... elements)
        Append to the string Builder all elements.
        Type Parameters:
        T - The elements type
        Parameters:
        sb - The string builder
        elements - The elements to append
        Returns:
        The new string builder
      • separateArrayBy

        public static <T> String separateArrayBy​(T[] array,
                                                 String separator)
        Generate a string based on array, with a specified separator.
        Type Parameters:
        T - The array type
        Parameters:
        array - The input array
        separator - The separator
        Returns:
        The generated string
      • separateTreeMapValuesBy

        public static <T> String separateTreeMapValuesBy​(Map<T,​String> map,
                                                         String separator)
        Generate a string based on map values, with a specified separator. Use a tree map to guarantee ordering.
        Type Parameters:
        T - The map key type
        Parameters:
        map - The input map
        separator - The separator
        Returns:
        The generated string
      • splitByChar

        public static String[] splitByChar​(String stringToSplit,
                                           char charToSplit)
        Split a string by a char.
        Parameters:
        stringToSplit - The string to be split
        charToSplit - The char used to split the string
        Returns:
        The string array
      • concatRange

        public static <T> String concatRange​(T[] arr,
                                             String separator,
                                             int from,
                                             int to)
        Generate a String by concatenating Array fields between 'from' and 'to' position.
        Parameters:
        arr - The array from which elements are obtained
        separator - The string used as separator
        from - The starting position
        to - The ending position
        Returns:
        The concatenated string
      • concatRanges

        public static <T> String concatRanges​(T[] arr,
                                              String separator,
                                              int... ranges)
        Generate a String by concatenating Array fields between some position ranges.
        Parameters:
        arr - The array from which elements are obtained
        separator - The string used as separator
        ranges - The pairs of ranges
        Returns:
        The concatenated string
      • duplicate

        public static String duplicate​(String stringToDuplicate,
                                       int times)
        Duplicate the string n times.
        Parameters:
        stringToDuplicate - The string to duplicate
        times - The number of duplications
        Returns:
        The duplicated string