Class StringUtil

java.lang.Object
me.josephsf.jobportaljosephsfeir.util.StringUtil

public final class StringUtil extends Object
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 Details

    • isEmpty

      public static boolean isEmpty(String str)
      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

      public static boolean isNotEmpty(String str)
      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

      public static boolean isValidEmail(String email)
      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

      public static boolean isValidPhoneNumber(String phoneNumber)
      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

      public static boolean isValidLinkedInUrl(String url)
      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

      public static String truncate(String str, int maxLength)
      Truncates a string to a specified maximum length, adding an ellipsis if truncated.
      Parameters:
      str - The string to truncate
      maxLength - The maximum length for the string
      Returns:
      The truncated string, or the original if it was already shorter than maxLength
    • toTitleCase

      public static String toTitleCase(String str)
      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

      public static String clean(String str)
      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

      public static String slugify(String str)
      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

      public static String maskEmail(String email)
      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

      public static String extractFirstName(String fullName)
      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

      public static String extractLastName(String fullName)
      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