FileDocCategorySizeDatePackage
RuleBasedCollationKey.javaAPI DocJava SE 6 API4005Tue Jun 10 00:25:52 BST 2008java.text

RuleBasedCollationKey

public final class RuleBasedCollationKey extends CollationKey
A RuleBasedCollationKey is a concrete implementation of CollationKey class. The RuleBasedCollationKey class is used by the RuleBasedCollator class.

Fields Summary
private String
key
Constructors Summary
RuleBasedCollationKey(String source, String key)
A RuleBasedCollationKey can only be generated by Collator objects.

	super(source);
        this.key = key;
    
Methods Summary
public intcompareTo(java.text.CollationKey target)
Compare this RuleBasedCollationKey to target. The collation rules of the Collator object which created these keys are applied. Note: RuleBasedCollationKeys created by different Collators can not be compared.

param
target target RuleBasedCollationKey
return
Returns an integer value. Value is less than zero if this is less than target, value is zero if this and target are equal and value is greater than zero if this is greater than target.
see
java.text.Collator#compare

        int result = key.compareTo(((RuleBasedCollationKey)(target)).key);
        if (result <= Collator.LESS)
            return Collator.LESS;
        else if (result >= Collator.GREATER)
            return Collator.GREATER;
        return Collator.EQUAL;
    
public booleanequals(java.lang.Object target)
Compare this RuleBasedCollationKey and the target for equality. The collation rules of the Collator object which created these keys are applied. Note: RuleBasedCollationKeys created by different Collators can not be compared.

param
target the RuleBasedCollationKey to compare to.
return
Returns true if two objects are equal, false otherwise.

        if (this == target) return true;
        if (target == null || !getClass().equals(target.getClass())) {
            return false;
        }
        RuleBasedCollationKey other = (RuleBasedCollationKey)target;
        return key.equals(other.key);
    
public inthashCode()
Creates a hash code for this RuleBasedCollationKey. The hash value is calculated on the key itself, not the String from which the key was created. Thus if x and y are RuleBasedCollationKeys, then x.hashCode(x) == y.hashCode() if x.equals(y) is true. This allows language-sensitive comparison in a hash table. See the CollatinKey class description for an example.

return
the hash value based on the string's collation order.

        return (key.hashCode());
    
public byte[]toByteArray()
Converts the RuleBasedCollationKey to a sequence of bits. If two RuleBasedCollationKeys could be legitimately compared, then one could compare the byte arrays for each of those keys to obtain the same result. Byte arrays are organized most significant byte first.


        char[] src = key.toCharArray();
        byte[] dest = new byte[ 2*src.length ];
        int j = 0;
        for( int i=0; i<src.length; i++ ) {
            dest[j++] = (byte)(src[i] >>> 8);
            dest[j++] = (byte)(src[i] & 0x00ff);
        }
        return dest;