CollationKeypublic final class CollationKey extends Object implements ComparableCollation key wrapper, containing the byte array sort key. |
Fields Summary |
---|
private byte[] | m_bytes_ | private static final int | UNSIGNED_BYTE_MASK_Mask value to retrieve a single unsigned byte | private int | m_hash_Cached hash value |
Constructors Summary |
---|
CollationKey()Default constructor, for use by the Collator and its subclasses.
m_hash_ = 0;
| CollationKey(byte[] bytes)Constructor, for use only by the Collator and its subclasses.
m_bytes_ = bytes;
m_hash_ = 0;
|
Methods Summary |
---|
public int | compareTo(com.ibm.icu4jni.text.CollationKey target)Bitwise comparison for the collation keys
byte tgtbytes[] = target.m_bytes_;
if (m_bytes_ == null || m_bytes_.length == 0) {
if (tgtbytes == null || tgtbytes.length == 0) {
return Collator.RESULT_EQUAL;
}
return Collator.RESULT_LESS;
}
else {
if (tgtbytes == null || tgtbytes.length == 0) {
return Collator.RESULT_GREATER;
}
}
int count = m_bytes_.length;
if (tgtbytes.length < count) {
count = tgtbytes.length;
}
int s,
t;
for (int i = 0; i < count; i ++)
{
// unable to use Arrays.equals
s = m_bytes_[i] & UNSIGNED_BYTE_MASK_;
t = tgtbytes[i] & UNSIGNED_BYTE_MASK_;
if (s < t) {
return Collator.RESULT_LESS;
}
if (s > t) {
return Collator.RESULT_GREATER;
}
}
if (m_bytes_.length < target.m_bytes_.length) {
return Collator.RESULT_LESS;
}
if (m_bytes_.length > target.m_bytes_.length) {
return Collator.RESULT_GREATER;
}
return Collator.RESULT_EQUAL;
| public int | compareTo(java.lang.Object target)Bitwise comparison for the collation keys.
Argument is casted to CollationKey
return compareTo((CollationKey)target);
| public boolean | equals(java.lang.Object target)Checks if target object is equal to this object.
Target is first casted to CollationKey and bitwise compared.
if (this == target) {
return true;
}
// checks getClass here since CollationKey is final not subclassable
if (target == null || target.getClass() != getClass()) {
return false;
}
return compareTo((CollationKey)target) == Collator.RESULT_EQUAL;
| public int | hashCode()Creates a hash code for this CollationKey.
Compute the hash by iterating sparsely over about 32 (up to 63) bytes
spaced evenly through the string. For each byte, multiply the previous
hash value by a prime number and add the new byte in, like a linear
congruential random number generator, producing a pseudorandom
deterministic value well distributed over the output range.
if (m_hash_ == 0)
{
if (m_bytes_ != null || m_bytes_.length != 0)
{
int len = m_bytes_.length;
int inc = ((len - 32) / 32) + 1;
for (int i = 0; i < len;)
{
m_hash_ = (m_hash_ * 37) + m_bytes_[i];
i += inc;
}
}
if (m_hash_ == 0)
m_hash_ = 1;
}
return m_hash_;
| public byte[] | toByteArray()Create the value of the Collation key in term of bytes
if (m_bytes_ == null || m_bytes_.length == 0)
return null;
return (byte[])m_bytes_.clone();
|
|