Class StringUtils

java.lang.Object
com._1c.g5.v8.dt.common.StringUtils

public class StringUtils extends Object
Utils are responsible for basic operations with strings
  • Field Details

  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • isEmpty

      public static boolean isEmpty(String str)
      Is empty string
      Parameters:
      str -
      Returns:
      true if null or empty
    • isNotEmpty

      public static boolean isNotEmpty(String str)
      Is not empty string
      Parameters:
      str -
      Returns:
      true if string not null and not empty
    • isBlank

      public static boolean isBlank(CharSequence cs)
      Checks whether the input string null, empty or contains only white space characters.
      Parameters:
      cs - the input CharSequence, can be null
      Returns:
      true if the input string null or empty or contains only white space characters, false otherwise.
    • isNotBlank

      public static boolean isNotBlank(CharSequence cs)
      Checks whether string is not blank.
      Parameters:
      cs - the input CharSequence, can be null
      Returns:
      true if the string is not blank, false otherwise.
      See Also:
    • defaultIfBlank

      public static String defaultIfBlank(String str, String defaultStr)
      Returns either the passed str in String, or if the str is blank, empty or null, the value of defaultStr.
      Parameters:
      str - the String to check, can be null
      defaultStr - the default String to return if the input is blank, empty or null, can be null
      Returns:
      the passed str in String, or the default, can be null
    • requireNonBlank

      public static <T extends CharSequence> T requireNonBlank(T cs)
      Checks that the specified char sequence is not blank. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:
       public Foo(String string) {
           this.string = StringUtils.requireNonBlank(string);
       }
       
      Type Parameters:
      T - the type of the char sequence.
      Parameters:
      cs - the char sequence to check
      Returns:
      cs if not blank, never null.
      Throws:
      NullPointerException - if cs is null.
      IllegalArgumentException - if cs is not null, but is blank.
    • equalsTrimValues

      public static boolean equalsTrimValues(String str1, String str2)
      Equals method for trimmed srings
      Parameters:
      str1 -
      str2 -
      Returns:
      true if strings are equal
    • equals

      public static boolean equals(String str1, String str2)
    • uncapitalize

      public static String uncapitalize(String source)
    • capitalize

      public static String capitalize(String source)
      Sets the first character to the Upper case
      Parameters:
      source - - the source string
      Returns:
      the capitalized string
    • nameToText

      public static String nameToText(String nameInput)
      Converts passed name input string into text string using next rules:
      1. A set of underline symbols ('_') changes to one empty symbol (space, ' ') If this symbol is first or last, it will be omitted
      2. Three and more upper case letters are not modified. Less than three upper case letters are placed in upper case if they are the last one in the string
      3. Before first upper case symbol, a space symbol is placed (only if there is no space before it)
      4. If there is a lower case or number symbol after one or two upper case symbols then upper case symbols are changed to lower case and there will be added a space symbol before them
      5. First character of a name is always in upper case
      Parameters:
      nameInput - - name of the element
      Returns:
      - text converted from name
    • removeExtension

      public static String removeExtension(String s)
    • fuzzyMatch

      public static FuzzyPattern.Match fuzzyMatch(String pattern, String sample, boolean useMutation)
      Performs fuzzy match given the pattern and sample.
      Parameters:
      pattern - pattern to match against, not null.
      sample - sample to match, not null.
      useMutation - use mutation (splitting) of pattern
      Returns:
      FuzzyPattern.Match.NONE if no match found, match describing the matched ranges otherwise, not null.
      See Also:
    • fuzzyMatch

      public static FuzzyPattern.Match fuzzyMatch(String pattern, String sample)
      Performs fuzzy match given the pattern and sample.
      Parameters:
      pattern - pattern to match against, not null.
      sample - sample to match, not null.
      Returns:
      FuzzyPattern.Match.NONE if no match found, match describing the matched ranges otherwise, not null
      See Also:
    • trimDigitSuffix

      public static String trimDigitSuffix(String original)
      Gets the copy of original string with trailing digit removed.
      Parameters:
      original - - a prototype
      Returns:
      A copy of original string with trailing digit removed, or original string if it has no trailing digit.
    • isValidName

      public static boolean isValidName(String name)
      Правильное имя свойства или метода контекста представляет собой строку ненулевой длины. Первый символ этой строки - буква или символ '_'. Все последующие символы должны быть буквами, десятичными цифрами или символами '_'
      Parameters:
      name - имя
      Returns:
    • lowerCaseHashCode

      public static int lowerCaseHashCode(String str)
      Gets hashCode for lower case string.
      Parameters:
      str - the string.
      Returns:
      a hashCode of lower case string.
    • stringAsRegEx

      public static String stringAsRegEx(String pattern)
      Escaped characters in string to use in regEx
      Parameters:
      pattern - - the input string (not null)
      Returns:
      an escaped string
    • processAmpersands

      public static Pair<String,Integer> processAmpersands(String string)
      Parses string with ampersands (if any) and returns modified string and position of first char that needs to be underlined.
      Parameters:
      string - original string, can be null or empty
      Returns:
      pair of result string and position of character that needs to be underlined in the result string, never null