diff --git a/collects/profj/libs/java/lang/Byte.java b/collects/profj/libs/java/lang/Byte.java new file mode 100644 index 0000000000..0434665284 --- /dev/null +++ b/collects/profj/libs/java/lang/Byte.java @@ -0,0 +1,357 @@ +/* Byte.java -- object wrapper for byte + Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * Instances of class Byte represent primitive byte + * values. + * + * Additionally, this class provides various helper functions and variables + * useful to bytes. + * + * @author Paul Fisher + * @author John Keiser + * @author Per Bothner + * @author Eric Blake + * @since 1.1 + * @status updated to 1.4 + */ +public final class Byte extends Number implements Comparable +{ + /** + * Compatible with JDK 1.1+. + */ + private static final long serialVersionUID = -7183698231559129828L; + + /** + * The minimum value a byte can represent is -128 (or + * -27). + */ + public static final byte MIN_VALUE = -128; + + /** + * The maximum value a byte can represent is 127 (or + * 27 - 1). + */ + public static final byte MAX_VALUE = 127; + + /** + * The primitive type byte is represented by this + * Class object. + */ + //public static final Class TYPE = VMClassLoader.getPrimitiveClass('B'); + + /** + * The immutable value of this Byte. + * + * @serial the wrapped byte + */ + private final byte value; + + /** + * Create a Byte object representing the value of the + * byte argument. + * + * @param value the value to use + */ + public Byte(byte value) + { + this.value = value; + } + + /** + * Create a Byte object representing the value specified + * by the String argument + * + * @param s the string to convert + * @throws NumberFormatException if the String does not contain a byte + * @see #valueOf(String) + */ + public Byte(String s) + { + value = parseByte(s, 10); + } + + /** + * Converts the byte to a String and assumes + * a radix of 10. + * + * @param b the byte to convert to String + * @return the String representation of the argument + */ + public static String toString(byte b) + { + return String.valueOf((int)b); + } + + /** + * Converts the specified String into a byte. + * This function assumes a radix of 10. + * + * @param s the String to convert + * @return the byte value of s + * @throws NumberFormatException if s cannot be parsed as a + * byte + * @see #parseByte(String) + */ + public static byte parseByte(String s) + { + return parseByte(s, 10); + } + + /** + * Converts the specified String into an int + * using the specified radix (base). The string must not be null + * or empty. It may begin with an optional '-', which will negate the answer, + * provided that there are also valid digits. Each digit is parsed as if by + * Character.digit(d, radix), and must be in the range + * 0 to radix - 1. Finally, the result must be + * within MIN_VALUE to MAX_VALUE, inclusive. + * Unlike Double.parseDouble, you may not have a leading '+'. + * + * @param s the String to convert + * @param radix the radix (base) to use in the conversion + * @return the String argument converted to byte + * @throws NumberFormatException if s cannot be parsed as a + * byte + */ + public static byte parseByte(String s, int radix) + { + int i = Integer.parseInt(s, radix, false); + if ((byte) i != i) + throw new NumberFormatException(); + return (byte) i; + } + + /** + * Creates a new Byte object using the String + * and specified radix (base). + * + * @param s the String to convert + * @param radix the radix (base) to convert with + * @return the new Byte + * @throws NumberFormatException if s cannot be parsed as a + * byte + * @see #parseByte(String, int) + */ + public static Byte valueOf(String s, int radix) + { + return new Byte(parseByte(s, radix)); + } + + /** + * Creates a new Byte object using the String, + * assuming a radix of 10. + * + * @param s the String to convert + * @return the new Byte + * @throws NumberFormatException if s cannot be parsed as a + * byte + * @see #Byte(String) + * @see #parseByte(String) + */ + public static Byte valueOf(String s) + { + return new Byte(parseByte(s, 10)); + } + + /** + * Convert the specified String into a Byte. + * The String may represent decimal, hexadecimal, or + * octal numbers. + * + *

The extended BNF grammar is as follows:
+ *

+   * DecodableString:
+   *      ( [ - ] DecimalNumber )
+   *    | ( [ - ] ( 0x | 0X
+   *              | # ) { HexDigit }+ )
+   *    | ( [ - ] 0 { OctalDigit } )
+   * DecimalNumber:
+   *        DecimalDigit except '0' { DecimalDigit }
+   * DecimalDigit:
+   *        Character.digit(d, 10) has value 0 to 9
+   * OctalDigit:
+   *        Character.digit(d, 8) has value 0 to 7
+   * DecimalDigit:
+   *        Character.digit(d, 16) has value 0 to 15
+   * 
+ * Finally, the value must be in the range MIN_VALUE to + * MAX_VALUE, or an exception is thrown. + * + * @param s the String to interpret + * @return the value of the String as a Byte + * @throws NumberFormatException if s cannot be parsed as a + * byte + * @throws NullPointerException if s is null + * @see Integer#decode(String) + */ + public static Byte decode(String s) + { + int i = Integer.parseInt(s, 10, true); + if ((byte) i != i) + throw new NumberFormatException(); + return new Byte((byte) i); + } + + /** + * Return the value of this Byte. + * + * @return the byte value + */ + public byte byteValue() + { + return value; + } + + /** + * Return the value of this Byte as a short. + * + * @return the short value + */ + public short shortValue() + { + return value; + } + + /** + * Return the value of this Byte as an int. + * + * @return the int value + */ + public int intValue() + { + return value; + } + + /** + * Return the value of this Byte as a long. + * + * @return the long value + */ + public long longValue() + { + return value; + } + + /** + * Return the value of this Byte as a float. + * + * @return the float value + */ + public float floatValue() + { + return value; + } + + /** + * Return the value of this Byte as a double. + * + * @return the double value + */ + public double doubleValue() + { + return value; + } + + /** + * Converts the Byte value to a String and + * assumes a radix of 10. + * + * @return the String representation of this Byte + * @see Integer#toString() + */ + public String toString() + { + return String.valueOf((int)value); + } + + /** + * Return a hashcode representing this Object. Byte's hash + * code is simply its value. + * + * @return this Object's hash code + */ + public int hashCode() + { + return value; + } + + /** + * Returns true if obj is an instance of + * Byte and represents the same byte value. + * + * @param obj the object to compare + * @return whether these Objects are semantically equal + */ + public boolean equals(Object obj) + { + return obj instanceof Byte && value == ((Byte) obj).value; + } + + /** + * Compare two Bytes numerically by comparing their byte values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param b the Byte to compare + * @return the comparison + * @since 1.2 + */ + public int compareTo(Byte b) + { + return value - b.value; + } + + /** + * Behaves like compareTo(Byte) unless the Object + * is not a Byte. + * + * @param o the object to compare + * @return the comparison + * @throws ClassCastException if the argument is not a Byte + * @see #compareTo(Byte) + * @see Comparable + * @since 1.2 + */ + public int compareTo(Object o) + { + return compareTo((Byte) o); + } +} diff --git a/collects/profj/libs/java/lang/Character.djava b/collects/profj/libs/java/lang/Character.djava new file mode 100644 index 0000000000..953a03e7a0 --- /dev/null +++ b/collects/profj/libs/java/lang/Character.djava @@ -0,0 +1,2282 @@ +/* java.lang.Character -- Wrapper class for char, and Unicode subsets + Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* Modified so that Character doesn't require proper static class support + or unicode support +*/ + + +package java.lang; + +import java.io.Serializable; + +import scheme.mz; + +//import gnu.java.lang.CharData; + +/** + * Wrapper class for the primitive char data type. In addition, this class + * allows one to retrieve property information and perform transformations + * on the 57,707 defined characters in the Unicode Standard, Version 3.0.0. + * java.lang.Character is designed to be very dynamic, and as such, it + * retrieves information on the Unicode character set from a separate + * database, gnu.java.lang.CharData, which can be easily upgraded. + * + *

For predicates, boundaries are used to describe + * the set of characters for which the method will return true. + * This syntax uses fairly normal regular expression notation. + * See 5.13 of the Unicode Standard, Version 3.0, for the + * boundary specification. + * + *

See http://www.unicode.org + * for more information on the Unicode Standard. + * + * @author Tom Tromey + * @author Paul N. Fisher + * @author Jochen Hoenicke + * @author Eric Blake + * @see CharData + * @since 1.0 + * @status updated to 1.4 + */ +public final class Character implements Serializable, Comparable +{ + /** + * A subset of Unicode blocks. + * + * @author Paul N. Fisher + * @author Eric Blake + * @since 1.2 + */ + //public static class Subset + //{ + /** The name of the subset. */ + //private final String name; + + /** + * Construct a new subset of characters. + * + * @param name the name of the subset + * @throws NullPointerException if name is null + */ + //protected Subset(String name) + //{ + // Note that name.toString() is name, unless name was null. + //this.name = name.toString(); + //} + + /** + * Compares two Subsets for equality. This is final, and + * restricts the comparison on the == operator, so it returns + * true only for the same object. + * + * @param o the object to compare + * @return true if o is this + */ + //public final boolean equals(Object o) + //{ + // return o == this; + //} + + /** + * Makes the original hashCode of Object final, to be consistent with + * equals. + * + * @return the hash code for this object + */ + //public final int hashCode() + //{ + // return super.hashCode(); + //} + + /** + * Returns the name of the subset. + * + * @return the name + */ + //public final String toString() + //{ + // return name; + //} + //} // class Subset + + /** + * A family of character subsets in the Unicode specification. A character + * is in at most one of these blocks. + * + * This inner class was generated automatically from + * doc/unicode/Block-3.txt, by some perl scripts. + * This Unicode definition file can be found on the + * http://www.unicode.org website. + * JDK 1.4 uses Unicode version 3.0.0. + * + * @author scripts/unicode-blocks.pl (written by Eric Blake) + * @since 1.2 + */ + //public static final class UnicodeBlock extends Subset + //{ + /** The start of the subset. */ + //private final char start; + + /** The end of the subset. */ + //private final char end; + + /** + * Constructor for strictly defined blocks. + * + * @param start the start character of the range + * @param end the end character of the range + * @param name the block name + */ + //private UnicodeBlock(char start, char end, String name) + //{ + // super(name); + // this.start = start; + // this.end = end; + //} + + /** + * Returns the Unicode character block which a character belongs to. + * + * @param ch the character to look up + * @return the set it belongs to, or null if it is not in one + */ + //public static UnicodeBlock of(char ch) + //{ + // Special case, since SPECIALS contains two ranges. + //if (ch == '\uFEFF') + //return SPECIALS; + // Simple binary search for the correct block. + //int low = 0; + //int hi = sets.length - 1; + //while (low <= hi) + // { + // int mid = (low + hi) >> 1; + // UnicodeBlock b = sets[mid]; + // if (ch < b.start) + // hi = mid - 1; + // else if (ch > b.end) + // low = mid + 1; + // else + // return b; + // } + //return null; + //} + + /** + * Basic Latin. + * '\u0000' - '\u007F'. + */ + //public final static UnicodeBlock BASIC_LATIN + // = new UnicodeBlock('\u0000', '\u007F', + // "BASIC_LATIN"); + + /** + * Latin-1 Supplement. + * '\u0080' - '\u00FF'. + */ + //public final static UnicodeBlock LATIN_1_SUPPLEMENT + // = new UnicodeBlock('\u0080', '\u00FF', + // "LATIN_1_SUPPLEMENT"); + + /** + * Latin Extended-A. + * '\u0100' - '\u017F'. + */ + //public final static UnicodeBlock LATIN_EXTENDED_A + // = new UnicodeBlock('\u0100', '\u017F', + // "LATIN_EXTENDED_A"); + + /** + * Latin Extended-B. + * '\u0180' - '\u024F'. + */ + //public final static UnicodeBlock LATIN_EXTENDED_B + // = new UnicodeBlock('\u0180', '\u024F', + // "LATIN_EXTENDED_B"); + + /** + * IPA Extensions. + * '\u0250' - '\u02AF'. + */ + //public final static UnicodeBlock IPA_EXTENSIONS + // = new UnicodeBlock('\u0250', '\u02AF', + // "IPA_EXTENSIONS"); + + /** + * Spacing Modifier Letters. + * '\u02B0' - '\u02FF'. + */ + //public final static UnicodeBlock SPACING_MODIFIER_LETTERS + // = new UnicodeBlock('\u02B0', '\u02FF', + // "SPACING_MODIFIER_LETTERS"); + + /** + * Combining Diacritical Marks. + * '\u0300' - '\u036F'. + */ + //public final static UnicodeBlock COMBINING_DIACRITICAL_MARKS + // = new UnicodeBlock('\u0300', '\u036F', + // "COMBINING_DIACRITICAL_MARKS"); + + /** + * Greek. + * '\u0370' - '\u03FF'. + */ + //public final static UnicodeBlock GREEK + // = new UnicodeBlock('\u0370', '\u03FF', + // "GREEK"); + + /** + * Cyrillic. + * '\u0400' - '\u04FF'. + */ + //public final static UnicodeBlock CYRILLIC + // = new UnicodeBlock('\u0400', '\u04FF', + // "CYRILLIC"); + + /** + * Armenian. + * '\u0530' - '\u058F'. + */ + //public final static UnicodeBlock ARMENIAN + // = new UnicodeBlock('\u0530', '\u058F', + // "ARMENIAN"); + + /** + * Hebrew. + * '\u0590' - '\u05FF'. + */ + //public final static UnicodeBlock HEBREW + // = new UnicodeBlock('\u0590', '\u05FF', + // "HEBREW"); + + /** + * Arabic. + * '\u0600' - '\u06FF'. + */ + //public final static UnicodeBlock ARABIC + // = new UnicodeBlock('\u0600', '\u06FF', + // "ARABIC"); + + /** + * Syriac. + * '\u0700' - '\u074F'. + * @since 1.4 + */ + //public final static UnicodeBlock SYRIAC + // = new UnicodeBlock('\u0700', '\u074F', + // "SYRIAC"); + + /** + * Thaana. + * '\u0780' - '\u07BF'. + * @since 1.4 + */ + //public final static UnicodeBlock THAANA + // = new UnicodeBlock('\u0780', '\u07BF', + // "THAANA"); + + /** + * Devanagari. + * '\u0900' - '\u097F'. + */ + //public final static UnicodeBlock DEVANAGARI + // = new UnicodeBlock('\u0900', '\u097F', + // "DEVANAGARI"); + + /** + * Bengali. + * '\u0980' - '\u09FF'. + */ + //public final static UnicodeBlock BENGALI + // = new UnicodeBlock('\u0980', '\u09FF', + // "BENGALI"); + + /** + * Gurmukhi. + * '\u0A00' - '\u0A7F'. + */ + //public final static UnicodeBlock GURMUKHI + // = new UnicodeBlock('\u0A00', '\u0A7F', + // "GURMUKHI"); + + /** + * Gujarati. + * '\u0A80' - '\u0AFF'. + */ + //public final static UnicodeBlock GUJARATI + // = new UnicodeBlock('\u0A80', '\u0AFF', + // "GUJARATI"); + + /** + * Oriya. + * '\u0B00' - '\u0B7F'. + */ + //public final static UnicodeBlock ORIYA + // = new UnicodeBlock('\u0B00', '\u0B7F', + // "ORIYA"); + + /** + * Tamil. + * '\u0B80' - '\u0BFF'. + */ + //public final static UnicodeBlock TAMIL + // = new UnicodeBlock('\u0B80', '\u0BFF', + // "TAMIL"); + + /** + * Telugu. + * '\u0C00' - '\u0C7F'. + */ + //public final static UnicodeBlock TELUGU + // = new UnicodeBlock('\u0C00', '\u0C7F', + // "TELUGU"); + + /** + * Kannada. + * '\u0C80' - '\u0CFF'. + */ + //public final static UnicodeBlock KANNADA + // = new UnicodeBlock('\u0C80', '\u0CFF', + // "KANNADA"); + + /** + * Malayalam. + * '\u0D00' - '\u0D7F'. + */ + //public final static UnicodeBlock MALAYALAM + // = new UnicodeBlock('\u0D00', '\u0D7F', + // "MALAYALAM"); + + /** + * Sinhala. + * '\u0D80' - '\u0DFF'. + * @since 1.4 + */ + //public final static UnicodeBlock SINHALA + // = new UnicodeBlock('\u0D80', '\u0DFF', + // "SINHALA"); + + /** + * Thai. + * '\u0E00' - '\u0E7F'. + */ + //public final static UnicodeBlock THAI + // = new UnicodeBlock('\u0E00', '\u0E7F', + // "THAI"); + + /** + * Lao. + * '\u0E80' - '\u0EFF'. + */ + //public final static UnicodeBlock LAO + // = new UnicodeBlock('\u0E80', '\u0EFF', + // "LAO"); + + /** + * Tibetan. + * '\u0F00' - '\u0FFF'. + */ + //public final static UnicodeBlock TIBETAN + // = new UnicodeBlock('\u0F00', '\u0FFF', + // "TIBETAN"); + + /** + * Myanmar. + * '\u1000' - '\u109F'. + * @since 1.4 + */ + //public final static UnicodeBlock MYANMAR + // = new UnicodeBlock('\u1000', '\u109F', + // "MYANMAR"); + + /** + * Georgian. + * '\u10A0' - '\u10FF'. + */ + //public final static UnicodeBlock GEORGIAN + // = new UnicodeBlock('\u10A0', '\u10FF', + // "GEORGIAN"); + + /** + * Hangul Jamo. + * '\u1100' - '\u11FF'. + */ + //public final static UnicodeBlock HANGUL_JAMO + // = new UnicodeBlock('\u1100', '\u11FF', + // "HANGUL_JAMO"); + + /** + * Ethiopic. + * '\u1200' - '\u137F'. + * @since 1.4 + */ + //public final static UnicodeBlock ETHIOPIC + // = new UnicodeBlock('\u1200', '\u137F', + // "ETHIOPIC"); + + /** + * Cherokee. + * '\u13A0' - '\u13FF'. + * @since 1.4 + */ + //public final static UnicodeBlock CHEROKEE + // = new UnicodeBlock('\u13A0', '\u13FF', + // "CHEROKEE"); + + /** + * Unified Canadian Aboriginal Syllabics. + * '\u1400' - '\u167F'. + * @since 1.4 + */ + //public final static UnicodeBlock UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS + // = new UnicodeBlock('\u1400', '\u167F', + // "UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS"); + + /** + * Ogham. + * '\u1680' - '\u169F'. + * @since 1.4 + */ + //public final static UnicodeBlock OGHAM + // = new UnicodeBlock('\u1680', '\u169F', + // "OGHAM"); + + /** + * Runic. + * '\u16A0' - '\u16FF'. + * @since 1.4 + */ + //public final static UnicodeBlock RUNIC + // = new UnicodeBlock('\u16A0', '\u16FF', + // "RUNIC"); + + /** + * Khmer. + * '\u1780' - '\u17FF'. + * @since 1.4 + */ + //public final static UnicodeBlock KHMER + // = new UnicodeBlock('\u1780', '\u17FF', + // "KHMER"); + + /** + * Mongolian. + * '\u1800' - '\u18AF'. + * @since 1.4 + */ + //public final static UnicodeBlock MONGOLIAN + // = new UnicodeBlock('\u1800', '\u18AF', + // "MONGOLIAN"); + + /** + * Latin Extended Additional. + * '\u1E00' - '\u1EFF'. + */ + //public final static UnicodeBlock LATIN_EXTENDED_ADDITIONAL + // = new UnicodeBlock('\u1E00', '\u1EFF', + // "LATIN_EXTENDED_ADDITIONAL"); + + /** + * Greek Extended. + * '\u1F00' - '\u1FFF'. + */ + //public final static UnicodeBlock GREEK_EXTENDED + // = new UnicodeBlock('\u1F00', '\u1FFF', + // "GREEK_EXTENDED"); + + /** + * General Punctuation. + * '\u2000' - '\u206F'. + */ + //public final static UnicodeBlock GENERAL_PUNCTUATION + // = new UnicodeBlock('\u2000', '\u206F', + // "GENERAL_PUNCTUATION"); + + /** + * Superscripts and Subscripts. + * '\u2070' - '\u209F'. + */ + //public final static UnicodeBlock SUPERSCRIPTS_AND_SUBSCRIPTS + // = new UnicodeBlock('\u2070', '\u209F', + // "SUPERSCRIPTS_AND_SUBSCRIPTS"); + + /** + * Currency Symbols. + * '\u20A0' - '\u20CF'. + */ + //public final static UnicodeBlock CURRENCY_SYMBOLS + // = new UnicodeBlock('\u20A0', '\u20CF', + // "CURRENCY_SYMBOLS"); + + /** + * Combining Marks for Symbols. + * '\u20D0' - '\u20FF'. + */ + //public final static UnicodeBlock COMBINING_MARKS_FOR_SYMBOLS + // = new UnicodeBlock('\u20D0', '\u20FF', + // "COMBINING_MARKS_FOR_SYMBOLS"); + + /** + * Letterlike Symbols. + * '\u2100' - '\u214F'. + */ + //public final static UnicodeBlock LETTERLIKE_SYMBOLS + // = new UnicodeBlock('\u2100', '\u214F', + // "LETTERLIKE_SYMBOLS"); + + /** + * Number Forms. + * '\u2150' - '\u218F'. + */ + //public final static UnicodeBlock NUMBER_FORMS + // = new UnicodeBlock('\u2150', '\u218F', + // "NUMBER_FORMS"); + + /** + * Arrows. + * '\u2190' - '\u21FF'. + */ + //public final static UnicodeBlock ARROWS + // = new UnicodeBlock('\u2190', '\u21FF', + // "ARROWS"); + + /** + * Mathematical Operators. + * '\u2200' - '\u22FF'. + */ + //public final static UnicodeBlock MATHEMATICAL_OPERATORS + // = new UnicodeBlock('\u2200', '\u22FF', + // "MATHEMATICAL_OPERATORS"); + + /** + * Miscellaneous Technical. + * '\u2300' - '\u23FF'. + */ + //public final static UnicodeBlock MISCELLANEOUS_TECHNICAL + // = new UnicodeBlock('\u2300', '\u23FF', + // "MISCELLANEOUS_TECHNICAL"); + + /** + * Control Pictures. + * '\u2400' - '\u243F'. + */ + //public final static UnicodeBlock CONTROL_PICTURES + // = new UnicodeBlock('\u2400', '\u243F', + // "CONTROL_PICTURES"); + + /** + * Optical Character Recognition. + * '\u2440' - '\u245F'. + */ + //public final static UnicodeBlock OPTICAL_CHARACTER_RECOGNITION + // = new UnicodeBlock('\u2440', '\u245F', + // "OPTICAL_CHARACTER_RECOGNITION"); + + /** + * Enclosed Alphanumerics. + * '\u2460' - '\u24FF'. + */ + //public final static UnicodeBlock ENCLOSED_ALPHANUMERICS + // = new UnicodeBlock('\u2460', '\u24FF', + // "ENCLOSED_ALPHANUMERICS"); + + /** + * Box Drawing. + * '\u2500' - '\u257F'. + */ + //public final static UnicodeBlock BOX_DRAWING + // = new UnicodeBlock('\u2500', '\u257F', + // "BOX_DRAWING"); + + /** + * Block Elements. + * '\u2580' - '\u259F'. + */ + //public final static UnicodeBlock BLOCK_ELEMENTS + // = new UnicodeBlock('\u2580', '\u259F', + // "BLOCK_ELEMENTS"); + + /** + * Geometric Shapes. + * '\u25A0' - '\u25FF'. + */ + //public final static UnicodeBlock GEOMETRIC_SHAPES + // = new UnicodeBlock('\u25A0', '\u25FF', + // "GEOMETRIC_SHAPES"); + + /** + * Miscellaneous Symbols. + * '\u2600' - '\u26FF'. + */ + //public final static UnicodeBlock MISCELLANEOUS_SYMBOLS + // = new UnicodeBlock('\u2600', '\u26FF', + // "MISCELLANEOUS_SYMBOLS"); + + /** + * Dingbats. + * '\u2700' - '\u27BF'. + */ + //public final static UnicodeBlock DINGBATS + // = new UnicodeBlock('\u2700', '\u27BF', + // "DINGBATS"); + + /** + * Braille Patterns. + * '\u2800' - '\u28FF'. + * @since 1.4 + */ + //public final static UnicodeBlock BRAILLE_PATTERNS + // = new UnicodeBlock('\u2800', '\u28FF', + // "BRAILLE_PATTERNS"); + + /** + * CJK Radicals Supplement. + * '\u2E80' - '\u2EFF'. + * @since 1.4 + */ + //public final static UnicodeBlock CJK_RADICALS_SUPPLEMENT + // = new UnicodeBlock('\u2E80', '\u2EFF', + // "CJK_RADICALS_SUPPLEMENT"); + + /** + * Kangxi Radicals. + * '\u2F00' - '\u2FDF'. + * @since 1.4 + */ + //public final static UnicodeBlock KANGXI_RADICALS + // = new UnicodeBlock('\u2F00', '\u2FDF', + // "KANGXI_RADICALS"); + + /** + * Ideographic Description Characters. + * '\u2FF0' - '\u2FFF'. + * @since 1.4 + */ + //public final static UnicodeBlock IDEOGRAPHIC_DESCRIPTION_CHARACTERS + // = new UnicodeBlock('\u2FF0', '\u2FFF', + // "IDEOGRAPHIC_DESCRIPTION_CHARACTERS"); + + /** + * CJK Symbols and Punctuation. + * '\u3000' - '\u303F'. + */ + //public final static UnicodeBlock CJK_SYMBOLS_AND_PUNCTUATION + // = new UnicodeBlock('\u3000', '\u303F', + // "CJK_SYMBOLS_AND_PUNCTUATION"); + + /** + * Hiragana. + * '\u3040' - '\u309F'. + */ + //public final static UnicodeBlock HIRAGANA + // = new UnicodeBlock('\u3040', '\u309F', + // "HIRAGANA"); + + /** + * Katakana. + * '\u30A0' - '\u30FF'. + */ + //public final static UnicodeBlock KATAKANA + // = new UnicodeBlock('\u30A0', '\u30FF', + // "KATAKANA"); + + /** + * Bopomofo. + * '\u3100' - '\u312F'. + */ + //public final static UnicodeBlock BOPOMOFO + // = new UnicodeBlock('\u3100', '\u312F', + // "BOPOMOFO"); + + /** + * Hangul Compatibility Jamo. + * '\u3130' - '\u318F'. + */ + //public final static UnicodeBlock HANGUL_COMPATIBILITY_JAMO + // = new UnicodeBlock('\u3130', '\u318F', + // "HANGUL_COMPATIBILITY_JAMO"); + + /** + * Kanbun. + * '\u3190' - '\u319F'. + */ + //public final static UnicodeBlock KANBUN + // = new UnicodeBlock('\u3190', '\u319F', + // "KANBUN"); + + /** + * Bopomofo Extended. + * '\u31A0' - '\u31BF'. + * @since 1.4 + */ + //public final static UnicodeBlock BOPOMOFO_EXTENDED + // = new UnicodeBlock('\u31A0', '\u31BF', + // "BOPOMOFO_EXTENDED"); + + /** + * Enclosed CJK Letters and Months. + * '\u3200' - '\u32FF'. + */ + //public final static UnicodeBlock ENCLOSED_CJK_LETTERS_AND_MONTHS + // = new UnicodeBlock('\u3200', '\u32FF', + // "ENCLOSED_CJK_LETTERS_AND_MONTHS"); + + /** + * CJK Compatibility. + * '\u3300' - '\u33FF'. + */ + //public final static UnicodeBlock CJK_COMPATIBILITY + // = new UnicodeBlock('\u3300', '\u33FF', + // "CJK_COMPATIBILITY"); + + /** + * CJK Unified Ideographs Extension A. + * '\u3400' - '\u4DB5'. + * @since 1.4 + */ + //public final static UnicodeBlock CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A + // = new UnicodeBlock('\u3400', '\u4DB5', + // "CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A"); + + /** + * CJK Unified Ideographs. + * '\u4E00' - '\u9FFF'. + */ + //public final static UnicodeBlock CJK_UNIFIED_IDEOGRAPHS + // = new UnicodeBlock('\u4E00', '\u9FFF', + // "CJK_UNIFIED_IDEOGRAPHS"); + + /** + * Yi Syllables. + * '\uA000' - '\uA48F'. + * @since 1.4 + */ + //public final static UnicodeBlock YI_SYLLABLES + // = new UnicodeBlock('\uA000', '\uA48F', + // "YI_SYLLABLES"); + + /** + * Yi Radicals. + * '\uA490' - '\uA4CF'. + * @since 1.4 + */ + //public final static UnicodeBlock YI_RADICALS + // = new UnicodeBlock('\uA490', '\uA4CF', + // "YI_RADICALS"); + + /** + * Hangul Syllables. + * '\uAC00' - '\uD7A3'. + */ + //public final static UnicodeBlock HANGUL_SYLLABLES + // = new UnicodeBlock('\uAC00', '\uD7A3', + // "HANGUL_SYLLABLES"); + + /** + * Surrogates Area. + * '\uD800' - '\uDFFF'. + */ + //public final static UnicodeBlock SURROGATES_AREA + // = new UnicodeBlock('\uD800', '\uDFFF', + // "SURROGATES_AREA"); + + /** + * Private Use Area. + * '\uE000' - '\uF8FF'. + */ + //public final static UnicodeBlock PRIVATE_USE_AREA + // = new UnicodeBlock('\uE000', '\uF8FF', + // "PRIVATE_USE_AREA"); + + /** + * CJK Compatibility Ideographs. + * '\uF900' - '\uFAFF'. + */ + //public final static UnicodeBlock CJK_COMPATIBILITY_IDEOGRAPHS + // = new UnicodeBlock('\uF900', '\uFAFF', + // "CJK_COMPATIBILITY_IDEOGRAPHS"); + + /** + * Alphabetic Presentation Forms. + * '\uFB00' - '\uFB4F'. + */ + //public final static UnicodeBlock ALPHABETIC_PRESENTATION_FORMS + // = new UnicodeBlock('\uFB00', '\uFB4F', + // "ALPHABETIC_PRESENTATION_FORMS"); + + /** + * Arabic Presentation Forms-A. + * '\uFB50' - '\uFDFF'. + */ + //public final static UnicodeBlock ARABIC_PRESENTATION_FORMS_A + // = new UnicodeBlock('\uFB50', '\uFDFF', + // "ARABIC_PRESENTATION_FORMS_A"); + + /** + * Combining Half Marks. + * '\uFE20' - '\uFE2F'. + */ + //public final static UnicodeBlock COMBINING_HALF_MARKS + // = new UnicodeBlock('\uFE20', '\uFE2F', + // "COMBINING_HALF_MARKS"); + + /** + * CJK Compatibility Forms. + * '\uFE30' - '\uFE4F'. + */ + //public final static UnicodeBlock CJK_COMPATIBILITY_FORMS + // = new UnicodeBlock('\uFE30', '\uFE4F', + // "CJK_COMPATIBILITY_FORMS"); + + /** + * Small Form Variants. + * '\uFE50' - '\uFE6F'. + */ + //public final static UnicodeBlock SMALL_FORM_VARIANTS + // = new UnicodeBlock('\uFE50', '\uFE6F', + // "SMALL_FORM_VARIANTS"); + + /** + * Arabic Presentation Forms-B. + * '\uFE70' - '\uFEFE'. + */ + //public final static UnicodeBlock ARABIC_PRESENTATION_FORMS_B + // = new UnicodeBlock('\uFE70', '\uFEFE', + // "ARABIC_PRESENTATION_FORMS_B"); + + /** + * Halfwidth and Fullwidth Forms. + * '\uFF00' - '\uFFEF'. + */ + //public final static UnicodeBlock HALFWIDTH_AND_FULLWIDTH_FORMS + // = new UnicodeBlock('\uFF00', '\uFFEF', + // "HALFWIDTH_AND_FULLWIDTH_FORMS"); + + /** + * Specials. + * '\uFEFF', '\uFFF0' - '\uFFFD'. + */ + //public final static UnicodeBlock SPECIALS + // = new UnicodeBlock('\uFFF0', '\uFFFD', + // "SPECIALS"); + + /** + * The defined subsets. + */ + /*private static final UnicodeBlock sets[] = { + BASIC_LATIN, + LATIN_1_SUPPLEMENT, + LATIN_EXTENDED_A, + LATIN_EXTENDED_B, + IPA_EXTENSIONS, + SPACING_MODIFIER_LETTERS, + COMBINING_DIACRITICAL_MARKS, + GREEK, + CYRILLIC, + ARMENIAN, + HEBREW, + ARABIC, + SYRIAC, + THAANA, + DEVANAGARI, + BENGALI, + GURMUKHI, + GUJARATI, + ORIYA, + TAMIL, + TELUGU, + KANNADA, + MALAYALAM, + SINHALA, + THAI, + LAO, + TIBETAN, + MYANMAR, + GEORGIAN, + HANGUL_JAMO, + ETHIOPIC, + CHEROKEE, + UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, + OGHAM, + RUNIC, + KHMER, + MONGOLIAN, + LATIN_EXTENDED_ADDITIONAL, + GREEK_EXTENDED, + GENERAL_PUNCTUATION, + SUPERSCRIPTS_AND_SUBSCRIPTS, + CURRENCY_SYMBOLS, + COMBINING_MARKS_FOR_SYMBOLS, + LETTERLIKE_SYMBOLS, + NUMBER_FORMS, + ARROWS, + MATHEMATICAL_OPERATORS, + MISCELLANEOUS_TECHNICAL, + CONTROL_PICTURES, + OPTICAL_CHARACTER_RECOGNITION, + ENCLOSED_ALPHANUMERICS, + BOX_DRAWING, + BLOCK_ELEMENTS, + GEOMETRIC_SHAPES, + MISCELLANEOUS_SYMBOLS, + DINGBATS, + BRAILLE_PATTERNS, + CJK_RADICALS_SUPPLEMENT, + KANGXI_RADICALS, + IDEOGRAPHIC_DESCRIPTION_CHARACTERS, + CJK_SYMBOLS_AND_PUNCTUATION, + HIRAGANA, + KATAKANA, + BOPOMOFO, + HANGUL_COMPATIBILITY_JAMO, + KANBUN, + BOPOMOFO_EXTENDED, + ENCLOSED_CJK_LETTERS_AND_MONTHS, + CJK_COMPATIBILITY, + CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, + CJK_UNIFIED_IDEOGRAPHS, + YI_SYLLABLES, + YI_RADICALS, + HANGUL_SYLLABLES, + SURROGATES_AREA, + PRIVATE_USE_AREA, + CJK_COMPATIBILITY_IDEOGRAPHS, + ALPHABETIC_PRESENTATION_FORMS, + ARABIC_PRESENTATION_FORMS_A, + COMBINING_HALF_MARKS, + CJK_COMPATIBILITY_FORMS, + SMALL_FORM_VARIANTS, + ARABIC_PRESENTATION_FORMS_B, + HALFWIDTH_AND_FULLWIDTH_FORMS, + SPECIALS, + };*/ +// } // class UnicodeBlock + + /** + * The immutable value of this Character. + * + * @serial the value of this Character + */ + private final char value; + + /** + * Compatible with JDK 1.0+. + */ + private static final long serialVersionUID = 3786198910865385080L; + + /** + * Smallest value allowed for radix arguments in Java. This value is 2. + * + * @see #digit(char, int) + * @see #forDigit(int, int) + * @see Integer#toString(int, int) + * @see Integer#valueOf(String) + */ + public static final int MIN_RADIX = 2; + + /** + * Largest value allowed for radix arguments in Java. This value is 36. + * + * @see #digit(char, int) + * @see #forDigit(int, int) + * @see Integer#toString(int, int) + * @see Integer#valueOf(String) + */ + public static final int MAX_RADIX = 36; + + /** + * The minimum value the char data type can hold. + * This value is '\\u0000'. + */ + public static final char MIN_VALUE = (char) 0; //'\u0000'; + + /** + * The maximum value the char data type can hold. + * This value is '\\uFFFF'. + */ + public static final char MAX_VALUE = (char) 65535;//'\uFFFF'; + + /** + * Class object representing the primitive char data type. + * + * @since 1.1 + */ +// public static final Class TYPE = VMClassLoader.getPrimitiveClass('C'); + + /** + * Lu = Letter, Uppercase (Informative). + * + * @since 1.1 + */ + public static final byte UPPERCASE_LETTER = 1; + + /** + * Ll = Letter, Lowercase (Informative). + * + * @since 1.1 + */ + public static final byte LOWERCASE_LETTER = 2; + + /** + * Lt = Letter, Titlecase (Informative). + * + * @since 1.1 + */ + public static final byte TITLECASE_LETTER = 3; + + /** + * Mn = Mark, Non-Spacing (Normative). + * + * @since 1.1 + */ + public static final byte NON_SPACING_MARK = 6; + + /** + * Mc = Mark, Spacing Combining (Normative). + * + * @since 1.1 + */ + public static final byte COMBINING_SPACING_MARK = 8; + + /** + * Me = Mark, Enclosing (Normative). + * + * @since 1.1 + */ + public static final byte ENCLOSING_MARK = 7; + + /** + * Nd = Number, Decimal Digit (Normative). + * + * @since 1.1 + */ + public static final byte DECIMAL_DIGIT_NUMBER = 9; + + /** + * Nl = Number, Letter (Normative). + * + * @since 1.1 + */ + public static final byte LETTER_NUMBER = 10; + + /** + * No = Number, Other (Normative). + * + * @since 1.1 + */ + public static final byte OTHER_NUMBER = 11; + + /** + * Zs = Separator, Space (Normative). + * + * @since 1.1 + */ + public static final byte SPACE_SEPARATOR = 12; + + /** + * Zl = Separator, Line (Normative). + * + * @since 1.1 + */ + public static final byte LINE_SEPARATOR = 13; + + /** + * Zp = Separator, Paragraph (Normative). + * + * @since 1.1 + */ + public static final byte PARAGRAPH_SEPARATOR = 14; + + /** + * Cc = Other, Control (Normative). + * + * @since 1.1 + */ + public static final byte CONTROL = 15; + + /** + * Cf = Other, Format (Normative). + * + * @since 1.1 + */ + public static final byte FORMAT = 16; + + /** + * Cs = Other, Surrogate (Normative). + * + * @since 1.1 + */ + public static final byte SURROGATE = 19; + + /** + * Co = Other, Private Use (Normative). + * + * @since 1.1 + */ + public static final byte PRIVATE_USE = 18; + + /** + * Cn = Other, Not Assigned (Normative). + * + * @since 1.1 + */ + public static final byte UNASSIGNED = 0; + + /** + * Lm = Letter, Modifier (Informative). + * + * @since 1.1 + */ + public static final byte MODIFIER_LETTER = 4; + + /** + * Lo = Letter, Other (Informative). + * + * @since 1.1 + */ + public static final byte OTHER_LETTER = 5; + + /** + * Pc = Punctuation, Connector (Informative). + * + * @since 1.1 + */ + public static final byte CONNECTOR_PUNCTUATION = 23; + + /** + * Pd = Punctuation, Dash (Informative). + * + * @since 1.1 + */ + public static final byte DASH_PUNCTUATION = 20; + + /** + * Ps = Punctuation, Open (Informative). + * + * @since 1.1 + */ + public static final byte START_PUNCTUATION = 21; + + /** + * Pe = Punctuation, Close (Informative). + * + * @since 1.1 + */ + public static final byte END_PUNCTUATION = 22; + + /** + * Pi = Punctuation, Initial Quote (Informative). + * + * @since 1.4 + */ + public static final byte INITIAL_QUOTE_PUNCTUATION = 29; + + /** + * Pf = Punctuation, Final Quote (Informative). + * + * @since 1.4 + */ + public static final byte FINAL_QUOTE_PUNCTUATION = 30; + + /** + * Po = Punctuation, Other (Informative). + * + * @since 1.1 + */ + public static final byte OTHER_PUNCTUATION = 24; + + /** + * Sm = Symbol, Math (Informative). + * + * @since 1.1 + */ + public static final byte MATH_SYMBOL = 25; + + /** + * Sc = Symbol, Currency (Informative). + * + * @since 1.1 + */ + public static final byte CURRENCY_SYMBOL = 26; + + /** + * Sk = Symbol, Modifier (Informative). + * + * @since 1.1 + */ + public static final byte MODIFIER_SYMBOL = 27; + + /** + * So = Symbol, Other (Informative). + * + * @since 1.1 + */ + public static final byte OTHER_SYMBOL = 28; + + /** + * Undefined bidirectional character type. Undefined char values have + * undefined directionality in the Unicode specification. + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_UNDEFINED = -1; + + /** + * Strong bidirectional character type "L". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0; + + /** + * Strong bidirectional character type "R". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1; + + /** + * Strong bidirectional character type "AL". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2; + + /** + * Weak bidirectional character type "EN". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3; + + /** + * Weak bidirectional character type "ES". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4; + + /** + * Weak bidirectional character type "ET". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5; + + /** + * Weak bidirectional character type "AN". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6; + + /** + * Weak bidirectional character type "CS". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7; + + /** + * Weak bidirectional character type "NSM". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_NONSPACING_MARK = 8; + + /** + * Weak bidirectional character type "BN". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9; + + /** + * Neutral bidirectional character type "B". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10; + + /** + * Neutral bidirectional character type "S". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11; + + /** + * Strong bidirectional character type "WS". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_WHITESPACE = 12; + + /** + * Neutral bidirectional character type "ON". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13; + + /** + * Strong bidirectional character type "LRE". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14; + + /** + * Strong bidirectional character type "LRO". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15; + + /** + * Strong bidirectional character type "RLE". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16; + + /** + * Strong bidirectional character type "RLO". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17; + + /** + * Weak bidirectional character type "PDF". + * + * @since 1.4 + */ + public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18; + + /** + * Stores unicode block offset lookup table. Exploit package visibility of + * String.value to avoid copying the array. + * @see #readChar(char) + * @see CharData#BLOCKS + */ +// private static final char[] blocks = CharData.BLOCKS.toCharArray(); + + /** + * Stores unicode attribute offset lookup table. Exploit package visibility + * of String.value to avoid copying the array. + * @see CharData#DATA + */ +// private static final char[] data = String.zeroBasedStringValue(CharData.DATA); + + /** + * Stores unicode numeric value attribute table. Exploit package visibility + * of String.value to avoid copying the array. + * @see CharData#NUM_VALUE + */ +// private static final char[] numValue +// = String.zeroBasedStringValue(CharData.NUM_VALUE); + + /** + * Stores unicode uppercase attribute table. Exploit package visibility + * of String.value to avoid copying the array. + * @see CharData#UPPER + */ +// private static final char[] upper = String.zeroBasedStringValue(CharData.UPPER); + + /** + * Stores unicode lowercase attribute table. Exploit package visibility + * of String.value to avoid copying the array. + * @see CharData#LOWER + */ +// private static final char[] lower = String.zeroBasedStringValue(CharData.LOWER); + + /** + * Stores unicode direction attribute table. Exploit package visibility + * of String.value to avoid copying the array. + * @see CharData#DIRECTION + */ + // Package visible for use by String. +// static final char[] direction = String.zeroBasedStringValue(CharData.DIRECTION); + + /** + * Stores unicode titlecase table. Exploit package visibility of + * String.value to avoid copying the array. + * @see CharData#TITLE + */ +// private static final char[] title = String.zeroBasedStringValue(CharData.TITLE); + + /** + * Mask for grabbing the type out of the contents of data. + * @see CharData#DATA + */ + private static final int TYPE_MASK = 0x1F; + + /** + * Mask for grabbing the non-breaking space flag out of the contents of + * data. + * @see CharData#DATA + */ + private static final int NO_BREAK_MASK = 0x20; + + /** + * Mask for grabbing the mirrored directionality flag out of the contents + * of data. + * @see CharData#DATA + */ + private static final int MIRROR_MASK = 0x40; + + /** + * Grabs an attribute offset from the Unicode attribute database. The lower + * 5 bits are the character type, the next 2 bits are flags, and the top + * 9 bits are the offset into the attribute tables. + * + * @param ch the character to look up + * @return the character's attribute offset and type + * @see #TYPE_MASK + * @see #NO_BREAK_MASK + * @see #MIRROR_MASK + * @see CharData#DATA + * @see CharData#SHIFT + */ + // Package visible for use in String. + static char readChar(char ch) + { return ch; + // Perform 16-bit addition to find the correct entry in data. +// return data[(char) (blocks[ch >> CharData.SHIFT] + ch)]; + } + + /** + * Wraps up a character. + * + * @param value the character to wrap + */ + public Character(char value) + { + this.value = value; + } + + /** + * Returns the character which has been wrapped by this class. + * + * @return the character wrapped + */ + public char charValue() + { + return value; + } + + /** + * Returns the numerical value (unsigned) of the wrapped character. + * Range of returned values: 0x0000-0xFFFF. + * + * @return the value of the wrapped character + */ + public int hashCode() + { + return value; + } + + /** + * Determines if an object is equal to this object. This is only true for + * another Character object wrapping the same value. + * + * @param o object to compare + * @return true if o is a Character with the same value + */ + public boolean equals(Object o) + { + return o instanceof Character && value == ((Character) o).value; + } + + /** + * Converts the wrapped character into a String. + * + * @return a String containing one character -- the wrapped character + * of this instance + */ + public String toString() + { + // Package constructor avoids an array copy. + return new String(new char[] { value }, 0, 1); //, true); + } + + /** + * Returns a String of length 1 representing the specified character. + * + * @param ch the character to convert + * @return a String containing the character + * @since 1.4 + */ + public static String toString(char ch) + { + // Package constructor avoids an array copy. + return new String(new char[] { ch }, 0, 1); //, true); + } + + /** + * Determines if a character is a Unicode lowercase letter. For example, + * 'a' is lowercase. + *
+ * lowercase = [Ll] + * + * @param ch character to test + * @return true if ch is a Unicode lowercase letter, else false + * @see #isUpperCase(char) + * @see #isTitleCase(char) + * @see #toLowerCase(char) + * @see #getType(char) + */ + public static boolean isLowerCase(char ch) + { + return mz.lowerCaseP(ch); + //return getType(ch) == LOWERCASE_LETTER; + } + + /** + * Determines if a character is a Unicode uppercase letter. For example, + * 'A' is uppercase. + *
+ * uppercase = [Lu] + * + * @param ch character to test + * @return true if ch is a Unicode uppercase letter, else false + * @see #isLowerCase(char) + * @see #isTitleCase(char) + * @see #toUpperCase(char) + * @see #getType(char) + */ + public static boolean isUpperCase(char ch) + { return mz.upperCaseP(ch); +// return getType(ch) == UPPERCASE_LETTER; + } + + /** + * Determines if a character is a Unicode titlecase letter. For example, + * the character "Lj" (Latin capital L with small letter j) is titlecase. + *
+ * titlecase = [Lt] + * + * @param ch character to test + * @return true if ch is a Unicode titlecase letter, else false + * @see #isLowerCase(char) + * @see #isUpperCase(char) + * @see #toTitleCase(char) + * @see #getType(char) + */ + public static boolean isTitleCase(char ch) + { + return mz.titleCaseP(ch); +// return getType(ch) == TITLECASE_LETTER; + } + + /** + * Determines if a character is a Unicode decimal digit. For example, + * '0' is a digit. + *
+ * Unicode decimal digit = [Nd] + * + * @param ch character to test + * @return true if ch is a Unicode decimal digit, else false + * @see #digit(char, int) + * @see #forDigit(int, int) + * @see #getType(char) + */ + public static boolean isDigit(char ch) + { + return mz.numericP(ch); +// return getType(ch) == DECIMAL_DIGIT_NUMBER; + } + + /** + * Determines if a character is part of the Unicode Standard. This is an + * evolving standard, but covers every character in the data file. + *
+ * defined = not [Cn] + * + * @param ch character to test + * @return true if ch is a Unicode character, else false + * @see #isDigit(char) + * @see #isLetter(char) + * @see #isLetterOrDigit(char) + * @see #isLowerCase(char) + * @see #isTitleCase(char) + * @see #isUpperCase(char) + */ + public static boolean isDefined(char ch) + { throw new RuntimeException("isDefined is unimplemented"); + //return getType(ch) != UNASSIGNED; + } + + /** + * Determines if a character is a Unicode letter. Not all letters have case, + * so this may return true when isLowerCase and isUpperCase return false. + *
+ * letter = [Lu]|[Ll]|[Lt]|[Lm]|[Lo] + * + * @param ch character to test + * @return true if ch is a Unicode letter, else false + * @see #isDigit(char) + * @see #isJavaIdentifierStart(char) + * @see #isJavaLetter(char) + * @see #isJavaLetterOrDigit(char) + * @see #isLetterOrDigit(char) + * @see #isLowerCase(char) + * @see #isTitleCase(char) + * @see #isUnicodeIdentifierStart(char) + * @see #isUpperCase(char) + */ + public static boolean isLetter(char ch) + { return mz.alphabeticP(ch); +/* return ((1 << getType(ch)) + & ((1 << UPPERCASE_LETTER) + | (1 << LOWERCASE_LETTER) + | (1 << TITLECASE_LETTER) + | (1 << MODIFIER_LETTER) + | (1 << OTHER_LETTER))) != 0; */ + } + + /** + * Determines if a character is a Unicode letter or a Unicode digit. This + * is the combination of isLetter and isDigit. + *
+ * letter or digit = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nd] + * + * @param ch character to test + * @return true if ch is a Unicode letter or a Unicode digit, else false + * @see #isDigit(char) + * @see #isJavaIdentifierPart(char) + * @see #isJavaLetter(char) + * @see #isJavaLetterOrDigit(char) + * @see #isLetter(char) + * @see #isUnicodeIdentifierPart(char) + */ + public static boolean isLetterOrDigit(char ch) + { return isLetter(ch) || isDigit(ch); +/* return ((1 << getType(ch)) + & ((1 << UPPERCASE_LETTER) + | (1 << LOWERCASE_LETTER) + | (1 << TITLECASE_LETTER) + | (1 << MODIFIER_LETTER) + | (1 << OTHER_LETTER) + | (1 << DECIMAL_DIGIT_NUMBER))) != 0; */ + } + + /** + * Determines if a character can start a Java identifier. This is the + * combination of isLetter, any character where getType returns + * LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation + * (like '_'). + * + * @param ch character to test + * @return true if ch can start a Java identifier, else false + * @deprecated Replaced by {@link #isJavaIdentifierStart(char)} + * @see #isJavaLetterOrDigit(char) + * @see #isJavaIdentifierStart(char) + * @see #isJavaIdentifierPart(char) + * @see #isLetter(char) + * @see #isLetterOrDigit(char) + * @see #isUnicodeIdentifierStart(char) + */ + public static boolean isJavaLetter(char ch) + { + return isJavaIdentifierStart(ch); + } + + /** + * Determines if a character can follow the first letter in + * a Java identifier. This is the combination of isJavaLetter (isLetter, + * type of LETTER_NUMBER, currency, connecting punctuation) and digit, + * numeric letter (like Roman numerals), combining marks, non-spacing marks, + * or isIdentifierIgnorable. + * + * @param ch character to test + * @return true if ch can follow the first letter in a Java identifier + * @deprecated Replaced by {@link #isJavaIdentifierPart(char)} + * @see #isJavaLetter(char) + * @see #isJavaIdentifierStart(char) + * @see #isJavaIdentifierPart(char) + * @see #isLetter(char) + * @see #isLetterOrDigit(char) + * @see #isUnicodeIdentifierPart(char) + * @see #isIdentifierIgnorable(char) + */ + public static boolean isJavaLetterOrDigit(char ch) + { + return isJavaIdentifierPart(ch); + } + + /** + * Determines if a character can start a Java identifier. This is the + * combination of isLetter, any character where getType returns + * LETTER_NUMBER, currency symbols (like '$'), and connecting punctuation + * (like '_'). + *
+ * Java identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc] + * + * @param ch character to test + * @return true if ch can start a Java identifier, else false + * @see #isJavaIdentifierPart(char) + * @see #isLetter(char) + * @see #isUnicodeIdentifierStart(char) + * @since 1.1 + */ + public static boolean isJavaIdentifierStart(char ch) + { throw new RuntimeException("isJavaIdentifierStart is unimplemented"); +/* return ((1 << getType(ch)) + & ((1 << UPPERCASE_LETTER) + | (1 << LOWERCASE_LETTER) + | (1 << TITLECASE_LETTER) + | (1 << MODIFIER_LETTER) + | (1 << OTHER_LETTER) + | (1 << LETTER_NUMBER) + | (1 << CURRENCY_SYMBOL) + | (1 << CONNECTOR_PUNCTUATION))) != 0; */ + } + + /** + * Determines if a character can follow the first letter in + * a Java identifier. This is the combination of isJavaLetter (isLetter, + * type of LETTER_NUMBER, currency, connecting punctuation) and digit, + * numeric letter (like Roman numerals), combining marks, non-spacing marks, + * or isIdentifierIgnorable. + *
+ * Java identifier extender = + * [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc]|[Mn]|[Mc]|[Nd]|[Cf] + * |U+0000-U+0008|U+000E-U+001B|U+007F-U+009F + * + * @param ch character to test + * @return true if ch can follow the first letter in a Java identifier + * @see #isIdentifierIgnorable(char) + * @see #isJavaIdentifierStart(char) + * @see #isLetterOrDigit(char) + * @see #isUnicodeIdentifierPart(char) + * @since 1.1 + */ + public static boolean isJavaIdentifierPart(char ch) + { throw new RuntimeException("isJavaIdentifierPart is unimplemented"); +/* int category = getType(ch); + return ((1 << category) + & ((1 << UPPERCASE_LETTER) + | (1 << LOWERCASE_LETTER) + | (1 << TITLECASE_LETTER) + | (1 << MODIFIER_LETTER) + | (1 << OTHER_LETTER) + | (1 << NON_SPACING_MARK) + | (1 << COMBINING_SPACING_MARK) + | (1 << DECIMAL_DIGIT_NUMBER) + | (1 << LETTER_NUMBER) + | (1 << CURRENCY_SYMBOL) + | (1 << CONNECTOR_PUNCTUATION) + | (1 << FORMAT))) != 0 + || (category == CONTROL && isIdentifierIgnorable(ch)); +*/ + } + + /** + * Determines if a character can start a Unicode identifier. Only + * letters can start a Unicode identifier, but this includes characters + * in LETTER_NUMBER. + *
+ * Unicode identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl] + * + * @param ch character to test + * @return true if ch can start a Unicode identifier, else false + * @see #isJavaIdentifierStart(char) + * @see #isLetter(char) + * @see #isUnicodeIdentifierPart(char) + * @since 1.1 + */ + public static boolean isUnicodeIdentifierStart(char ch) + { throw new RuntimeException("isUnicodeIdentifierStart is unimplemented"); +/* return ((1 << getType(ch)) + & ((1 << UPPERCASE_LETTER) + | (1 << LOWERCASE_LETTER) + | (1 << TITLECASE_LETTER) + | (1 << MODIFIER_LETTER) + | (1 << OTHER_LETTER) + | (1 << LETTER_NUMBER))) != 0; */ + } + + /** + * Determines if a character can follow the first letter in + * a Unicode identifier. This includes letters, connecting punctuation, + * digits, numeric letters, combining marks, non-spacing marks, and + * isIdentifierIgnorable. + *
+ * Unicode identifier extender = + * [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Mn]|[Mc]|[Nd]|[Pc]|[Cf]| + * |U+0000-U+0008|U+000E-U+001B|U+007F-U+009F + * + * @param ch character to test + * @return true if ch can follow the first letter in a Unicode identifier + * @see #isIdentifierIgnorable(char) + * @see #isJavaIdentifierPart(char) + * @see #isLetterOrDigit(char) + * @see #isUnicodeIdentifierStart(char) + * @since 1.1 + */ + public static boolean isUnicodeIdentifierPart(char ch) + { throw new RuntimeException("isUnicodeIdentifierPart"); +/* int category = getType(ch); + return ((1 << category) + & ((1 << UPPERCASE_LETTER) + | (1 << LOWERCASE_LETTER) + | (1 << TITLECASE_LETTER) + | (1 << MODIFIER_LETTER) + | (1 << OTHER_LETTER) + | (1 << NON_SPACING_MARK) + | (1 << COMBINING_SPACING_MARK) + | (1 << DECIMAL_DIGIT_NUMBER) + | (1 << LETTER_NUMBER) + | (1 << CONNECTOR_PUNCTUATION) + | (1 << FORMAT))) != 0 + || (category == CONTROL && isIdentifierIgnorable(ch)); +*/ } + + /** + * Determines if a character is ignorable in a Unicode identifier. This + * includes the non-whitespace ISO control characters ('\u0000' + * through '\u0008', '\u000E' through + * '\u001B', and '\u007F' through + * '\u009F'), and FORMAT characters. + *
+ * Unicode identifier ignorable = [Cf]|U+0000-U+0008|U+000E-U+001B + * |U+007F-U+009F + * + * @param ch character to test + * @return true if ch is ignorable in a Unicode or Java identifier + * @see #isJavaIdentifierPart(char) + * @see #isUnicodeIdentifierPart(char) + * @since 1.1 + */ + public static boolean isIdentifierIgnorable(char ch) + { + throw new RuntimeException("isIdentifierIgnorable depends on unicode, so it not implemented"); + /*return (ch <= '\u009F' && (ch < '\t' || ch >= '\u007F' + || (ch <= '\u001B' && ch >= '\u000E'))) + || getType(ch) == FORMAT; */ + } + + /** + * Converts a Unicode character into its lowercase equivalent mapping. + * If a mapping does not exist, then the character passed is returned. + * Note that isLowerCase(toLowerCase(ch)) does not always return true. + * + * @param ch character to convert to lowercase + * @return lowercase mapping of ch, or ch if lowercase mapping does + * not exist + * @see #isLowerCase(char) + * @see #isUpperCase(char) + * @see #toTitleCase(char) + * @see #toUpperCase(char) + */ + public static char toLowerCase(char ch) + { + return mz.downcase(ch); + // Signedness doesn't matter, as result is cast back to char. + // return (char) (ch + lower[readChar(ch) >> 7]); + } + + /** + * Converts a Unicode character into its uppercase equivalent mapping. + * If a mapping does not exist, then the character passed is returned. + * Note that isUpperCase(toUpperCase(ch)) does not always return true. + * + * @param ch character to convert to uppercase + * @return uppercase mapping of ch, or ch if uppercase mapping does + * not exist + * @see #isLowerCase(char) + * @see #isUpperCase(char) + * @see #toLowerCase(char) + * @see #toTitleCase(char) + */ + public static char toUpperCase(char ch) + { + return mz.upcase(ch); + // Signedness doesn't matter, as result is cast back to char. + //return (char) (ch + upper[readChar(ch) >> 7]); + } + + /** + * Converts a Unicode character into its titlecase equivalent mapping. + * If a mapping does not exist, then the character passed is returned. + * Note that isTitleCase(toTitleCase(ch)) does not always return true. + * + * @param ch character to convert to titlecase + * @return titlecase mapping of ch, or ch if titlecase mapping does + * not exist + * @see #isTitleCase(char) + * @see #toLowerCase(char) + * @see #toUpperCase(char) + */ + public static char toTitleCase(char ch) + { return mz.titlecase(ch); +// throw new RuntimeException("toTitleCase is unimplemented"); + // As title is short, it doesn't hurt to exhaustively iterate over it. +// for (int i = title.length - 2; i >= 0; i -= 2) +// if (title[i] == ch) +// return title[i + 1]; +// return toUpperCase(ch); + } + + /** + * Converts a character into a digit of the specified radix. If the radix + * exceeds MIN_RADIX or MAX_RADIX, or if the result of getNumericValue(ch) + * exceeds the radix, or if ch is not a decimal digit or in the case + * insensitive set of 'a'-'z', the result is -1. + *
+ * character argument boundary = [Nd]|U+0041-U+005A|U+0061-U+007A + * |U+FF21-U+FF3A|U+FF41-U+FF5A + * + * @param ch character to convert into a digit + * @param radix radix in which ch is a digit + * @return digit which ch represents in radix, or -1 not a valid digit + * @see #MIN_RADIX + * @see #MAX_RADIX + * @see #forDigit(int, int) + * @see #isDigit(char) + * @see #getNumericValue(char) + */ + public static int digit(char ch, int radix) + { + if (radix < MIN_RADIX || radix > MAX_RADIX) + return -1; + + /* + char attr = readChar(ch); + if (((1 << (attr & TYPE_MASK)) + & ((1 << UPPERCASE_LETTER) + | (1 << LOWERCASE_LETTER) + | (1 << DECIMAL_DIGIT_NUMBER))) != 0) + { + // Signedness doesn't matter; 0xffff vs. -1 are both rejected. + int digit = numValue[attr >> 7]; + return (digit < radix) ? digit : -1; + } + */ + if (radix == 2 || radix == 8 || radix == 10 || radix == 16) { + dynamic dig = mz.getNum(String.valueOf(ch), radix); + if ( mz.boolP(dig) ) + return -1; + else + return (dig < radix) ? dig : -1; + } + //return -1; + throw new RuntimeException("digit does not support character or radix given"); + } + + /** + * Returns the Unicode numeric value property of a character. For example, + * '\\u216C' (the Roman numeral fifty) returns 50. + * + *

