1 /* |
1 /* |
2 * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
66 * allows it to be faster when doing single comparisons. |
66 * allows it to be faster when doing single comparisons. |
67 * <p> |
67 * <p> |
68 * The following example shows how <code>CollationKey</code>s might be used |
68 * The following example shows how <code>CollationKey</code>s might be used |
69 * to sort a list of <code>String</code>s. |
69 * to sort a list of <code>String</code>s. |
70 * <blockquote> |
70 * <blockquote> |
71 * <pre> |
71 * <pre>{@code |
72 * // Create an array of CollationKeys for the Strings to be sorted. |
72 * // Create an array of CollationKeys for the Strings to be sorted. |
73 * Collator myCollator = Collator.getInstance(); |
73 * Collator myCollator = Collator.getInstance(); |
74 * CollationKey[] keys = new CollationKey[3]; |
74 * CollationKey[] keys = new CollationKey[3]; |
75 * keys[0] = myCollator.getCollationKey("Tom"); |
75 * keys[0] = myCollator.getCollationKey("Tom"); |
76 * keys[1] = myCollator.getCollationKey("Dick"); |
76 * keys[1] = myCollator.getCollationKey("Dick"); |
77 * keys[2] = myCollator.getCollationKey("Harry"); |
77 * keys[2] = myCollator.getCollationKey("Harry"); |
78 * sort( keys ); |
78 * sort(keys); |
79 * <br> |
79 * |
80 * //... |
80 * //... |
81 * <br> |
81 * |
82 * // Inside body of sort routine, compare keys this way |
82 * // Inside body of sort routine, compare keys this way |
83 * if( keys[i].compareTo( keys[j] ) > 0 ) |
83 * if (keys[i].compareTo(keys[j]) > 0) |
84 * // swap keys[i] and keys[j] |
84 * // swap keys[i] and keys[j] |
85 * <br> |
85 * |
86 * //... |
86 * //... |
87 * <br> |
87 * |
88 * // Finally, when we've returned from sort. |
88 * // Finally, when we've returned from sort. |
89 * System.out.println( keys[0].getSourceString() ); |
89 * System.out.println(keys[0].getSourceString()); |
90 * System.out.println( keys[1].getSourceString() ); |
90 * System.out.println(keys[1].getSourceString()); |
91 * System.out.println( keys[2].getSourceString() ); |
91 * System.out.println(keys[2].getSourceString()); |
92 * </pre> |
92 * }</pre> |
93 * </blockquote> |
93 * </blockquote> |
94 * |
94 * |
95 * @see Collator |
95 * @see Collator |
96 * @see RuleBasedCollator |
96 * @see RuleBasedCollator |
97 * @author Helena Shih |
97 * @author Helena Shih |
121 /** |
123 /** |
122 * Converts the CollationKey to a sequence of bits. If two CollationKeys |
124 * Converts the CollationKey to a sequence of bits. If two CollationKeys |
123 * could be legitimately compared, then one could compare the byte arrays |
125 * could be legitimately compared, then one could compare the byte arrays |
124 * for each of those keys to obtain the same result. Byte arrays are |
126 * for each of those keys to obtain the same result. Byte arrays are |
125 * organized most significant byte first. |
127 * organized most significant byte first. |
|
128 * |
|
129 * @return a byte array representation of the CollationKey |
126 */ |
130 */ |
127 abstract public byte[] toByteArray(); |
131 abstract public byte[] toByteArray(); |
128 |
132 |
129 |
133 |
130 /** |
134 /** |
131 * CollationKey constructor. |
135 * CollationKey constructor. |
132 * |
136 * |
133 * @param source - the source string. |
137 * @param source the source string |
134 * @exception NullPointerException if <code>source</code> is null. |
138 * @exception NullPointerException if {@code source} is null |
135 * @since 1.6 |
139 * @since 1.6 |
136 */ |
140 */ |
137 protected CollationKey(String source) { |
141 protected CollationKey(String source) { |
138 if (source==null){ |
142 if (source==null){ |
139 throw new NullPointerException(); |
143 throw new NullPointerException(); |