Class StringUtil

java.lang.Object
com.reve.utils.string.StringUtil

public class StringUtil extends Object
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • isEqual

      public static boolean isEqual(String a, String b)
      Check the equality of the given two Strings. In this method, parameters can be null. If both parameter is null method will return true. Otherwise, will check the equality.
      Parameters:
      a - First String
      b - Second String
      Returns:
      true, if both strings are null, or they are equals in content. otherwise, return false.
    • parseString

      public static String parseString(String message, String key, String delimiter)
      Get the String from the message, that starts after the key and ends before the given delimiter. Consider a message = '\r\nVC=99\r\n', key = '\r\nVC=', delimiter = '\r\n', then this method will return '99' as string.
      Parameters:
      message - The message from where expected part will be taken.
      key - After this string result string will start.
      delimiter - result string will continue until this value is found.
      Returns:
      the result string starting after the key and ending before delimiter.
    • parseStringWithoutTrim

      public static String parseStringWithoutTrim(String message, String key, String delimiter)
      Get the String from the message, that starts after the key and ends before the given delimiter. Consider a message = '\r\nVC=99\r\n', key = '\r\nVC=', delimiter = '\r\n', then this method will return '99' as string.
      Parameters:
      message - The message from where expected part will be taken.
      key - After this string result string will start.
      delimiter - result string will continue until this value is found. If this value is null, then method will return the substring starting after key and end of the message.
      Returns:
      the result string starting after the key and ending before delimiter. If no key or delimiter is found it will return null string instead.
    • parseString

      public static String parseString(String message, String key, char... delimiters)
      Get the String from the message, that starts after the key and ends before the given delimiter. Consider a message = '\r\nVC=99\r\n', key = '\r\nVC=', delimiter = '\r\n', then this method will return '99' as string.
      Parameters:
      message - The message from where expected part will be taken.
      key - After this string result string will start.
      delimiters - result string will continue until any char from this value is found.
      Returns:
      the result string starting after the key and ending before delimiter.
    • parseStringWithKey

      public static String parseStringWithKey(String message, String key, String delimiter)
      Parse the string from given message and keep the key in returning string. Consider: message = "Hi this is a test message", key = "this", delimiter = "message". Then this method will return "this is a test "
      Parameters:
      message - message from where a string will be parsed.
      key - prefix of searched string.
      delimiter - ending string of searched string.
      Returns:
      the parsed string from given information. Return string will not be trimmed.
    • parseStringCyclic

      public static void parseStringCyclic(String message, String key, String delimiter, List<String> list)
      Parse all the strings from given message and keep the key in returning string. Consider: message = "Hi this is a test message. ", key = "this", delimiter = "message". Then this method will return "this is a test "
      Parameters:
      message - message from where a string will be parsed.
      key - prefix of searched string.
      delimiter - ending string of searched string.
      list - parsed lines will be appended into this instance sequentially.
    • parseInteger

      public static int parseInteger(String message, String key)
      Parse the integer value from given message that starts after the given key. It will consider all digits until a non digit character found. Also, it will discard initial non digit characters.
      Parameters:
      message - The message from which integer value should be parsed.
      key - parsing index will start after first occurrence of this sub-string.
      Returns:
      the parsed integer value
    • parseInteger

      public static int parseInteger(String message, int index)
      Parse the integer value from given message that starts after the given index. It will consider all digits until a non digit character found. Also, it will discard initial non digit characters.
      Parameters:
      message - The message from which integer value should be parsed.
      index - parsing index will start from this given index.
      Returns:
      the parsed integer value
    • parseInteger

      public static int parseInteger(String message, int index, int digitCount)
      Parse the integer value from given message that starts after the given index. It will consider all digits until a non digit character found. Also, it will discard initial non digit characters.
      Parameters:
      message - The message from which integer value should be parsed.
      index - parsing index will start from this given index.
      digitCount - number of digit to be parsed as integer.
      Returns:
      the parsed integer value
    • parseLong

      public static long parseLong(String message, String key)
      Parse the integer value from given message that starts after the given key. It will consider all digits until a non digit character found. Also, it will discard initial non digit characters.
      Parameters:
      message - The message from which integer value should be parsed.
      key - parsing index will start after first occurrence of this sub-string.
      Returns:
      the parsed integer value
    • parseLong

      public static long parseLong(String message, int index)
      Parse the integer value from given message that starts after the given index. It will consider all digits until a non digit character found. Also, it will discard initial non digit characters.
      Parameters:
      message - The message from which integer value should be parsed.
      index - parsing index will start from this given index.
      Returns:
      the parsed integer value
    • parseLong

      public static long parseLong(String message, int index, int digitCount)
      Parse the integer value from given message that starts after the given index. It will consider all digits until a non digit character found. Also, it will discard initial non digit characters.
      Parameters:
      message - The message from which integer value should be parsed.
      index - parsing index will start from this given index.
      digitCount - number of digit to be parsed as integer.
      Returns:
      the parsed integer value
    • removeLeadingChars

      public static String removeLeadingChars(String s, char ch)
      Remove all leading given char from given string.
      Parameters:
      s - this value will be modified.
      ch - this char will be ignored from leading positions
      Returns:
      the string after removing all leading given chars
    • removeTrailingChars

      public static String removeTrailingChars(String s, char ch)
      Remove all trailing given char from given string.
      Parameters:
      s - this value will be modified.
      ch - this char will be ignored from trailing positions
      Returns:
      the string after removing all trailing given chars
    • trim

      public static String trim(String s, char ch)
      Remove all leading and trailing given char from given string.
      Parameters:
      s - this value will be modified.
      ch - this char will be ignored from leading and trailing positions
      Returns:
      the string after removing all leading and trailing given chars
    • replaceString

      public static String replaceString(String message, String startingString, String endString, String replacement)
      Replace a part of string with new string, This method will search for replacing String. Replacing String will start from the index of starting String, and end at the index of endString
      Parameters:
      message - This message's part of string will be replaced and returned.
      startingString - Start index of replacing string will start at the index of this string.
      endString - End index of the replacing string will be at the index of this string.
      replacement - Replacing string will be replaced by this String
      Returns:
      the output replaced string.
    • getConsecutiveCharCount

      public static int getConsecutiveCharCount(String message, char ch, int index)
      Get the number of consecutive occurrence of the given char in the given message. This method will start checking from the given index of the given string message.
      Parameters:
      message - String message, where the char will be searched.
      ch - Consecutive occurrence of this char will be counted into the message. If the first char of the given index doesn't match with this char, method will immediately return 0 value.
      index - starting index of the given message, where the given char will be looked for.
      Returns:
      the count of consecutive occurrence of the given char.
    • getRepeatedString

      public static String getRepeatedString(String repeat, int count)
      Generate a new string by repeating the given string to given count.
      Parameters:
      repeat - This string will be repeated
      count - Defines how many times the given repeat string should be repeated.
      Returns:
      the generated string from given constraints.