Class JKStringUtil

java.lang.Object
com.jk.core.util.JKStringUtil

public class JKStringUtil extends Object
This class is a utility class used for string manipulation and formatting.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    This method capitalizes all the words in a string, converting the first character of each word to upper-case and the rest to lower-case.
    static String
    compile(String sql, Object... param)
    This method compiles a SQL statement by replacing place-holders with parameter values.
    static String
    concat(Object... msg)
    This method concatenates multiple objects into a single string, separated by a space.
    static String
    This method concatenates an array of strings, ignoring null values.
    static void
    This method copies the provided text to the system clip board.
    static String
    This method escapes single quotes in a given string by adding a backslash before each single quote.
    static String
    This method fixes the formatting of a value by capitalizing words and handling line breaks.
    static String
    This method retrieves the first line of a multi-line string or the entire string if it's a single line.
    static boolean
    This method checks if a given string is empty or consists of only whitespace characters.
    static void
    main(String[] args)
    This main method demonstrates the utility of this class.
    static String
    plurize(String singular)
    This method converts a singular noun to its plural form using predefined rules.
    static String
    This method removes extra spaces from the provided string.
    removeLast(StringBuilder builder, String string)
    This method removes the last occurrence of a specified substring from a StringBuilder.
    static String
    removeLast(String original, String string)
    This method removes the last occurrence of a specified substring from the original string.
    static String
    setParameters(String value, Object[] params)
    This method sets parameters in a string template by replacing place-holders with values.
    static String
    setSize(String value, int size)
    This method truncates or pads the given string to the specified size.
    static String
    trim(String str)
    This method trims leading and trailing whitespace from a string.

    Methods inherited from class java.lang.Object

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

    • JKStringUtil

      public JKStringUtil()
  • Method Details

    • compile

      public static String compile(String sql, Object... param)
      This method compiles a SQL statement by replacing place-holders with parameter values.
      Parameters:
      sql - Specifies the SQL statement with place-holders.
      param - Specifies the parameter values to be inserted into the SQL statement.
      Returns:
      the compiled SQL statement.
    • fixValue

      public static String fixValue(String value)
      This method fixes the formatting of a value by capitalizing words and handling line breaks.
      Parameters:
      value - Specifies the value to be formatted.
      Returns:
      the formatted value.
    • setParameters

      public static String setParameters(String value, Object[] params)
      This method sets parameters in a string template by replacing place-holders with values.
      Parameters:
      value - Specifies the string template with place-holders.
      params - Specifies the values to be inserted into the template.
      Returns:
      the string with replaced place-holders
    • trim

      public static String trim(String str)
      This method trims leading and trailing whitespace from a string.
      Parameters:
      str - Specifies the input string to be trimmed.
      Returns:
      the trimmed string.
    • capitalizeFully

      public static String capitalizeFully(String label)
      This method capitalizes all the words in a string, converting the first character of each word to upper-case and the rest to lower-case.
      Parameters:
      label - Specifies the input string to be capitalized.
      Returns:
      the capitalized string with the first character of each word in upper-case and the rest in lower-case.
    • removeLast

      public static String removeLast(String original, String string)
      This method removes the last occurrence of a specified substring from the original string.
      Parameters:
      original - Specifies the original string from which the substring will be removed.
      string - Specifies the substring to be removed from the original string.
      Returns:
      the new string with the last occurrence of the specified substring removed, or the original string if the substring is not found.
    • escapeValue

      public static String escapeValue(String value)
      This method escapes single quotes in a given string by adding a backslash before each single quote.

      The resulting string is enclosed in single quotes.

      Parameters:
      value - Specifies the input string that needs to have its single quotes escaped.
      Returns:
      the new string with single quotes escaped by adding a backslash before each single quote, and enclosed within single quotes.
    • isEmpty

      public static boolean isEmpty(String str)
      This method checks if a given string is empty or consists of only whitespace characters.
      Parameters:
      str - Specifies the string to be checked for emptiness.
      Returns:
      true, if the string is `null` or contains only whitespace characters, false otherwise.
    • concat

      public static String concat(Object... msg)
      This method concatenates multiple objects into a single string, separated by a space.
      Parameters:
      msg - Specifies the objects to be concatenated.
      Returns:
      a string containing the concatenated values of the provided objects, separated by a space.
    • getFirstLine

      public static String getFirstLine(String message)
      This method retrieves the first line of a multi-line string or the entire string if it's a single line.
      Parameters:
      message - Specifies the input string.
      Returns:
      the first line of the input string if it's multi-line, otherwise the entire input string.
    • removeLast

      public static StringBuilder removeLast(StringBuilder builder, String string)
      This method removes the last occurrence of a specified substring from a StringBuilder.
      Parameters:
      builder - Specifies the StringBuilder from which to remove the substring.
      string - Specifies the substring to be removed.
      Returns:
      a new StringBuilder with the last occurrence of the substring removed, or the original StringBuilder if the substring is not found.
    • copyToClipboard

      public static void copyToClipboard(String text)
      This method copies the provided text to the system clip board.
      Parameters:
      text - Specifies the text to be copied to the clip board.
    • removeExtraSpaces

      public static String removeExtraSpaces(String number)
      This method removes extra spaces from the provided string.
      Parameters:
      number - Specifies the string from which to remove extra spaces.
      Returns:
      the input string with extra spaces removed.
    • plurize

      public static String plurize(String singular)
      This method converts a singular noun to its plural form using predefined rules.
      Parameters:
      singular - Specifies the singular noun to be pluralized.
      Returns:
      the plural form of the input singular noun.
    • setSize

      public static String setSize(String value, int size)
      This method truncates or pads the given string to the specified size.
      Parameters:
      value - Specifies the string to be resized.
      size - Specifies the desired size of the string.
      Returns:
      the resized string. If the input string is shorter than the specified size, it will be padded with spaces. If the input string is longer, it will be truncated.
    • main

      public static void main(String[] args)
      This main method demonstrates the utility of this class.
      Parameters:
      args - the command-line arguments.
    • concatIgnoreNull

      public static String concatIgnoreNull(String... list)
      This method concatenates an array of strings, ignoring null values.
      Parameters:
      list - Specifies the array of strings to be concatenated.
      Returns:
      the single string resulting from the concatenation of non-null values in the array.