Home | History | Annotate | Download | only in text
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 //  2016 and later: Unicode, Inc. and others.
      3 // License & terms of use: http://www.unicode.org/copyright.html#License
      4 /**
      5  *******************************************************************************
      6  * Copyright (C) 1996-2016, International Business Machines Corporation and    *
      7  * others. All Rights Reserved.                                                *
      8  *******************************************************************************
      9  */
     10 
     11 package android.icu.text;
     12 
     13 import android.icu.util.ByteArrayWrapper;
     14 
     15 /**
     16  * <p>
     17  * Simple class wrapper to store the internal byte representation of a
     18  * CollationKey. Unlike the CollationKey, this class do not contain information
     19  * on the source string the sort order represents. RawCollationKey is mutable
     20  * and users can reuse its objects with the method in
     21  * RuleBasedCollator.getRawCollationKey(..).
     22  * </p>
     23  * <p>
     24  * Please refer to the documentation on CollationKey for a detail description
     25  * on the internal byte representation. Note the internal byte representation
     26  * is always null-terminated.
     27  * </p>
     28  * <code>
     29  * Example of use:<br>
     30  * String str[] = {.....};
     31  * RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance();
     32  * RawCollationKey key = new RawCollationKey(128);
     33  * for (int i = 0; i &lt; str.length; i ++) {
     34  *     collator.getRawCollationKey(str[i], key);
     35  *     // do something with key.bytes
     36  * }
     37  * </code>
     38  * <p><strong>Note:</strong> Comparison between RawCollationKeys created by
     39  * different Collators might return incorrect results.
     40  * See class documentation for Collator.</p>
     41  * @see RuleBasedCollator
     42  * @see CollationKey
     43  * @hide Only a subset of ICU is exposed in Android
     44  */
     45 public final class RawCollationKey extends ByteArrayWrapper
     46 {
     47     // public constructors --------------------------------------------------
     48 
     49     /**
     50      * Default constructor, internal byte array is null and its size set to 0.
     51      */
     52     public RawCollationKey()
     53     {
     54     }
     55 
     56     /**
     57      * RawCollationKey created with an empty internal byte array of length
     58      * capacity. Size of the internal byte array will be set to 0.
     59      * @param capacity length of internal byte array
     60      */
     61     public RawCollationKey(int capacity)
     62     {
     63         bytes = new byte[capacity];
     64     }
     65 
     66     /**
     67      * RawCollationKey created, adopting bytes as the internal byte array.
     68      * Size of the internal byte array will be set to 0.
     69      * @param bytes byte array to be adopted by RawCollationKey
     70      */
     71     public RawCollationKey(byte[] bytes)
     72     {
     73         this.bytes = bytes;
     74     }
     75 
     76     /**
     77      * Construct a RawCollationKey from a byte array and size.
     78      * @param bytesToAdopt the byte array to adopt
     79      * @param size the length of valid data in the byte array
     80      * @throws IndexOutOfBoundsException if bytesToAdopt == null and size != 0, or
     81      * size &lt; 0, or size &gt; bytesToAdopt.length.
     82      */
     83     public RawCollationKey(byte[] bytesToAdopt, int size)
     84     {
     85         super(bytesToAdopt, size);
     86     }
     87 
     88     /**
     89      * Compare this RawCollationKey to another, which must not be null.  This overrides
     90      * the inherited implementation to ensure the returned values are -1, 0, or 1.
     91      * @param rhs the RawCollationKey to compare to.
     92      * @return -1, 0, or 1 as this compares less than, equal to, or
     93      * greater than rhs.
     94      * @throws ClassCastException if the other object is not a RawCollationKey.
     95      */
     96     public int compareTo(RawCollationKey rhs) {
     97         int result = super.compareTo(rhs);
     98         return result < 0 ? -1 : result == 0 ? 0 : 1;
     99     }
    100 }
    101