KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > core > misc > ReusableChar


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64 package com.jcorporate.expresso.core.misc;
65
66 import java.io.ObjectInputStream JavaDoc;
67 import java.io.ObjectOutputStream JavaDoc;
68
69
70 //for Javadoc only
71

72 /**
73  * The Character class wraps a value of the primitive type <code>char</code> in
74  * an object. An object of type <code>Character</code> contains a single field
75  * whose type is <code>char</code>. This class is distinct from Java's
76  * Character class in that you can set a new value without having to create a
77  * new instance of an object. This saves on the GarbageCollecter in
78  * server/client environments. If you need to just use the static methods, it
79  * IS recommended that you use Character directory since the implementations
80  * require one less method call than through here.
81  *
82  * @author Michael Rimov
83  */

84 public final class ReusableChar implements java.io.Serializable JavaDoc, Comparable JavaDoc {
85     /**
86      * The minimum radix available for conversion to and from Strings. The
87      * constant value of this field is the smallest value permitted for the
88      * radix argument in radix-conversion methods such as the
89      * <code>digit</code> method, the <code>forDigit</code> method, and the
90      * <code>toString</code> method of class <code>Integer</code>.
91      *
92      * @see java.lang.Character#digit(char, int)
93      * @see java.lang.Character#forDigit(int, int)
94      * @see java.lang.Integer#toString(int, int)
95      * @see java.lang.Integer#valueOf(java.lang.String)
96      */

97     public static final int MIN_RADIX = 2;
98
99     /**
100      * The maximum radix available for conversion to and from Strings. The
101      * constant value of this field is the largest value permitted for the
102      * radix argument in radix-conversion methods such as the
103      * <code>digit</code> method, the <code>forDigit</code> method, and the
104      * <code>toString</code> method of class <code>Integer</code>.
105      *
106      * @see java.lang.Character#digit(char, int)
107      * @see java.lang.Character#forDigit(int, int)
108      * @see java.lang.Integer#toString(int, int)
109      * @see java.lang.Integer#valueOf(java.lang.String)
110      */

111     public static final int MAX_RADIX = 36;
112
113     /**
114      * The constant value of this field is the smallest value of type
115      * <code>char</code>.
116      *
117      * @since JDK1.0.2
118      */

119     public static final char MIN_VALUE = '\u0000';
120
121     /**
122      * The constant value of this field is the largest value of type
123      * <code>char</code>.
124      *
125      * @since JDK1.0.2
126      */

127     public static final char MAX_VALUE = '\uffff';
128
129     /**
130      * The value of the Character.
131      *
132      * @serial
133      */

134     private char value;
135
136     /**
137      * Constructs a <code>Character</code> object and initializes it so that it
138      * represents the primitive <code>value</code> argument.
139      *
140      * @param value value for the new <code>Character</code> object.
141      */

142     public ReusableChar(char value) {
143         this.value = value;
144     }
145
146     /**
147      * Sets the character value without having to recreate an object.
148      *
149      * @param ch
150      */

151     public void setCharValue(char ch) {
152         value = ch;
153     }
154
155     /**
156      * Determines if a character has a defined meaning in Unicode. A character
157      * is defined if at least one of the following is true:
158      * <p/>
159      * <ul>
160      * <li>
161      * It has an entry in the Unicode attribute table.
162      * </li>
163      * <li>
164      * Its value is in the range <code>
165      * '&#92;u3040'&nbsp;&lt;=&nbsp;ch&nbsp;&lt;=&nbsp;'&#92;u9FA5'</code>.
166      * </li>
167      * <li>
168      * Its value is in the range <code>
169      * '&#92;uF900'&nbsp;&lt;=&nbsp;ch&nbsp;&lt;=&nbsp;'&#92;uFA2D'</code>.
170      * </li>
171      * </ul>
172      *
173      * @param ch the character to be tested
174      * @return <code>true</code> if the character has a defined meaning in
175      * Unicode; <code>false</code> otherwise.
176      * @see java.lang.Character#isDigit(char)
177      * @see java.lang.Character#isLetter(char)
178      * @see java.lang.Character#isLetterOrDigit(char)
179      * @see java.lang.Character#isLowerCase(char)
180      * @see java.lang.Character#isTitleCase(char)
181      * @see java.lang.Character#isUpperCase(char)
182      */

183     public static boolean isDefined(char ch) {
184         return Character.isDefined(ch);
185     }
186
187     /**
188      * Determines if the specified character is a digit. A character is
189      * considered to be a digit if it is not in the range
190      * <code>'&#92;u2000'&nbsp;&lt;=&nbsp;ch&nbsp;&lt;=&nbsp;'&#92;u2FFF'</code>
191      * and its Unicode name contains the word "<code>DIGIT</code>". For a more
192      * complete specification that encompasses all Unicode characters that are
193      * defined as digits, see Gosling, Joy, and Steele, <i>The Java Language
194      * Specification</i>.
195      * <p/>
196      * <p/>
197      * These are the ranges of Unicode characters that are considered digits:
198      * </p>
199      *
200      * @param ch the character to be tested.
201      * @return <code>true</code> if the character is a digit;
202      * <code>false</code> otherwise.
203      * @see java.lang.Character#digit(char, int)
204      * @see java.lang.Character#forDigit(int, int)
205      */

206     public static boolean isDigit(char ch) {
207         return Character.isDigit(ch);
208     }
209
210     /**
211      * Determines if the specified character is an ISO control character. A
212      * character is considered to be an ISO control character if its code is
213      * in the range &#92;u0000 through &#92;u001F or in the range &#92;u007F
214      * through &#92;u009F.
215      *
216      * @param ch the character to be tested.
217      * @return true if the character is an ISO control character; false
218      * otherwise.
219      * @see java.lang.Character#isSpaceChar(char)
220      * @see java.lang.Character#isWhitespace(char)
221      */

222     public static boolean isISOControl(char ch) {
223         return Character.isISOControl(ch);
224     }
225
226     /**
227      * Determines if the specified character should be regarded as an ignorable
228      * character in a Java identifier or a Unicode identifier. The following
229      * Unicode characters are ignorable in a Java identifier or a Unicode
230      * identifier:
231      * <p/>
232      * <table>
233      * <tr><td>
234      * 0x0000 through 0x0008,
235      * </td><td>
236      * ISO control characters that
237      * </td></tr>
238      * <tr><td>
239      * 0x000E through 0x001B,
240      * </td><td>
241      * are not whitespace
242      * </td></tr>
243      * <tr><td>
244      * and 0x007F through 0x009F
245      * </td></tr>
246      * <tr><td>
247      * 0x200C through 0x200F
248      * </td><td>
249      * join controls
250      * </td></tr>
251      * <tr><td>
252      * 0x200A through 0x200E
253      * </td><td>
254      * bidirectional controls
255      * </td></tr>
256      * <tr><td>
257      * 0x206A through 0x206F
258      * </td><td>
259      * format controls
260      * </td></tr>
261      * <tr><td>
262      * 0xFEFF
263      * </td><td>
264      * zero-width no-break space
265      * </td></tr>
266      * </table>
267      *
268      * @param ch the character to be tested.
269      * @return true if the character may be part of a Unicode identifier; false
270      * otherwise.
271      * @see java.lang.Character#isJavaIdentifierPart(char)
272      * @see java.lang.Character#isUnicodeIdentifierPart(char)
273      */

274     public static boolean isIdentifierIgnorable(char ch) {
275         return Character.isIdentifierIgnorable(ch);
276     }
277
278     /**
279      * Determines if the specified character may be part of a Java identifier
280      * as other than the first character. A character may be part of a Java
281      * identifier if and only if it is one of the following:
282      * <p/>
283      * <ul>
284      * <li>
285      * a letter
286      * </li>
287      * <li>
288      * a currency symbol (such as "$")
289      * </li>
290      * <li>
291      * a connecting punctuation character (such as "_").
292      * </li>
293      * <li>
294      * a digit
295      * </li>
296      * <li>
297      * a numeric letter (such as a Roman numeral character)
298      * </li>
299      * <li>
300      * a combining mark
301      * </li>
302      * <li>
303      * a non-spacing mark
304      * </li>
305      * <li>
306      * an ignorable control character
307      * </li>
308      * </ul>
309      *
310      * @param ch the character to be tested.
311      * @return true if the character may be part of a Unicode identifier; false
312      * otherwise.
313      * @see java.lang.Character#isIdentifierIgnorable(char)
314      * @see java.lang.Character#isJavaIdentifierStart(char)
315      * @see java.lang.Character#isLetterOrDigit(char)
316      * @see java.lang.Character#isUnicodeIdentifierPart(char)
317      */

318     public static boolean isJavaIdentifierPart(char ch) {
319         return Character.isJavaIdentifierPart(ch);
320     }
321
322     /**
323      * Determines if the specified character is permissible as the first
324      * character in a Java identifier. A character may start a Java identifier
325      * if and only if it is one of the following:
326      * <p/>
327      * <ul>
328      * <li>
329      * a letter
330      * </li>
331      * <li>
332      * a currency symbol (such as "$")
333      * </li>
334      * <li>
335      * a connecting punctuation character (such as "_").
336      * </li>
337      * </ul>
338      *
339      * @param ch the character to be tested.
340      * @return true if the character may start a Java identifier; false
341      * otherwise.
342      * @see java.lang.Character#isJavaIdentifierPart(char)
343      * @see java.lang.Character#isLetter(char)
344      * @see java.lang.Character#isUnicodeIdentifierStart(char)
345      */

346     public static boolean isJavaIdentifierStart(char ch) {
347         return Character.isJavaIdentifierStart(ch);
348     }
349
350     /**
351      * Determines if the specified character is a letter. For a more complete
352      * specification that encompasses all Unicode characters, see Gosling,
353      * Joy, and Steele, <i>The Java Language Specification</i>.
354      * <p/>
355      * <p/>
356      * A character is considered to be a letter if and only if it is specified
357      * to be a letter by the Unicode 2.0 standard (category "Lu", "Ll", "Lt",
358      * "Lm", or "Lo" in the Unicode specification data file).
359      * </p>
360      * <p/>
361      * <p/>
362      * Note that most ideographic characters are considered to be letters
363      * (category "Lo") for this purpose.
364      * </p>
365      * <p/>
366      * <p/>
367      * Note also that not all letters have case: many Unicode characters are
368      * letters but are neither uppercase nor lowercase nor titlecase.
369      * </p>
370      *
371      * @param ch the character to be tested.
372      * @return <code>true</code> if the character is a letter;
373      * <code>false</code> otherwise.
374      * @see java.lang.Character#isDigit(char)
375      * @see java.lang.Character#isJavaIdentifierStart(char)
376      * @see java.lang.Character#isJavaLetter(char)
377      * @see java.lang.Character#isJavaLetterOrDigit(char)
378      * @see java.lang.Character#isLetterOrDigit(char)
379      * @see java.lang.Character#isLowerCase(char)
380      * @see java.lang.Character#isTitleCase(char)
381      * @see java.lang.Character#isUnicodeIdentifierStart(char)
382      * @see java.lang.Character#isUpperCase(char)
383      */

384     public static boolean isLetter(char ch) {
385         return Character.isLetter(ch);
386     }
387
388     /**
389      * Determines if the specified character is a letter or digit. For a more
390      * complete specification that encompasses all Unicode characters, see
391      * Gosling, Joy, and Steele, <i>The Java Language Specification</i>.
392      * <p/>
393      * <p/>
394      * A character is considered to be a letter if and only if it is specified
395      * to be a letter or a digit by the Unicode 2.0 standard (category "Lu",
396      * "Ll", "Lt", "Lm", "Lo", or "Nd" in the Unicode specification data
397      * file). In other words, isLetterOrDigit is true of a character if and
398      * only if either isLetter is true of the character or isDigit is true of
399      * the character.
400      * </p>
401      *
402      * @param ch the character to be tested.
403      * @return <code>true</code> if the character is a letter or digit;
404      * <code>false</code> otherwise.
405      * @see java.lang.Character#isDigit(char)
406      * @see java.lang.Character#isJavaIdentifierPart(char)
407      * @see java.lang.Character#isJavaLetter(char)
408      * @see java.lang.Character#isJavaLetterOrDigit(char)
409      * @see java.lang.Character#isLetter(char)
410      * @see java.lang.Character#isUnicodeIdentifierPart(char)
411      */

412     public static boolean isLetterOrDigit(char ch) {
413         return Character.isLetterOrDigit(ch);
414     }
415
416     /**
417      * Determines if the specified character is a lowercase character. A
418      * character is lowercase if it is not in the range
419      * <code>'&#92;u2000'</code> through <code>'&#92;u2FFF'</code>, the
420      * Unicode attribute table does not specify a mapping to lowercase for the
421      * character, and at least one of the following is true:
422      * <p/>
423      * <ul>
424      * <li>
425      * The attribute table specifies a mapping to uppercase for the character.
426      * </li>
427      * <li>
428      * The name for the character contains the words "<code>SMALL
429      * LETTER</code>".
430      * </li>
431      * <li>
432      * The name for the character contains the words "<code>SMALL
433      * LIGATURE</code>".
434      * </li>
435      * </ul>
436      * <p/>
437      * <p/>
438      * A character is considered to be lowercase if and only if it is specified
439      * to be lowercase by the Unicode 2.0 standard (category "Ll" in the
440      * Unicode specification data file).
441      * </p>
442      * <p/>
443      * <p/>
444      * Of the ISO-LATIN-1 characters (character codes 0x0000 through 0x00FF),
445      * the following are lowercase:
446      * </p>
447      * <p/>
448      * <p/>
449      * <blockquote>
450      * <pre>
451      * a b c d e f g h i j k l m n o p q r s t u v w x y z
452      * &#92;u00DF &#92;u00E0 &#92;u00E1 &#92;u00E2 &#92;u00E3 &#92;u00E4 &#92;u00E5 &#92;u00E6 &#92;u00E7
453      * &#92;u00E8 &#92;u00E9 &#92;u00EA &#92;u00EB &#92;u00EC &#92;u00ED &#92;u00EE &#92;u00EF &#92;u00F0
454      * &#92;u00F1 &#92;u00F2 &#92;u00F3 &#92;u00F4 &#92;u00F5 &#92;u00F6 &#92;u00F8 &#92;u00F9 &#92;u00FA
455      * &#92;u00FB &#92;u00FC &#92;u00FD &#92;u00FE &#92;u00FF
456      * </pre>
457      * </blockquote>
458      * </p>
459      * <p/>
460      * <p/>
461      * Many other Unicode characters are lowercase, too.
462      * </p>
463      *
464      * @param ch the character to be tested.
465      * @return <code>true</code> if the character is lowercase;
466      * <code>false</code> otherwise.
467      * @see java.lang.Character#isLowerCase(char)
468      * @see java.lang.Character#isTitleCase(char)
469      * @see java.lang.Character#toLowerCase(char)
470      */

471     public static boolean isLowerCase(char ch) {
472         return Character.isLowerCase(ch);
473     }
474
475     /**
476      * Returns the Unicode numeric value of the character as a nonnegative
477      * integer. If the character does not have a numeric value, then -1 is
478      * returned. If the character has a numeric value that cannot be
479      * represented as a nonnegative integer (for example, a fractional value),
480      * then -2 is returned.
481      *
482      * @param ch the character to be converted.
483      * @return the numeric value of the character, as a nonnegative int value;
484      * -2 if the character has a numeric value that is not a
485      * nonnegative integer; -1 if the character has no numeric value.
486      * @see java.lang.Character#forDigit(int, int)
487      * @see java.lang.Character#isDigit(char)
488      * @since JDK1.1
489      */

490     public static int getNumericValue(char ch) {
491         return Character.getNumericValue(ch);
492     }
493
494     /**
495      * Determines if the specified character is a Unicode space character. A
496      * character is considered to be a space character if and only if it is
497      * specified to be a space character by the Unicode 2.0 standard (category
498      * "Zs", "Zl, or "Zp" in the Unicode specification data file).
499      *
500      * @param ch the character to be tested.
501      * @return true if the character is a space character; false otherwise.
502      * @see java.lang.Character#isWhitespace(char)
503      * @since JDK1.1
504      */

505     public static boolean isSpaceChar(char ch) {
506         return Character.isSpaceChar(ch);
507     }
508
509     /**
510      * Determines if the specified character is a titlecase character. A
511      * character is considered to be titlecase if and only if it is specified
512      * to be titlecase by the Unicode 2.0 standard (category "Lt" in the
513      * Unicode specification data file).
514      * <p/>
515      * <p/>
516      * The printed representations of four Unicode characters look like pairs
517      * of Latin letters. For example, there is an uppercase letter that looks
518      * like "LJ" and has a corresponding lowercase letter that looks like
519      * "lj". A third form, which looks like "Lj", is the appropriate form to
520      * use when rendering a word in lowercase with initial capitals, as for a
521      * book title.
522      * </p>
523      * <p/>
524      * <p/>
525      * These are the Unicode characters for which this method returns
526      * <code>true</code>:
527      * <p/>
528      * <ul>
529      * <li>
530      * <code>LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON</code>
531      * </li>
532      * <li>
533      * <code>LATIN CAPITAL LETTER L WITH SMALL LETTER J</code>
534      * </li>
535      * <li>
536      * <code>LATIN CAPITAL LETTER N WITH SMALL LETTER J</code>
537      * </li>
538      * <li>
539      * <code>LATIN CAPITAL LETTER D WITH SMALL LETTER Z</code>
540      * </li>
541      * </ul>
542      * </p>
543      *
544      * @param ch the character to be tested.
545      * @return <code>true</code> if the character is titlecase;
546      * <code>false</code> otherwise.
547      * @see java.lang.Character#isLowerCase(char)
548      * @see java.lang.Character#isUpperCase(char)
549      * @see java.lang.Character#toTitleCase(char)
550      * @since JDK1.0.2
551      */

552     public static boolean isTitleCase(char ch) {
553         return Character.isTitleCase(ch);
554     }
555
556     /**
557      * Returns a value indicating a character category.
558      *
559      * @param ch the character to be tested.
560      * @return a value of type int, the character category.
561      * @see java.lang.Character#COMBINING_SPACING_MARK
562      * @see java.lang.Character#CONNECTOR_PUNCTUATION
563      * @see java.lang.Character#CONTROL
564      * @see java.lang.Character#CURRENCY_SYMBOL
565      * @see java.lang.Character#DASH_PUNCTUATION
566      * @see java.lang.Character#DECIMAL_DIGIT_NUMBER
567      * @see java.lang.Character#ENCLOSING_MARK
568      * @see java.lang.Character#END_PUNCTUATION
569      * @see java.lang.Character#FORMAT
570      * @see java.lang.Character#LETTER_NUMBER
571      * @see java.lang.Character#LINE_SEPARATOR
572      * @see java.lang.Character#LOWERCASE_LETTER
573      * @see java.lang.Character#MATH_SYMBOL
574      * @see java.lang.Character#MODIFIER_LETTER
575      * @see java.lang.Character#MODIFIER_SYMBOL
576      * @see java.lang.Character#NON_SPACING_MARK
577      * @see java.lang.Character#OTHER_LETTER
578      * @see java.lang.Character#OTHER_NUMBER
579      * @see java.lang.Character#OTHER_PUNCTUATION
580      * @see java.lang.Character#OTHER_SYMBOL
581      * @see java.lang.Character#PARAGRAPH_SEPARATOR
582      * @see java.lang.Character#PRIVATE_USE
583      * @see java.lang.Character#SPACE_SEPARATOR
584      * @see java.lang.Character#START_PUNCTUATION
585      * @see java.lang.Character#SURROGATE
586      * @see java.lang.Character#TITLECASE_LETTER
587      * @see java.lang.Character#UNASSIGNED
588      * @see java.lang.Character#UPPERCASE_LETTER
589      */

590     public static int getType(char ch) {
591         return Character.getType(ch);
592     }
593
594     /**
595      * Determines if the specified character may be part of a Unicode
596      * identifier as other than the first character. A character may be part
597      * of a Unicode identifier if and only if it is one of the following:
598      * <p/>
599      * <ul>
600      * <li>
601      * a letter
602      * </li>
603      * <li>
604      * a connecting punctuation character (such as "_").
605      * </li>
606      * <li>
607      * a digit
608      * </li>
609      * <li>
610      * a numeric letter (such as a Roman numeral character)
611      * </li>
612      * <li>
613      * a combining mark
614      * </li>
615      * <li>
616      * a non-spacing mark
617      * </li>
618      * <li>
619      * an ignorable control character
620      * </li>
621      * </ul>
622      *
623      * @param ch the character to be tested.
624      * @return true if the character may be part of a Unicode identifier; false
625      * otherwise.
626      * @see java.lang.Character#isIdentifierIgnorable(char)
627      * @see java.lang.Character#isJavaIdentifierPart(char)
628      * @see java.lang.Character#isLetterOrDigit(char)
629      * @see java.lang.Character#isUnicodeIdentifierStart(char)
630      */

631     public static boolean isUnicodeIdentifierPart(char ch) {
632         return Character.isUnicodeIdentifierPart(ch);
633     }
634
635     /**
636      * Determines if the specified character is permissible as the first
637      * character in a Unicode identifier. A character may start a Unicode
638      * identifier if and only if it is a letter.
639      *
640      * @param ch the character to be tested.
641      * @return true if the character may start a Unicode identifier; false
642      * otherwise.
643      * @see java.lang.Character#isJavaIdentifierStart(char)
644      * @see java.lang.Character#isLetter(char)
645      * @see java.lang.Character#isUnicodeIdentifierPart(char)
646      * @since JDK1.1
647      */

648     public static boolean isUnicodeIdentifierStart(char ch) {
649         return Character.isUnicodeIdentifierStart(ch);
650     }
651
652     /**
653      * Determines if the specified character is an uppercase character. A
654      * character is uppercase if it is not in the range
655      * <code>'&#92;u2000'</code> through <code>'&#92;u2FFF'</code>, the
656      * Unicode attribute table does not specify a mapping to uppercase for the
657      * character, and at least one of the following is true:
658      * <p/>
659      * <ul>
660      * <li>
661      * The attribute table specifies a mapping to lowercase for the character.
662      * </li>
663      * <li>
664      * The name for the character contains the words "<code>CAPITAL
665      * LETTER</code>".
666      * </li>
667      * <li>
668      * The name for the character contains the words "<code>CAPITAL
669      * LIGATURE</code>".
670      * </li>
671      * </ul>
672      * <p/>
673      * <p/>
674      * Of the ISO-LATIN-1 characters (character codes 0x0000 through 0x00FF),
675      * the following are uppercase:
676      * </p>
677      * <p/>
678      * <p/>
679      * <blockquote>
680      * <pre>
681      * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
682      * &#92;u00C0 &#92;u00C1 &#92;u00C2 &#92;u00C3 &#92;u00C4 &#92;u00C5 &#92;u00C6 &#92;u00C7
683      * &#92;u00C8 &#92;u00C9 &#92;u00CA &#92;u00CB &#92;u00CC &#92;u00CD &#92;u00CE &#92;u00CF &#92;u00D0
684      * &#92;u00D1 &#92;u00D2 &#92;u00D3 &#92;u00D4 &#92;u00D5 &#92;u00D6 &#92;u00D8 &#92;u00D9 &#92;u00DA
685      * &#92;u00DB &#92;u00DC &#92;u00DD &#92;u00DE
686      * </pre>
687      * </blockquote>
688      * </p>
689      * <p/>
690      * <p/>
691      * Many other Unicode characters are uppercase, too.
692      * </p>
693      *
694      * @param ch the character to be tested.
695      * @return <code>true</code> if the character is uppercase;
696      * <code>false</code> otherwise.
697      * @see java.lang.Character#isLowerCase(char)
698      * @see java.lang.Character#isTitleCase(char)
699      * @see java.lang.Character#toUpperCase(char)
700      * @since 1.0
701      */

702     public static boolean isUpperCase(char ch) {
703         return Character.isUpperCase(ch);
704     }
705
706     /**
707      * Determines if the specified character is white space according to Java.
708      * A character is considered to be a Java whitespace character if and only
709      * if it satisfies one of the following criteria:
710      * <p/>
711      * <ul>
712      * <li>
713      * It is a Unicode space separator (category "Zs"), but is not a no-break
714      * space (&#92;u00A0 or &#92;uFEFF).
715      * </li>
716      * <li>
717      * It is a Unicode line separator (category "Zl").
718      * </li>
719      * <li>
720      * It is a Unicode paragraph separator (category "Zp").
721      * </li>
722      * <li>
723      * It is &#92;u0009, HORIZONTAL TABULATION.
724      * </li>
725      * <li>
726      * It is &#92;u000A, LINE FEED.
727      * </li>
728      * <li>
729      * It is &#92;u000B, VERTICAL TABULATION.
730      * </li>
731      * <li>
732      * It is &#92;u000C, FORM FEED.
733      * </li>
734      * <li>
735      * It is &#92;u000D, CARRIAGE RETURN.
736      * </li>
737      * <li>
738      * It is &#92;u001C, FILE SEPARATOR.
739      * </li>
740      * <li>
741      * It is &#92;u001D, GROUP SEPARATOR.
742      * </li>
743      * <li>
744      * It is &#92;u001E, RECORD SEPARATOR.
745      * </li>
746      * <li>
747      * It is &#92;u001F, UNIT SEPARATOR.
748      * </li>
749      * </ul>
750      *
751      * @param ch the character to be tested.
752      * @return true if the character is a Java whitespace character; false
753      * otherwise.
754      * @see java.lang.Character#isSpaceChar(char)
755      */

756     public static boolean isWhitespace(char ch) {
757         return Character.isWhitespace(ch);
758     }
759
760     /**
761      * Returns the value of this Character object.
762      *
763      * @return the primitive <code>char</code> value represented by this
764      * object.
765      */

766     public char charValue() {
767         return value;
768     }
769
770     /**
771      * Returns the numeric value of the character <code>ch</code> in the
772      * specified radix.
773      * <p/>
774      * <p/>
775      * If the radix is not in the range <code>MIN_RADIX</code>&nbsp;&lt;=
776      * <code>radix</code>&nbsp;&lt;= <code>MAX_RADIX</code> or if the value of
777      * <code>ch</code> is not a valid digit in the specified radix,
778      * <code>-1</code> is returned. A character is a valid digit if at least
779      * one of the following is true:
780      * <p/>
781      * <ul>
782      * <li>
783      * The method <code>isDigit</code> is true of the character and the Unicode
784      * decimal digit value of the character (or its single-character
785      * decomposition) is less than the specified radix. In this case the
786      * decimal digit value is returned.
787      * </li>
788      * <li>
789      * The character is one of the uppercase Latin letters <code>'A'</code>
790      * through <code>'Z'</code> and its code is less than <code>radix&nbsp;+
791      * 'A'&nbsp;-&nbsp;10</code>. In this case, <code>ch&nbsp;-
792      * 'A'&nbsp;+&nbsp;10</code> is returned.
793      * </li>
794      * <li>
795      * The character is one of the lowercase Latin letters <code>'a'</code>
796      * through <code>'z'</code> and its code is less than <code>radix&nbsp;+
797      * 'a'&nbsp;-&nbsp;10</code>. In this case, <code>ch&nbsp;-
798      * 'a'&nbsp;+&nbsp;10</code> is returned.
799      * </li>
800      * </ul>
801      * </p>
802      *
803      * @param ch the character to be converted.
804      * @param radix the radix.
805      * @return the numeric value represented by the character in the specified
806      * radix.
807      * @see java.lang.Character#forDigit(int, int)
808      * @see java.lang.Character#isDigit(char)
809      */

810     public static int digit(char ch, int radix) {
811         return Character.digit(ch, radix);
812     }
813
814     /**
815      * Compares this object against the specified object. The result is
816      * <code>true</code> if and only if the argument is not <code>null</code>
817      * and is a <code>Character</code> object that represents the same
818      * <code>char</code> value as this object.
819      *
820      * @param obj the object to compare with.
821      * @return <code>true</code> if the objects are the same;
822      * <code>false</code> otherwise.
823      */

824     public boolean equals(Object JavaDoc obj) {
825         if (obj instanceof ReusableChar) {
826             return value == ((ReusableChar) obj).charValue();
827         }
828
829         return false;
830     }
831
832     /**
833      * Determines the character representation for a specific digit in the
834      * specified radix. If the value of <code>radix</code> is not a valid
835      * radix, or the value of <code>digit</code> is not a valid digit in the
836      * specified radix, the null character (<code>'&#92;u0000'</code>) is
837      * returned.
838      * <p/>
839      * <p/>
840      * The <code>radix</code> argument is valid if it is greater than or equal
841      * to <code>MIN_RADIX</code> and less than or equal to
842      * <code>MAX_RADIX</code>. The <code>digit</code> argument is valid if
843      * <code>0&nbsp;&lt;= digit&nbsp;&lt;=&nbsp;radix</code>.
844      * </p>
845      * <p/>
846      * <p/>
847      * If the digit is less than 10, then <code>'0'&nbsp;+ digit</code> is
848      * returned. Otherwise, the value <code>'a'&nbsp;+
849      * digit&nbsp;-&nbsp;10</code> is returned.
850      * </p>
851      *
852      * @param digit the number to convert to a character.
853      * @param radix the radix.
854      * @return the <code>char</code> representation of the specified digit in
855      * the specified radix.
856      * @see java.lang.Character#MIN_RADIX
857      * @see java.lang.Character#MAX_RADIX
858      * @see java.lang.Character#digit(char, int)
859      */

860     public static char forDigit(int digit, int radix) {
861         return Character.forDigit(digit, radix);
862     }
863
864     /**
865      * Returns a hash code for this Character.
866      *
867      * @return a hash code value for this object.
868      */

869     public int hashCode() {
870         return (int) value;
871     }
872
873     /**
874      * The given character is mapped to its lowercase equivalent; if the
875      * character has no lowercase equivalent, the character itself is
876      * returned.
877      * <p/>
878      * <p/>
879      * A character has a lowercase equivalent if and only if a lowercase
880      * mapping is specified for the character in the Unicode attribute table.
881      * </p>
882      * <p/>
883      * <p/>
884      * Note that some Unicode characters in the range <code>'&#92;u2000'</code>
885      * to <code>'&#92;u2FFF'</code> have lowercase mappings; this method does
886      * map such characters to their lowercase equivalents even though the
887      * method <code>isUpperCase</code> does not return <code>true</code> for
888      * such characters.
889      * </p>
890      *
891      * @param ch the character to be converted.
892      * @return the lowercase equivalent of the character, if any; otherwise the
893      * character itself.
894      * @see java.lang.Character#isLowerCase(char)
895      * @see java.lang.Character#isUpperCase(char)
896      * @see java.lang.Character#toTitleCase(char)
897      * @see java.lang.Character#toUpperCase(char)
898      */

899     public static char toLowerCase(char ch) {
900         return Character.toLowerCase(ch);
901     }
902
903     /**
904      * Returns a String object representing this character's value. Converts
905      * this <code>Character</code> object to a string. The result is a string
906      * whose length is <code>1</code>. The string's sole component is the
907      * primitive <code>char</code> value represented by this object.
908      *
909      * @return a string representation of this object.
910      */

911     public String JavaDoc toString() {
912         char[] buf = {value};
913
914         return String.valueOf(buf);
915     }
916
917     /**
918      * Converts the character argument to titlecase. A character has a
919      * titlecase equivalent if and only if a titlecase mapping is specified
920      * for the character in the Unicode attribute table.
921      * <p/>
922      * <p/>
923      * Note that some Unicode characters in the range <code>'&#92;u2000'</code>
924      * through <code>'&#92;u2FFF'</code> have titlecase mappings; this method
925      * does map such characters to their titlecase equivalents even though the
926      * method <code>isTitleCase</code> does not return <code>true</code> for
927      * such characters.
928      * </p>
929      * <p/>
930      * <p/>
931      * There are only four Unicode characters that are truly titlecase forms
932      * that are distinct from uppercase forms. As a rule, if a character has
933      * no true titlecase equivalent but does have an uppercase mapping, then
934      * the Unicode 2.0 attribute table specifies a titlecase mapping that is
935      * the same as the uppercase mapping.
936      * </p>
937      *
938      * @param ch the character to be converted.
939      * @return the titlecase equivalent of the character, if any; otherwise the
940      * character itself.
941      * @see java.lang.Character#isTitleCase(char)
942      * @see java.lang.Character#toLowerCase(char)
943      * @see java.lang.Character#toUpperCase(char)
944      */

945     public static char toTitleCase(char ch) {
946         return Character.toTitleCase(ch);
947     }
948
949     /**
950      * Converts the character argument to uppercase. A character has an
951      * uppercase equivalent if and only if an uppercase mapping is specified
952      * for the character in the Unicode attribute table.
953      * <p/>
954      * <p/>
955      * Note that some Unicode characters in the range <code>'&#92;u2000'</code>
956      * to <code>'&#92;u2000FFF'</code> have uppercase mappings; this method
957      * does map such characters to their titlecase equivalents even though the
958      * method <code>isLowerCase</code> does not return <code>true</code> for
959      * such characters.
960      * </p>
961      *
962      * @param ch the character to be converted.
963      * @return the uppercase equivalent of the character, if any; otherwise the
964      * character itself.
965      * @see java.lang.Character#isLowerCase(char)
966      * @see java.lang.Character#isUpperCase(char)
967      * @see java.lang.Character#toLowerCase(char)
968      * @see java.lang.Character#toTitleCase(char)
969      */

970     public static char toUpperCase(char ch) {
971         return Character.toUpperCase(ch);
972     }
973
974     /**
975      * Compares two Characters numerically.
976      *
977      * @param anotherCharacter the <code>Character</code> to be compared.
978      * @return the value <code>0</code> if the argument Character is equal to
979      * this Character; a value less than <code>0</code> if this
980      * Character is numerically less than the Character argument; and
981      * a value greater than <code>0</code> if this Character is
982      * numerically greater than the Character argument (unsigned
983      * comparison). Note that this is strictly a numerical
984      * comparison; it is not locale-dependent.
985      */

986     public int compareTo(ReusableChar anotherCharacter) {
987         return this.value - anotherCharacter.value;
988     }
989
990     /**
991      * Compares this Character to another Object. If the Object is a
992      * Character, this function behaves like
993      * <code>compareTo(ReusableChar)</code>. Otherwise, it throws a
994      * <code>ClassCastException</code> (as Characters are comparable only to
995      * other Characters).
996      *
997      * @param o the <code>Object</code> to be compared.
998      * @return the value <code>0</code> if the argument is a Character
999      * numerically equal to this Character; a value less than
1000     * <code>0</code> if the argument is a Character numerically
1001     * greater than this Character; and a value greater than
1002     * <code>0</code> if the argument is a Character numerically less
1003     * than this Character.
1004     * @see java.lang.Comparable
1005     */

1006    public int compareTo(Object JavaDoc o) {
1007        return compareTo((ReusableChar) o);
1008    }
1009
1010    /**
1011     * Serialization capabilities Written out for performance sake
1012     *
1013     * @param ois Object input stream to read from
1014     * @throws ClassNotFoundException upon class instantiation error
1015     * @throws java.io.IOException i/o error
1016     */

1017    private void readObject(ObjectInputStream JavaDoc ois)
1018            throws ClassNotFoundException JavaDoc, java.io.IOException JavaDoc {
1019        value = ois.readChar();
1020    }
1021
1022    private void writeObject(ObjectOutputStream JavaDoc oos) throws java.io.IOException JavaDoc {
1023        oos.writeChar((int) value);
1024    }
1025}
1026
Popular Tags