Class Strings


  • public class Strings
    extends java.lang.Object
    Helper class for dealing with strings.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Set<java.lang.String> KEYWORDS  
      private static char UNDERSCORE  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Strings()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String capitalize​(java.lang.String string)  
      static java.lang.String decapitalize​(java.lang.String string)  
      (package private) static java.lang.Iterable<java.lang.String> extractParts​(java.lang.String name)
      It removes the dots from the name and creates an Iterable from them.
      static java.lang.String getMostSimilarWord​(java.lang.String word, java.util.Collection<java.lang.String> similarWords)  
      static java.lang.String getSafeVariableName​(java.lang.String name, java.lang.String... existingVariableNames)  
      static java.lang.String getSafeVariableName​(java.lang.String name, java.util.Collection<java.lang.String> existingVariableNames)
      Returns a variable name which doesn't conflict with the given variable names existing in the same scope and the Java keywords.
      static boolean isEmpty​(java.lang.String string)  
      static boolean isNotEmpty​(java.lang.String string)  
      static java.lang.String join​(java.lang.Iterable<?> iterable, java.lang.String separator)  
      static <T> java.lang.String join​(java.lang.Iterable<T> iterable, java.lang.String separator, Extractor<T,​java.lang.String> extractor)  
      static java.lang.String joinAndCamelize​(java.lang.Iterable<?> iterable)  
      private static int levenshteinDistance​(java.lang.String s, java.lang.String t)  
      static java.lang.String sanitizeIdentifierName​(java.lang.String identifier)  
      static java.lang.String stubPropertyName​(java.lang.String fullyQualifiedName)
      Returns a stub property name from full class name by stripping away the package and decapitalizing the name For example will return fooBar for com.foo.bar.baz.FooBar class name
      • Methods inherited from class java.lang.Object

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

      • KEYWORDS

        private static final java.util.Set<java.lang.String> KEYWORDS
    • Constructor Detail

      • Strings

        private Strings()
    • Method Detail

      • capitalize

        public static java.lang.String capitalize​(java.lang.String string)
      • decapitalize

        public static java.lang.String decapitalize​(java.lang.String string)
      • join

        public static java.lang.String join​(java.lang.Iterable<?> iterable,
                                            java.lang.String separator)
      • join

        public static <T> java.lang.String join​(java.lang.Iterable<T> iterable,
                                                java.lang.String separator,
                                                Extractor<T,​java.lang.String> extractor)
      • joinAndCamelize

        public static java.lang.String joinAndCamelize​(java.lang.Iterable<?> iterable)
      • isEmpty

        public static boolean isEmpty​(java.lang.String string)
      • isNotEmpty

        public static boolean isNotEmpty​(java.lang.String string)
      • getSafeVariableName

        public static java.lang.String getSafeVariableName​(java.lang.String name,
                                                           java.lang.String... existingVariableNames)
      • getSafeVariableName

        public static java.lang.String getSafeVariableName​(java.lang.String name,
                                                           java.util.Collection<java.lang.String> existingVariableNames)
        Returns a variable name which doesn't conflict with the given variable names existing in the same scope and the Java keywords.
        Parameters:
        name - the name to get a safe version for
        existingVariableNames - the names of other variables existing in the same scope
        Returns:
        a variable name based on the given original name, not conflicting with any of the given other names or any Java keyword; starting with a lower-case letter
      • sanitizeIdentifierName

        public static java.lang.String sanitizeIdentifierName​(java.lang.String identifier)
        Parameters:
        identifier - identifier to sanitize
        Returns:
        the identifier without any characters that are not allowed as part of a Java identifier.
      • stubPropertyName

        public static java.lang.String stubPropertyName​(java.lang.String fullyQualifiedName)
        Returns a stub property name from full class name by stripping away the package and decapitalizing the name For example will return fooBar for com.foo.bar.baz.FooBar class name
        Parameters:
        fullyQualifiedName - fully qualified class name, such as com.foo.bar.baz.FooBar
        Returns:
        stup property name, such as fooBar
      • extractParts

        static java.lang.Iterable<java.lang.String> extractParts​(java.lang.String name)
        It removes the dots from the name and creates an Iterable from them. E.q. for the name props.font it will return an Iterable containing the props and font
        Parameters:
        name - the name that needs to be parsed into parts
        Returns:
        an Iterable containing all the parts of the name.
      • getMostSimilarWord

        public static java.lang.String getMostSimilarWord​(java.lang.String word,
                                                          java.util.Collection<java.lang.String> similarWords)
      • levenshteinDistance

        private static int levenshteinDistance​(java.lang.String s,
                                               java.lang.String t)