Class RawCollationKey
java.lang.Object
com.ibm.icu.util.ByteArrayWrapper
com.ibm.icu.text.RawCollationKey
- All Implemented Interfaces:
Comparable<ByteArrayWrapper>
Simple class wrapper to store the internal byte representation of a CollationKey. Unlike the
CollationKey, this class do not contain information on the source string the sort order
represents. RawCollationKey is mutable and users can reuse its objects with the method in
RuleBasedCollator.getRawCollationKey(..).
Please refer to the documentation on CollationKey for a detail description on the internal
byte representation. Note the internal byte representation is always null-terminated.
Example of use:
String str[] = {.....};
RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance();
RawCollationKey key = new RawCollationKey(128);
for (int i = 0; i < str.length; i ++) {
collator.getRawCollationKey(str[i], key);
// do something with key.bytes
}
Note: Comparison between RawCollationKeys created by different Collators might return incorrect results. See class documentation for Collator.
- See Also:
- Status:
- Stable ICU 2.8.
-
Field Summary
Fields inherited from class ByteArrayWrapper
bytes, size -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, internal byte array is null and its size set to 0.RawCollationKey(byte[] bytes) RawCollationKey created, adopting bytes as the internal byte array.RawCollationKey(byte[] bytesToAdopt, int size) Construct a RawCollationKey from a byte array and size.RawCollationKey(int capacity) RawCollationKey created with an empty internal byte array of length capacity. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(RawCollationKey rhs) Compare this RawCollationKey to another, which must not be null.Methods inherited from class ByteArrayWrapper
append, compareTo, ensureCapacity, equals, hashCode, releaseBytes, set, toStringModifier and TypeMethodDescriptionfinal ByteArrayWrapperappend(byte[] src, int start, int limit) Appends the internal byte array from offset size with the contents of src from offset start to limit.intcompareTo(ByteArrayWrapper other) Compare this object to another ByteArrayWrapper, which must not be null.ensureCapacity(int capacity) Ensure that the internal byte array is at least of length capacity.booleanReturn true if the bytes in each wrapper are equal.inthashCode()Return the hashcode.final byte[]Releases the internal byte array to the caller, resets the internal byte array to null and its size to 0.final ByteArrayWrapperset(byte[] src, int start, int limit) Set the internal byte array from offset 0 to (limit - start) with the contents of src from offset start to limit.toString()Returns string value for debugging
-
Constructor Details
-
RawCollationKey
public RawCollationKey()Default constructor, internal byte array is null and its size set to 0.- Status:
- Stable ICU 2.8.
-
RawCollationKey
public RawCollationKey(int capacity) RawCollationKey created with an empty internal byte array of length capacity. Size of the internal byte array will be set to 0.- Parameters:
capacity- length of internal byte array- Status:
- Stable ICU 2.8.
-
RawCollationKey
public RawCollationKey(byte[] bytes) RawCollationKey created, adopting bytes as the internal byte array. Size of the internal byte array will be set to 0.- Parameters:
bytes- byte array to be adopted by RawCollationKey- Status:
- Stable ICU 2.8.
-
RawCollationKey
public RawCollationKey(byte[] bytesToAdopt, int size) Construct a RawCollationKey from a byte array and size.- Parameters:
bytesToAdopt- the byte array to adoptsize- the length of valid data in the byte array- Throws:
IndexOutOfBoundsException- if bytesToAdopt == null and size != 0, or size < 0, or size > bytesToAdopt.length.- Status:
- Stable ICU 2.8.
-
-
Method Details
-
compareTo
Compare this RawCollationKey to another, which must not be null. This overrides the inherited implementation to ensure the returned values are -1, 0, or 1.- Parameters:
rhs- the RawCollationKey to compare to.- Returns:
- -1, 0, or 1 as this compares less than, equal to, or greater than rhs.
- Throws:
ClassCastException- if the other object is not a RawCollationKey.- Status:
- Stable ICU 4.4.
-