0001: /* ====================================================================
0002: * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
0003: *
0004: * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
0005: *
0006: * Redistribution and use in source and binary forms, with or without
0007: * modification, are permitted provided that the following conditions
0008: * are met:
0009: *
0010: * 1. Redistributions of source code must retain the above copyright
0011: * notice, this list of conditions and the following disclaimer.
0012: *
0013: * 2. Redistributions in binary form must reproduce the above copyright
0014: * notice, this list of conditions and the following disclaimer in
0015: * the documentation and/or other materials provided with the
0016: * distribution.
0017: *
0018: * 3. The end-user documentation included with the redistribution,
0019: * if any, must include the following acknowledgment:
0020: * "This product includes software developed by Jcorporate Ltd.
0021: * (http://www.jcorporate.com/)."
0022: * Alternately, this acknowledgment may appear in the software itself,
0023: * if and wherever such third-party acknowledgments normally appear.
0024: *
0025: * 4. "Jcorporate" and product names such as "Expresso" must
0026: * not be used to endorse or promote products derived from this
0027: * software without prior written permission. For written permission,
0028: * please contact info@jcorporate.com.
0029: *
0030: * 5. Products derived from this software may not be called "Expresso",
0031: * or other Jcorporate product names; nor may "Expresso" or other
0032: * Jcorporate product names appear in their name, without prior
0033: * written permission of Jcorporate Ltd.
0034: *
0035: * 6. No product derived from this software may compete in the same
0036: * market space, i.e. framework, without prior written permission
0037: * of Jcorporate Ltd. For written permission, please contact
0038: * partners@jcorporate.com.
0039: *
0040: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0041: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0042: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0043: * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
0044: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0045: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
0046: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0047: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0048: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0049: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0050: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0051: * SUCH DAMAGE.
0052: * ====================================================================
0053: *
0054: * This software consists of voluntary contributions made by many
0055: * individuals on behalf of the Jcorporate Ltd. Contributions back
0056: * to the project(s) are encouraged when you make modifications.
0057: * Please send them to support@jcorporate.com. For more information
0058: * on Jcorporate Ltd. and its products, please see
0059: * <http://www.jcorporate.com/>.
0060: *
0061: * Portions of this software are based upon other open source
0062: * products and are subject to their respective licenses.
0063: */
0064: package com.jcorporate.expresso.core.misc;
0065:
0066: import java.io.ObjectInputStream;
0067: import java.io.ObjectOutputStream;
0068:
0069: //for Javadoc only
0070:
0071: /**
0072: * The Character class wraps a value of the primitive type <code>char</code> in
0073: * an object. An object of type <code>Character</code> contains a single field
0074: * whose type is <code>char</code>. This class is distinct from Java's
0075: * Character class in that you can set a new value without having to create a
0076: * new instance of an object. This saves on the GarbageCollecter in
0077: * server/client environments. If you need to just use the static methods, it
0078: * IS recommended that you use Character directory since the implementations
0079: * require one less method call than through here.
0080: *
0081: * @author Michael Rimov
0082: */
0083: public final class ReusableChar implements java.io.Serializable,
0084: Comparable {
0085: /**
0086: * The minimum radix available for conversion to and from Strings. The
0087: * constant value of this field is the smallest value permitted for the
0088: * radix argument in radix-conversion methods such as the
0089: * <code>digit</code> method, the <code>forDigit</code> method, and the
0090: * <code>toString</code> method of class <code>Integer</code>.
0091: *
0092: * @see java.lang.Character#digit(char, int)
0093: * @see java.lang.Character#forDigit(int, int)
0094: * @see java.lang.Integer#toString(int, int)
0095: * @see java.lang.Integer#valueOf(java.lang.String)
0096: */
0097: public static final int MIN_RADIX = 2;
0098:
0099: /**
0100: * The maximum radix available for conversion to and from Strings. The
0101: * constant value of this field is the largest value permitted for the
0102: * radix argument in radix-conversion methods such as the
0103: * <code>digit</code> method, the <code>forDigit</code> method, and the
0104: * <code>toString</code> method of class <code>Integer</code>.
0105: *
0106: * @see java.lang.Character#digit(char, int)
0107: * @see java.lang.Character#forDigit(int, int)
0108: * @see java.lang.Integer#toString(int, int)
0109: * @see java.lang.Integer#valueOf(java.lang.String)
0110: */
0111: public static final int MAX_RADIX = 36;
0112:
0113: /**
0114: * The constant value of this field is the smallest value of type
0115: * <code>char</code>.
0116: *
0117: * @since JDK1.0.2
0118: */
0119: public static final char MIN_VALUE = '\u0000';
0120:
0121: /**
0122: * The constant value of this field is the largest value of type
0123: * <code>char</code>.
0124: *
0125: * @since JDK1.0.2
0126: */
0127: public static final char MAX_VALUE = '\uffff';
0128:
0129: /**
0130: * The value of the Character.
0131: *
0132: * @serial
0133: */
0134: private char value;
0135:
0136: /**
0137: * Constructs a <code>Character</code> object and initializes it so that it
0138: * represents the primitive <code>value</code> argument.
0139: *
0140: * @param value value for the new <code>Character</code> object.
0141: */
0142: public ReusableChar(char value) {
0143: this .value = value;
0144: }
0145:
0146: /**
0147: * Sets the character value without having to recreate an object.
0148: *
0149: * @param ch
0150: */
0151: public void setCharValue(char ch) {
0152: value = ch;
0153: }
0154:
0155: /**
0156: * Determines if a character has a defined meaning in Unicode. A character
0157: * is defined if at least one of the following is true:
0158: * <p/>
0159: * <ul>
0160: * <li>
0161: * It has an entry in the Unicode attribute table.
0162: * </li>
0163: * <li>
0164: * Its value is in the range <code>
0165: * '\u3040' <= ch <= '\u9FA5'</code>.
0166: * </li>
0167: * <li>
0168: * Its value is in the range <code>
0169: * '\uF900' <= ch <= '\uFA2D'</code>.
0170: * </li>
0171: * </ul>
0172: *
0173: * @param ch the character to be tested
0174: * @return <code>true</code> if the character has a defined meaning in
0175: * Unicode; <code>false</code> otherwise.
0176: * @see java.lang.Character#isDigit(char)
0177: * @see java.lang.Character#isLetter(char)
0178: * @see java.lang.Character#isLetterOrDigit(char)
0179: * @see java.lang.Character#isLowerCase(char)
0180: * @see java.lang.Character#isTitleCase(char)
0181: * @see java.lang.Character#isUpperCase(char)
0182: */
0183: public static boolean isDefined(char ch) {
0184: return Character.isDefined(ch);
0185: }
0186:
0187: /**
0188: * Determines if the specified character is a digit. A character is
0189: * considered to be a digit if it is not in the range
0190: * <code>'\u2000' <= ch <= '\u2FFF'</code>
0191: * and its Unicode name contains the word "<code>DIGIT</code>". For a more
0192: * complete specification that encompasses all Unicode characters that are
0193: * defined as digits, see Gosling, Joy, and Steele, <i>The Java Language
0194: * Specification</i>.
0195: * <p/>
0196: * <p/>
0197: * These are the ranges of Unicode characters that are considered digits:
0198: * </p>
0199: *
0200: * @param ch the character to be tested.
0201: * @return <code>true</code> if the character is a digit;
0202: * <code>false</code> otherwise.
0203: * @see java.lang.Character#digit(char, int)
0204: * @see java.lang.Character#forDigit(int, int)
0205: */
0206: public static boolean isDigit(char ch) {
0207: return Character.isDigit(ch);
0208: }
0209:
0210: /**
0211: * Determines if the specified character is an ISO control character. A
0212: * character is considered to be an ISO control character if its code is
0213: * in the range \u0000 through \u001F or in the range \u007F
0214: * through \u009F.
0215: *
0216: * @param ch the character to be tested.
0217: * @return true if the character is an ISO control character; false
0218: * otherwise.
0219: * @see java.lang.Character#isSpaceChar(char)
0220: * @see java.lang.Character#isWhitespace(char)
0221: */
0222: public static boolean isISOControl(char ch) {
0223: return Character.isISOControl(ch);
0224: }
0225:
0226: /**
0227: * Determines if the specified character should be regarded as an ignorable
0228: * character in a Java identifier or a Unicode identifier. The following
0229: * Unicode characters are ignorable in a Java identifier or a Unicode
0230: * identifier:
0231: * <p/>
0232: * <table>
0233: * <tr><td>
0234: * 0x0000 through 0x0008,
0235: * </td><td>
0236: * ISO control characters that
0237: * </td></tr>
0238: * <tr><td>
0239: * 0x000E through 0x001B,
0240: * </td><td>
0241: * are not whitespace
0242: * </td></tr>
0243: * <tr><td>
0244: * and 0x007F through 0x009F
0245: * </td></tr>
0246: * <tr><td>
0247: * 0x200C through 0x200F
0248: * </td><td>
0249: * join controls
0250: * </td></tr>
0251: * <tr><td>
0252: * 0x200A through 0x200E
0253: * </td><td>
0254: * bidirectional controls
0255: * </td></tr>
0256: * <tr><td>
0257: * 0x206A through 0x206F
0258: * </td><td>
0259: * format controls
0260: * </td></tr>
0261: * <tr><td>
0262: * 0xFEFF
0263: * </td><td>
0264: * zero-width no-break space
0265: * </td></tr>
0266: * </table>
0267: *
0268: * @param ch the character to be tested.
0269: * @return true if the character may be part of a Unicode identifier; false
0270: * otherwise.
0271: * @see java.lang.Character#isJavaIdentifierPart(char)
0272: * @see java.lang.Character#isUnicodeIdentifierPart(char)
0273: */
0274: public static boolean isIdentifierIgnorable(char ch) {
0275: return Character.isIdentifierIgnorable(ch);
0276: }
0277:
0278: /**
0279: * Determines if the specified character may be part of a Java identifier
0280: * as other than the first character. A character may be part of a Java
0281: * identifier if and only if it is one of the following:
0282: * <p/>
0283: * <ul>
0284: * <li>
0285: * a letter
0286: * </li>
0287: * <li>
0288: * a currency symbol (such as "$")
0289: * </li>
0290: * <li>
0291: * a connecting punctuation character (such as "_").
0292: * </li>
0293: * <li>
0294: * a digit
0295: * </li>
0296: * <li>
0297: * a numeric letter (such as a Roman numeral character)
0298: * </li>
0299: * <li>
0300: * a combining mark
0301: * </li>
0302: * <li>
0303: * a non-spacing mark
0304: * </li>
0305: * <li>
0306: * an ignorable control character
0307: * </li>
0308: * </ul>
0309: *
0310: * @param ch the character to be tested.
0311: * @return true if the character may be part of a Unicode identifier; false
0312: * otherwise.
0313: * @see java.lang.Character#isIdentifierIgnorable(char)
0314: * @see java.lang.Character#isJavaIdentifierStart(char)
0315: * @see java.lang.Character#isLetterOrDigit(char)
0316: * @see java.lang.Character#isUnicodeIdentifierPart(char)
0317: */
0318: public static boolean isJavaIdentifierPart(char ch) {
0319: return Character.isJavaIdentifierPart(ch);
0320: }
0321:
0322: /**
0323: * Determines if the specified character is permissible as the first
0324: * character in a Java identifier. A character may start a Java identifier
0325: * if and only if it is one of the following:
0326: * <p/>
0327: * <ul>
0328: * <li>
0329: * a letter
0330: * </li>
0331: * <li>
0332: * a currency symbol (such as "$")
0333: * </li>
0334: * <li>
0335: * a connecting punctuation character (such as "_").
0336: * </li>
0337: * </ul>
0338: *
0339: * @param ch the character to be tested.
0340: * @return true if the character may start a Java identifier; false
0341: * otherwise.
0342: * @see java.lang.Character#isJavaIdentifierPart(char)
0343: * @see java.lang.Character#isLetter(char)
0344: * @see java.lang.Character#isUnicodeIdentifierStart(char)
0345: */
0346: public static boolean isJavaIdentifierStart(char ch) {
0347: return Character.isJavaIdentifierStart(ch);
0348: }
0349:
0350: /**
0351: * Determines if the specified character is a letter. For a more complete
0352: * specification that encompasses all Unicode characters, see Gosling,
0353: * Joy, and Steele, <i>The Java Language Specification</i>.
0354: * <p/>
0355: * <p/>
0356: * A character is considered to be a letter if and only if it is specified
0357: * to be a letter by the Unicode 2.0 standard (category "Lu", "Ll", "Lt",
0358: * "Lm", or "Lo" in the Unicode specification data file).
0359: * </p>
0360: * <p/>
0361: * <p/>
0362: * Note that most ideographic characters are considered to be letters
0363: * (category "Lo") for this purpose.
0364: * </p>
0365: * <p/>
0366: * <p/>
0367: * Note also that not all letters have case: many Unicode characters are
0368: * letters but are neither uppercase nor lowercase nor titlecase.
0369: * </p>
0370: *
0371: * @param ch the character to be tested.
0372: * @return <code>true</code> if the character is a letter;
0373: * <code>false</code> otherwise.
0374: * @see java.lang.Character#isDigit(char)
0375: * @see java.lang.Character#isJavaIdentifierStart(char)
0376: * @see java.lang.Character#isJavaLetter(char)
0377: * @see java.lang.Character#isJavaLetterOrDigit(char)
0378: * @see java.lang.Character#isLetterOrDigit(char)
0379: * @see java.lang.Character#isLowerCase(char)
0380: * @see java.lang.Character#isTitleCase(char)
0381: * @see java.lang.Character#isUnicodeIdentifierStart(char)
0382: * @see java.lang.Character#isUpperCase(char)
0383: */
0384: public static boolean isLetter(char ch) {
0385: return Character.isLetter(ch);
0386: }
0387:
0388: /**
0389: * Determines if the specified character is a letter or digit. For a more
0390: * complete specification that encompasses all Unicode characters, see
0391: * Gosling, Joy, and Steele, <i>The Java Language Specification</i>.
0392: * <p/>
0393: * <p/>
0394: * A character is considered to be a letter if and only if it is specified
0395: * to be a letter or a digit by the Unicode 2.0 standard (category "Lu",
0396: * "Ll", "Lt", "Lm", "Lo", or "Nd" in the Unicode specification data
0397: * file). In other words, isLetterOrDigit is true of a character if and
0398: * only if either isLetter is true of the character or isDigit is true of
0399: * the character.
0400: * </p>
0401: *
0402: * @param ch the character to be tested.
0403: * @return <code>true</code> if the character is a letter or digit;
0404: * <code>false</code> otherwise.
0405: * @see java.lang.Character#isDigit(char)
0406: * @see java.lang.Character#isJavaIdentifierPart(char)
0407: * @see java.lang.Character#isJavaLetter(char)
0408: * @see java.lang.Character#isJavaLetterOrDigit(char)
0409: * @see java.lang.Character#isLetter(char)
0410: * @see java.lang.Character#isUnicodeIdentifierPart(char)
0411: */
0412: public static boolean isLetterOrDigit(char ch) {
0413: return Character.isLetterOrDigit(ch);
0414: }
0415:
0416: /**
0417: * Determines if the specified character is a lowercase character. A
0418: * character is lowercase if it is not in the range
0419: * <code>'\u2000'</code> through <code>'\u2FFF'</code>, the
0420: * Unicode attribute table does not specify a mapping to lowercase for the
0421: * character, and at least one of the following is true:
0422: * <p/>
0423: * <ul>
0424: * <li>
0425: * The attribute table specifies a mapping to uppercase for the character.
0426: * </li>
0427: * <li>
0428: * The name for the character contains the words "<code>SMALL
0429: * LETTER</code>".
0430: * </li>
0431: * <li>
0432: * The name for the character contains the words "<code>SMALL
0433: * LIGATURE</code>".
0434: * </li>
0435: * </ul>
0436: * <p/>
0437: * <p/>
0438: * A character is considered to be lowercase if and only if it is specified
0439: * to be lowercase by the Unicode 2.0 standard (category "Ll" in the
0440: * Unicode specification data file).
0441: * </p>
0442: * <p/>
0443: * <p/>
0444: * Of the ISO-LATIN-1 characters (character codes 0x0000 through 0x00FF),
0445: * the following are lowercase:
0446: * </p>
0447: * <p/>
0448: * <p/>
0449: * <blockquote>
0450: * <pre>
0451: * 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
0452: * \u00DF \u00E0 \u00E1 \u00E2 \u00E3 \u00E4 \u00E5 \u00E6 \u00E7
0453: * \u00E8 \u00E9 \u00EA \u00EB \u00EC \u00ED \u00EE \u00EF \u00F0
0454: * \u00F1 \u00F2 \u00F3 \u00F4 \u00F5 \u00F6 \u00F8 \u00F9 \u00FA
0455: * \u00FB \u00FC \u00FD \u00FE \u00FF
0456: * </pre>
0457: * </blockquote>
0458: * </p>
0459: * <p/>
0460: * <p/>
0461: * Many other Unicode characters are lowercase, too.
0462: * </p>
0463: *
0464: * @param ch the character to be tested.
0465: * @return <code>true</code> if the character is lowercase;
0466: * <code>false</code> otherwise.
0467: * @see java.lang.Character#isLowerCase(char)
0468: * @see java.lang.Character#isTitleCase(char)
0469: * @see java.lang.Character#toLowerCase(char)
0470: */
0471: public static boolean isLowerCase(char ch) {
0472: return Character.isLowerCase(ch);
0473: }
0474:
0475: /**
0476: * Returns the Unicode numeric value of the character as a nonnegative
0477: * integer. If the character does not have a numeric value, then -1 is
0478: * returned. If the character has a numeric value that cannot be
0479: * represented as a nonnegative integer (for example, a fractional value),
0480: * then -2 is returned.
0481: *
0482: * @param ch the character to be converted.
0483: * @return the numeric value of the character, as a nonnegative int value;
0484: * -2 if the character has a numeric value that is not a
0485: * nonnegative integer; -1 if the character has no numeric value.
0486: * @see java.lang.Character#forDigit(int, int)
0487: * @see java.lang.Character#isDigit(char)
0488: * @since JDK1.1
0489: */
0490: public static int getNumericValue(char ch) {
0491: return Character.getNumericValue(ch);
0492: }
0493:
0494: /**
0495: * Determines if the specified character is a Unicode space character. A
0496: * character is considered to be a space character if and only if it is
0497: * specified to be a space character by the Unicode 2.0 standard (category
0498: * "Zs", "Zl, or "Zp" in the Unicode specification data file).
0499: *
0500: * @param ch the character to be tested.
0501: * @return true if the character is a space character; false otherwise.
0502: * @see java.lang.Character#isWhitespace(char)
0503: * @since JDK1.1
0504: */
0505: public static boolean isSpaceChar(char ch) {
0506: return Character.isSpaceChar(ch);
0507: }
0508:
0509: /**
0510: * Determines if the specified character is a titlecase character. A
0511: * character is considered to be titlecase if and only if it is specified
0512: * to be titlecase by the Unicode 2.0 standard (category "Lt" in the
0513: * Unicode specification data file).
0514: * <p/>
0515: * <p/>
0516: * The printed representations of four Unicode characters look like pairs
0517: * of Latin letters. For example, there is an uppercase letter that looks
0518: * like "LJ" and has a corresponding lowercase letter that looks like
0519: * "lj". A third form, which looks like "Lj", is the appropriate form to
0520: * use when rendering a word in lowercase with initial capitals, as for a
0521: * book title.
0522: * </p>
0523: * <p/>
0524: * <p/>
0525: * These are the Unicode characters for which this method returns
0526: * <code>true</code>:
0527: * <p/>
0528: * <ul>
0529: * <li>
0530: * <code>LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON</code>
0531: * </li>
0532: * <li>
0533: * <code>LATIN CAPITAL LETTER L WITH SMALL LETTER J</code>
0534: * </li>
0535: * <li>
0536: * <code>LATIN CAPITAL LETTER N WITH SMALL LETTER J</code>
0537: * </li>
0538: * <li>
0539: * <code>LATIN CAPITAL LETTER D WITH SMALL LETTER Z</code>
0540: * </li>
0541: * </ul>
0542: * </p>
0543: *
0544: * @param ch the character to be tested.
0545: * @return <code>true</code> if the character is titlecase;
0546: * <code>false</code> otherwise.
0547: * @see java.lang.Character#isLowerCase(char)
0548: * @see java.lang.Character#isUpperCase(char)
0549: * @see java.lang.Character#toTitleCase(char)
0550: * @since JDK1.0.2
0551: */
0552: public static boolean isTitleCase(char ch) {
0553: return Character.isTitleCase(ch);
0554: }
0555:
0556: /**
0557: * Returns a value indicating a character category.
0558: *
0559: * @param ch the character to be tested.
0560: * @return a value of type int, the character category.
0561: * @see java.lang.Character#COMBINING_SPACING_MARK
0562: * @see java.lang.Character#CONNECTOR_PUNCTUATION
0563: * @see java.lang.Character#CONTROL
0564: * @see java.lang.Character#CURRENCY_SYMBOL
0565: * @see java.lang.Character#DASH_PUNCTUATION
0566: * @see java.lang.Character#DECIMAL_DIGIT_NUMBER
0567: * @see java.lang.Character#ENCLOSING_MARK
0568: * @see java.lang.Character#END_PUNCTUATION
0569: * @see java.lang.Character#FORMAT
0570: * @see java.lang.Character#LETTER_NUMBER
0571: * @see java.lang.Character#LINE_SEPARATOR
0572: * @see java.lang.Character#LOWERCASE_LETTER
0573: * @see java.lang.Character#MATH_SYMBOL
0574: * @see java.lang.Character#MODIFIER_LETTER
0575: * @see java.lang.Character#MODIFIER_SYMBOL
0576: * @see java.lang.Character#NON_SPACING_MARK
0577: * @see java.lang.Character#OTHER_LETTER
0578: * @see java.lang.Character#OTHER_NUMBER
0579: * @see java.lang.Character#OTHER_PUNCTUATION
0580: * @see java.lang.Character#OTHER_SYMBOL
0581: * @see java.lang.Character#PARAGRAPH_SEPARATOR
0582: * @see java.lang.Character#PRIVATE_USE
0583: * @see java.lang.Character#SPACE_SEPARATOR
0584: * @see java.lang.Character#START_PUNCTUATION
0585: * @see java.lang.Character#SURROGATE
0586: * @see java.lang.Character#TITLECASE_LETTER
0587: * @see java.lang.Character#UNASSIGNED
0588: * @see java.lang.Character#UPPERCASE_LETTER
0589: */
0590: public static int getType(char ch) {
0591: return Character.getType(ch);
0592: }
0593:
0594: /**
0595: * Determines if the specified character may be part of a Unicode
0596: * identifier as other than the first character. A character may be part
0597: * of a Unicode identifier if and only if it is one of the following:
0598: * <p/>
0599: * <ul>
0600: * <li>
0601: * a letter
0602: * </li>
0603: * <li>
0604: * a connecting punctuation character (such as "_").
0605: * </li>
0606: * <li>
0607: * a digit
0608: * </li>
0609: * <li>
0610: * a numeric letter (such as a Roman numeral character)
0611: * </li>
0612: * <li>
0613: * a combining mark
0614: * </li>
0615: * <li>
0616: * a non-spacing mark
0617: * </li>
0618: * <li>
0619: * an ignorable control character
0620: * </li>
0621: * </ul>
0622: *
0623: * @param ch the character to be tested.
0624: * @return true if the character may be part of a Unicode identifier; false
0625: * otherwise.
0626: * @see java.lang.Character#isIdentifierIgnorable(char)
0627: * @see java.lang.Character#isJavaIdentifierPart(char)
0628: * @see java.lang.Character#isLetterOrDigit(char)
0629: * @see java.lang.Character#isUnicodeIdentifierStart(char)
0630: */
0631: public static boolean isUnicodeIdentifierPart(char ch) {
0632: return Character.isUnicodeIdentifierPart(ch);
0633: }
0634:
0635: /**
0636: * Determines if the specified character is permissible as the first
0637: * character in a Unicode identifier. A character may start a Unicode
0638: * identifier if and only if it is a letter.
0639: *
0640: * @param ch the character to be tested.
0641: * @return true if the character may start a Unicode identifier; false
0642: * otherwise.
0643: * @see java.lang.Character#isJavaIdentifierStart(char)
0644: * @see java.lang.Character#isLetter(char)
0645: * @see java.lang.Character#isUnicodeIdentifierPart(char)
0646: * @since JDK1.1
0647: */
0648: public static boolean isUnicodeIdentifierStart(char ch) {
0649: return Character.isUnicodeIdentifierStart(ch);
0650: }
0651:
0652: /**
0653: * Determines if the specified character is an uppercase character. A
0654: * character is uppercase if it is not in the range
0655: * <code>'\u2000'</code> through <code>'\u2FFF'</code>, the
0656: * Unicode attribute table does not specify a mapping to uppercase for the
0657: * character, and at least one of the following is true:
0658: * <p/>
0659: * <ul>
0660: * <li>
0661: * The attribute table specifies a mapping to lowercase for the character.
0662: * </li>
0663: * <li>
0664: * The name for the character contains the words "<code>CAPITAL
0665: * LETTER</code>".
0666: * </li>
0667: * <li>
0668: * The name for the character contains the words "<code>CAPITAL
0669: * LIGATURE</code>".
0670: * </li>
0671: * </ul>
0672: * <p/>
0673: * <p/>
0674: * Of the ISO-LATIN-1 characters (character codes 0x0000 through 0x00FF),
0675: * the following are uppercase:
0676: * </p>
0677: * <p/>
0678: * <p/>
0679: * <blockquote>
0680: * <pre>
0681: * 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
0682: * \u00C0 \u00C1 \u00C2 \u00C3 \u00C4 \u00C5 \u00C6 \u00C7
0683: * \u00C8 \u00C9 \u00CA \u00CB \u00CC \u00CD \u00CE \u00CF \u00D0
0684: * \u00D1 \u00D2 \u00D3 \u00D4 \u00D5 \u00D6 \u00D8 \u00D9 \u00DA
0685: * \u00DB \u00DC \u00DD \u00DE
0686: * </pre>
0687: * </blockquote>
0688: * </p>
0689: * <p/>
0690: * <p/>
0691: * Many other Unicode characters are uppercase, too.
0692: * </p>
0693: *
0694: * @param ch the character to be tested.
0695: * @return <code>true</code> if the character is uppercase;
0696: * <code>false</code> otherwise.
0697: * @see java.lang.Character#isLowerCase(char)
0698: * @see java.lang.Character#isTitleCase(char)
0699: * @see java.lang.Character#toUpperCase(char)
0700: * @since 1.0
0701: */
0702: public static boolean isUpperCase(char ch) {
0703: return Character.isUpperCase(ch);
0704: }
0705:
0706: /**
0707: * Determines if the specified character is white space according to Java.
0708: * A character is considered to be a Java whitespace character if and only
0709: * if it satisfies one of the following criteria:
0710: * <p/>
0711: * <ul>
0712: * <li>
0713: * It is a Unicode space separator (category "Zs"), but is not a no-break
0714: * space (\u00A0 or \uFEFF).
0715: * </li>
0716: * <li>
0717: * It is a Unicode line separator (category "Zl").
0718: * </li>
0719: * <li>
0720: * It is a Unicode paragraph separator (category "Zp").
0721: * </li>
0722: * <li>
0723: * It is \u0009, HORIZONTAL TABULATION.
0724: * </li>
0725: * <li>
0726: * It is \u000A, LINE FEED.
0727: * </li>
0728: * <li>
0729: * It is \u000B, VERTICAL TABULATION.
0730: * </li>
0731: * <li>
0732: * It is \u000C, FORM FEED.
0733: * </li>
0734: * <li>
0735: * It is \u000D, CARRIAGE RETURN.
0736: * </li>
0737: * <li>
0738: * It is \u001C, FILE SEPARATOR.
0739: * </li>
0740: * <li>
0741: * It is \u001D, GROUP SEPARATOR.
0742: * </li>
0743: * <li>
0744: * It is \u001E, RECORD SEPARATOR.
0745: * </li>
0746: * <li>
0747: * It is \u001F, UNIT SEPARATOR.
0748: * </li>
0749: * </ul>
0750: *
0751: * @param ch the character to be tested.
0752: * @return true if the character is a Java whitespace character; false
0753: * otherwise.
0754: * @see java.lang.Character#isSpaceChar(char)
0755: */
0756: public static boolean isWhitespace(char ch) {
0757: return Character.isWhitespace(ch);
0758: }
0759:
0760: /**
0761: * Returns the value of this Character object.
0762: *
0763: * @return the primitive <code>char</code> value represented by this
0764: * object.
0765: */
0766: public char charValue() {
0767: return value;
0768: }
0769:
0770: /**
0771: * Returns the numeric value of the character <code>ch</code> in the
0772: * specified radix.
0773: * <p/>
0774: * <p/>
0775: * If the radix is not in the range <code>MIN_RADIX</code> <=
0776: * <code>radix</code> <= <code>MAX_RADIX</code> or if the value of
0777: * <code>ch</code> is not a valid digit in the specified radix,
0778: * <code>-1</code> is returned. A character is a valid digit if at least
0779: * one of the following is true:
0780: * <p/>
0781: * <ul>
0782: * <li>
0783: * The method <code>isDigit</code> is true of the character and the Unicode
0784: * decimal digit value of the character (or its single-character
0785: * decomposition) is less than the specified radix. In this case the
0786: * decimal digit value is returned.
0787: * </li>
0788: * <li>
0789: * The character is one of the uppercase Latin letters <code>'A'</code>
0790: * through <code>'Z'</code> and its code is less than <code>radix +
0791: * 'A' - 10</code>. In this case, <code>ch -
0792: * 'A' + 10</code> is returned.
0793: * </li>
0794: * <li>
0795: * The character is one of the lowercase Latin letters <code>'a'</code>
0796: * through <code>'z'</code> and its code is less than <code>radix +
0797: * 'a' - 10</code>. In this case, <code>ch -
0798: * 'a' + 10</code> is returned.
0799: * </li>
0800: * </ul>
0801: * </p>
0802: *
0803: * @param ch the character to be converted.
0804: * @param radix the radix.
0805: * @return the numeric value represented by the character in the specified
0806: * radix.
0807: * @see java.lang.Character#forDigit(int, int)
0808: * @see java.lang.Character#isDigit(char)
0809: */
0810: public static int digit(char ch, int radix) {
0811: return Character.digit(ch, radix);
0812: }
0813:
0814: /**
0815: * Compares this object against the specified object. The result is
0816: * <code>true</code> if and only if the argument is not <code>null</code>
0817: * and is a <code>Character</code> object that represents the same
0818: * <code>char</code> value as this object.
0819: *
0820: * @param obj the object to compare with.
0821: * @return <code>true</code> if the objects are the same;
0822: * <code>false</code> otherwise.
0823: */
0824: public boolean equals(Object obj) {
0825: if (obj instanceof ReusableChar) {
0826: return value == ((ReusableChar) obj).charValue();
0827: }
0828:
0829: return false;
0830: }
0831:
0832: /**
0833: * Determines the character representation for a specific digit in the
0834: * specified radix. If the value of <code>radix</code> is not a valid
0835: * radix, or the value of <code>digit</code> is not a valid digit in the
0836: * specified radix, the null character (<code>'\u0000'</code>) is
0837: * returned.
0838: * <p/>
0839: * <p/>
0840: * The <code>radix</code> argument is valid if it is greater than or equal
0841: * to <code>MIN_RADIX</code> and less than or equal to
0842: * <code>MAX_RADIX</code>. The <code>digit</code> argument is valid if
0843: * <code>0 <= digit <= radix</code>.
0844: * </p>
0845: * <p/>
0846: * <p/>
0847: * If the digit is less than 10, then <code>'0' + digit</code> is
0848: * returned. Otherwise, the value <code>'a' +
0849: * digit - 10</code> is returned.
0850: * </p>
0851: *
0852: * @param digit the number to convert to a character.
0853: * @param radix the radix.
0854: * @return the <code>char</code> representation of the specified digit in
0855: * the specified radix.
0856: * @see java.lang.Character#MIN_RADIX
0857: * @see java.lang.Character#MAX_RADIX
0858: * @see java.lang.Character#digit(char, int)
0859: */
0860: public static char forDigit(int digit, int radix) {
0861: return Character.forDigit(digit, radix);
0862: }
0863:
0864: /**
0865: * Returns a hash code for this Character.
0866: *
0867: * @return a hash code value for this object.
0868: */
0869: public int hashCode() {
0870: return (int) value;
0871: }
0872:
0873: /**
0874: * The given character is mapped to its lowercase equivalent; if the
0875: * character has no lowercase equivalent, the character itself is
0876: * returned.
0877: * <p/>
0878: * <p/>
0879: * A character has a lowercase equivalent if and only if a lowercase
0880: * mapping is specified for the character in the Unicode attribute table.
0881: * </p>
0882: * <p/>
0883: * <p/>
0884: * Note that some Unicode characters in the range <code>'\u2000'</code>
0885: * to <code>'\u2FFF'</code> have lowercase mappings; this method does
0886: * map such characters to their lowercase equivalents even though the
0887: * method <code>isUpperCase</code> does not return <code>true</code> for
0888: * such characters.
0889: * </p>
0890: *
0891: * @param ch the character to be converted.
0892: * @return the lowercase equivalent of the character, if any; otherwise the
0893: * character itself.
0894: * @see java.lang.Character#isLowerCase(char)
0895: * @see java.lang.Character#isUpperCase(char)
0896: * @see java.lang.Character#toTitleCase(char)
0897: * @see java.lang.Character#toUpperCase(char)
0898: */
0899: public static char toLowerCase(char ch) {
0900: return Character.toLowerCase(ch);
0901: }
0902:
0903: /**
0904: * Returns a String object representing this character's value. Converts
0905: * this <code>Character</code> object to a string. The result is a string
0906: * whose length is <code>1</code>. The string's sole component is the
0907: * primitive <code>char</code> value represented by this object.
0908: *
0909: * @return a string representation of this object.
0910: */
0911: public String toString() {
0912: char[] buf = { value };
0913:
0914: return String.valueOf(buf);
0915: }
0916:
0917: /**
0918: * Converts the character argument to titlecase. A character has a
0919: * titlecase equivalent if and only if a titlecase mapping is specified
0920: * for the character in the Unicode attribute table.
0921: * <p/>
0922: * <p/>
0923: * Note that some Unicode characters in the range <code>'\u2000'</code>
0924: * through <code>'\u2FFF'</code> have titlecase mappings; this method
0925: * does map such characters to their titlecase equivalents even though the
0926: * method <code>isTitleCase</code> does not return <code>true</code> for
0927: * such characters.
0928: * </p>
0929: * <p/>
0930: * <p/>
0931: * There are only four Unicode characters that are truly titlecase forms
0932: * that are distinct from uppercase forms. As a rule, if a character has
0933: * no true titlecase equivalent but does have an uppercase mapping, then
0934: * the Unicode 2.0 attribute table specifies a titlecase mapping that is
0935: * the same as the uppercase mapping.
0936: * </p>
0937: *
0938: * @param ch the character to be converted.
0939: * @return the titlecase equivalent of the character, if any; otherwise the
0940: * character itself.
0941: * @see java.lang.Character#isTitleCase(char)
0942: * @see java.lang.Character#toLowerCase(char)
0943: * @see java.lang.Character#toUpperCase(char)
0944: */
0945: public static char toTitleCase(char ch) {
0946: return Character.toTitleCase(ch);
0947: }
0948:
0949: /**
0950: * Converts the character argument to uppercase. A character has an
0951: * uppercase equivalent if and only if an uppercase mapping is specified
0952: * for the character in the Unicode attribute table.
0953: * <p/>
0954: * <p/>
0955: * Note that some Unicode characters in the range <code>'\u2000'</code>
0956: * to <code>'\u2000FFF'</code> have uppercase mappings; this method
0957: * does map such characters to their titlecase equivalents even though the
0958: * method <code>isLowerCase</code> does not return <code>true</code> for
0959: * such characters.
0960: * </p>
0961: *
0962: * @param ch the character to be converted.
0963: * @return the uppercase equivalent of the character, if any; otherwise the
0964: * character itself.
0965: * @see java.lang.Character#isLowerCase(char)
0966: * @see java.lang.Character#isUpperCase(char)
0967: * @see java.lang.Character#toLowerCase(char)
0968: * @see java.lang.Character#toTitleCase(char)
0969: */
0970: public static char toUpperCase(char ch) {
0971: return Character.toUpperCase(ch);
0972: }
0973:
0974: /**
0975: * Compares two Characters numerically.
0976: *
0977: * @param anotherCharacter the <code>Character</code> to be compared.
0978: * @return the value <code>0</code> if the argument Character is equal to
0979: * this Character; a value less than <code>0</code> if this
0980: * Character is numerically less than the Character argument; and
0981: * a value greater than <code>0</code> if this Character is
0982: * numerically greater than the Character argument (unsigned
0983: * comparison). Note that this is strictly a numerical
0984: * comparison; it is not locale-dependent.
0985: */
0986: public int compareTo(ReusableChar anotherCharacter) {
0987: return this .value - anotherCharacter.value;
0988: }
0989:
0990: /**
0991: * Compares this Character to another Object. If the Object is a
0992: * Character, this function behaves like
0993: * <code>compareTo(ReusableChar)</code>. Otherwise, it throws a
0994: * <code>ClassCastException</code> (as Characters are comparable only to
0995: * other Characters).
0996: *
0997: * @param o the <code>Object</code> to be compared.
0998: * @return the value <code>0</code> if the argument is a Character
0999: * 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 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 ois)
1018: throws ClassNotFoundException, java.io.IOException {
1019: value = ois.readChar();
1020: }
1021:
1022: private void writeObject(ObjectOutputStream oos)
1023: throws java.io.IOException {
1024: oos.writeChar((int) value);
1025: }
1026: }
|