Package Util
Class StringUtil
- java.lang.Object
-
- Util.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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanareStringsTheSame(String compareFrom, String compareTo)Compares two strings for equality, accounting for null values.static StringescapeCharacters(String text)Escapes special characters in a string for safe regex or query use.static StringextractStreet(String streetTerm)Extracts the street name from an address string by removing trailing house numbers.static StringfixFinalSigma(String word)Converts a final lowercase sigma ('σ') at the end of a Greek word to the final sigma character ('ς').static StringinputStreamToString(InputStream is)Converts the contents of anInputStreamto a string.static booleanmatchRegex(String text, String regex)Checks if a string matches a given regex pattern, ignoring spaces.static booleannullOrEmpty(String text)Checks if a string is null or empty.static Stringpad(String text, char character, int length, int direction)Pads a string with a specific character either to the left or right.static StringproperCase(String text)Converts a given string to proper case, capitalizing the first letter of each word while making the rest lowercase.static StringstripAccents(String original)Removes diacritical marks (accents) from a string.
-
-
-
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 stringcharacter- the padding characterlength- the final total length of the padded stringdirection- 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:
trueif the string is null or empty;falseotherwise
-
areStringsTheSame
public static boolean areStringsTheSame(String compareFrom, String compareTo)
Compares two strings for equality, accounting for null values.- Parameters:
compareFrom- the first stringcompareTo- the second string- Returns:
trueif both strings are equal or both are null
-
inputStreamToString
public static String inputStreamToString(InputStream is)
Converts the contents of anInputStreamto 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 stringregex- the regular expression to match- Returns:
trueif the string matches the pattern;falseotherwise
-
-