From 8f523f3a1047919d3563daf1ef47ba87336ebe89 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 15 Nov 2005 23:20:01 +0000 Subject: Imported GNU Classpath 0.19 + gcj-import-20051115. * sources.am: Regenerated. * Makefile.in: Likewise. * scripts/makemake.tcl: Use glob -nocomplain. From-SVN: r107049 --- libjava/classpath/java/lang/Boolean.java | 32 +++ libjava/classpath/java/lang/Byte.java | 32 ++- libjava/classpath/java/lang/Character.java | 275 ++++++++++++++++++++- libjava/classpath/java/lang/Class.java | 11 +- libjava/classpath/java/lang/ClassLoader.java | 36 ++- libjava/classpath/java/lang/Double.java | 23 +- .../java/lang/EnumConstantNotPresentException.java | 93 +++++++ libjava/classpath/java/lang/Float.java | 22 ++ libjava/classpath/java/lang/Integer.java | 4 +- libjava/classpath/java/lang/Long.java | 153 +++++++++++- libjava/classpath/java/lang/Object.java | 4 +- libjava/classpath/java/lang/Process.java | 1 + libjava/classpath/java/lang/Readable.java | 1 + libjava/classpath/java/lang/RuntimePermission.java | 1 + libjava/classpath/java/lang/SecurityManager.java | 30 ++- libjava/classpath/java/lang/Short.java | 44 ++++ libjava/classpath/java/lang/StrictMath.java | 10 +- libjava/classpath/java/lang/String.java | 207 ++++++++++++++-- libjava/classpath/java/lang/StringBuffer.java | 259 ++++++++++++++++++- libjava/classpath/java/lang/StringBuilder.java | 65 +++++ libjava/classpath/java/lang/System.java | 2 +- libjava/classpath/java/lang/Thread.java | 12 +- libjava/classpath/java/lang/ThreadLocal.java | 1 - libjava/classpath/java/lang/ref/Reference.java | 6 +- libjava/classpath/java/lang/ref/WeakReference.java | 2 +- libjava/classpath/java/lang/reflect/Member.java | 4 +- libjava/classpath/java/lang/reflect/Proxy.java | 19 +- .../lang/reflect/UndeclaredThrowableException.java | 2 +- 28 files changed, 1273 insertions(+), 78 deletions(-) create mode 100644 libjava/classpath/java/lang/EnumConstantNotPresentException.java (limited to 'libjava/classpath/java/lang') diff --git a/libjava/classpath/java/lang/Boolean.java b/libjava/classpath/java/lang/Boolean.java index b691028..902c93b 100644 --- a/libjava/classpath/java/lang/Boolean.java +++ b/libjava/classpath/java/lang/Boolean.java @@ -221,4 +221,36 @@ public final class Boolean implements Serializable return false; return "true".equalsIgnoreCase(System.getProperty(name)); } + + /** + * If the String argument is "true", ignoring case, return true. + * Otherwise, return false. + * + * @param b String to parse + * @since 1.5 + */ + public static boolean parseBoolean(String b) + { + return "true".equalsIgnoreCase(b) ? true : false; + } + + /** + * Compares this Boolean to another. + * @param b the Boolean to compare this Boolean to + * @return 0 if both Booleans represent the same value, a positive number + * if this Boolean represents true and b represents false, or a negative + * number otherwise. + * @since 1.5 + */ + public int compareTo (Boolean b) + { + if (b == null) + throw new NullPointerException("argument passed to compareTo(Boolean) cannot be null"); + + if (this.value == b.value) + return 0; + if (this.value == true) + return 1; + return -1; + } } diff --git a/libjava/classpath/java/lang/Byte.java b/libjava/classpath/java/lang/Byte.java index 338e216..2560bfc 100644 --- a/libjava/classpath/java/lang/Byte.java +++ b/libjava/classpath/java/lang/Byte.java @@ -50,7 +50,7 @@ package java.lang; * @author Per Bothner * @author Eric Blake (ebb9@email.byu.edu) * @since 1.1 - * @status updated to 1.4 + * @status updated to 1.5 */ public final class Byte extends Number implements Comparable { @@ -78,6 +78,16 @@ public final class Byte extends Number implements Comparable public static final Class TYPE = VMClassLoader.getPrimitiveClass('B'); /** + * The number of bits needed to represent a byte. + * @since 1.5 + */ + public static final int SIZE = 8; + + // This caches Byte values, and is used by boxing conversions via + // valueOf(). We're required to cache all possible values here. + private static Byte[] byteCache = new Byte[MAX_VALUE - MIN_VALUE + 1]; + + /** * The immutable value of this Byte. * * @serial the wrapped byte @@ -192,6 +202,26 @@ public final class Byte extends Number implements Comparable } /** + * Returns a Byte object wrapping the value. + * In contrast to the Byte constructor, this method + * will cache some values. It is used by boxing conversion. + * + * @param val the value to wrap + * @return the Byte + * + * @since 1.5 + */ + public static Byte valueOf(byte val) + { + synchronized (byteCache) + { + if (byteCache[val - MIN_VALUE] == null) + byteCache[val - MIN_VALUE] = new Byte(val); + return byteCache[val - MIN_VALUE]; + } + } + + /** * Convert the specified String into a Byte. * The String may represent decimal, hexadecimal, or * octal numbers. diff --git a/libjava/classpath/java/lang/Character.java b/libjava/classpath/java/lang/Character.java index 1e4f219..78db41e 100644 --- a/libjava/classpath/java/lang/Character.java +++ b/libjava/classpath/java/lang/Character.java @@ -1,5 +1,5 @@ /* java.lang.Character -- Wrapper class for char, and Unicode subsets - Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -1034,6 +1034,18 @@ public final class Character implements Serializable, Comparable public static final Class TYPE = VMClassLoader.getPrimitiveClass('C'); /** + * The number of bits needed to represent a char. + * @since 1.5 + */ + public static final int SIZE = 16; + + // This caches some Character values, and is used by boxing + // conversions via valueOf(). We must cache at least 0..127; + // this constant controls how much we actually cache. + private static final int MAX_CACHE = 127; + private static Character[] charCache = new Character[MAX_CACHE + 1]; + + /** * Lu = Letter, Uppercase (Informative). * * @since 1.1 @@ -1480,34 +1492,48 @@ public final class Character implements Serializable, Comparable /** - * Minimum high surrrogate code in UTF-16 encoding. + * Minimum high surrogate code in UTF-16 encoding. * * @since 1.5 */ public static final char MIN_HIGH_SURROGATE = '\ud800'; /** - * Maximum high surrrogate code in UTF-16 encoding. + * Maximum high surrogate code in UTF-16 encoding. * * @since 1.5 */ public static final char MAX_HIGH_SURROGATE = '\udbff'; /** - * Minimum low surrrogate code in UTF-16 encoding. + * Minimum low surrogate code in UTF-16 encoding. * * @since 1.5 */ public static final char MIN_LOW_SURROGATE = '\udc00'; /** - * Maximum low surrrogate code in UTF-16 encoding. + * Maximum low surrogate code in UTF-16 encoding. * * @since 1.5 */ public static final char MAX_LOW_SURROGATE = '\udfff'; /** + * Minimum surrogate code in UTF-16 encoding. + * + * @since 1.5 + */ + public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE; + + /** + * Maximum low surrogate code in UTF-16 encoding. + * + * @since 1.5 + */ + public static final char MAX_SURROGATE = MAX_LOW_SURROGATE; + + /** * 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. @@ -2303,6 +2329,37 @@ public final class Character implements Serializable, Comparable } /** + * Returns an Character object wrapping the value. + * In contrast to the Character constructor, this method + * will cache some values. It is used by boxing conversion. + * + * @param val the value to wrap + * @return the Character + * + * @since 1.5 + */ + public static Character valueOf(char val) + { + if (val > MAX_CACHE) + return new Character(val); + synchronized (charCache) + { + if (charCache[val - MIN_VALUE] == null) + charCache[val - MIN_VALUE] = new Character(val); + return charCache[val - MIN_VALUE]; + } + } + + /** + * Reverse the bytes in val. + * @since 1.5 + */ + public static char reverseBytes(char val) + { + return (char) (((val >> 8) & 0xff) | ((val << 8) & 0xff00)); + } + + /** * Converts a unicode code point to a UTF-16 representation of that * code point. * @@ -2370,7 +2427,7 @@ public final class Character implements Serializable, Comparable * Return number of 16-bit characters required to represent the given * code point. * - * @param codePoint a uncode code point + * @param codePoint a unicode code point * * @return 2 if codePoint >= 0x10000, 1 otherwise. * @@ -2415,4 +2472,210 @@ public final class Character implements Serializable, Comparable { return codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT; } + + /** + * Return true if the given character is a high surrogate. + * @param ch the character + * @return true if the character is a high surrogate character + * + * @since 1.5 + */ + public static boolean isHighSurrogate(char ch) + { + return ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE; + } + + /** + * Return true if the given character is a low surrogate. + * @param ch the character + * @return true if the character is a low surrogate character + * + * @since 1.5 + */ + public static boolean isLowSurrogate(char ch) + { + return ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE; + } + + /** + * Return true if the given characters compose a surrogate pair. + * This is true if the first character is a high surrogate and the + * second character is a low surrogate. + * @param ch1 the first character + * @param ch2 the first character + * @return true if the characters compose a surrogate pair + * + * @since 1.5 + */ + public static boolean isSurrogatePair(char ch1, char ch2) + { + return isHighSurrogate(ch1) && isLowSurrogate(ch2); + } + + /** + * Given a valid surrogate pair, this returns the corresponding + * code point. + * @param high the high character of the pair + * @param low the low character of the pair + * @return the corresponding code point + * + * @since 1.5 + */ + public static int toCodePoint(char high, char low) + { + return ((high - MIN_HIGH_SURROGATE) << 10) + (low - MIN_LOW_SURROGATE); + } + + /** + * Get the code point at the specified index in the CharSequence. + * This is like CharSequence#charAt(int), but if the character is + * the start of a surrogate pair, and there is a following + * character, and this character completes the pair, then the + * corresponding supplementary code point is returned. Otherwise, + * the character at the index is returned. + * + * @param sequence the CharSequence + * @param index the index of the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public static int codePointAt(CharSequence sequence, int index) + { + int len = sequence.length(); + if (index < 0 || index >= len) + throw new IndexOutOfBoundsException(); + char high = sequence.charAt(index); + if (! isHighSurrogate(high) || ++index >= len) + return high; + char low = sequence.charAt(index); + if (! isLowSurrogate(low)) + return high; + return toCodePoint(high, low); + } + + /** + * Get the code point at the specified index in the CharSequence. + * If the character is the start of a surrogate pair, and there is a + * following character, and this character completes the pair, then + * the corresponding supplementary code point is returned. + * Otherwise, the character at the index is returned. + * + * @param chars the character array in which to look + * @param index the index of the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public static int codePointAt(char[] chars, int index) + { + return codePointAt(chars, index, chars.length); + } + + /** + * Get the code point at the specified index in the CharSequence. + * If the character is the start of a surrogate pair, and there is a + * following character within the specified range, and this + * character completes the pair, then the corresponding + * supplementary code point is returned. Otherwise, the character + * at the index is returned. + * + * @param chars the character array in which to look + * @param index the index of the codepoint to get, starting at 0 + * @param limit the limit past which characters should not be examined + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= + * limit, or if limit is negative or >= the length of the array + * @since 1.5 + */ + public static int codePointAt(char[] chars, int index, int limit) + { + if (index < 0 || index >= limit || limit < 0 || limit >= chars.length) + throw new IndexOutOfBoundsException(); + char high = chars[index]; + if (! isHighSurrogate(high) || ++index >= limit) + return high; + char low = chars[index]; + if (! isLowSurrogate(low)) + return high; + return toCodePoint(high, low); + } + + /** + * Get the code point before the specified index. This is like + * #codePointAt(char[], int), but checks the characters at + * index-1 and index-2 to see if they form + * a supplementary code point. If they do not, the character at + * index-1 is returned. + * + * @param chars the character array + * @param index the index just past the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public static int codePointBefore(char[] chars, int index) + { + return codePointBefore(chars, index, 1); + } + + /** + * Get the code point before the specified index. This is like + * #codePointAt(char[], int), but checks the characters at + * index-1 and index-2 to see if they form + * a supplementary code point. If they do not, the character at + * index-1 is returned. The start parameter is used to + * limit the range of the array which may be examined. + * + * @param chars the character array + * @param index the index just past the codepoint to get, starting at 0 + * @param start the index before which characters should not be examined + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is > start or > + * the length of the array, or if limit is negative or >= the + * length of the array + * @since 1.5 + */ + public static int codePointBefore(char[] chars, int index, int start) + { + if (index < start || index > chars.length + || start < 0 || start >= chars.length) + throw new IndexOutOfBoundsException(); + --index; + char low = chars[index]; + if (! isLowSurrogate(low) || --index < start) + return low; + char high = chars[index]; + if (! isHighSurrogate(high)) + return low; + return toCodePoint(high, low); + } + + /** + * Get the code point before the specified index. This is like + * #codePointAt(CharSequence, int), but checks the characters at + * index-1 and index-2 to see if they form + * a supplementary code point. If they do not, the character at + * index-1 is returned. + * + * @param sequence the CharSequence + * @param index the index just past the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public static int codePointBefore(CharSequence sequence, int index) + { + int len = sequence.length(); + if (index < 1 || index > len) + throw new IndexOutOfBoundsException(); + --index; + char low = sequence.charAt(index); + if (! isLowSurrogate(low) || --index < 0) + return low; + char high = sequence.charAt(index); + if (! isHighSurrogate(high)) + return low; + return toCodePoint(high, low); + } } // class Character diff --git a/libjava/classpath/java/lang/Class.java b/libjava/classpath/java/lang/Class.java index 22f148e..726c794 100644 --- a/libjava/classpath/java/lang/Class.java +++ b/libjava/classpath/java/lang/Class.java @@ -41,7 +41,9 @@ package java.lang; import gnu.classpath.VMStackWalker; import java.io.InputStream; +import java.io.ObjectStreamClass; import java.io.Serializable; +import java.lang.reflect.Array; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -99,7 +101,7 @@ public final class Class implements Serializable /** The class signers. */ private Object[] signers = null; /** The class protection domain. */ - private final ProtectionDomain pd; + private final transient ProtectionDomain pd; /* We use an inner class, so that Class doesn't have a static initializer */ private static final class StaticData @@ -592,7 +594,8 @@ public final class Class implements Serializable ClassLoader cl = getClassLoader(); if (cl != null) return cl.getPackage(getPackagePortion(getName())); - return null; + else + return VMClassLoader.getPackage(getPackagePortion(getName())); } /** @@ -721,7 +724,7 @@ public final class Class implements Serializable * @param list List of methods to search * @param name Name of method * @param args Method parameter types - * @see #getMethod() + * @see #getMethod(String, Class[]) */ private static Method matchMethod(Method[] list, String name, Class[] args) { @@ -829,7 +832,7 @@ public final class Class implements Serializable * public and final, but not an interface. * * @return the modifiers of this class - * @see Modifer + * @see Modifier * @since 1.1 */ public int getModifiers() diff --git a/libjava/classpath/java/lang/ClassLoader.java b/libjava/classpath/java/lang/ClassLoader.java index 0d50a6e..9f586c4 100644 --- a/libjava/classpath/java/lang/ClassLoader.java +++ b/libjava/classpath/java/lang/ClassLoader.java @@ -49,6 +49,7 @@ import java.io.InputStream; import java.lang.reflect.Constructor; import java.net.URL; import java.net.URLClassLoader; +import java.nio.ByteBuffer; import java.security.CodeSource; import java.security.PermissionCollection; import java.security.Policy; @@ -472,6 +473,35 @@ public abstract class ClassLoader } /** + * Helper to define a class using the contents of a byte buffer. If + * the domain is null, the default of + * Policy.getPolicy().getPermissions(new CodeSource(null, + * null)) is used. Once a class has been defined in a + * package, all further classes in that package must have the same + * set of certificates or a SecurityException is thrown. + * + * @param name the name to give the class. null if unknown + * @param buf a byte buffer containing bytes that form a class. + * @param domain the ProtectionDomain to give to the class, null for the + * default protection domain + * @return the class that was defined + * @throws ClassFormatError if data is not in proper classfile format + * @throws NoClassDefFoundError if the supplied name is not the same as + * the one specified by the byte buffer. + * @throws SecurityException if name starts with "java.", or if certificates + * do not match up + * @since 1.5 + */ + protected final Class defineClass(String name, ByteBuffer buf, + ProtectionDomain domain) + throws ClassFormatError + { + byte[] data = new byte[buf.remaining()]; + buf.get(data); + return defineClass(name, data, 0, data.length, domain); + } + + /** * Links the class, if that has not already been done. Linking basically * resolves all references to other classes made by this class. * @@ -883,7 +913,7 @@ public abstract class ClassLoader * * @param name the (system specific) name of the requested library * @return the full pathname to the requested library, or null - * @see Runtime#loadLibrary() + * @see Runtime#loadLibrary(String) * @since 1.2 */ protected String findLibrary(String name) @@ -913,7 +943,7 @@ public abstract class ClassLoader * * @param name the package (and subpackages) to affect * @param enabled true to set the default to enabled - * @see #setDefaultAssertionStatus(String, boolean) + * @see #setDefaultAssertionStatus(boolean) * @see #setClassAssertionStatus(String, boolean) * @see #clearAssertionStatus() * @since 1.4 @@ -934,7 +964,7 @@ public abstract class ClassLoader * @param name the class to affect * @param enabled true to set the default to enabled * @throws NullPointerException if name is null - * @see #setDefaultAssertionStatus(String, boolean) + * @see #setDefaultAssertionStatus(boolean) * @see #setPackageAssertionStatus(String, boolean) * @see #clearAssertionStatus() * @since 1.4 diff --git a/libjava/classpath/java/lang/Double.java b/libjava/classpath/java/lang/Double.java index 4fa47f4..26b398b 100644 --- a/libjava/classpath/java/lang/Double.java +++ b/libjava/classpath/java/lang/Double.java @@ -38,7 +38,6 @@ exception statement from your version. */ package java.lang; -import gnu.classpath.Configuration; /** * Instances of class Double represent primitive @@ -89,6 +88,12 @@ public final class Double extends Number implements Comparable public static final double NaN = 0.0 / 0.0; /** + * The number of bits needed to represent a double. + * @since 1.5 + */ + public static final int SIZE = 64; + + /** * The primitive type double is represented by this * Class object. * @since 1.1 @@ -168,6 +173,22 @@ public final class Double extends Number implements Comparable } /** + * Returns a Double object wrapping the value. + * In contrast to the Double constructor, this method + * may cache some values. It is used by boxing conversion. + * + * @param val the value to wrap + * @return the Double + * + * @since 1.5 + */ + public static Double valueOf(double val) + { + // We don't actually cache, but we could. + return new Double(val); + } + + /** * Create a new Double object using the String. * * @param s the String to convert diff --git a/libjava/classpath/java/lang/EnumConstantNotPresentException.java b/libjava/classpath/java/lang/EnumConstantNotPresentException.java new file mode 100644 index 0000000..dbec9d6 --- /dev/null +++ b/libjava/classpath/java/lang/EnumConstantNotPresentException.java @@ -0,0 +1,93 @@ +/* EnumConstantNotPresentException.java -- thrown when enum constant + not available + Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 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; + +/** + * An exception of this type is thrown when a symbolic reference is + * made to an enum constant which does not exist. + * + * @author Tom Tromey (tromey@redhat.com) + * @since 1.5 + */ +public class EnumConstantNotPresentException extends RuntimeException +{ + /** + * The enum's type. Note that the name is fixed by the + * serialization spec. + */ + private Class enumType; + + /** + * The name of the missing enum constant. Note that the name is + * fixed by the serialization spec. + */ + private String constantName; + + /** + * Create a new EnumConstantNotPresentException with the indicated + * enum type and enum constant name. + * @param theEnum the enum's class + * @param name the name of the missing enum constant + */ + public EnumConstantNotPresentException(Class theEnum, String name) + { + super("enum " + theEnum + " is missing the constant " + name); + enumType = theEnum; + constantName = name; + } + + /** + * Return the name of the missing constant. + * @return the name of the missing constant + */ + public String constantName() + { + return constantName; + } + + /** + * Return the enum type which is missing a constant. + * @return the enum type which is missing a constant + */ + public Class enumType() + { + return enumType; + } +} diff --git a/libjava/classpath/java/lang/Float.java b/libjava/classpath/java/lang/Float.java index e6200da..eef34a0 100644 --- a/libjava/classpath/java/lang/Float.java +++ b/libjava/classpath/java/lang/Float.java @@ -94,6 +94,12 @@ public final class Float extends Number implements Comparable public static final Class TYPE = VMClassLoader.getPrimitiveClass('F'); /** + * The number of bits needed to represent a float. + * @since 1.5 + */ + public static final int SIZE = 32; + + /** * The immutable value of this Float. * * @serial the wrapped float @@ -192,6 +198,22 @@ public final class Float extends Number implements Comparable } /** + * Returns a Float object wrapping the value. + * In contrast to the Float constructor, this method + * may cache some values. It is used by boxing conversion. + * + * @param val the value to wrap + * @return the Float + * + * @since 1.5 + */ + public static Float valueOf(float val) + { + // We don't actually cache, but we could. + return new Float(val); + } + + /** * Parse the specified String as a float. The * extended BNF grammar is as follows:
*
diff --git a/libjava/classpath/java/lang/Integer.java b/libjava/classpath/java/lang/Integer.java
index 53de9ab..f3fe85f 100644
--- a/libjava/classpath/java/lang/Integer.java
+++ b/libjava/classpath/java/lang/Integer.java
@@ -707,8 +707,8 @@ public final class Integer extends Number implements Comparable
    * @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)
