Class StringUtil
java.lang.Object
me.josephsf.jobportaljosephsfeir.util.StringUtil
Utility class for string manipulation and validation in the Job Portal system.
This class provides static methods for common string operations such as validation, formatting, transformation, and checking. It includes utilities for validating emails, phone numbers, and URLs, as well as various string manipulation methods.
The class is final with a private constructor to prevent instantiation, as it only contains static utility methods.
- Since:
- 2025-05-15
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringCleans and normalizes a string by trimming and reducing multiple spaces to single spaces.static StringextractFirstName(String fullName) Extracts the first name from a full name string.static StringextractLastName(String fullName) Extracts the last name from a full name string.static booleanChecks if a string is null or empty (contains only whitespace).static booleanisNotEmpty(String str) Checks if a string is not null and not empty.static booleanisValidEmail(String email) Validates if a string is a properly formatted email address.static booleanisValidLinkedInUrl(String url) Validates if a string is a properly formatted LinkedIn URL.static booleanisValidPhoneNumber(String phoneNumber) Validates if a string is a properly formatted phone number.static StringMasks an email address for privacy by showing only the first and last characters of the local part (before the @ symbol).static StringGenerates a URL-friendly slug from a string.static StringtoTitleCase(String str) Converts a string to title case (first letter of each word capitalized).static StringTruncates a string to a specified maximum length, adding an ellipsis if truncated.
-
Method Details
-
isEmpty
Checks if a string is null or empty (contains only whitespace).- Parameters:
str- The string to check- Returns:
- true if the string is null or empty, false otherwise
-
isNotEmpty
Checks if a string is not null and not empty.- Parameters:
str- The string to check- Returns:
- true if the string is not null and not empty, false otherwise
-
isValidEmail
Validates if a string is a properly formatted email address.- Parameters:
email- The email address to validate- Returns:
- true if the email is valid, false otherwise
-
isValidPhoneNumber
Validates if a string is a properly formatted phone number.- Parameters:
phoneNumber- The phone number to validate- Returns:
- true if the phone number is valid, false otherwise
-
isValidLinkedInUrl
Validates if a string is a properly formatted LinkedIn URL.- Parameters:
url- The LinkedIn URL to validate- Returns:
- true if the URL is a valid LinkedIn profile URL, false otherwise
-
truncate
Truncates a string to a specified maximum length, adding an ellipsis if truncated.- Parameters:
str- The string to truncatemaxLength- The maximum length for the string- Returns:
- The truncated string, or the original if it was already shorter than maxLength
-
toTitleCase
Converts a string to title case (first letter of each word capitalized).- Parameters:
str- The string to convert- Returns:
- The string in title case
-
clean
Cleans and normalizes a string by trimming and reducing multiple spaces to single spaces.- Parameters:
str- The string to clean- Returns:
- The cleaned string
-
slugify
Generates a URL-friendly slug from a string. Converts to lowercase, replaces non-alphanumeric characters with hyphens, and removes leading and trailing hyphens.- Parameters:
str- The string to convert to a slug- Returns:
- The slugified string
-
maskEmail
Masks an email address for privacy by showing only the first and last characters of the local part (before the @ symbol).- Parameters:
email- The email address to mask- Returns:
- The masked email address
-
extractFirstName
Extracts the first name from a full name string.- Parameters:
fullName- The full name- Returns:
- The first name, or an empty string if the input is null or empty
-
extractLastName
Extracts the last name from a full name string.- Parameters:
fullName- The full name- Returns:
- The last name, or an empty string if the input is null, empty, or contains only one word
-