Class StringUtils

java.lang.Object
me.hugmanrique.cartage.util.StringUtils

public final class StringUtils extends Object
Provides String-related utilities.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    padEnd​(String string, int length, char padChar)
    Returns a string of the given length, consisting of string followed by as many instances of padChar as necessary to reach that length.
    static void
    requireLength​(CharSequence sequence, int length)
    Ensures the length of the given sequence is length.
    static void
    requireMaxLength​(CharSequence sequence, int maxLength)
    Ensures the length of the given sequence is less than or equal to maxLength.
    static void
    Ensures the given string is composed of uppercase ASCII characters, spaces, and null terminators (\0).
    static void
    requireUppercaseAscii​(String string, boolean acceptNullTerminators)
    Ensures the given string is composed of uppercase ASCII characters and spaces, ignoring null terminators (\0) if specified.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • requireLength

      public static void requireLength(CharSequence sequence, int length)
      Ensures the length of the given sequence is length.
      Parameters:
      sequence - the sequence to check
      length - the expected length
      Throws:
      IllegalArgumentException - if the length of the sequence is not length
    • requireMaxLength

      public static void requireMaxLength(CharSequence sequence, int maxLength)
      Ensures the length of the given sequence is less than or equal to maxLength.
      Parameters:
      sequence - the sequence to check
      maxLength - the maximum length allowed
      Throws:
      IllegalArgumentException - if the length of the sequence is greater than maxLength
    • requireUppercaseAscii

      public static void requireUppercaseAscii(String string)
      Ensures the given string is composed of uppercase ASCII characters, spaces, and null terminators (\0).
      Parameters:
      string - the string to check
      Throws:
      IllegalArgumentException - if the string contains non-ASCII or non-uppercase characters
    • requireUppercaseAscii

      public static void requireUppercaseAscii(String string, boolean acceptNullTerminators)
      Ensures the given string is composed of uppercase ASCII characters and spaces, ignoring null terminators (\0) if specified.
      Parameters:
      string - the string to check
      acceptNullTerminators - whether to ignore null terminators
      Throws:
      IllegalArgumentException - if the string contains non-ASCII or non-uppercase characters
    • padEnd

      public static String padEnd(String string, int length, char padChar)
      Returns a string of the given length, consisting of string followed by as many instances of padChar as necessary to reach that length.
      Parameters:
      string - the string to pad
      length - the length of the returned string
      padChar - the character to append at the end of the string
      Returns:
      the padded string
      Throws:
      IllegalArgumentException - if string.length() > length