java.lang.Object
org.cybergarage.util.StringUtil

public final class StringUtilextends Object
Utility class for string manipulation and conversion operations. This class provides static methods for string validation, type conversion, character searching, and custom trimming operations.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Every validator, converter and trimmer below is static, so an instance carries nothing.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    static final int
    Finds the first character that is NOT in the specified character set.
    static final int
    findFirstOf(String str, String chars)
    Finds the first occurrence of any character from the specified set.
    static final int
    Finds the last character that is NOT in the specified character set.
    static final int
    findLastOf(String str, String chars)
    Finds the last occurrence of any character from the specified set.
    static final int
    findOf(String str, String chars, int startIdx, int endIdx, int offset, boolean isEqual)
    Generic character finding method with customizable search parameters.
    static final boolean
    hasData(String value)
    Checks if a string contains valid data (not null and not empty).
    static final int
    Converts a string to an integer value.
    static final long
    toLong(String value)
    Converts a string to a long value.
    static final String
    trim(String trimStr, String trimChars)
    Trims specified characters from both ends of a string.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StringUtil

      public StringUtil()
      Every validator, converter and trimmer below is static, so an instance carries nothing.
  • Method Details

    • hasData

      public static final boolean hasData(String value)
      Checks if a string contains valid data (not null and not empty).
      Parameters:
      value - the string to check
      Returns:
      true if the string is not null and has length > 0, false otherwise
    • toInteger

      public static final int toInteger(String value)
      Converts a string to an integer value.
      Parameters:
      value - the string to convert
      Returns:
      the integer value, or 0 if conversion fails
    • toLong

      public static final long toLong(String value)
      Converts a string to a long value.
      Parameters:
      value - the string to convert
      Returns:
      the long value, or 0 if conversion fails
    • findOf

      public static final int findOf(String str, String chars, int startIdx, int endIdx, int offset, boolean isEqual)
      Generic character finding method with customizable search parameters.
      Parameters:
      str - the string to search in
      chars - the characters to search for
      startIdx - the starting index
      endIdx - the ending index
      offset - the search direction (1 for forward, -1 for backward)
      isEqual - true to find matching characters, false to find non-matching
      Returns:
      the index of the found character, or -1 if not found
    • findFirstOf

      public static final int findFirstOf(String str, String chars)
      Finds the first occurrence of any character from the specified set.
      Parameters:
      str - string to search in
      chars - characters to search for
      Returns:
      index of first matching character, or -1 if not found
    • findFirstNotOf

      public static final int findFirstNotOf(String str, String chars)
      Finds the first character that is NOT in the specified character set.
      Parameters:
      str - string to search in
      chars - characters to exclude from search
      Returns:
      index of first non-matching character, or -1 if not found
    • findLastOf

      public static final int findLastOf(String str, String chars)
      Finds the last occurrence of any character from the specified set.
      Parameters:
      str - string to search in
      chars - characters to search for
      Returns:
      index of last matching character, or -1 if not found
    • findLastNotOf

      public static final int findLastNotOf(String str, String chars)
      Finds the last character that is NOT in the specified character set.
      Parameters:
      str - string to search in
      chars - characters to exclude from search
      Returns:
      index of last non-matching character, or -1 if not found
    • trim

      public static final String trim(String trimStr, String trimChars)
      Trims specified characters from both ends of a string.
      Parameters:
      trimStr - string to trim
      trimChars - characters to remove from both ends
      Returns:
      trimmed string