Class NameUtil


  • public class NameUtil
    extends java.lang.Object
    Author:
    Kohsuke Kawaguchi
    • Constructor Summary

      Constructors 
      Constructor Description
      NameUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String capitalize​(java.lang.String s)
      Capitalizes the first character of the specified string, and de-capitalize the rest of characters.
      static boolean equal​(java.lang.String s, java.lang.String t)
      determine if two Strings are iqual allowing null values
      static boolean equalsIgnoreCase​(java.lang.String s, java.lang.String t)
      determine if two Strings are equal ignoring case allowing null values
      static void escape​(java.lang.StringBuffer sb, java.lang.String s, int start)
      Escapes characters is the given string so that they can be printed by only using US-ASCII characters.
      static java.lang.String escapeURI​(java.lang.String s)
      Escape any characters that would cause the single arg constructor of java.net.URI to complain about illegal chars.
      static java.lang.String getParentUriPath​(java.lang.String uriPath)
      Calculate the parent URI path of the given URI path.
      protected static boolean isDigit​(char c)  
      protected static boolean isLetter​(char c)  
      protected static boolean isLower​(char c)  
      protected static boolean isPunct​(char c)  
      protected static boolean isUpper​(char c)  
      protected static int nextBreak​(java.lang.String s, int start)  
      static java.lang.String normalizeUriPath​(java.lang.String uriPath)
      Calculate the normalized form of the given uriPath.
      static java.lang.String toClassName​(java.lang.String s)  
      static java.lang.String toConstantName​(java.lang.String s)
      Formats a string into "THIS_KIND_OF_FORMAT_ABC_DEF".
      static java.lang.String toConstantName​(java.lang.String[] ss)
      Formats a string into "THIS_KIND_OF_FORMAT_ABC_DEF".
      static java.lang.String toInterfaceName​(java.lang.String token)  
      static java.lang.String toMethodName​(java.lang.String s)  
      protected static java.lang.String toMixedCaseName​(java.lang.String[] ss, boolean startUpper)  
      protected static java.lang.String toMixedCaseVariableName​(java.lang.String[] ss, boolean startUpper, boolean cdrUpper)  
      static java.lang.String toPackageName​(java.lang.String s)  
      static java.lang.String toPropertyName​(java.lang.String s)  
      static java.lang.String toVariableName​(java.lang.String s)  
      static java.lang.String[] toWordList​(java.lang.String s)
      Tokenizes a string into words and capitalizes the first character of each word.
      • Methods inherited from class java.lang.Object

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

      • NameUtil

        public NameUtil()
    • Method Detail

      • isPunct

        protected static boolean isPunct​(char c)
      • isDigit

        protected static boolean isDigit​(char c)
      • isUpper

        protected static boolean isUpper​(char c)
      • isLower

        protected static boolean isLower​(char c)
      • isLetter

        protected static boolean isLetter​(char c)
      • capitalize

        public static java.lang.String capitalize​(java.lang.String s)
        Capitalizes the first character of the specified string, and de-capitalize the rest of characters.
      • nextBreak

        protected static int nextBreak​(java.lang.String s,
                                       int start)
      • toWordList

        public static java.lang.String[] toWordList​(java.lang.String s)
        Tokenizes a string into words and capitalizes the first character of each word.

        This method uses a change in character type as a splitter of two words. For example, "abc100ghi" will be splitted into {"Abc", "100","Ghi"}.

      • toMixedCaseName

        protected static java.lang.String toMixedCaseName​(java.lang.String[] ss,
                                                          boolean startUpper)
      • toMixedCaseVariableName

        protected static java.lang.String toMixedCaseVariableName​(java.lang.String[] ss,
                                                                  boolean startUpper,
                                                                  boolean cdrUpper)
      • toConstantName

        public static java.lang.String toConstantName​(java.lang.String s)
        Formats a string into "THIS_KIND_OF_FORMAT_ABC_DEF".
        Returns:
        Always return a string but there's no guarantee that the generated code is a valid Java identifier.
      • toConstantName

        public static java.lang.String toConstantName​(java.lang.String[] ss)
        Formats a string into "THIS_KIND_OF_FORMAT_ABC_DEF".
        Returns:
        Always return a string but there's no guarantee that the generated code is a valid Java identifier.
      • escape

        public static void escape​(java.lang.StringBuffer sb,
                                  java.lang.String s,
                                  int start)
        Escapes characters is the given string so that they can be printed by only using US-ASCII characters. The escaped characters will be appended to the given StringBuffer.
        Parameters:
        sb - StringBuffer that receives escaped string.
        s - String to be escaped. s.substring(start) will be escaped and copied to the string buffer.
      • escapeURI

        public static java.lang.String escapeURI​(java.lang.String s)
        Escape any characters that would cause the single arg constructor of java.net.URI to complain about illegal chars.
        Parameters:
        s - source string to be escaped
      • getParentUriPath

        public static java.lang.String getParentUriPath​(java.lang.String uriPath)
        Calculate the parent URI path of the given URI path.
        Parameters:
        uriPath - the uriPath (as returned by java.net.URI#getPath()
        Returns:
        the parent URI path of the given URI path
      • normalizeUriPath

        public static java.lang.String normalizeUriPath​(java.lang.String uriPath)
        Calculate the normalized form of the given uriPath. For example: /a/b/c/ -> /a/b/c/ /a/b/c -> /a/b/ /a/ -> /a/ /a -> /
        Parameters:
        uriPath - path of a URI (as returned by java.net.URI#getPath()
        Returns:
        the normalized uri path
      • equalsIgnoreCase

        public static boolean equalsIgnoreCase​(java.lang.String s,
                                               java.lang.String t)
        determine if two Strings are equal ignoring case allowing null values
        Parameters:
        s - string 1
        t - string 2
        Returns:
        true iff the given strings are equal ignoring case, false if they aren't equal or either of them are null.
      • equal

        public static boolean equal​(java.lang.String s,
                                    java.lang.String t)
        determine if two Strings are iqual allowing null values
        Parameters:
        s - string 1
        t - string 2
        Returns:
        true iff the strings are equal, false if they aren't equal or either of them are null.
      • toClassName

        public static java.lang.String toClassName​(java.lang.String s)
      • toVariableName

        public static java.lang.String toVariableName​(java.lang.String s)
      • toMethodName

        public static java.lang.String toMethodName​(java.lang.String s)
      • toInterfaceName

        public static java.lang.String toInterfaceName​(java.lang.String token)
      • toPropertyName

        public static java.lang.String toPropertyName​(java.lang.String s)
      • toPackageName

        public static java.lang.String toPackageName​(java.lang.String s)