This method also returns values for the letters A through Z, (not + * specified by Unicode), in these ranges: '\u0041' + * through '\u005A' (uppercase); '\u0061' + * through '\u007A' (lowercase); and '\uFF21' + * through '\uFF3A', '\uFF41' through + * '\uFF5A' (full width variants). + * + *

If the character lacks a numeric value property, -1 is returned. + * If the character has a numeric value property which is not representable + * as a nonnegative integer, such as a fraction, -2 is returned. + * + * character argument boundary = [Nd]|[Nl]|[No]|U+0041-U+005A|U+0061-U+007A + * |U+FF21-U+FF3A|U+FF41-U+FF5A + * + * @param ch character from which the numeric value property will + * be retrieved + * @return the numeric value property of ch, or -1 if it does not exist, or + * -2 if it is not representable as a nonnegative integer + * @see #forDigit(int, int) + * @see #digit(char, int) + * @see #isDigit(char) + * @since 1.1 + */ + public static int getNumericValue(char ch) + { throw new RuntimeException("getNumericeValue is unimplemented"); + // Treat numValue as signed. +// return (short) numValue[readChar(ch) >> 7]; + } + + /** + * Determines if a character is a ISO-LATIN-1 space. This is only the five + * characters '\t', '\n', '\f', + * '\r', and ' '. + *
+ * Java space = U+0020|U+0009|U+000A|U+000C|U+000D + * + * @param ch character to test + * @return true if ch is a space, else false + * @deprecated Replaced by {@link #isWhitespace(char)} + * @see #isSpaceChar(char) + * @see #isWhitespace(char) + */ + public static boolean isSpace(char ch) + { + // Performing the subtraction up front alleviates need to compare longs. + return ch-- <= ' ' && ((1 << ch) + & ((1 << (' ' - 1)) + | (1 << ('\t' - 1)) + | (1 << ('\n' - 1)) + | (1 << ('\r' - 1)) + | (1 << ('\f' - 1)))) != 0; + } + + /** + * Determines if a character is a Unicode space character. This includes + * SPACE_SEPARATOR, LINE_SEPARATOR, and PARAGRAPH_SEPARATOR. + *
+ * Unicode space = [Zs]|[Zp]|[Zl] + * + * @param ch character to test + * @return true if ch is a Unicode space, else false + * @see #isWhitespace(char) + * @since 1.1 + */ + public static boolean isSpaceChar(char ch) + { return mz.whitespaceP(ch); +/* return ((1 << getType(ch)) + & ((1 << SPACE_SEPARATOR) + | (1 << LINE_SEPARATOR) + | (1 << PARAGRAPH_SEPARATOR))) != 0; */ + } + + /** + * Determines if a character is Java whitespace. This includes Unicode + * space characters (SPACE_SEPARATOR, LINE_SEPARATOR, and + * PARAGRAPH_SEPARATOR) except the non-breaking spaces + * ('\u00A0', '\u2007', and '\u202F'); + * and these characters: '\u0009', '\u000A', + * '\u000B', '\u000C', '\u000D', + * '\u001C', '\u001D', '\u001E', + * and '\u001F'. + *
+ * Java whitespace = ([Zs] not Nb)|[Zl]|[Zp]|U+0009-U+000D|U+001C-U+001F + * + * @param ch character to test + * @return true if ch is Java whitespace, else false + * @see #isSpaceChar(char) + * @since 1.1 + */ + public static boolean isWhitespace(char ch) + { return mz.blankP(ch); + /*int attr = readChar(ch); + return ((((1 << (attr & TYPE_MASK)) + & ((1 << SPACE_SEPARATOR) + | (1 << LINE_SEPARATOR) + | (1 << PARAGRAPH_SEPARATOR))) != 0) + && (attr & NO_BREAK_MASK) == 0) + || (ch <= '\u001F' && ((1 << ch) + & ((1 << '\t') + | (1 << '\n') + | (1 << '\u000B') + | (1 << '\u000C') + | (1 << '\r') + | (1 << '\u001C') + | (1 << '\u001D') + | (1 << '\u001E') + | (1 << '\u001F'))) != 0); */ + } + + /** + * Determines if a character has the ISO Control property. + *
+ * ISO Control = [Cc] + * + * @param ch character to test + * @return true if ch is an ISO Control character, else false + * @see #isSpaceChar(char) + * @see #isWhitespace(char) + * @since 1.1 + */ + public static boolean isISOControl(char ch) + { return mz.isoControlP(ch); + //return getType(ch) == CONTROL; + } + + /** + * Returns the Unicode general category property of a character. + * + * @param ch character from which the general category property will + * be retrieved + * @return the character category property of ch as an integer + * @see #UNASSIGNED + * @see #UPPERCASE_LETTER + * @see #LOWERCASE_LETTER + * @see #TITLECASE_LETTER + * @see #MODIFIER_LETTER + * @see #OTHER_LETTER + * @see #NON_SPACING_MARK + * @see #ENCLOSING_MARK + * @see #COMBINING_SPACING_MARK + * @see #DECIMAL_DIGIT_NUMBER + * @see #LETTER_NUMBER + * @see #OTHER_NUMBER + * @see #SPACE_SEPARATOR + * @see #LINE_SEPARATOR + * @see #PARAGRAPH_SEPARATOR + * @see #CONTROL + * @see #FORMAT + * @see #PRIVATE_USE + * @see #SURROGATE + * @see #DASH_PUNCTUATION + * @see #START_PUNCTUATION + * @see #END_PUNCTUATION + * @see #CONNECTOR_PUNCTUATION + * @see #OTHER_PUNCTUATION + * @see #MATH_SYMBOL + * @see #CURRENCY_SYMBOL + * @see #MODIFIER_SYMBOL + * @see #INITIAL_QUOTE_PUNCTUATION + * @see #FINAL_QUOTE_PUNCTUATION + * @since 1.1 + */ + public static int getType(char ch) + { throw new RuntimeException("getType not implemented yet"); +// return readChar(ch) & TYPE_MASK; + } + + /** + * Converts a digit into a character which represents that digit + * in a specified radix. If the radix exceeds MIN_RADIX or MAX_RADIX, + * or the digit exceeds the radix, then the null character '\0' + * is returned. Otherwise the return value is in '0'-'9' and 'a'-'z'. + *
+ * return value boundary = U+0030-U+0039|U+0061-U+007A + * + * @param digit digit to be converted into a character + * @param radix radix of digit + * @return character representing digit in radix, or '\0' + * @see #MIN_RADIX + * @see #MAX_RADIX + * @see #digit(char, int) + */ + public static char forDigit(int digit, int radix) + { + if (radix < MIN_RADIX || radix > MAX_RADIX + || digit < 0 || digit >= radix) + return '\0'; + return Number.digits[digit]; + } + + /** + * Returns the Unicode directionality property of the character. This + * is used in the visual ordering of text. + * + * @param ch the character to look up + * @return the directionality constant, or DIRECTIONALITY_UNDEFINED + * @see #DIRECTIONALITY_UNDEFINED + * @see #DIRECTIONALITY_LEFT_TO_RIGHT + * @see #DIRECTIONALITY_RIGHT_TO_LEFT + * @see #DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC + * @see #DIRECTIONALITY_EUROPEAN_NUMBER + * @see #DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR + * @see #DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR + * @see #DIRECTIONALITY_ARABIC_NUMBER + * @see #DIRECTIONALITY_COMMON_NUMBER_SEPARATOR + * @see #DIRECTIONALITY_NONSPACING_MARK + * @see #DIRECTIONALITY_BOUNDARY_NEUTRAL + * @see #DIRECTIONALITY_PARAGRAPH_SEPARATOR + * @see #DIRECTIONALITY_SEGMENT_SEPARATOR + * @see #DIRECTIONALITY_WHITESPACE + * @see #DIRECTIONALITY_OTHER_NEUTRALS + * @see #DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING + * @see #DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE + * @see #DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING + * @see #DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE + * @see #DIRECTIONALITY_POP_DIRECTIONAL_FORMAT + * @since 1.4 + */ + public static byte getDirectionality(char ch) + { throw new RuntimeException("getDirectionality is unimplemented"); + // The result will correctly be signed. + //return (byte) (direction[readChar(ch) >> 7] >> 2); + } + + /** + * Determines whether the character is mirrored according to Unicode. For + * example, \u0028 (LEFT PARENTHESIS) appears as '(' in + * left-to-right text, but ')' in right-to-left text. + * + * @param ch the character to look up + * @return true if the character is mirrored + * @since 1.4 + */ + public static boolean isMirrored(char ch) + { throw new RuntimeException("isMirrored is unimplemented"); + //return (readChar(ch) & MIRROR_MASK) != 0; + } + + /** + * Compares another Character to this Character, numerically. + * + * @param anotherCharacter Character to compare with this Character + * @return a negative integer if this Character is less than + * anotherCharacter, zero if this Character is equal, and + * a positive integer if this Character is greater + * @throws NullPointerException if anotherCharacter is null + * @since 1.2 + */ + public int compareTo(Character anotherCharacter) + { + return value - anotherCharacter.value; + } + + /** + * Compares an object to this Character. Assuming the object is a + * Character object, this method performs the same comparison as + * compareTo(Character). + * + * @param o object to compare + * @return the comparison value + * @throws ClassCastException if o is not a Character object + * @throws NullPointerException if o is null + * @see #compareTo(Character) + * @since 1.2 + */ + public int compareTo(Object o) + { + return compareTo((Character) o); + } + +} // class Character + + + diff --git a/collects/profj/libs/java/lang/Integer.java b/collects/profj/libs/java/lang/Integer.java new file mode 100644 index 0000000000..23772e05ec --- /dev/null +++ b/collects/profj/libs/java/lang/Integer.java @@ -0,0 +1,608 @@ +/* Integer.java -- object wrapper for int + Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * Instances of class Integer represent primitive + * int values. + * + * Additionally, this class provides various helper functions and variables + * related to ints. + * + * @author Paul Fisher + * @author John Keiser + * @author Warren Levy + * @author Eric Blake + * @since 1.0 + * @status updated to 1.4 + */ +public final class Integer extends Number implements Comparable +{ + /** + * Compatible with JDK 1.0.2+. + */ + private static final long serialVersionUID = 1360826667806852920L; + + /** + * The minimum value an int can represent is -2147483648 (or + * -231). + */ + public static final int MIN_VALUE = 0x80000000; + + /** + * The maximum value an int can represent is 2147483647 (or + * 231 - 1). + */ + public static final int MAX_VALUE = 0x7fffffff; + + /** + * The primitive type int is represented by this + * Class object. + * @since 1.1 + */ + //public static final Class TYPE = VMClassLoader.getPrimitiveClass('I'); + + /** + * The immutable value of this Integer. + * + * @serial the wrapped int + */ + private final int value; + + /** + * Create an Integer object representing the value of the + * int argument. + * + * @param value the value to use + */ + public Integer(int value) + { + this.value = value; + } + + /** + * Create an Integer object representing the value of the + * argument after conversion to an int. + * + * @param s the string to convert + * @throws NumberFormatException if the String does not contain an int + * @see #valueOf(String) + */ + public Integer(String s) + { + value = parseInt(s, 10, false); + } + + /** + * Converts the int to a String using + * the specified radix (base). If the radix exceeds + * Character.MIN_RADIX or Character.MAX_RADIX, 10 + * is used instead. If the result is negative, the leading character is + * '-' ('\\u002D'). The remaining characters come from + * Character.forDigit(digit, radix) ('0'-'9','a'-'z'). + * + * @param num the int to convert to String + * @param radix the radix (base) to use in the conversion + * @return the String representation of the argument + */ + public static String toString(int num, int radix) + { + if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) + radix = 10; + + // For negative numbers, print out the absolute value w/ a leading '-'. + // Use an array large enough for a binary number. + char[] buffer = new char[33]; + int i = 33; + boolean isNeg = false; + if (num < 0) + { + isNeg = true; + num = -num; + + // When the value is MIN_VALUE, it overflows when made positive + if (num < 0) + { + buffer[--i] = digits[(int) (-(num + radix) % radix)]; + num = -(num / radix); + } + } + + do + { + buffer[--i] = digits[num % radix]; + num /= radix; + } + while (num > 0); + + if (isNeg) + buffer[--i] = '-'; + + // Package constructor avoids an array copy. + return new String(buffer, i, 33 - i); + } + + /** + * Converts the int to a String assuming it is + * unsigned in base 16. + * + * @param i the int to convert to String + * @return the String representation of the argument + */ + public static String toHexString(int i) + { + return toUnsignedString(i, 4); + } + + /** + * Converts the int to a String assuming it is + * unsigned in base 8. + * + * @param i the int to convert to String + * @return the String representation of the argument + */ + public static String toOctalString(int i) + { + return toUnsignedString(i, 3); + } + + /** + * Converts the int to a String assuming it is + * unsigned in base 2. + * + * @param i the int to convert to String + * @return the String representation of the argument + */ + public static String toBinaryString(int i) + { + return toUnsignedString(i, 1); + } + + /** + * Converts the int to a String and assumes + * a radix of 10. + * + * @param i the int to convert to String + * @return the String representation of the argument + * @see #toString(int, int) + */ + public static String toString(int i) + { + // This is tricky: in libgcj, String.valueOf(int) is a fast native + // implementation. In Classpath it just calls back to + // Integer.toString(int, int). + return String.valueOf(i); + } + + /** + * Converts the specified String into an int + * using the specified radix (base). The string must not be null + * or empty. It may begin with an optional '-', which will negate the answer, + * provided that there are also valid digits. Each digit is parsed as if by + * Character.digit(d, radix), and must be in the range + * 0 to radix - 1. Finally, the result must be + * within MIN_VALUE to MAX_VALUE, inclusive. + * Unlike Double.parseDouble, you may not have a leading '+'. + * + * @param str the String to convert + * @param radix the radix (base) to use in the conversion + * @return the String argument converted to int + * @throws NumberFormatException if s cannot be parsed as an + * int + */ + public static int parseInt(String str, int radix) + { + return parseInt(str, radix, false); + } + + /** + * Converts the specified String into an int. + * This function assumes a radix of 10. + * + * @param s the String to convert + * @return the int value of s + * @throws NumberFormatException if s cannot be parsed as an + * int + * @see #parseInt(String, int) + */ + public static int parseInt(String s) + { + return parseInt(s, 10, false); + } + + /** + * Creates a new Integer object using the String + * and specified radix (base). + * + * @param s the String to convert + * @param radix the radix (base) to convert with + * @return the new Integer + * @throws NumberFormatException if s cannot be parsed as an + * int + * @see #parseInt(String, int) + */ + public static Integer valueOf(String s, int radix) + { + return new Integer(parseInt(s, radix, false)); + } + + /** + * Creates a new Integer object using the String, + * assuming a radix of 10. + * + * @param s the String to convert + * @return the new Integer + * @throws NumberFormatException if s cannot be parsed as an + * int + * @see #Integer(String) + * @see #parseInt(String) + */ + public static Integer valueOf(String s) + { + return new Integer(parseInt(s, 10, false)); + } + + /** + * Return the value of this Integer as a byte. + * + * @return the byte value + */ + public byte byteValue() + { + return (byte) value; + } + + /** + * Return the value of this Integer as a short. + * + * @return the short value + */ + public short shortValue() + { + return (short) value; + } + + /** + * Return the value of this Integer. + * @return the int value + */ + public int intValue() + { + return value; + } + + /** + * Return the value of this Integer as a long. + * + * @return the long value + */ + public long longValue() + { + return value; + } + + /** + * Return the value of this Integer as a float. + * + * @return the float value + */ + public float floatValue() + { + return value; + } + + /** + * Return the value of this Integer as a double. + * + * @return the double value + */ + public double doubleValue() + { + return value; + } + + /** + * Converts the Integer value to a String and + * assumes a radix of 10. + * + * @return the String representation + */ + public String toString() + { + return String.valueOf(value); + } + + /** + * Return a hashcode representing this Object. Integer's hash + * code is simply its value. + * + * @return this Object's hash code + */ + public int hashCode() + { + return value; + } + + /** + * Returns true if obj is an instance of + * Integer and represents the same int value. + * + * @param obj the object to compare + * @return whether these Objects are semantically equal + */ + public boolean equals(Object obj) + { + return obj instanceof Integer && value == ((Integer) obj).value; + } + + /** + * Get the specified system property as an Integer. The + * decode() method will be used to interpret the value of + * the property. + * + * @param nm the name of the system property + * @return the system property as an Integer, or null if the + * property is not found or cannot be decoded + * @throws SecurityException if accessing the system property is forbidden + * @see System#getProperty(String) + * @see #decode(String) + */ + public static Integer getInteger(String nm) + { + return getInteger(nm, null); + } + + /** + * Get the specified system property as an Integer, or use a + * default int value if the property is not found or is not + * decodable. The decode() method will be used to interpret + * the value of the property. + * + * @param nm the name of the system property + * @param val the default value + * @return the value of the system property, or the default + * @throws SecurityException if accessing the system property is forbidden + * @see System#getProperty(String) + * @see #decode(String) + */ + public static Integer getInteger(String nm, int val) + { + Integer result = getInteger(nm, null); + return result == null ? new Integer(val) : result; + } + + /** + * Get the specified system property as an Integer, or use a + * default Integer value if the property is not found or is + * not decodable. The decode() method will be used to + * interpret the value of the property. + * + * @param nm the name of the system property + * @param def the default value + * @return the value of the system property, or the default + * @throws SecurityException if accessing the system property is forbidden + * @see System#getProperty(String) + * @see #decode(String) + */ + public static Integer getInteger(String nm, Integer def) + { + if (nm == null || "".equals(nm)) + return def; + else + return def; + /*nm = System.getProperty(nm); + if (nm == null) + return def; + try + { + return decode(nm); + } + catch (NumberFormatException e) + { + return def; + }*/ + } + + /** + * Convert the specified String into an Integer. + * The String may represent decimal, hexadecimal, or + * octal numbers. + * + *

The extended BNF grammar is as follows:
+ *

+   * DecodableString:
+   *      ( [ - ] DecimalNumber )
+   *    | ( [ - ] ( 0x | 0X
+   *              | # ) HexDigit { HexDigit } )
+   *    | ( [ - ] 0 { OctalDigit } )
+   * DecimalNumber:
+   *        DecimalDigit except '0' { DecimalDigit }
+   * DecimalDigit:
+   *        Character.digit(d, 10) has value 0 to 9
+   * OctalDigit:
+   *        Character.digit(d, 8) has value 0 to 7
+   * DecimalDigit:
+   *        Character.digit(d, 16) has value 0 to 15
+   * 
+ * Finally, the value must be in the range MIN_VALUE to + * MAX_VALUE, or an exception is thrown. + * + * @param str the String to interpret + * @return the value of the String as an Integer + * @throws NumberFormatException if s cannot be parsed as a + * int + * @throws NullPointerException if s is null + * @since 1.2 + */ + public static Integer decode(String str) + { + return new Integer(parseInt(str, 10, true)); + } + + /** + * Compare two Integers numerically by comparing their int + * values. The result is positive if the first is greater, negative if the + * second is greater, and 0 if the two are equal. + * + * @param i the Integer to compare + * @return the comparison + * @since 1.2 + */ + public int compareTo(Integer i) + { + if (value == i.value) + return 0; + // Returns just -1 or 1 on inequality; doing math might overflow. + return value > i.value ? 1 : -1; + } + + /** + * Behaves like compareTo(Integer) unless the Object + * is not an Integer. + * + * @param o the object to compare + * @return the comparison + * @throws ClassCastException if the argument is not an Integer + * @see #compareTo(Integer) + * @see Comparable + * @since 1.2 + */ + public int compareTo(Object o) + { + return compareTo((Integer) o); + } + + /** + * Helper for converting unsigned numbers to String. + * + * @param num the number + * @param exp log2(digit) (ie. 1, 3, or 4 for binary, oct, hex) + */ + // Package visible for use by Long. + static String toUnsignedString(int num, int exp) + { + // Use an array large enough for a binary number. + int mask = (1 << exp) - 1; + char[] buffer = new char[32]; + int i = 32; + do + { + buffer[--i] = digits[num & mask]; + num >>>= exp; + } + while (num != 0); + + // Package constructor avoids an array copy. + return new String(buffer, i, 32 - i); + } + + /** + * Helper for parsing ints, used by Integer, Short, and Byte. + * + * @param str the string to parse + * @param radix the radix to use, must be 10 if decode is true + * @param decode if called from decode + * @return the parsed int value + * @throws NumberFormatException if there is an error + * @throws NullPointerException if decode is true and str if null + * @see #parseInt(String, int) + * @see #decode(String) + * @see Byte#parseInt(String, int) + * @see Short#parseInt(String, int) + */ + static int parseInt(String str, int radix, boolean decode) + { + if (! decode && str == null) + throw new NumberFormatException("parseInt cannot convert an empty String into an int"); + int index = 0; + int len = str.length(); + boolean isNeg = false; + if (len == 0) + throw new NumberFormatException("parseInt cannot convert and empty String into an int"); + int ch = (int) str.charAt(index); + if (ch == '-') + { + if (len == 1) + throw new NumberFormatException("parseInt cannot convert - into an int"); + isNeg = true; + ch = str.charAt(++index); + } + if (decode) + { + if (ch == '0') + { + if (++index == len) + return 0; + if ((str.charAt(index) & ~('x' ^ 'X')) == 'X') + { + radix = 16; + index++; + } + else + radix = 8; + } + else if (ch == '#') + { + radix = 16; + index++; + } + } + if (index == len) + throw new NumberFormatException("parseInt cannot convert " + str + " into an int"); + + int max = MAX_VALUE / radix; + // We can't directly write `max = (MAX_VALUE + 1) / radix'. + // So instead we fake it. + if (isNeg && MAX_VALUE % radix == radix - 1) + ++max; + + int val = 0; + while (index < len) + { + if (val < 0 || val > max) + throw new NumberFormatException("Number given to parseInt exceeded allowed size."); + + ch = Character.digit(str.charAt(index++), radix); + val = val * radix + ch; + if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE))) + throw new NumberFormatException("Input given to parseInt contains non-numeric character"); + } + return isNeg ? -val : val; + } +} diff --git a/collects/profj/libs/java/lang/Long.java b/collects/profj/libs/java/lang/Long.java new file mode 100644 index 0000000000..734734da98 --- /dev/null +++ b/collects/profj/libs/java/lang/Long.java @@ -0,0 +1,616 @@ +/* Long.java -- object wrapper for long + Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * Instances of class Long represent primitive + * long values. + * + * Additionally, this class provides various helper functions and variables + * related to longs. + * + * @author Paul Fisher + * @author John Keiser + * @author Warren Levy + * @author Eric Blake + * @since 1.0 + * @status updated to 1.4 + */ +public final class Long extends Number implements Comparable +{ + /** + * Compatible with JDK 1.0.2+. + */ + private static final long serialVersionUID = 4290774380558885855L; + + /** + * The minimum value a long can represent is + * -9223372036854775808L (or -263). + */ + public static final long MIN_VALUE = 0x8000000000000000L; + + /** + * The maximum value a long can represent is + * 9223372036854775807 (or 263 - 1). + */ + public static final long MAX_VALUE = 0x7fffffffffffffffL; + + /** + * The primitive type long is represented by this + * Class object. + * @since 1.1 + */ + //public static final Class TYPE = VMClassLoader.getPrimitiveClass ('J'); + + /** + * The immutable value of this Long. + * + * @serial the wrapped long + */ + private final long value; + + /** + * Create a Long object representing the value of the + * long argument. + * + * @param value the value to use + */ + public Long(long value) + { + this.value = value; + } + + /** + * Create a Long object representing the value of the + * argument after conversion to a long. + * + * @param s the string to convert + * @throws NumberFormatException if the String does not contain a long + * @see #valueOf(String) + */ + public Long(String s) + { + value = parseLong(s, 10, false); + } + + /** + * Converts the long to a String using + * the specified radix (base). If the radix exceeds + * Character.MIN_RADIX or Character.MAX_RADIX, 10 + * is used instead. If the result is negative, the leading character is + * '-' ('\\u002D'). The remaining characters come from + * Character.forDigit(digit, radix) ('0'-'9','a'-'z'). + * + * @param num the long to convert to String + * @param radix the radix (base) to use in the conversion + * @return the String representation of the argument + */ + public static String toString(long num, int radix) + { + // Use the Integer toString for efficiency if possible. + if ((int) num == num) + return Integer.toString((int) num, radix); + + if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) + radix = 10; + + // For negative numbers, print out the absolute value w/ a leading '-'. + // Use an array large enough for a binary number. + char[] buffer = new char[65]; + int i = 65; + boolean isNeg = false; + if (num < 0) + { + isNeg = true; + num = -num; + + // When the value is MIN_VALUE, it overflows when made positive + if (num < 0) + { + buffer[--i] = digits[(int) (-(num + radix) % radix)]; + num = -(num / radix); + } + } + + do + { + buffer[--i] = digits[(int) (num % radix)]; + num /= radix; + } + while (num > 0); + + if (isNeg) + buffer[--i] = '-'; + + // Package constructor avoids an array copy. + return new String(buffer, i, 65 - i); + } + + /** + * Converts the long to a String assuming it is + * unsigned in base 16. + * + * @param l the long to convert to String + * @return the String representation of the argument + */ + public static String toHexString(long l) + { + return toUnsignedString(l, 4); + } + + /** + * Converts the long to a String assuming it is + * unsigned in base 8. + * + * @param l the long to convert to String + * @return the String representation of the argument + */ + public static String toOctalString(long l) + { + return toUnsignedString(l, 3); + } + + /** + * Converts the long to a String assuming it is + * unsigned in base 2. + * + * @param l the long to convert to String + * @return the String representation of the argument + */ + public static String toBinaryString(long l) + { + return toUnsignedString(l, 1); + } + + /** + * Converts the long to a String and assumes + * a radix of 10. + * + * @param num the long to convert to String + * @return the String representation of the argument + * @see #toString(long, int) + */ + public static String toString(long num) + { + return toString(num, 10); + } + + /** + * Converts the specified String into an int + * using the specified radix (base). The string must not be null + * or empty. It may begin with an optional '-', which will negate the answer, + * provided that there are also valid digits. Each digit is parsed as if by + * Character.digit(d, radix), and must be in the range + * 0 to radix - 1. Finally, the result must be + * within MIN_VALUE to MAX_VALUE, inclusive. + * Unlike Double.parseDouble, you may not have a leading '+'; and 'l' or + * 'L' as the last character is only valid in radices 22 or greater, where + * it is a digit and not a type indicator. + * + * @param str the String to convert + * @param radix the radix (base) to use in the conversion + * @return the String argument converted to long + * @throws NumberFormatException if s cannot be parsed as a + * long + */ + public static long parseLong(String str, int radix) + { + return parseLong(str, radix, false); + } + + /** + * Converts the specified String into a long. + * This function assumes a radix of 10. + * + * @param s the String to convert + * @return the int value of s + * @throws NumberFormatException if s cannot be parsed as a + * long + * @see #parseLong(String, int) + */ + public static long parseLong(String s) + { + return parseLong(s, 10, false); + } + + /** + * Creates a new Long object using the String + * and specified radix (base). + * + * @param s the String to convert + * @param radix the radix (base) to convert with + * @return the new Long + * @throws NumberFormatException if s cannot be parsed as a + * long + * @see #parseLong(String, int) + */ + public static Long valueOf(String s, int radix) + { + return new Long(parseLong(s, radix, false)); + } + + /** + * Creates a new Long object using the String, + * assuming a radix of 10. + * + * @param s the String to convert + * @return the new Long + * @throws NumberFormatException if s cannot be parsed as a + * long + * @see #Long(String) + * @see #parseLong(String) + */ + public static Long valueOf(String s) + { + return new Long(parseLong(s, 10, false)); + } + + /** + * Convert the specified String into a Long. + * The String may represent decimal, hexadecimal, or + * octal numbers. + * + *

The extended BNF grammar is as follows:
+ *

+   * DecodableString:
+   *      ( [ - ] DecimalNumber )
+   *    | ( [ - ] ( 0x | 0X
+   *              | # ) HexDigit { HexDigit } )
+   *    | ( [ - ] 0 { OctalDigit } )
+   * DecimalNumber:
+   *        DecimalDigit except '0' { DecimalDigit }
+   * DecimalDigit:
+   *        Character.digit(d, 10) has value 0 to 9
+   * OctalDigit:
+   *        Character.digit(d, 8) has value 0 to 7
+   * DecimalDigit:
+   *        Character.digit(d, 16) has value 0 to 15
+   * 
+ * Finally, the value must be in the range MIN_VALUE to + * MAX_VALUE, or an exception is thrown. Note that you cannot + * use a trailing 'l' or 'L', unlike in Java source code. + * + * @param str the String to interpret + * @return the value of the String as a Long + * @throws NumberFormatException if s cannot be parsed as a + * long + * @throws NullPointerException if s is null + * @since 1.2 + */ + public static Long decode(String str) + { + return new Long(parseLong(str, 10, true)); + } + + /** + * Return the value of this Long as a byte. + * + * @return the byte value + */ + public byte byteValue() + { + return (byte) value; + } + + /** + * Return the value of this Long as a short. + * + * @return the short value + */ + public short shortValue() + { + return (short) value; + } + + /** + * Return the value of this Long as an int. + * + * @return the int value + */ + public int intValue() + { + return (int) value; + } + + /** + * Return the value of this Long. + * + * @return the long value + */ + public long longValue() + { + return value; + } + + /** + * Return the value of this Long as a float. + * + * @return the float value + */ + public float floatValue() + { + return value; + } + + /** + * Return the value of this Long as a double. + * + * @return the double value + */ + public double doubleValue() + { + return value; + } + + /** + * Converts the Long value to a String and + * assumes a radix of 10. + * + * @return the String representation + */ + public String toString() + { + return toString(value, 10); + } + + /** + * Return a hashcode representing this Object. Long's hash + * code is calculated by (int) (value ^ (value >> 32)). + * + * @return this Object's hash code + */ + public int hashCode() + { + return (int) (value ^ (value >>> 32)); + } + + /** + * Returns true if obj is an instance of + * Long and represents the same long value. + * + * @param obj the object to compare + * @return whether these Objects are semantically equal + */ + public boolean equals(Object obj) + { + return obj instanceof Long && value == ((Long) obj).value; + } + + /** + * Get the specified system property as a Long. The + * decode() method will be used to interpret the value of + * the property. + * + * @param nm the name of the system property + * @return the system property as a Long, or null if the + * property is not found or cannot be decoded + * @throws SecurityException if accessing the system property is forbidden + * @see System#getProperty(String) + * @see #decode(String) + */ + public static Long getLong(String nm) + { + return getLong(nm, null); + } + + /** + * Get the specified system property as a Long, or use a + * default long value if the property is not found or is not + * decodable. The decode() method will be used to interpret + * the value of the property. + * + * @param nm the name of the system property + * @param val the default value + * @return the value of the system property, or the default + * @throws SecurityException if accessing the system property is forbidden + * @see System#getProperty(String) + * @see #decode(String) + */ + public static Long getLong(String nm, long val) + { + Long result = getLong(nm, null); + return result == null ? new Long(val) : result; + } + + /** + * Get the specified system property as a Long, or use a + * default Long value if the property is not found or is + * not decodable. The decode() method will be used to + * interpret the value of the property. + * + * @param nm the name of the system property + * @param def the default value + * @return the value of the system property, or the default + * @throws SecurityException if accessing the system property is forbidden + * @see System#getProperty(String) + * @see #decode(String) + */ + public static Long getLong(String nm, Long def) + { + if (nm == null || "".equals(nm)) + return def; + else + return def; + /*nm = System.getProperty(nm); + if (nm == null) + return def; + try + { + return decode(nm); + } + catch (NumberFormatException e) + { + return def; + }*/ + } + + /** + * Compare two Longs numerically by comparing their long + * values. The result is positive if the first is greater, negative if the + * second is greater, and 0 if the two are equal. + * + * @param l the Long to compare + * @return the comparison + * @since 1.2 + */ + public int compareTo(Long l) + { + if (value == l.value) + return 0; + // Returns just -1 or 1 on inequality; doing math might overflow the long. + return value > l.value ? 1 : -1; + } + + /** + * Behaves like compareTo(Long) unless the Object + * is not a Long. + * + * @param o the object to compare + * @return the comparison + * @throws ClassCastException if the argument is not a Long + * @see #compareTo(Long) + * @see Comparable + * @since 1.2 + */ + public int compareTo(Object o) + { + return compareTo((Long) o); + } + + /** + * Helper for converting unsigned numbers to String. + * + * @param num the number + * @param exp log2(digit) (ie. 1, 3, or 4 for binary, oct, hex) + */ + private static String toUnsignedString(long num, int exp) + { + // Use the Integer toUnsignedString for efficiency if possible. + // If NUM<0 then this particular optimization doesn't work + // properly. + if (num >= 0 && (int) num == num) + return Integer.toUnsignedString((int) num, exp); + + // Use an array large enough for a binary number. + int mask = (1 << exp) - 1; + char[] buffer = new char[64]; + int i = 64; + do + { + buffer[--i] = digits[(int) num & mask]; + num >>>= exp; + } + while (num != 0); + + // Package constructor avoids an array copy. + return new String(buffer, i, 64 - i); + } + + /** + * Helper for parsing longs. + * + * @param str the string to parse + * @param radix the radix to use, must be 10 if decode is true + * @param decode if called from decode + * @return the parsed long value + * @throws NumberFormatException if there is an error + * @throws NullPointerException if decode is true and str is null + * @see #parseLong(String, int) + * @see #decode(String) + */ + private static long parseLong(String str, int radix, boolean decode) + { + if (! decode && str == null) + throw new NumberFormatException(); + int index = 0; + int len = str.length(); + boolean isNeg = false; + if (len == 0) + throw new NumberFormatException(); + int ch = str.charAt(index); + if (ch == '-') + { + if (len == 1) + throw new NumberFormatException(); + isNeg = true; + ch = str.charAt(++index); + } + if (decode) + { + if (ch == '0') + { + if (++index == len) + return 0; + if ((str.charAt(index) & ~('x' ^ 'X')) == 'X') + { + radix = 16; + index++; + } + else + radix = 8; + } + else if (ch == '#') + { + radix = 16; + index++; + } + } + if (index == len) + throw new NumberFormatException(); + + long max = MAX_VALUE / radix; + // We can't directly write `max = (MAX_VALUE + 1) / radix'. + // So instead we fake it. + if (isNeg && MAX_VALUE % radix == radix - 1) + ++max; + + long val = 0; + while (index < len) + { + if (val < 0 || val > max) + throw new NumberFormatException(); + + ch = Character.digit(str.charAt(index++), radix); + val = val * radix + ch; + if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE))) + throw new NumberFormatException(); + } + return isNeg ? -val : val; + } +} diff --git a/collects/profj/libs/java/lang/Short.java b/collects/profj/libs/java/lang/Short.java new file mode 100644 index 0000000000..a915223a1a --- /dev/null +++ b/collects/profj/libs/java/lang/Short.java @@ -0,0 +1,353 @@ +/* Short.java -- object wrapper for short + Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * Instances of class Short represent primitive + * short values. + * + * Additionally, this class provides various helper functions and variables + * related to shorts. + * + * @author Paul Fisher + * @author John Keiser + * @author Eric Blake + * @since 1.1 + * @status updated to 1.4 + */ +public final class Short extends Number implements Comparable +{ + /** + * Compatible with JDK 1.1+. + */ + private static final long serialVersionUID = 7515723908773894738L; + + /** + * The minimum value a short can represent is -32768 (or + * -215). + */ + public static final short MIN_VALUE = (short) -32768; + + /** + * The minimum value a short can represent is 32767 (or + * 215). + */ + public static final short MAX_VALUE = (short) 32767; + + /** + * The primitive type short is represented by this + * Class object. + */ + //public static final Class TYPE = VMClassLoader.getPrimitiveClass('S'); + + /** + * The immutable value of this Short. + * + * @serial the wrapped short + */ + private final short value; + + /** + * Create a Short object representing the value of the + * short argument. + * + * @param value the value to use + */ + public Short(short value) + { + this.value = value; + } + + /** + * Create a Short object representing the value of the + * argument after conversion to a short. + * + * @param s the string to convert + * @throws NumberFormatException if the String cannot be parsed + */ + public Short(String s) + { + value = parseShort(s, 10); + } + + /** + * Converts the short to a String and assumes + * a radix of 10. + * + * @param s the short to convert to String + * @return the String representation of the argument + */ + public static String toString(short s) + { + return String.valueOf((int) s); + } + + /** + * Converts the specified String into a short. + * This function assumes a radix of 10. + * + * @param s the String to convert + * @return the short value of s + * @throws NumberFormatException if s cannot be parsed as a + * short + */ + public static short parseShort(String s) + { + return parseShort(s, 10); + } + + /** + * Converts the specified String into a short + * using the specified radix (base). The string must not be null + * or empty. It may begin with an optional '-', which will negate the answer, + * provided that there are also valid digits. Each digit is parsed as if by + * Character.digit(d, radix), and must be in the range + * 0 to radix - 1. Finally, the result must be + * within MIN_VALUE to MAX_VALUE, inclusive. + * Unlike Double.parseDouble, you may not have a leading '+'. + * + * @param s the String to convert + * @param radix the radix (base) to use in the conversion + * @return the String argument converted to short + * @throws NumberFormatException if s cannot be parsed as a + * short + */ + public static short parseShort(String s, int radix) + { + int i = Integer.parseInt(s, radix, false); + if ((short) i != i) + throw new NumberFormatException(); + return (short) i; + } + + /** + * Creates a new Short object using the String + * and specified radix (base). + * + * @param s the String to convert + * @param radix the radix (base) to convert with + * @return the new Short + * @throws NumberFormatException if s cannot be parsed as a + * short + * @see #parseShort(String, int) + */ + public static Short valueOf(String s, int radix) + { + return new Short(parseShort(s, radix)); + } + + /** + * Creates a new Short object using the String, + * assuming a radix of 10. + * + * @param s the String to convert + * @return the new Short + * @throws NumberFormatException if s cannot be parsed as a + * short + * @see #Short(String) + * @see #parseShort(String) + */ + public static Short valueOf(String s) + { + return new Short(parseShort(s, 10)); + } + + /** + * Convert the specified String into a Short. + * The String may represent decimal, hexadecimal, or + * octal numbers. + * + *

The extended BNF grammar is as follows:
+ *

+   * DecodableString:
+   *      ( [ - ] DecimalNumber )
+   *    | ( [ - ] ( 0x | 0X
+   *              | # ) HexDigit { HexDigit } )
+   *    | ( [ - ] 0 { OctalDigit } )
+   * DecimalNumber:
+   *        DecimalDigit except '0' { DecimalDigit }
+   * DecimalDigit:
+   *        Character.digit(d, 10) has value 0 to 9
+   * OctalDigit:
+   *        Character.digit(d, 8) has value 0 to 7
+   * DecimalDigit:
+   *        Character.digit(d, 16) has value 0 to 15
+   * 
+ * Finally, the value must be in the range MIN_VALUE to + * MAX_VALUE, or an exception is thrown. + * + * @param s the String to interpret + * @return the value of the String as a Short + * @throws NumberFormatException if s cannot be parsed as a + * short + * @throws NullPointerException if s is null + * @see Integer#decode(String) + */ + public static Short decode(String s) + { + int i = Integer.parseInt(s, 10, true); + if ((short) i != i) + throw new NumberFormatException(); + return new Short((short) i); + } + + /** + * Return the value of this Short as a byte. + * + * @return the byte value + */ + public byte byteValue() + { + return (byte) value; + } + + /** + * Return the value of this Short. + * + * @return the short value + */ + public short shortValue() + { + return value; + } + + /** + * Return the value of this Short as an int. + * + * @return the int value + */ + public int intValue() + { + return value; + } + + /** + * Return the value of this Short as a long. + * + * @return the long value + */ + public long longValue() + { + return value; + } + + /** + * Return the value of this Short as a float. + * + * @return the float value + */ + public float floatValue() + { + return value; + } + + /** + * Return the value of this Short as a double. + * + * @return the double value + */ + public double doubleValue() + { + return value; + } + + /** + * Converts the Short value to a String and + * assumes a radix of 10. + * + * @return the String representation of this Short + */ + public String toString() + { + return String.valueOf((int) value); + } + + /** + * Return a hashcode representing this Object. Short's hash + * code is simply its value. + * + * @return this Object's hash code + */ + public int hashCode() + { + return value; + } + + /** + * Returns true if obj is an instance of + * Short and represents the same short value. + * + * @param obj the object to compare + * @return whether these Objects are semantically equal + */ + public boolean equals(Object obj) + { + return obj instanceof Short && value == ((Short) obj).value; + } + + /** + * Compare two Shorts numerically by comparing their short + * values. The result is positive if the first is greater, negative if the + * second is greater, and 0 if the two are equal. + * + * @param s the Short to compare + * @return the comparison + * @since 1.2 + */ + public int compareTo(Short s) + { + return value - s.value; + } + + /** + * Behaves like compareTo(Short) unless the Object + * is not a Short. + * + * @param o the object to compare + * @return the comparison + * @throws ClassCastException if the argument is not a Short + * @see #compareTo(Short) + * @see Comparable + * @since 1.2 + */ + public int compareTo(Object o) + { + return compareTo((Short)o); + } +} diff --git a/collects/profj/libs/java/lang/installer.ss b/collects/profj/libs/java/lang/installer.ss index e810699e01..0299e650cc 100644 --- a/collects/profj/libs/java/lang/installer.ss +++ b/collects/profj/libs/java/lang/installer.ss @@ -17,10 +17,22 @@ #f #f)))]) (javac "Util.djava") + ;(printf "util~n") (javac "Math.java") + ;(printf "math~n") (javac "System.java") + ;(printf "sys~n") (javac "Number.java") + ;(printf "num~n") + (javac "Boolean.java") + ;(printf "boolean ~n") + (javac "Character.djava") + ;(printf "character ~n") + (javac "Integer.java") + ;(printf "integer~n") + (javac "Short.java") + (javac "Byte.java") + (javac "Long.java") (javac "Double.java") (javac "Float.java") - (javac "Boolean.java") (javac "CharSequence.java"))))) diff --git a/collects/profj/libs/java/lang/mz.ss b/collects/profj/libs/java/lang/mz.ss new file mode 100644 index 0000000000..450fbb48ea --- /dev/null +++ b/collects/profj/libs/java/lang/mz.ss @@ -0,0 +1,17 @@ +(module mz mzscheme + (provide (all-defined)) + + (define downcase char-downcase) + (define lower-case? char-lower-case?) + (define upcase char-upcase) + (define upper-case? char-upper-case?) + (define title-case? char-title-case?) + (define numeric? char-numeric?) + (define alphabetic? char-alphabetic?) + (define titlecase char-titlecase) + (define whitespace? char-whitespace?) + (define blank? char-blank?) + (define iso-control? char-iso-control?) + (define get-num string->number) + (define bool? boolean?) + ) \ No newline at end of file diff --git a/collects/profj/tester.scm b/collects/profj/tester.scm index 4880080132..1528b21a1d 100644 --- a/collects/profj/tester.scm +++ b/collects/profj/tester.scm @@ -179,14 +179,16 @@ (send current-tab current-test-editor content) (unless curr-win (send current-tab current-test-window window) - (send drscheme-frame register-test-window window)) - (send window update-switch - (lambda () (send drscheme-frame dock-tests))) - (send window update-closer - (lambda() - (send drscheme-frame deregister-test-window window) - (send current-tab current-test-window #f) - (send current-tab current-test-editor #f))) + (send drscheme-frame register-test-window window) + (send window update-switch + (lambda () (send drscheme-frame dock-tests))) + (send window update-disable + (lambda () (send current-tab update-test-preference #f))) + (send window update-closer + (lambda() + (send drscheme-frame deregister-test-window window) + (send current-tab current-test-window #f) + (send current-tab current-test-editor #f)))) (if (get-preference 'profj:test-window:docked? (lambda () (put-preferences '(profj:test-window:docked?) '(#f)) #f)) (send drscheme-frame display-test-panel content) @@ -281,6 +283,7 @@ (define editor #f) (define switch-func void) + (define disable-func void) (define close-cleanup void) (define content @@ -302,7 +305,7 @@ button-panel (lambda (b c) (when (eq? 'button (send c get-event-type)) - (put-preferences '(profj:test-enable) '(#f)) + (disable-func) (close-cleanup) (send this show #f)))) (make-object button% @@ -324,6 +327,8 @@ (set! switch-func thunk)) (define/public (update-closer thunk) (set! close-cleanup thunk)) + (define/public (update-disable thunk) + (set! disable-func thunk)) )) (define test-panel% @@ -356,7 +361,7 @@ (lambda (b c) (when (eq? 'button (send c get-event-type)) (hide) - (put-preferences '(profj:test-enable) '(#f))))) + (send (send frame get-current-tab) update-test-preference #f)))) (make-object button% (string-constant undock) button-panel @@ -563,7 +568,7 @@ (class % () (inherit get-current-tab) - + (define/public (display-test-panel editor) (send test-panel update-editor editor) (unless (send test-panel is-shown?) @@ -618,7 +623,7 @@ (define (test-tab%-mixin %) (class % () - (inherit get-frame) + (inherit get-frame get-defs) (define test-editor #f) (define/public (get-test-editor) test-editor) @@ -630,6 +635,25 @@ (define/public (current-test-window w) (set! test-window w)) + (define/public (update-test-preference test?) + (let* ([language-settings + (preferences:get + (drscheme:language-configuration:get-settings-preferences-symbol))] + [language + (drscheme:language-configuration:language-settings-language + language-settings)] + [settings + (drscheme:language-configuration:language-settings-settings + language-settings)]) + (when (object-method-arity-includes? language 'update-test-setting 2) + (let ((next-setting (drscheme:language-configuration:make-language-settings + language + (send language update-test-setting settings test?)))) + (preferences:set + (drscheme:language-configuration:get-settings-preferences-symbol) + next-setting) + (send (get-defs) set-next-settings next-setting))))) + (define/augment (on-close) (when test-window (when (send test-window is-shown?) diff --git a/collects/profj/tool.ss b/collects/profj/tool.ss index 39225f431f..6f53a7fcbc 100644 --- a/collects/profj/tool.ss +++ b/collects/profj/tool.ss @@ -179,9 +179,17 @@ (define/public (default-settings) (if (memq level `(beginner intermediate advanced)) (make-profj-settings 'field #f #t #t #t null) - (make-profj-settings 'type #f #t #f #t null))) + (make-profj-settings 'type #f #t #f #f null))) ;default-settings? any -> bool (define/public (default-settings? s) (equal? s (default-settings))) + + (define/public (update-test-setting s test?) + (make-profj-settings (profj-settings-print-style s) + (profj-settings-print-full? s) + (profj-settings-allow-check? s) + test? + (profj-settings-coverage? s) + (profj-settings-classpath s))) ;marshall-settings: profj-settings -> (list (list symbol) (list bool) (list string)) (define/public (marshall-settings s) @@ -200,8 +208,7 @@ (pair? (cadddr s)) (= (length (cadddr s)) 1) (pair? (list-ref s 4)) (= (length (list-ref s 4)) 1)) (make-profj-settings (caar s) (caadr s) (caaddr s) - (get-preference 'profj:test-enable - (lambda () (car (cadddr s)))) + (car (cadddr s)) (car (list-ref s 4)) null) #f)) @@ -248,8 +255,6 @@ [update-at (lambda () (void))] [update-dt (lambda (box event) (when (eq? 'check-box (send event get-event-type)) - (put-preferences '(profj:test-enable) - `(,(send box get-value))) (send collect-coverage enable (send box get-value))))] [update-cc (lambda () (void))] @@ -414,8 +419,7 @@ (send print-full set-value (profj-settings-print-full? settings))) (when (eq? level 'full) (send allow-testing set-value (profj-settings-allow-check? settings))) - (send display-testing set-value - (get-preference 'profj:test-enable (lambda () (profj-settings-run-tests? settings)))) + (send display-testing set-value (profj-settings-run-tests? settings)) (if (send display-testing get-value) (send collect-coverage set-value (profj-settings-coverage? settings)) (send collect-coverage enable #f)) @@ -590,17 +594,13 @@ [n (current-namespace)] [e (current-eventspace)]) (test-ext? (profj-settings-allow-check? settings)) - (tests? (get-preference 'profj:test-enable - (lambda () (profj-settings-run-tests? settings)))) - (coverage? (profj-settings-coverage? settings)) (let ((execute-types (create-type-record))) (read-case-sensitive #t) (run-in-user-thread (lambda () (test-ext? (profj-settings-allow-check? settings)) - (tests? (get-preference 'profj:test-enable - (lambda () (profj-settings-run-tests? settings)))) - (coverage? (profj-settings-coverage? settings)) + (tests? (profj-settings-run-tests? settings)) + (coverage? (and (tests?) (profj-settings-coverage? settings))) (error-display-handler (drscheme:debug:make-debug-error-display-handler (error-display-handler))) (let ((old-current-eval (drscheme:debug:make-debug-eval-handler (current-eval)))) diff --git a/collects/tests/profj/advanced-tests.ss b/collects/tests/profj/advanced-tests.ss index 8367adb7a2..22f492be64 100644 --- a/collects/tests/profj/advanced-tests.ss +++ b/collects/tests/profj/advanced-tests.ss @@ -6,6 +6,17 @@ ;;Execution tests without errors + (execute-test + "class OneC { } + class TwoC extends OneC { } + class ThreeC extends TwoC { } + class Overload { + int num(OneC o) { return 1; } + int num(TwoC o) { return 2; } + int t() { return num(new ThreeC()); } + } + " 'advanced #f "Overloading resolution") + (execute-test "class Checkclass { } class ExampleCheck { @@ -294,8 +305,12 @@ class WeeklyPlanner{ ;;Interaction tests, mix of right and error - (interact-test 'advanced '("int a = 1;" "++a") '((void) 2) "Test of ++") + (interact-test + 'advanced + '("int a = 'a';" "a" "int b;" "b = 'a';") + '((void) 97 (void) 97) "Conversion of char to int") + (interact-test 'advanced '("int a = 1;" "++a") '((void) 2) "Test of ++") (interact-test 'advanced diff --git a/collects/tests/profj/full-tests.ss b/collects/tests/profj/full-tests.ss index 32b9e301bd..269f9813da 100644 --- a/collects/tests/profj/full-tests.ss +++ b/collects/tests/profj/full-tests.ss @@ -4,6 +4,11 @@ (prepare-for-tests "Full") + (execute-test + "class hasCharArray { + char[] b = new char[]{'a'}; + }" 'full #f "Test of array alloc init") + (execute-test "class Aextendee { int f (Aextendee x) { return 4; } diff --git a/collects/tests/profj/intermediate-tests.ss b/collects/tests/profj/intermediate-tests.ss index dce8e731d7..a479264aa1 100644 --- a/collects/tests/profj/intermediate-tests.ss +++ b/collects/tests/profj/intermediate-tests.ss @@ -21,6 +21,15 @@ 'intermediate #f "class implementing abstract class's unimplmenented interface") + (execute-test + "interface ToImplement { int a(); } + abstract class ToExtend implements ToImplement { int a() { return 2; } } + class ToBe extends ToExtend implements ToImplement { + }" + 'intermediate + #f "Repetition of fully satisfied interface in class hierarchy") + + (execute-test "abstract class Foo { abstract int f();