Package com.cedarsoftware.util
Class CaseInsensitiveMap.CaseInsensitiveString
java.lang.Object
com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString
- All Implemented Interfaces:
Serializable
,CharSequence
,Comparable<Object>
- Enclosing class:
CaseInsensitiveMap<K,
V>
public static final class CaseInsensitiveMap.CaseInsensitiveString
extends Object
implements Comparable<Object>, CharSequence, Serializable
Wrapper class for String keys to enforce case-insensitive comparison.
Implements CharSequence for compatibility with String operations and
Serializable for persistence support.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int index) Returns the character at the specified index.chars()
Returns a stream of int zero-extending the char values from this sequence.Returns a stream of code point values from this sequence.int
Compares this CaseInsensitiveString to another object.boolean
Returns true if this case-insensitive string contains the specified character sequence.boolean
Compares this object to another for equality in a case-insensitive manner.int
hashCode()
Returns the hash code for this object, computed in a case-insensitive manner.int
length()
Returns the length of this character sequence.Factory method to get a CaseInsensitiveString, using cached instances when possible.subSequence
(int start, int end) Returns a CharSequence that is a subsequence of this sequence.toString()
Returns the original String.
-
Method Details
-
of
Factory method to get a CaseInsensitiveString, using cached instances when possible. This method guarantees that the same CaseInsensitiveString instance will be returned for equal strings (ignoring case) as long as they're within the maxCacheLengthString limit. -
toString
Returns the original String.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
- Returns:
- the original String
-
hashCode
public int hashCode()Returns the hash code for this object, computed in a case-insensitive manner. -
equals
Compares this object to another for equality in a case-insensitive manner. -
compareTo
Compares this CaseInsensitiveString to another object. If the object is a String or CaseInsensitiveString, comparison is case-insensitive. Otherwise, Strings are considered "less" than non-Strings.- Specified by:
compareTo
in interfaceComparable<Object>
- Parameters:
o
- the object to compare to- Returns:
- a negative integer, zero, or a positive integer depending on ordering
-
length
public int length()Returns the length of this character sequence.- Specified by:
length
in interfaceCharSequence
- Returns:
- the number of characters in this sequence
-
charAt
public char charAt(int index) Returns the character at the specified index.- Specified by:
charAt
in interfaceCharSequence
- Parameters:
index
- the index of the character to be returned- Returns:
- the specified character
- Throws:
IndexOutOfBoundsException
- if the index is negative or greater than or equal to length()
-
subSequence
Returns a CharSequence that is a subsequence of this sequence.- Specified by:
subSequence
in interfaceCharSequence
- Parameters:
start
- the start index, inclusiveend
- the end index, exclusive- Returns:
- the specified subsequence
- Throws:
IndexOutOfBoundsException
- if start or end are negative, if end is greater than length(), or if start is greater than end
-
chars
Returns a stream of int zero-extending the char values from this sequence.- Specified by:
chars
in interfaceCharSequence
- Returns:
- an IntStream of char values from this sequence
-
codePoints
Returns a stream of code point values from this sequence.- Specified by:
codePoints
in interfaceCharSequence
- Returns:
- an IntStream of Unicode code points from this sequence
-
contains
Returns true if this case-insensitive string contains the specified character sequence. The search is case-insensitive.- Parameters:
s
- the sequence to search for- Returns:
- true if this string contains s, false otherwise
-