Package Util

Class StringUtil


  • public class StringUtil
    extends Object
    Utility class for common string operations such as formatting, normalization, comparison, and regex handling.

    This is a static utility class and cannot be instantiated.

    Author:
    ckonstantakis
    • Method Detail

      • properCase

        public static String properCase​(String text)
        Converts a given string to proper case, capitalizing the first letter of each word while making the rest lowercase.
        Parameters:
        text - the input string
        Returns:
        the string in proper case
      • stripAccents

        public static String stripAccents​(String original)
        Removes diacritical marks (accents) from a string.
        Parameters:
        original - the input string
        Returns:
        the string without accents
      • fixFinalSigma

        public static String fixFinalSigma​(String word)
        Converts a final lowercase sigma ('σ') at the end of a Greek word to the final sigma character ('ς').
        Parameters:
        word - the Greek word to process
        Returns:
        the word with corrected final sigma
      • extractStreet

        public static String extractStreet​(String streetTerm)
        Extracts the street name from an address string by removing trailing house numbers.
        Parameters:
        streetTerm - the full address or street string
        Returns:
        the street name without number
      • pad

        public static String pad​(String text,
                                 char character,
                                 int length,
                                 int direction)
        Pads a string with a specific character either to the left or right.
        Parameters:
        text - the original string
        character - the padding character
        length - the final total length of the padded string
        direction - the direction of padding: 0 for left, 1 for right
        Returns:
        the padded string
      • nullOrEmpty

        public static boolean nullOrEmpty​(String text)
        Checks if a string is null or empty.
        Parameters:
        text - the string to check
        Returns:
        true if the string is null or empty; false otherwise
      • areStringsTheSame

        public static boolean areStringsTheSame​(String compareFrom,
                                                String compareTo)
        Compares two strings for equality, accounting for null values.
        Parameters:
        compareFrom - the first string
        compareTo - the second string
        Returns:
        true if both strings are equal or both are null
      • inputStreamToString

        public static String inputStreamToString​(InputStream is)
        Converts the contents of an InputStream to a string.
        Parameters:
        is - the input stream
        Returns:
        the string representation of the stream contents
      • matchRegex

        public static boolean matchRegex​(String text,
                                         String regex)
        Checks if a string matches a given regex pattern, ignoring spaces.
        Parameters:
        text - the input string
        regex - the regular expression to match
        Returns:
        true if the string matches the pattern; false otherwise
      • escapeCharacters

        public static String escapeCharacters​(String text)
        Escapes special characters in a string for safe regex or query use.
        Parameters:
        text - the input string
        Returns:
        the escaped string