Class Utils


  • public final class Utils
    extends java.lang.Object
    Author:
    Tim Dudgeon
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean containsIgnoreCase​(java.lang.String[] vals, java.lang.String item)
      Does this array of strings contain the specified item (case is ignored).
      static boolean containsIgnoreCase​(java.util.Collection<java.lang.String> vals, java.lang.String item)
      Does this collection of strings contain the specified item (case is ignored).
      static java.lang.String createGuid()  
      static java.lang.String findFreeName​(java.lang.String name, java.lang.Iterable<? extends java.lang.String> forbidden, java.lang.String prefix, java.lang.String suffix, boolean caseInsensitive)
      Gets a unique name variant.
      static java.lang.String generateMD5String​(java.lang.String str)  
      static java.lang.String normalize​(java.lang.String s)
      Gets the normalized version of a string.
      • Methods inherited from class java.lang.Object

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

      • createGuid

        public static java.lang.String createGuid()
      • generateMD5String

        public static java.lang.String generateMD5String​(java.lang.String str)
      • containsIgnoreCase

        public static boolean containsIgnoreCase​(java.lang.String[] vals,
                                                 java.lang.String item)
        Does this array of strings contain the specified item (case is ignored).
      • containsIgnoreCase

        public static boolean containsIgnoreCase​(java.util.Collection<java.lang.String> vals,
                                                 java.lang.String item)
        Does this collection of strings contain the specified item (case is ignored).
      • findFreeName

        public static java.lang.String findFreeName​(java.lang.String name,
                                                    java.lang.Iterable<? extends java.lang.String> forbidden,
                                                    java.lang.String prefix,
                                                    java.lang.String suffix,
                                                    boolean caseInsensitive)
        Gets a unique name variant. This method returns the name or its modification that does not exist among the forbidden names.

        The typical usecase for this method is to find a new available name for an object (eg. a file or a table), which will not conflict with the names of existing objects. The list of existing names is passed in as the forbidden parameter. The initial variant of the new name is passed in as the name parameter.

        It is guaranteed that this method will return the initial name without any modification if it is not among the forbidden variants. Otherwise this method will transform the name according to the following pattern with <N> starting at 1 and incrementing until a unique name variant is found.

        prefix + name + suffix + <N>

        Parameters:
        name - The initial name. Must not be null and must not be empty.
        forbidden - The list of name variants that are to be skipped.
        prefix - A string to prepend when transforming name. Can be null or empty.
        suffix - A string to append when transforming name. Can be null or empty.
        caseInsensitive - If true the name variants will be compared in case-insensitive manner.
        Returns:
        The name variant that is not among the forbidden variants list.
        Since:
        6.3
      • normalize

        public static java.lang.String normalize​(java.lang.String s)
        Gets the normalized version of a string. This method transforms the input string using the following rules.
        • Remove all accents and/or diacritic marks.
        • Replace all characters except letters and digits with the underscore character ('_').
        • Prepend a letter if the string does not start with one.
        Parameters:
        s - The string to normalize.
        Returns:
        The normalized string.
        Since:
        6.3