|
16 | 16 | package org.htmlunit.cyberneko.util; |
17 | 17 |
|
18 | 18 | /** |
19 | | - * String utilities class for utility functions not covered by third party libraries. |
| 19 | + * String utilities class providing utility functions not covered by third party libraries. |
| 20 | + * |
| 21 | + * <p>This class contains static utility methods for common string operations used |
| 22 | + * throughout the HtmlUnit NekoHtml parser. It focuses on lightweight, performance-oriented |
| 23 | + * string checks that avoid creating unnecessary String objects or using expensive operations.</p> |
20 | 24 | * |
21 | 25 | * @author Ronald Brill |
22 | 26 | */ |
23 | 27 | public final class StringUtils { |
24 | 28 |
|
25 | 29 | /** |
26 | | - * Disallow instantiation of this class. |
| 30 | + * Private constructor to prevent instantiation of this utility class. |
27 | 31 | */ |
28 | 32 | private StringUtils() { |
29 | | - // Empty. |
| 33 | + // Empty - utility class should not be instantiated |
30 | 34 | } |
31 | 35 |
|
32 | 36 | /** |
33 | | - * Returns true if the param is not null and empty. This is different from |
34 | | - * org.apache.commons.lang3.StringUtils#isEmpty(CharSequence) because |
35 | | - * this returns false if the provided string is null. |
| 37 | + * Checks if the provided character sequence is not null and has zero length. |
| 38 | + * |
| 39 | + * <p>This method differs from {@code org.apache.commons.lang3.StringUtils#isEmpty(CharSequence)} |
| 40 | + * in that it returns {@code false} if the provided string is {@code null}.</p> |
36 | 41 | * |
37 | | - * @param s the string to check |
38 | | - * @return true if the param is not null and empty |
| 42 | + * @param s the character sequence to check, may be null |
| 43 | + * @return {@code true} if the sequence is not null AND has length of zero; {@code false} otherwise |
39 | 44 | */ |
40 | 45 | public static boolean isEmptyString(final CharSequence s) { |
41 | 46 | return s != null && s.length() == 0; |
42 | 47 | } |
43 | 48 |
|
44 | 49 | /** |
45 | | - * @param expected the char that we expect |
46 | | - * @param s the string to check |
47 | | - * @return true if the provided string has only one char and this matches the expectation |
| 50 | + * Checks if the provided character sequence consists of exactly one character that matches |
| 51 | + * the expected character. |
| 52 | + * |
| 53 | + * <p>This is an optimized equality check for single-character strings, avoiding the overhead |
| 54 | + * of full string comparison. It's particularly useful during HTML parsing when checking for |
| 55 | + * single-character tokens or delimiters.</p> |
| 56 | + * |
| 57 | + * @param expected the character that we expect to match |
| 58 | + * @param s the character sequence to check, may be null |
| 59 | + * @return {@code true} if and only if the provided sequence is not null, has exactly one character, |
| 60 | + * and that character equals the expected character; {@code false} otherwise |
48 | 61 | */ |
49 | 62 | public static boolean equalsChar(final char expected, final CharSequence s) { |
50 | 63 | return s != null && s.length() == 1 && expected == s.charAt(0); |
|
0 commit comments