2 *******************************************************************************
\r
3 * Copyright (C) 1996-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.text;
\r
10 import com.ibm.icu.util.ByteArrayWrapper;
\r
14 * Simple class wrapper to store the internal byte representation of a
\r
15 * CollationKey. Unlike the CollationKey, this class do not contain information
\r
16 * on the source string the sort order represents. RawCollationKey is mutable
\r
17 * and users can reuse its objects with the method in
\r
18 * RuleBasedCollator.getRawCollationKey(..).
\r
21 * Please refer to the documentation on CollationKey for a detail description
\r
22 * on the internal byte representation. Note the internal byte representation
\r
23 * is always null-terminated.
\r
26 * Example of use:<br>
\r
27 * String str[] = {.....};
\r
28 * RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance();
\r
29 * RawCollationKey key = new RawCollationKey(128);
\r
30 * for (int i = 0; i < str.length; i ++) {
\r
31 * collator.getRawCollationKey(str[i], key);
\r
32 * // do something with key.bytes
\r
35 * <p><strong>Note:</strong> Comparison between RawCollationKeys created by
\r
36 * different Collators might return incorrect results.
\r
37 * See class documentation for Collator.</p>
\r
39 * @see RuleBasedCollator
\r
42 public final class RawCollationKey extends ByteArrayWrapper
\r
44 // public constructors --------------------------------------------------
\r
47 * Default constructor, internal byte array is null and its size set to 0.
\r
50 public RawCollationKey()
\r
55 * RawCollationKey created with an empty internal byte array of length
\r
56 * capacity. Size of the internal byte array will be set to 0.
\r
57 * @param capacity length of internal byte array
\r
60 public RawCollationKey(int capacity)
\r
62 bytes = new byte[capacity];
\r
66 * RawCollationKey created, adopting bytes as the internal byte array.
\r
67 * Size of the internal byte array will be set to 0.
\r
68 * @param bytes byte array to be adopted by RawCollationKey
\r
71 public RawCollationKey(byte[] bytes)
\r
77 * Construct a RawCollationKey from a byte array and size.
\r
78 * @param bytesToAdopt the byte array to adopt
\r
79 * @param size the length of valid data in the byte array
\r
80 * @throws IndexOutOfBoundsException if bytesToAdopt == null and size != 0, or
\r
81 * size < 0, or size > bytesToAdopt.length.
\r
84 public RawCollationKey(byte[] bytesToAdopt, int size)
\r
86 super(bytesToAdopt, size);
\r
90 * Compare this RawCollationKey to another, which must not be null. This overrides
\r
91 * the inherited implementation to ensure the returned values are -1, 0, or 1.
\r
92 * @param rhs the RawCollationKey to compare to.
\r
93 * @return -1, 0, or 1 as this compares less than, equal to, or
\r
95 * @throws ClassCastException if the other object is not a RawCollationKey.
\r
98 public int compareTo(RawCollationKey rhs) {
\r
99 int result = super.compareTo(rhs);
\r
100 return result < 0 ? -1 : result == 0 ? 0 : 1;
\r