001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package java.lang;
028:
029: import com.sun.cldc.i18n.uclc.*;
030:
031: /**
032: * The Character class wraps a value of the primitive type <code>char</code>
033: * in an object. An object of type <code>Character</code> contains a
034: * single field whose type is <code>char</code>.
035: * <p>
036: * In addition, this class provides several methods for determining
037: * the type of a character and converting characters from uppercase
038: * to lowercase and vice versa.
039: * <p>
040: * Character information is based on the Unicode Standard, version 3.0.
041: * However, in order to reduce footprint, by default the character
042: * property and case conversion operations in CLDC are available
043: * only for the ISO Latin-1 range of characters. Other Unicode
044: * character blocks can be supported as necessary.
045: * <p>
046: *
047: * @version 12/17/01 (CLDC 1.1)
048: * @since JDK1.0, CLDC 1.0
049: */
050:
051: /*
052: * Implementation note:
053: *
054: * The character property and case conversion facilities
055: * provided by this CLDC implementation can be
056: * extended by overriding an implementation class called
057: * DefaultCaseConverter. Refer to the end of this file
058: * for details.
059: */
060:
061: public final class Character extends Object {
062:
063: /**
064: * The minimum radix available for conversion to and from Strings.
065: *
066: * @see java.lang.Integer#toString(int, int)
067: * @see java.lang.Integer#valueOf(java.lang.String)
068: */
069: public static final int MIN_RADIX = 2;
070:
071: /**
072: * The maximum radix available for conversion to and from Strings.
073: *
074: * @see java.lang.Integer#toString(int, int)
075: * @see java.lang.Integer#valueOf(java.lang.String)
076: */
077: public static final int MAX_RADIX = 36;
078:
079: /**
080: * The constant value of this field is the smallest value of type
081: * <code>char</code>.
082: *
083: * @since JDK1.0.2
084: */
085: public static final char MIN_VALUE = '\u0000';
086:
087: /**
088: * The constant value of this field is the largest value of type
089: * <code>char</code>.
090: *
091: * @since JDK1.0.2
092: */
093: public static final char MAX_VALUE = '\uffff';
094:
095: /**
096: * The value of the Character.
097: */
098: private char value;
099:
100: /**
101: * Constructs a <code>Character</code> object and initializes it so
102: * that it represents the primitive <code>value</code> argument.
103: *
104: * @param value value for the new <code>Character</code> object.
105: */
106: public Character(char value) {
107: this .value = value;
108: }
109:
110: /**
111: * Returns the value of this Character object.
112: * @return the primitive <code>char</code> value represented by
113: * this object.
114: */
115: public char charValue() {
116: return value;
117: }
118:
119: /**
120: * Returns a hash code for this Character.
121: * @return a hash code value for this object.
122: */
123: public int hashCode() {
124: return (int) value;
125: }
126:
127: /**
128: * Compares this object against the specified object.
129: * The result is <code>true</code> if and only if the argument is not
130: * <code>null</code> and is a <code>Character</code> object that
131: * represents the same <code>char</code> value as this object.
132: *
133: * @param obj the object to compare with.
134: * @return <code>true</code> if the objects are the same;
135: * <code>false</code> otherwise.
136: */
137: public boolean equals(Object obj) {
138: if (obj instanceof Character) {
139: return value == ((Character) obj).charValue();
140: }
141: return false;
142: }
143:
144: /**
145: * Returns a String object representing this character's value.
146: * Converts this <code>Character</code> object to a string. The
147: * result is a string whose length is <code>1</code>. The string's
148: * sole component is the primitive <code>char</code> value represented
149: * by this object.
150: *
151: * @return a string representation of this object.
152: */
153: public String toString() {
154: char buf[] = { value };
155: return String.valueOf(buf);
156: }
157:
158: /**
159: * Determines if the specified character is a lowercase character.
160: * <p>
161: * Note that by default CLDC only supports
162: * the ISO Latin-1 range of characters.
163: * <p>
164: * Of the ISO Latin-1 characters (character codes 0x0000 through 0x00FF),
165: * the following are lowercase:
166: * <p>
167: * 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
168: * \u00DF \u00E0 \u00E1 \u00E2 \u00E3 \u00E4 \u00E5 \u00E6 \u00E7
169: * \u00E8 \u00E9 \u00EA \u00EB \u00EC \u00ED \u00EE \u00EF \u00F0
170: * \u00F1 \u00F2 \u00F3 \u00F4 \u00F5 \u00F6 \u00F8 \u00F9 \u00FA
171: * \u00FB \u00FC \u00FD \u00FE \u00FF
172: *
173: * @param ch the character to be tested.
174: * @return <code>true</code> if the character is lowercase;
175: * <code>false</code> otherwise.
176: * @since JDK1.0
177: */
178: public static boolean isLowerCase(char ch) {
179: return DefaultCaseConverter.isLowerCase(ch);
180: }
181:
182: /**
183: * Determines if the specified character is an uppercase character.
184: * <p>
185: * Note that by default CLDC only supports
186: * the ISO Latin-1 range of characters.
187: * <p>
188: * Of the ISO Latin-1 characters (character codes 0x0000 through 0x00FF),
189: * the following are uppercase:
190: * <p>
191: * 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
192: * \u00C0 \u00C1 \u00C2 \u00C3 \u00C4 \u00C5 \u00C6 \u00C7
193: * \u00C8 \u00C9 \u00CA \u00CB \u00CC \u00CD \u00CE \u00CF \u00D0
194: * \u00D1 \u00D2 \u00D3 \u00D4 \u00D5 \u00D6 \u00D8 \u00D9 \u00DA
195: * \u00DB \u00DC \u00DD \u00DE
196: *
197: * @param ch the character to be tested.
198: * @return <code>true</code> if the character is uppercase;
199: * <code>false</code> otherwise.
200: * @see java.lang.Character#isLowerCase(char)
201: * @see java.lang.Character#toUpperCase(char)
202: * @since 1.0
203: */
204: public static boolean isUpperCase(char ch) {
205: return DefaultCaseConverter.isUpperCase(ch);
206: }
207:
208: /**
209: * Determines if the specified character is a digit.
210: *
211: * @param ch the character to be tested.
212: * @return <code>true</code> if the character is a digit;
213: * <code>false</code> otherwise.
214: * @since JDK1.0
215: */
216: public static boolean isDigit(char ch) {
217: return DefaultCaseConverter.isDigit(ch);
218: }
219:
220: /**
221: * The given character is mapped to its lowercase equivalent; if the
222: * character has no lowercase equivalent, the character itself is
223: * returned.
224: * <p>
225: * Note that by default CLDC only supports
226: * the ISO Latin-1 range of characters.
227: *
228: * @param ch the character to be converted.
229: * @return the lowercase equivalent of the character, if any;
230: * otherwise the character itself.
231: * @see java.lang.Character#isLowerCase(char)
232: * @see java.lang.Character#isUpperCase(char)
233: * @see java.lang.Character#toUpperCase(char)
234: * @since JDK1.0
235: */
236: public static char toLowerCase(char ch) {
237: return DefaultCaseConverter.toLowerCase(ch);
238: }
239:
240: /**
241: * Converts the character argument to uppercase; if the
242: * character has no uppercase equivalent, the character itself is
243: * returned.
244: * <p>
245: * Note that by default CLDC only supports
246: * the ISO Latin-1 range of characters.
247: *
248: * @param ch the character to be converted.
249: * @return the uppercase equivalent of the character, if any;
250: * otherwise the character itself.
251: * @see java.lang.Character#isLowerCase(char)
252: * @see java.lang.Character#isUpperCase(char)
253: * @see java.lang.Character#toLowerCase(char)
254: * @since JDK1.0
255: */
256: public static char toUpperCase(char ch) {
257: return DefaultCaseConverter.toUpperCase(ch);
258: }
259:
260: /**
261: * Returns the numeric value of the character <code>ch</code> in the
262: * specified radix.
263: *
264: * @param ch the character to be converted.
265: * @param radix the radix.
266: * @return the numeric value represented by the character in the
267: * specified radix.
268: * @see java.lang.Character#isDigit(char)
269: * @since JDK1.0
270: */
271: public static int digit(char ch, int radix) {
272: return DefaultCaseConverter.digit(ch, radix);
273: }
274: }
|