Class StringUtils


  • public final class StringUtils
    extends java.lang.Object
    String utilities class providing utility functions not covered by third party libraries.

    This class contains static utility methods for common string operations used throughout the HtmlUnit NekoHtml parser. It focuses on lightweight, performance-oriented string checks that avoid creating unnecessary String objects or using expensive operations.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private StringUtils()
      Private constructor to prevent instantiation of this utility class.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean equalsChar​(char expected, java.lang.CharSequence s)
      Checks if the provided character sequence consists of exactly one character that matches the expected character.
      static boolean isEmptyString​(java.lang.CharSequence s)
      Checks if the provided character sequence is not null and has zero length.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StringUtils

        private StringUtils()
        Private constructor to prevent instantiation of this utility class.
    • Method Detail

      • isEmptyString

        public static boolean isEmptyString​(java.lang.CharSequence s)
        Checks if the provided character sequence is not null and has zero length.

        This method differs from org.apache.commons.lang3.StringUtils#isEmpty(CharSequence) in that it returns false if the provided string is null.

        Parameters:
        s - the character sequence to check, may be null
        Returns:
        true if the sequence is not null AND has length of zero; false otherwise
      • equalsChar

        public static boolean equalsChar​(char expected,
                                         java.lang.CharSequence s)
        Checks if the provided character sequence consists of exactly one character that matches the expected character.

        This is an optimized equality check for single-character strings, avoiding the overhead of full string comparison. It's particularly useful during HTML parsing when checking for single-character tokens or delimiters.

        Parameters:
        expected - the character that we expect to match
        s - the character sequence to check, may be null
        Returns:
        true if and only if the provided sequence is not null, has exactly one character, and that character equals the expected character; false otherwise