Package io.deephaven.base.string.cache
Class CharSequenceUtils
java.lang.Object
io.deephaven.base.string.cache.CharSequenceUtils
Static helpers for hashCode, equality, and comparison of CharSequences.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<CharSequence>A re-usable case-insensitive Comparator for CharSequences.static final Comparator<CharSequence>A re-usable case-sensitive Comparator for CharSequences. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcaseInsensitiveHashCode(@NotNull CharSequence charSequence) Calculate the hash code of a CharSequence, consistent withcontentEqualsIgnoreCase(CharSequence, CharSequence).static intcompareToIgnoreCase(@NotNull CharSequence cs1, @NotNull CharSequence cs2) Compares two char sequences lexicographically, ignoring case differences, with the same Unicode code point semantics asString.compareToIgnoreCase(String).static booleancontentEquals(@NotNull CharSequence cs1, @NotNull CharSequence cs2) Compare two CharSequences for equality, disregarding class.static booleancontentEqualsIgnoreCase(@NotNull CharSequence cs1, @NotNull CharSequence cs2) Compare two CharSequences ignoring case differences, with the same Unicode code point semantics asString.equalsIgnoreCase(String).static inthashCode(@NotNull CharSequence charSequence) Calculate the hash code of a CharSequence as if it were a String.static booleannullSafeContentEquals(@Nullable CharSequence cs1, @Nullable CharSequence cs2) Compare two CharSequences for equality, disregarding class and allowing for nullity.static booleannullSafeContentEqualsIgnoreCase(@Nullable CharSequence cs1, @Nullable CharSequence cs2) Compare two CharSequences for case-insensitive equality, disregarding class and allowing for nullity.static booleanregionMatches(boolean ignoreCase, CharSequence cs1, int cs1Offset, CharSequence cs2, int cs2Offset, int length) Test content equality for two CharSequence sub-regions.
-
Field Details
-
CASE_SENSITIVE_COMPARATOR
A re-usable case-sensitive Comparator for CharSequences. -
CASE_INSENSITIVE_COMPARATOR
A re-usable case-insensitive Comparator for CharSequences.
-
-
Constructor Details
-
CharSequenceUtils
public CharSequenceUtils()
-
-
Method Details
-
hashCode
Calculate the hash code of a CharSequence as if it were a String.- Parameters:
charSequence- The CharSequence- Returns:
- A hash code for the specified CharSequence.
-
caseInsensitiveHashCode
Calculate the hash code of a CharSequence, consistent withcontentEqualsIgnoreCase(CharSequence, CharSequence).- Parameters:
charSequence- The CharSequence- Returns:
- A hash code for the specified CharSequence.
-
contentEquals
public static boolean contentEquals(@NotNull @NotNull CharSequence cs1, @NotNull @NotNull CharSequence cs2) Compare two CharSequences for equality, disregarding class.- Parameters:
cs1- The first CharSequencecs2- The second CharSequence- Returns:
- Whether the supplied CharSequences represent an equal sequence of chars.
-
nullSafeContentEquals
public static boolean nullSafeContentEquals(@Nullable @Nullable CharSequence cs1, @Nullable @Nullable CharSequence cs2) Compare two CharSequences for equality, disregarding class and allowing for nullity.- Parameters:
cs1- The first CharSequencecs2- The second CharSequence- Returns:
- Whether the supplied CharSequences represent an equal sequence of chars.
-
contentEqualsIgnoreCase
public static boolean contentEqualsIgnoreCase(@NotNull @NotNull CharSequence cs1, @NotNull @NotNull CharSequence cs2) Compare two CharSequences ignoring case differences, with the same Unicode code point semantics asString.equalsIgnoreCase(String).- Parameters:
cs1- The first CharSequencecs2- The second CharSequence- Returns:
- Whether the supplied CharSequences represent an equal sequence of chars, ignoring case differences.
-
compareToIgnoreCase
public static int compareToIgnoreCase(@NotNull @NotNull CharSequence cs1, @NotNull @NotNull CharSequence cs2) Compares two char sequences lexicographically, ignoring case differences, with the same Unicode code point semantics asString.compareToIgnoreCase(String).- Parameters:
cs1- The first CharSequencecs2- The second CharSequence- Returns:
- The comparison between the CharSequences, disregarding case.
-
nullSafeContentEqualsIgnoreCase
public static boolean nullSafeContentEqualsIgnoreCase(@Nullable @Nullable CharSequence cs1, @Nullable @Nullable CharSequence cs2) Compare two CharSequences for case-insensitive equality, disregarding class and allowing for nullity.- Parameters:
cs1- The first CharSequencecs2- The second CharSequence- Returns:
- Whether the supplied CharSequences represent an equal sequence of chars.
-
regionMatches
public static boolean regionMatches(boolean ignoreCase, CharSequence cs1, int cs1Offset, CharSequence cs2, int cs2Offset, int length) Test content equality for two CharSequence sub-regions. See String.regionMatches(...).- Parameters:
ignoreCase- Whether to use a case-insensitive comparisoncs1- The first CharSequencecs1Offset- The offset into the first CharSequencecs2- The second CharSequencecs2Offset- The offset into the second CharSequencelength- The number of characters to compare- Returns:
- Whether the regions match
-