Class StrUtils

java.lang.Object
adalid.commons.util.StrUtils

public class StrUtils extends Object
Author:
Jorge Campins
  • Field Details

  • Constructor Details

    • StrUtils

      public StrUtils()
  • Method Details

    • digest

      public static String digest(String credentials)
      Digest password or other credentials and convert the result to a corresponding hex string.
      Parameters:
      credentials - Password or other credentials
      Returns:
      the digested hex string. If exception, the plain credentials string is returned.
    • digest

      public static String digest(String credentials, String algorithm)
      Digest password or other credentials and convert the result to a corresponding hex string.
      Parameters:
      credentials - Password or other credentials
      algorithm - Algorithm used to do the digest
      Returns:
      the digested hex string. If exception, the plain credentials string is returned.
    • digest

      public static String digest(String credentials, String algorithm, String encoding)
      Digest password using the algorithm especified and convert the result to a corresponding hex string.
      Parameters:
      credentials - Password or other credentials
      algorithm - Algorithm used to do the digest
      encoding - Character encoding of the string to digest
      Returns:
      the digested hex string. If exception, the plain credentials string is returned.
    • getCrypticName

      public static String getCrypticName(String prefix, String string, String suffix)
    • getSha256Base36

      public static String getSha256Base36(String string)
    • uniteWords

      public static String uniteWords(String string1, String string2)
    • separateLines

      public static String separateLines(String string, int maxLineLength)
    • separateLines

      public static String separateLines(String string, int maxLineLength, String separator)
    • separateLines

      public static String separateLines(String string, int maxLineLength, String separator, boolean separatorLine)
    • split

      public static List<String> split(String string)
    • split

      public static List<String> split(String string, int max)
    • split

      public static List<String> split(String string, int max, String separator)
    • split

      public static List<String> split(String string, int max, String separator, boolean separatorLine)
    • split

      public static List<String> split(String string, int max, String separator, boolean separatorLine, String prefix)
      split a text into a list of lines.
      Parameters:
      string - the text to split.
      max - the maximum line length.
      separator - the paragraph separator string.
      separatorLine - if true, the paragraph separator is added as a line between paragraphs.
      prefix - the new line prefix
      Returns:
      the list of split.
    • ltrim

      public static String ltrim(String s)
    • ltrimToNull

      public static String ltrimToNull(String s)
    • rtrim

      public static String rtrim(String s)
    • rtrimToNull

      public static String rtrimToNull(String s)
    • format

      public static String format(String string, String template)
    • getStringJson

      public static String getStringJson(String key, Object value)
    • toString

      public static String toString(Object obj)
    • allAreBlank

      public static boolean allAreBlank(String... strings)
    • noneIsBlank

      public static boolean noneIsBlank(String... strings)
    • notAllAreBlank

      public static boolean notAllAreBlank(String... strings)
    • oneIsBlank

      public static boolean oneIsBlank(String... strings)
    • equalsAny

      public static boolean equalsAny(String string, String strings)
    • equalsAny

      public static boolean equalsAny(String string, String... strings)
    • blankless

      public static String[] blankless(String... strings)
    • blankless

      public static Set<String> blankless(Set<String> strings)
    • blankless

      public static List<String> blankless(List<String> strings)
    • coalesce

      public static String coalesce(String... strings)
    • coalesceToDefault

      public static String coalesceToDefault(String defaultString, String strings)
    • coalesceToDefault

      public static String coalesceToDefault(String defaultString, String... strings)
    • coalesceToEmpty

      public static String coalesceToEmpty(String strings)
    • coalesceToEmpty

      public static String coalesceToEmpty(String... strings)
    • coalesceToNull

      public static String coalesceToNull(String strings)
    • coalesceToNull

      public static String coalesceToNull(String... strings)
    • getLongNumericKey

      public static String getLongNumericKey(String string)
      Returns a long numeric key for string. See template opcion_menu.sql.vm
      Parameters:
      string - a string
      Returns:
      string's long numeric key
    • getLongNumericCode

      public static String getLongNumericCode(String string)
      Returns a long numeric code for string.
      Parameters:
      string - a string
      Returns:
      string's long numeric code
      See Also:
    • getLongNumericKeyCode

      public static String getLongNumericKeyCode(String string)
      Returns a long numeric key code for string.
      Parameters:
      string - a string
      Returns:
      string's long numeric key code
    • firstWordCase

      public static char firstWordCase(String string)
      This method inspects the characters in the first word of the string. The first word ends with the first character that is not a letter, a digit, a hyphen, or an underscore; if the string contains only those characters, the first word is the entire string.
      Parameters:
      string - the string to inspect
      Returns:
      one of the following characters:
      • ? if the string is null or empty
      • M if the first word contains both lowercase and uppercase letters
      • L if the first word contains only lowercase letters
      • U if the first word contains only uppercase letters
      • X if the first word contains at least one character that is not a letter (a digit, a hyphen, or an underscore)
    • getRandomString

      public static String getRandomString()
    • getRandomString

      public static String getRandomString(int length)
    • getSimpleString

      public static String getSimpleString(Object obj)
    • getString

      public static String getString(int n, char c)
    • getString

      public static String getString(Object obj)
    • getSubString

      public static String getSubString(Clob clob)
    • getStringDelimitado

      public static String getStringDelimitado(Object obj)
    • getStringNoDelimitado

      public static String getStringNoDelimitado(String delimitado)
    • getStringParametrizado

      public static String getStringParametrizado(String patron, Object... argumentos)
    • getStringStandard

      public static String getStringStandard(Object obj)
    • getStringSql

      public static String getStringSql(Object obj)
    • getStringSqlDelimitado

      public static String getStringSqlDelimitado(Object obj)
    • getStringSqlNoDelimitado

      public static String getStringSqlNoDelimitado(Object obj)
    • getStringSqlParametrizado

      public static String getStringSqlParametrizado(String patron, Object... argumentos)
    • getString

      public static String getString(ResourceBundle resourceBundle, String key)
    • getString

      public static String getString(ResourceBundle resourceBundle, String key, String left, String right)
    • getString

      public static String getString(String equals, String separator, String open, String close, Object object)
    • getString

      public static String getString(String equals, String separator, String open, String close, Object... objects)
    • getNullStringWhenBlankOrEqualsToKey

      public static String getNullStringWhenBlankOrEqualsToKey(String string, String key)
    • getNullStringWhenBlankOrEqualsToKey

      public static String getNullStringWhenBlankOrEqualsToKey(String string, String key, String left, String right)
    • esIdentificadorSqlValido

      public static boolean esIdentificadorSqlValido(String string)
    • esIdentificadorArchivoValido

      public static boolean esIdentificadorArchivoValido(String string)
    • getIdentificadorSql

      public static String getIdentificadorSql(String string, int maxLength)
    • getIdentificadorSql

      public static String getIdentificadorSql(String prefix, String string, String suffix, int maxLength)
    • getIdentificadorSql

      public static String getIdentificadorSql(String string)
    • getIdentificadorSqlLowerCase

      public static String getIdentificadorSqlLowerCase(String string)
    • getIdentificadorSqlUpperCase

      public static String getIdentificadorSqlUpperCase(String string)
    • getArtifactName

      public static String getArtifactName(String string)
    • getArtifactName

      public static String getArtifactName(String string, char separator)
    • getArtifactName

      public static String getArtifactName(String string, String separator)
    • getIdentifier

      public static String getIdentifier(String string)
    • getIdentifier

      public static String getIdentifier(String string, char separator)
    • getIdentifier

      public static String getIdentifier(String string, String separator)
    • getLowerCaseIdentifier

      public static String getLowerCaseIdentifier(String string)
    • getLowerCaseIdentifier

      public static String getLowerCaseIdentifier(String string, char separator)
    • getLowerCaseIdentifier

      public static String getLowerCaseIdentifier(String string, String separator)
    • getUpperCaseIdentifier

      public static String getUpperCaseIdentifier(String string)
    • getUpperCaseIdentifier

      public static String getUpperCaseIdentifier(String string, char separator)
    • getUpperCaseIdentifier

      public static String getUpperCaseIdentifier(String string, String separator)
    • getMavenIdentifier

      public static String getMavenIdentifier(String string)
    • getMavenVersion

      public static String getMavenVersion(String string)
    • getOracleVersionNumber

      public static String getOracleVersionNumber(String string)
    • getFileName

      public static String getFileName(String string)
    • getFileName

      public static String getFileName(String string, String separator)
    • getPageName

      public static String getPageName(String url)
    • getQualifiedName

      public static String getQualifiedName(String name, String qualifier)
    • getUnqualifiedName

      public static String getUnqualifiedName(String name, String qualifier)
    • getQualifiedShortName

      public static String getQualifiedShortName(String name, String qualifier)
    • getUnqualifiedShortName

      public static String getUnqualifiedShortName(String name, String qualifier)
    • isASCII

      public static boolean isASCII(char c)
    • isASCII

      public static boolean isASCII(String string)
    • ascii

      public static String ascii(String string)
      replaces all non-printable and control characters in a string with an underscore.
      Parameters:
      string - a string
      Returns:
      an ASCII string
    • ascii

      public static String ascii(String string, char replacement)
      replaces all non-printable and control characters in a string with the specified replacement character.
      Parameters:
      string - a string
      replacement - replacement character
      Returns:
      an ASCII string
    • ascii

      public static String ascii(String string, String replacement)
      replaces all non-printable and control characters in a string with the specified replacement string.
      Parameters:
      string - a string
      replacement - replacement string
      Returns:
      an ASCII string
    • diacriticless

      public static String diacriticless(String string)
      replaces all characters with diacritical marks in a string with their corresponding letter.
      Parameters:
      string - a string
      Returns:
      a string without diacritical marks
    • diacriticlessAscii

      public static String diacriticlessAscii(String string)
      replaces all characters with diacritical marks with their corresponding letter and all non-printable and control characters with an undersocre.
      Parameters:
      string - a string
      Returns:
      an ASCII string
    • diacriticlessAscii

      public static String diacriticlessAscii(String string, String replacement)
      replaces all characters with diacritical marks with their corresponding letter and all non-printable and control characters with the specified replacement string.
      Parameters:
      string - a string
      replacement - replacement string
      Returns:
      an ASCII string
    • getStringAscii

      public static String getStringAscii(String string)
    • getStringUtf8

      public static String getStringUtf8(String string)
    • encode

      public static String encode(String string)
    • decode

      public static String decode(String string)
    • getCamelCase

      public static String getCamelCase(String string)
    • getCamelCase

      public static String getCamelCase(String string, String gap)
    • getCamelCase

      public static String getCamelCase(String string, boolean toLowerCaseLess)
    • getCamelCase

      public static String getCamelCase(String string, String gap, boolean toLowerCaseLess)
    • getLowerCamelCase

      public static String getLowerCamelCase(String string)
    • getUpperCamelCase

      public static String getUpperCamelCase(String string)
    • getSpaceCamelCase

      public static String getSpaceCamelCase(String string)
    • getSnakeCase

      public static String getSnakeCase(String string)
    • getSnakeCase

      public static String getSnakeCase(String string, char hump)
    • getSnakeCase

      public static String getSnakeCase(String string, String hump)
    • getLowerSnakeCase

      public static String getLowerSnakeCase(String string)
    • getUpperSnakeCase

      public static String getUpperSnakeCase(String string)
    • getHumplessCase

      public static String getHumplessCase(String string)
    • getHumplessCase

      public static String getHumplessCase(String string, char hump)
    • getHumplessCase

      public static String getHumplessCase(String string, String hump)
    • getLowerHumplessCase

      public static String getLowerHumplessCase(String string)
    • getUpperHumplessCase

      public static String getUpperHumplessCase(String string)
    • isMixedCase

      public static boolean isMixedCase(String string)
    • isNotMixedCase

      public static boolean isNotMixedCase(String string)
    • getWordyString

      public static String getWordyString(String string)
    • getUnderscoreless

      public static String getUnderscoreless(String string)
    • getStringHtml

      public static String getStringHtml(String string)
    • getStringJava

      public static String getStringJava(String string)
    • getStringXml

      public static String getStringXml(String string)
    • escapeBundleKey

      public static String escapeBundleKey(String string)
    • escapeMeta

      public static String escapeMeta(String string)
    • escapeDoubleQuotes

      public static String escapeDoubleQuotes(String string)
    • escapeSlashedChars

      public static String escapeSlashedChars(String string)
    • getToken

      public static String getToken(String string)
    • getToken

      public static String getToken(String string, int index)
    • getToken

      public static String getToken(String string, String regex)
    • getToken

      public static String getToken(String string, int index, String regex)
    • getPatronParametrizado

      public static String getPatronParametrizado(String string)
    • getParametros

      public static String[] getParametros(String string)
    • getObjeto

      public static Object getObjeto(String string)
    • getObjeto

      public static Object getObjeto(String string, String clazz)
    • getObjeto

      public static Object getObjeto(String string, Class<?> clazz)
    • newline

      public static char newline()
    • tab

      public static char tab()
    • tabs

      public static String tabs(int n)
    • isDelimited

      public static boolean isDelimited(String string, char delimiter)
    • isDelimited

      public static boolean isDelimited(String string, String delimiter)
    • isDelimited

      public static boolean isDelimited(String string, char open, char close)
    • isDelimited

      public static boolean isDelimited(String string, char open, char close, char... quotes)
    • isDelimited

      public static boolean isDelimited(String string, String open, String close)
    • isDelimited

      public static boolean isDelimited(String string, String open, String close, char... quotes)
    • enclose

      public static String enclose(String argument)
    • enclose

      public static String enclose(String argument, char delimiter)
    • enclose

      public static String enclose(String argument, char open, char close)
    • enclose

      public static String enclose(String argument, String delimiter)
    • enclose

      public static String enclose(String argument, String open, String close)
    • disclose

      public static String disclose(String argument)
    • disclose

      public static String disclose(String argument, char delimiter)
    • disclose

      public static String disclose(String argument, char open, char close)
    • disclose

      public static String disclose(String argument, String delimiter)
    • disclose

      public static String disclose(String argument, String open, String close)
    • encloseSqlExpression

      public static String encloseSqlExpression(String expression)
    • discloseSqlExpression

      public static String discloseSqlExpression(String expression)
    • removeAfter

      public static String removeAfter(String text, String search, String preceding)
      Removes all occurrences of a String within another String that are found after another String.
      Parameters:
      text - the String to search and remove in
      search - the String to search for
      preceding - the String used as lower boundary of the search; if it is null or empty, the search begins at the beginning of text
      Returns:
      the text with any removements processed
    • removeBefore

      public static String removeBefore(String text, String search, String following)
      Removes all occurrences of a String within another String that are found before another String.
      Parameters:
      text - the String to search and remove in
      search - the String to search for
      following - the String used as upper boundary of the search; if it is null or empty, the search ends at the end of text
      Returns:
      the text with any removements processed
    • removeBetween

      public static String removeBetween(String text, String search, String preceding, String following)
      Removes all occurrences of a String within another String that are found between another two Strings.
      Parameters:
      text - the String to search and remove in
      search - the String to search for
      preceding - the String used as lower boundary of the search; if it is null or empty, the search begins at the beginning of text
      following - the String used as upper boundary of the search; if it is null or empty, the search ends at the end of text
      Returns:
      the text with any removements processed
    • replaceAfter

      public static String replaceAfter(String text, String search, String replacement, String preceding)
      Replaces all occurrences of a String within another String that are found after another String.
      Parameters:
      text - the String to search and replace in
      search - the String to search for
      replacement - the String to replace it with
      preceding - the String used as lower boundary of the search; if it is null or empty, the search begins at the beginning of text
      Returns:
      the text with any replacements processed
    • replaceBefore

      public static String replaceBefore(String text, String search, String replacement, String following)
      Replaces all occurrences of a String within another String that are found before another String.
      Parameters:
      text - the String to search and replace in
      search - the String to search for
      replacement - the String to replace it with
      following - the String used as upper boundary of the search; if it is null or empty, the search ends at the end of text
      Returns:
      the text with any replacements processed
    • replaceBetween

      public static String replaceBetween(String text, String search, String replacement, String preceding, String following)
      Replaces all occurrences of a String within another String that are found between another two Strings.
      Parameters:
      text - the String to search and replace in
      search - the String to search for
      replacement - the String to replace it with
      preceding - the String used as lower boundary of the search; if it is null or empty, the search begins at the beginning of text
      following - the String used as upper boundary of the search; if it is null or empty, the search ends at the end of text
      Returns:
      the text with any replacements processed
    • removeWords

      public static String removeWords(String string, Class<?> dataType)
    • removeWords

      public static String removeWords(String string, Class<?> dataType, String separator)
    • removeWords

      public static String removeWords(String string, Class<?> dataType, char affixType)
    • removeWords

      public static String removeWords(String string, Class<?> dataType, char affixType, String separator)
    • removeWord

      public static String removeWord(String string, String remove)
    • removeWords

      public static String removeWords(String string, String remove)
    • removeWords

      public static String removeWords(String string, String remove, String separator)
    • removeWords

      public static String removeWords(String string, String remove, char affixType)
    • removeWords

      public static String removeWords(String string, String remove, char affixType, String separator)
    • removeWholeWord

      public static String removeWholeWord(String string, String remove)
    • removeWholeWord

      public static String removeWholeWord(String string, String remove, String separator)
    • removeWholeWord

      public static String removeWholeWord(String string, String remove, char affixType)
    • removeWholeWord

      public static String removeWholeWord(String string, String remove, char affixType, String separator)
    • replaceOnceRepeatedly

      public static String replaceOnceRepeatedly(String text, String searchString, Object... replacements)