+   * @see Byte#parseByte(String, int)
+   * @see Short#parseShort(String, int)
    */
   static int parseInt(String str, int radix, boolean decode)
   {
diff --git a/libjava/classpath/java/lang/Long.java b/libjava/classpath/java/lang/Long.java
index 703eab8..74e2a52 100644
--- a/libjava/classpath/java/lang/Long.java
+++ b/libjava/classpath/java/lang/Long.java
@@ -50,7 +50,7 @@ package java.lang;
  * @author Warren Levy
  * @author Eric Blake (ebb9@email.byu.edu)
  * @since 1.0
- * @status updated to 1.4
+ * @status updated to 1.5
  */
 public final class Long extends Number implements Comparable
 {
@@ -79,6 +79,12 @@ public final class Long extends Number implements Comparable
   public static final Class TYPE = VMClassLoader.getPrimitiveClass ('J');
 
   /**
+   * The number of bits needed to represent a long.
+   * @since 1.5
+   */
+  public static final int SIZE = 64;
+
+  /**
    * The immutable value of this Long.
    *
    * @serial the wrapped long
@@ -282,6 +288,21 @@ public final class Long extends Number implements Comparable
   }
 
   /**
+   * Returns a Long object wrapping the value.
+   *
+   * @param val the value to wrap
+   * @return the Long
+   * 
+   * @since 1.5
+   */
+  public static synchronized Long valueOf(long val)
+  {
+    // We aren't required to cache here.  We could, though perhaps we
+    // ought to consider that as an empirical question.
+    return new Long(val);
+  }
+
+  /**
    * Convert the specified String into a Long.
    * The String may represent decimal, hexadecimal, or
    * octal numbers.
@@ -512,6 +533,136 @@ public final class Long extends Number implements Comparable
   }
 
   /**
+   * Return the number of bits set in x.
+   * @param x value to examine
+   * @since 1.5
+   */
+  public static int bitCount(long x)
+  {
+    // Successively collapse alternating bit groups into a sum.
+    x = ((x >> 1) & 0x5555555555555555L) + (x & 0x5555555555555555L);
+    x = ((x >> 2) & 0x3333333333333333L) + (x & 0x3333333333333333L);
+    int v = (int) ((x >>> 32) + x);
+    v = ((v >> 4) & 0x0f0f0f0f) + (v & 0x0f0f0f0f);
+    v = ((v >> 8) & 0x00ff00ff) + (v & 0x00ff00ff);
+    return ((v >> 16) & 0x0000ffff) + (v & 0x0000ffff);
+  }
+
+  /**
+   * Rotate x to the left by distance bits.
+   * @param x the value to rotate
+   * @param distance the number of bits by which to rotate
+   * @since 1.5
+   */
+  public static long rotateLeft(long x, int distance)
+  {
+    // This trick works because the shift operators implicitly mask
+    // the shift count.
+    return (x << distance) | (x >>> - distance);
+  }
+
+  /**
+   * Rotate x to the right by distance bits.
+   * @param x the value to rotate
+   * @param distance the number of bits by which to rotate
+   * @since 1.5
+   */
+  public static long rotateRight(long x, int distance)
+  {
+    // This trick works because the shift operators implicitly mask
+    // the shift count.
+    return (x << - distance) | (x >>> distance);
+  }
+
+  /**
+   * Find the highest set bit in value, and return a new value
+   * with only that bit set.
+   * @param value the value to examine
+   * @since 1.5
+   */
+  public static long highestOneBit(long value)
+  {
+    value |= value >>> 1;
+    value |= value >>> 2;
+    value |= value >>> 4;
+    value |= value >>> 8;
+    value |= value >>> 16;
+    value |= value >>> 32;
+    return value ^ (value >>> 1);
+  }
+
+  /**
+   * Return the number of leading zeros in value.
+   * @param value the value to examine
+   * @since 1.5
+   */
+  public static int numberOfLeadingZeros(long value)
+  {
+    value |= value >>> 1;
+    value |= value >>> 2;
+    value |= value >>> 4;
+    value |= value >>> 8;
+    value |= value >>> 16;
+    value |= value >>> 32;
+    return bitCount(~value);
+  }
+
+  /**
+   * Find the lowest set bit in value, and return a new value
+   * with only that bit set.
+   * @param value the value to examine
+   * @since 1.5
+   */
+  public static long lowestOneBit(long value)
+  {
+    // Classic assembly trick.
+    return value & - value;
+  }
+
+  /**
+   * Find the number of trailing zeros in value.
+   * @param value the value to examine
+   * @since 1.5
+   */
+  public static int numberOfTrailingZeros(long value)
+  {
+    return bitCount((value & -value) - 1);
+  }
+
+  /**
+   * Return 1 if x is positive, -1 if it is negative, and 0 if it is
+   * zero.
+   * @param x the value to examine
+   * @since 1.5
+   */
+  public static int signum(long x)
+  {
+    return x < 0 ? -1 : (x > 0 ? 1 : 0);
+  }
+
+  /**
+   * Reverse the bytes in val.
+   * @since 1.5
+   */
+  public static long reverseBytes(long val)
+  {
+    int hi = Integer.reverseBytes((int) val);
+    int lo = Integer.reverseBytes((int) (val >>> 32));
+    return (((long) hi) << 32) | lo;
+  }
+
+  /**
+   * Reverse the bits in val.
+   * @since 1.5
+   */
+  public static long reverse(long val)
+  {
+    long hi = Integer.reverse((int) val) & 0xffffffffL;
+    long lo = Integer.reverse((int) (val >>> 32)) & 0xffffffffL;
+    return (hi << 32) | lo;
+  }
+
+  /**
    * Helper for converting unsigned numbers to String.
    *
    * @param num the number
diff --git a/libjava/classpath/java/lang/Object.java b/libjava/classpath/java/lang/Object.java
index f8c389a..6212d7d 100644
--- a/libjava/classpath/java/lang/Object.java
+++ b/libjava/classpath/java/lang/Object.java
@@ -343,7 +343,7 @@ public class Object
    *
    * 

This thread still holds a lock on the object, so it is * typical to release the lock by exiting the synchronized - * code, calling wait(), or calling {@link Thread#sleep()}, so + * code, calling wait(), or calling {@link Thread#sleep(long)}, so * that the newly awakened thread can actually resume. The * awakened thread will most likely be awakened with an * {@link InterruptedException}, but that is not guaranteed. @@ -372,7 +372,7 @@ public class Object * *

This thread still holds a lock on the object, so it is * typical to release the lock by exiting the synchronized - * code, calling wait(), or calling {@link Thread#sleep()}, so + * code, calling wait(), or calling {@link Thread#sleep(long)}, so * that one of the newly awakened threads can actually resume. * The resuming thread will most likely be awakened with an * {@link InterruptedException}, but that is not guaranteed. diff --git a/libjava/classpath/java/lang/Process.java b/libjava/classpath/java/lang/Process.java index b6e18ca..ccaa3f1 100644 --- a/libjava/classpath/java/lang/Process.java +++ b/libjava/classpath/java/lang/Process.java @@ -39,6 +39,7 @@ exception statement from your version. */ package java.lang; +import java.io.File; import java.io.InputStream; import java.io.OutputStream; diff --git a/libjava/classpath/java/lang/Readable.java b/libjava/classpath/java/lang/Readable.java index efc1985..d896765 100644 --- a/libjava/classpath/java/lang/Readable.java +++ b/libjava/classpath/java/lang/Readable.java @@ -39,6 +39,7 @@ package java.lang; import java.io.IOException; import java.nio.CharBuffer; +import java.nio.ReadOnlyBufferException; /** * A Readable object is simply a source for Unicode character diff --git a/libjava/classpath/java/lang/RuntimePermission.java b/libjava/classpath/java/lang/RuntimePermission.java index ca33307..2f80b91 100644 --- a/libjava/classpath/java/lang/RuntimePermission.java +++ b/libjava/classpath/java/lang/RuntimePermission.java @@ -39,6 +39,7 @@ exception statement from your version. */ package java.lang; import java.security.BasicPermission; +import java.security.Permission; /** * A RuntimePermission contains a permission name, but no diff --git a/libjava/classpath/java/lang/SecurityManager.java b/libjava/classpath/java/lang/SecurityManager.java index ef9e759..26d56a6 100644 --- a/libjava/classpath/java/lang/SecurityManager.java +++ b/libjava/classpath/java/lang/SecurityManager.java @@ -41,19 +41,35 @@ package java.lang; import gnu.classpath.VMStackWalker; import java.awt.AWTPermission; +import java.awt.Frame; +import java.awt.Toolkit; +import java.awt.Window; import java.io.File; import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.FilePermission; +import java.io.RandomAccessFile; import java.lang.reflect.Member; import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketImplFactory; import java.net.SocketPermission; +import java.net.URL; +import java.net.URLStreamHandlerFactory; import java.security.AccessControlContext; +import java.security.AccessControlException; import java.security.AccessController; import java.security.AllPermission; +import java.security.BasicPermission; import java.security.Permission; +import java.security.Policy; import java.security.PrivilegedAction; +import java.security.ProtectionDomain; import java.security.Security; import java.security.SecurityPermission; +import java.util.Properties; import java.util.PropertyPermission; import java.util.StringTokenizer; @@ -196,7 +212,7 @@ public class SecurityManager *

@@ -219,7 +235,7 @@ public class SecurityManager * @@ -258,7 +274,7 @@ public class SecurityManager * @@ -431,7 +447,7 @@ public class SecurityManager * @throws SecurityException if permission is denied * @throws NullPointerException if g is null * @see Thread#Thread() - * @see ThreadGroup#ThreadGroup() + * @see ThreadGroup#ThreadGroup(String) * @see ThreadGroup#stop() * @see ThreadGroup#suspend() * @see ThreadGroup#resume() @@ -537,7 +553,7 @@ public class SecurityManager * @throws NullPointerException if filename is null * @see File * @see FileInputStream#FileInputStream(String) - * @see RandomAccessFile#RandomAccessFile(String) + * @see RandomAccessFile#RandomAccessFile(String, String) */ public void checkRead(String filename) { @@ -602,9 +618,9 @@ public class SecurityManager * @see File * @see File#canWrite() * @see File#mkdir() - * @see File#renameTo() + * @see File#renameTo(File) * @see FileOutputStream#FileOutputStream(String) - * @see RandomAccessFile#RandomAccessFile(String) + * @see RandomAccessFile#RandomAccessFile(String, String) */ public void checkWrite(String filename) { diff --git a/libjava/classpath/java/lang/Short.java b/libjava/classpath/java/lang/Short.java index fbeea91..eb40cd9 100644 --- a/libjava/classpath/java/lang/Short.java +++ b/libjava/classpath/java/lang/Short.java @@ -77,6 +77,19 @@ public final class Short extends Number implements Comparable public static final Class TYPE = VMClassLoader.getPrimitiveClass('S'); /** + * The number of bits needed to represent a short. + * @since 1.5 + */ + public static final int SIZE = 16; + + // This caches some Short values, and is used by boxing conversions + // via valueOf(). We must cache at least -128..127; these constants + // control how much we actually cache. + private static final int MIN_CACHE = -128; + private static final int MAX_CACHE = 127; + private static Short[] shortCache = new Short[MAX_CACHE - MIN_CACHE + 1]; + + /** * The immutable value of this Short. * * @serial the wrapped short @@ -189,6 +202,28 @@ public final class Short extends Number implements Comparable } /** + * Returns a Short object wrapping the value. + * In contrast to the Short constructor, this method + * will cache some values. It is used by boxing conversion. + * + * @param val the value to wrap + * @return the Short + * + * @since 1.5 + */ + public static Short valueOf(short val) + { + if (val < MIN_CACHE || val > MAX_CACHE) + return new Short(val); + synchronized (shortCache) + { + if (shortCache[val - MIN_CACHE] == null) + shortCache[val - MIN_CACHE] = new Short(val); + return shortCache[val - MIN_CACHE]; + } + } + + /** * Convert the specified String into a Short. * The String may represent decimal, hexadecimal, or * octal numbers. @@ -350,4 +385,13 @@ public final class Short extends Number implements Comparable { return compareTo((Short)o); } + + /** + * Reverse the bytes in val. + * @since 1.5 + */ + public static short reverseBytes(short val) + { + return (short) (((val >> 8) & 0xff) | ((val << 8) & 0xff00)); + } } diff --git a/libjava/classpath/java/lang/StrictMath.java b/libjava/classpath/java/lang/StrictMath.java index 32bd354..2079cc1 100644 --- a/libjava/classpath/java/lang/StrictMath.java +++ b/libjava/classpath/java/lang/StrictMath.java @@ -1254,7 +1254,7 @@ public final strictfp class StrictMath /** * Super precision for 2/pi in 24-bit chunks, for use in - * {@link #remPiOver2()}. + * {@link #remPiOver2(double, double[])}. */ private static final int TWO_OVER_PI[] = { 0xa2f983, 0x6e4e44, 0x1529fc, 0x2757d1, 0xf534dd, 0xc0db62, @@ -1272,7 +1272,7 @@ public final strictfp class StrictMath /** * Super precision for pi/2 in 24-bit chunks, for use in - * {@link #remPiOver2()}. + * {@link #remPiOver2(double, double[])}. */ private static final double PI_OVER_TWO[] = { 1.570796251296997, // Long bits 0x3ff921fb40000000L. @@ -1286,8 +1286,8 @@ public final strictfp class StrictMath }; /** - * More constants related to pi, used in {@link #remPiOver2()} and - * elsewhere. + * More constants related to pi, used in + * {@link #remPiOver2(double, double[])} and elsewhere. */ private static final double PI_L = 1.2246467991473532e-16, // Long bits 0x3ca1a62633145c07L. @@ -1301,7 +1301,7 @@ public final strictfp class StrictMath /** * Natural log and square root constants, for calculation of * {@link #exp(double)}, {@link #log(double)} and - * {@link #power(double, double)}. CP is 2/(3*ln(2)). + * {@link #pow(double, double)}. CP is 2/(3*ln(2)). */ private static final double SQRT_1_5 = 1.224744871391589, // Long bits 0x3ff3988e1409212eL. diff --git a/libjava/classpath/java/lang/String.java b/libjava/classpath/java/lang/String.java index b4db850..369d808 100644 --- a/libjava/classpath/java/lang/String.java +++ b/libjava/classpath/java/lang/String.java @@ -98,7 +98,7 @@ public final class String implements Serializable, Comparable, CharSequence /** * Stores unicode multi-character uppercase expansion table. - * @see #toUpperCase(char) + * @see #toUpperCase(Locale) * @see CharData#UPPER_EXPAND */ private static final char[] upperExpand @@ -139,7 +139,7 @@ public final class String implements Serializable, Comparable, CharSequence final int offset; /** - * An implementation for {@link CASE_INSENSITIVE_ORDER}. + * An implementation for {@link #CASE_INSENSITIVE_ORDER}. * This must be {@link Serializable}. The class name is dictated by * compatibility with Sun's JDK. */ @@ -233,6 +233,7 @@ public final class String implements Serializable, Comparable, CharSequence * @param count the number of characters from data to copy * @throws NullPointerException if data is null * @throws IndexOutOfBoundsException if (offset < 0 || count < 0 + * || offset + count < 0 (overflow) * || offset + count > data.length) * (while unspecified, this is a StringIndexOutOfBoundsException) */ @@ -256,6 +257,7 @@ public final class String implements Serializable, Comparable, CharSequence * @param count the number of characters from ascii to copy * @throws NullPointerException if ascii is null * @throws IndexOutOfBoundsException if (offset < 0 || count < 0 + * || offset + count < 0 (overflow) * || offset + count > ascii.length) * (while unspecified, this is a StringIndexOutOfBoundsException) * @see #String(byte[]) @@ -267,8 +269,13 @@ public final class String implements Serializable, Comparable, CharSequence */ public String(byte[] ascii, int hibyte, int offset, int count) { - if (offset < 0 || count < 0 || offset + count > ascii.length) - throw new StringIndexOutOfBoundsException(); + if (offset < 0) + throw new StringIndexOutOfBoundsException("offset: " + offset); + if (count < 0) + throw new StringIndexOutOfBoundsException("count: " + count); + if (offset + count < 0 || offset + count > ascii.length) + throw new StringIndexOutOfBoundsException("offset + count: " + + (offset + count)); value = new char[count]; this.offset = 0; this.count = count; @@ -327,8 +334,13 @@ public final class String implements Serializable, Comparable, CharSequence public String(byte[] data, int offset, int count, String encoding) throws UnsupportedEncodingException { - if (offset < 0 || count < 0 || offset + count > data.length) - throw new StringIndexOutOfBoundsException(); + if (offset < 0) + throw new StringIndexOutOfBoundsException("offset: " + offset); + if (count < 0) + throw new StringIndexOutOfBoundsException("count: " + count); + if (offset + count < 0 || offset + count > data.length) + throw new StringIndexOutOfBoundsException("offset + count: " + + (offset + count)); try { CharsetDecoder csd = Charset.forName(encoding).newDecoder(); @@ -402,8 +414,13 @@ public final class String implements Serializable, Comparable, CharSequence */ public String(byte[] data, int offset, int count) { - if (offset < 0 || count < 0 || offset + count > data.length) - throw new StringIndexOutOfBoundsException(); + if (offset < 0) + throw new StringIndexOutOfBoundsException("offset: " + offset); + if (count < 0) + throw new StringIndexOutOfBoundsException("count: " + count); + if (offset + count < 0 || offset + count > data.length) + throw new StringIndexOutOfBoundsException("offset + count: " + + (offset + count)); int o, c; char[] v; String encoding; @@ -512,8 +529,13 @@ public final class String implements Serializable, Comparable, CharSequence */ String(char[] data, int offset, int count, boolean dont_copy) { - if (offset < 0 || count < 0 || offset + count > data.length) - throw new StringIndexOutOfBoundsException(); + if (offset < 0) + throw new StringIndexOutOfBoundsException("offset: " + offset); + if (count < 0) + throw new StringIndexOutOfBoundsException("count: " + count); + if (offset + count < 0 || offset + count > data.length) + throw new StringIndexOutOfBoundsException("offset + count: " + + (offset + count)); if (dont_copy) { value = data; @@ -554,6 +576,40 @@ public final class String implements Serializable, Comparable, CharSequence } /** + * Get the code point at the specified index. This is like #charAt(int), + * but if the character is the start of a surrogate pair, and the + * following character completes the pair, then the corresponding + * supplementary code point is returned. + * @param index the index of the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * @since 1.5 + */ + public synchronized int codePointAt(int index) + { + // Use the CharSequence overload as we get better range checking + // this way. + return Character.codePointAt(this, index); + } + + /** + * Get the code point before the specified index. This is like + * #codePointAt(int), but checks the characters at index-1 and + * index-2 to see if they form a supplementary code point. + * @param index the index just past the codepoint to get, starting at 0 + * @return the codepoint at the specified index + * @throws IndexOutOfBoundsException if index is negative or >= length() + * (while unspecified, this is a StringIndexOutOfBoundsException) + * @since 1.5 + */ + public synchronized int codePointBefore(int index) + { + // Use the CharSequence overload as we get better range checking + // this way. + return Character.codePointBefore(this, index); + } + + /** * Copies characters from this String starting at a specified start index, * ending at a specified stop index, to a character array starting at * a specified destination begin index. @@ -628,21 +684,26 @@ public final class String implements Serializable, Comparable, CharSequence ByteBuffer bbuf = cse.encode(CharBuffer.wrap(value, offset, count)); if(bbuf.hasArray()) return bbuf.array(); - + // Doubt this will happen. But just in case. byte[] bytes = new byte[bbuf.remaining()]; bbuf.get(bytes); return bytes; - - } catch(IllegalCharsetNameException e){ - throw new UnsupportedEncodingException("Encoding: "+enc+ - " not found."); - } catch(UnsupportedCharsetException e){ - throw new UnsupportedEncodingException("Encoding: "+enc+ - " not found."); - } catch(CharacterCodingException e){ - // XXX - Ignore coding exceptions? They shouldn't really happen. - return null; + } + catch(IllegalCharsetNameException e) + { + throw new UnsupportedEncodingException("Encoding: " + enc + + " not found."); + } + catch(UnsupportedCharsetException e) + { + throw new UnsupportedEncodingException("Encoding: " + enc + + " not found."); + } + catch(CharacterCodingException e) + { + // This shouldn't ever happen. + throw (InternalError) new InternalError().initCause(e); } } @@ -726,6 +787,26 @@ public final class String implements Serializable, Comparable, CharSequence } /** + * Compares the given CharSequence to this String. This is true if + * the CharSequence has the same content as this String at this + * moment. + * + * @param seq the CharSequence to compare to + * @return true if CharSequence has the same character sequence + * @throws NullPointerException if the given CharSequence is null + * @since 1.5 + */ + public boolean contentEquals(CharSequence seq) + { + if (seq.length() != count) + return false; + for (int i = 0; i < count; ++i) + if (value[offset + i] != seq.charAt(i)) + return false; + return true; + } + + /** * Compares a String to this String, ignoring case. This does not handle * multi-character capitalization exceptions; instead the comparison is * made on a character-by-character basis, and is true if:
* *

Proxy Instances

@@ -126,7 +126,7 @@ import java.util.Set; * a {@link ClassCastException}. *
  • Each proxy instance has an invocation handler, which can be * accessed by {@link #getInvocationHandler(Object)}. Any call - * to an interface method, including {@link Object#hashcode()}, + * to an interface method, including {@link Object#hashCode()}, * {@link Object#equals(Object)}, or {@link Object#toString()}, * but excluding the public final methods of Object, will be * encoded and passed to the {@link InvocationHandler#invoke} @@ -413,8 +413,6 @@ public class Proxy implements Serializable */ ProxyType(ClassLoader loader, Class[] interfaces) { - if (loader == null) - loader = ClassLoader.getSystemClassLoader(); this.loader = loader; this.interfaces = interfaces; } @@ -426,8 +424,7 @@ public class Proxy implements Serializable */ public int hashCode() { - //loader is always not null - int hash = loader.hashCode(); + int hash = loader == null ? 0 : loader.hashCode(); for (int i = 0; i < interfaces.length; i++) hash = hash * 31 + interfaces[i].hashCode(); return hash; @@ -436,7 +433,7 @@ public class Proxy implements Serializable /** * Calculates equality. * - * @param the object to compare to + * @param other object to compare to * @return true if it is a ProxyType with same data */ public boolean equals(Object other) @@ -586,7 +583,7 @@ public class Proxy implements Serializable /** * Calculates equality. * - * @param the object to compare to + * @param other object to compare to * @return true if it is a ProxySignature with same data */ public boolean equals(Object other) @@ -617,7 +614,7 @@ public class Proxy implements Serializable * The package this class is in including the trailing dot * or an empty string for the unnamed (aka default) package. */ - String pack; + String pack = ""; /** * The interfaces this class implements. Non-null, but possibly empty. diff --git a/libjava/classpath/java/lang/reflect/UndeclaredThrowableException.java b/libjava/classpath/java/lang/reflect/UndeclaredThrowableException.java index 6d5a800..ea574ad 100644 --- a/libjava/classpath/java/lang/reflect/UndeclaredThrowableException.java +++ b/libjava/classpath/java/lang/reflect/UndeclaredThrowableException.java @@ -65,7 +65,7 @@ public class UndeclaredThrowableException extends RuntimeException /** * The immutable exception that this wraps. This field is redundant - * with {@link Throwable#cause}, but is necessary for serial compatibility. + * with {@link Throwable#getCause()}, but is necessary for serial compatibility. * * @serial the chained exception */ -- cgit v1.1