You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/12/01 07:04:00 UTC

svn commit: r350181 [106/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Short.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Short.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Short.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Short.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,275 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * Shorts are objects (non-base types) which represent short values.
+ */
+public final class Short extends Number implements Comparable {
+
+	static final long serialVersionUID = 7515723908773894738L;
+
+	/**
+	 * The value which the receiver represents.
+	 */
+	final short value;
+
+	/**
+	 * Most positive and most negative possible short values.
+	 */
+	public static final short MAX_VALUE = (short) 0x7FFF;
+
+	public static final short MIN_VALUE = (short) 0x8000;
+
+	/**
+	 * The java.lang.Class that represents this class.
+	 */
+	public static final Class TYPE = new short[0].getClass().getComponentType();
+
+	// Note: This can't be set to "short.class", since *that* is
+	// defined to be "java.lang.Short.TYPE";
+
+	/**
+	 * Constructs a new instance of this class given a string.
+	 * 
+	 * @param string
+	 *            a string representation of a short quantity.
+	 * @exception NumberFormatException
+	 *                if the argument could not be parsed as a short quantity.
+	 */
+	public Short(String string) throws NumberFormatException {
+		this(parseShort(string));
+	}
+
+	/**
+	 * Constructs a new instance of the receiver which represents the short
+	 * valued argument.
+	 * 
+	 * @param value
+	 *            the short to store in the new instance.
+	 */
+	public Short(short value) {
+		this.value = value;
+	}
+
+	/**
+	 * Answers the byte value which the receiver represents
+	 * 
+	 * @return byte the value of the receiver.
+	 */
+	public byte byteValue() {
+		return (byte) value;
+	}
+
+	public int compareTo(Object object) {
+		return compareTo((Short) object);
+	}
+
+	public int compareTo(Short object) {
+		return value > object.value ? 1 : (value < object.value ? -1 : 0);
+	}
+
+	/**
+	 * Parses the string argument as if it was a short value and returns the
+	 * result. Throws NumberFormatException if the string does not represent an
+	 * int quantity. The string may be a hexadecimal ("0x..."), octal ("0..."),
+	 * or decimal ("...") representation of a byte.
+	 * 
+	 * @param string
+	 *            a string representation of a short quantity.
+	 * @return Short the value represented by the argument
+	 * @exception NumberFormatException
+	 *                if the argument could not be parsed as a short quantity.
+	 */
+	public static Short decode(String string) throws NumberFormatException {
+		int intValue = Integer.decode(string).intValue();
+		short result = (short) intValue;
+		if (result == intValue)
+			return new Short(result);
+		throw new NumberFormatException();
+	}
+
+	/**
+	 * Answers the double value which the receiver represents
+	 * 
+	 * @return double the value of the receiver.
+	 */
+	public double doubleValue() {
+		return value;
+	}
+
+	/**
+	 * Compares the argument to the receiver, and answers true if they represent
+	 * the <em>same</em> object using a class specific comparison.
+	 * <p>
+	 * In this case, the argument must also be a Short, and the receiver and
+	 * argument must represent the same short value.
+	 * 
+	 * @param object
+	 *            the object to compare with this object
+	 * @return <code>true</code> if the object is the same as this object
+	 *         <code>false</code> if it is different from this object
+	 * @see #hashCode
+	 */
+	public boolean equals(Object object) {
+		return (object == this) || (object instanceof Short)
+				&& (value == ((Short) object).value);
+	}
+
+	/**
+	 * Answers the float value which the receiver represents
+	 * 
+	 * @return float the value of the receiver.
+	 */
+	public float floatValue() {
+		return value;
+	}
+
+	/**
+	 * Answers an integer hash code for the receiver. Any two objects which
+	 * answer <code>true</code> when passed to <code>equals</code> must
+	 * answer the same value for this method.
+	 * 
+	 * @return the receiver's hash
+	 * 
+	 * @see #equals
+	 */
+	public int hashCode() {
+		return value;
+	}
+
+	/**
+	 * Answers the int value which the receiver represents
+	 * 
+	 * @return int the value of the receiver.
+	 */
+	public int intValue() {
+		return value;
+	}
+
+	/**
+	 * Answers the long value which the receiver represents
+	 * 
+	 * @return long the value of the receiver.
+	 */
+	public long longValue() {
+		return value;
+	}
+
+	/**
+	 * Parses the string argument as if it was a short value and returns the
+	 * result. Throws NumberFormatException if the string does not represent an
+	 * short quantity.
+	 * 
+	 * @param string
+	 *            a string representation of a short quantity.
+	 * @return short the value represented by the argument
+	 * @exception NumberFormatException
+	 *                if the argument could not be parsed as a short quantity.
+	 */
+	public static short parseShort(String string) throws NumberFormatException {
+		return parseShort(string, 10);
+	}
+
+	/**
+	 * Parses the string argument as if it was a short value and returns the
+	 * result. Throws NumberFormatException if the string does not represent a
+	 * single short quantity. The second argument specifies the radix to use
+	 * when parsing the value.
+	 * 
+	 * @param string
+	 *            a string representation of a short quantity.
+	 * @param radix
+	 *            the radix to use when parsing.
+	 * @return short the value represented by the argument
+	 * @exception NumberFormatException
+	 *                if the argument could not be parsed as a short quantity.
+	 */
+	public static short parseShort(String string, int radix)
+			throws NumberFormatException {
+		int intValue = Integer.parseInt(string, radix);
+		short result = (short) intValue;
+		if (result == intValue)
+			return result;
+		throw new NumberFormatException();
+	}
+
+	/**
+	 * Answers the short value which the receiver represents
+	 * 
+	 * @return short the value of the receiver.
+	 */
+	public short shortValue() {
+		return value;
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * receiver.
+	 * 
+	 * @return a printable representation for the receiver.
+	 */
+	public String toString() {
+		return Integer.toString(value);
+	}
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * argument.
+	 * 
+	 * @param value
+	 *            short the short to convert.
+	 * @return String a printable representation for the short.
+	 */
+	public static String toString(short value) {
+		return Integer.toString(value);
+	}
+
+	/**
+	 * Parses the string argument as if it was a short value and returns a Short
+	 * representing the result. Throws NumberFormatException if the string does
+	 * not represent a single short quantity.
+	 * 
+	 * @param string
+	 *            a string representation of a short quantity.
+	 * @return Short the value represented by the argument
+	 * @exception NumberFormatException
+	 *                if the argument could not be parsed as a short quantity.
+	 */
+	public static Short valueOf(String string) throws NumberFormatException {
+		return new Short(parseShort(string));
+	}
+
+	/**
+	 * Parses the string argument as if it was a short value and returns a Short
+	 * representing the result. Throws NumberFormatException if the string does
+	 * not represent a short quantity. The second argument specifies the radix
+	 * to use when parsing the value.
+	 * 
+	 * @param string
+	 *            a string representation of a short quantity.
+	 * @param radix
+	 *            the radix to use when parsing.
+	 * @return Short the value represented by the argument
+	 * @exception NumberFormatException
+	 *                if the argument could not be parsed as a short quantity.
+	 */
+	public static Short valueOf(String string, int radix)
+			throws NumberFormatException {
+		return new Short(parseShort(string, radix));
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StackOverflowError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StackOverflowError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StackOverflowError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StackOverflowError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,44 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This error is thrown when the depth of the callstack of the running program
+ * excedes some platform or virtual machine specific limit. Typically, this will
+ * occur only when a program becomes infinitely recursive, but can occur in
+ * correctly written (but deeply recursive) programs.
+ */
+public class StackOverflowError extends java.lang.VirtualMachineError {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public StackOverflowError() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public StackOverflowError(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StrictMath.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StrictMath.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StrictMath.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StrictMath.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,466 @@
+/* Copyright 2001, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+import java.util.Random;
+
+/**
+ * Class StrictMath provides various numeric operations using the standards set
+ * by the known "Freely Distributable Math Library" (fdlibm). The standard is
+ * set by the January 4th, 1995 version of the library.
+ */
+public final class StrictMath {
+
+	/**
+	 * Standard math constant
+	 */
+	public final static double E = Math.E;
+
+	/**
+	 * Standard math constant
+	 */
+	public final static double PI = Math.PI;
+
+	private static java.util.Random random;
+
+	/**
+	 * Prevents this class from being instantiated.
+	 */
+	private StrictMath() {
+	}
+
+	/**
+	 * Answers the absolute value of the argument.
+	 * 
+	 * @param d
+	 *            the value to be converted
+	 * @return the argument if it is positive, otherwise the negation of the
+	 *         argument.
+	 */
+	public static double abs(double d) {
+		long bits = Double.doubleToLongBits(d);
+		bits &= 0x7fffffffffffffffL;
+		return Double.longBitsToDouble(bits);
+	}
+
+	/**
+	 * Answers the absolute value of the argument.
+	 * 
+	 * @param f
+	 *            the value to be converted
+	 * @return the argument if it is positive, otherwise the negation of the
+	 *         argument.
+	 */
+	public static float abs(float f) {
+		int bits = Float.floatToIntBits(f);
+		bits &= 0x7fffffff;
+		return Float.intBitsToFloat(bits);
+	}
+
+	/**
+	 * Answers the absolute value of the argument.
+	 * 
+	 * @param i
+	 *            the value to be converted
+	 * @return the argument if it is positive, otherwise the negation of the
+	 *         argument.
+	 */
+	public static int abs(int i) {
+		return i >= 0 ? i : -i;
+	}
+
+	/**
+	 * Answers the absolute value of the argument.
+	 * 
+	 * @param l
+	 *            the value to be converted
+	 * @return the argument if it is positive, otherwise the negation of the
+	 *         argument.
+	 */
+	public static long abs(long l) {
+		return l >= 0 ? l : -l;
+	}
+
+	/**
+	 * Answers the closest double approximation of the arc cosine of the
+	 * argument
+	 * 
+	 * @param d
+	 *            the value to compute acos of
+	 * @return the arc cosine of the argument.
+	 */
+	public static native double acos(double d);
+
+	/**
+	 * Answers the closest double approximation of the arc sine of the argument
+	 * 
+	 * @param d
+	 *            the value to compute asin of
+	 * @return the arc sine of the argument.
+	 */
+	public static native double asin(double d);
+
+	/**
+	 * Answers the closest double approximation of the arc tangent of the
+	 * argument
+	 * 
+	 * @param d
+	 *            the value to compute atan of
+	 * @return the arc tangent of the argument.
+	 */
+	public static native double atan(double d);
+
+	/**
+	 * Answers the closest double approximation of the arc tangent of the result
+	 * of dividing the first argument by the second argument.
+	 * 
+	 * @param d1
+	 *            the numerator of the value to compute atan of
+	 * @param d2
+	 *            the denominator of the value to compute atan of
+	 * @return the arc tangent of d1/d2.
+	 */
+	public static native double atan2(double d1, double d2);
+
+	/**
+	 * Answers the double conversion of the most negative (i.e. closest to
+	 * negative infinity) integer value which is greater than the argument.
+	 * 
+	 * @param d
+	 *            the value to be converted
+	 * @return the ceiling of the argument.
+	 */
+	public static native double ceil(double d);
+
+	/**
+	 * Answers the closest double approximation of the cosine of the argument
+	 * 
+	 * @param d
+	 *            the value to compute cos of
+	 * @return the cosine of the argument.
+	 */
+	public static native double cos(double d);
+
+	/**
+	 * Answers the closest double approximation of the raising "e" to the power
+	 * of the argument
+	 * 
+	 * @param d
+	 *            the value to compute the exponential of
+	 * @return the exponential of the argument.
+	 */
+	public static native double exp(double d);
+
+	/**
+	 * Answers the double conversion of the most positive (i.e. closest to
+	 * positive infinity) integer value which is less than the argument.
+	 * 
+	 * 
+	 * @param d
+	 *            the value to be converted
+	 * @return the ceiling of the argument.
+	 */
+	public static native double floor(double d);
+
+	/**
+	 * Answers the remainder of dividing the first argument by the second using
+	 * the IEEE 754 rules.
+	 * 
+	 * @param d1
+	 *            the numerator of the operation
+	 * @param d2
+	 *            the denominator of the operation
+	 * @return the result of d1/d2.
+	 */
+	public static native double IEEEremainder(double d1, double d2);
+
+	/**
+	 * Answers the closest double approximation of the natural logarithm of the
+	 * argument
+	 * 
+	 * @param d
+	 *            the value to compute the log of
+	 * @return the natural logarithm of the argument.
+	 */
+	public static native double log(double d);
+
+	/**
+	 * Answers the most positive (i.e. closest to positive infinity) of the two
+	 * arguments.
+	 * 
+	 * @param d1
+	 *            the first argument to check
+	 * @param d2
+	 *            the second argument
+	 * @return the larger of d1 and d2.
+	 */
+	public static double max(double d1, double d2) {
+		if (d1 > d2)
+			return d1;
+		if (d1 < d2)
+			return d2;
+		/* if either arg is NaN, return NaN */
+		if (d1 != d2)
+			return Double.NaN;
+		/* max( +0.0,-0.0) == +0.0 */
+		if (d1 == 0.0
+				&& ((Double.doubleToLongBits(d1) & Double.doubleToLongBits(d2)) & 0x8000000000000000L) == 0)
+			return 0.0;
+		return d1;
+	}
+
+	/**
+	 * Answers the most positive (i.e. closest to positive infinity) of the two
+	 * arguments.
+	 * 
+	 * @param f1
+	 *            the first argument to check
+	 * @param f2
+	 *            the second argument
+	 * @return the larger of f1 and f2.
+	 */
+	public static float max(float f1, float f2) {
+		if (f1 > f2)
+			return f1;
+		if (f1 < f2)
+			return f2;
+		/* if either arg is NaN, return NaN */
+		if (f1 != f2)
+			return Float.NaN;
+		/* max( +0.0,-0.0) == +0.0 */
+		if (f1 == 0.0f
+				&& ((Float.floatToIntBits(f1) & Float.floatToIntBits(f2)) & 0x80000000) == 0)
+			return 0.0f;
+		return f1;
+	}
+
+	/**
+	 * Answers the most positive (i.e. closest to positive infinity) of the two
+	 * arguments.
+	 * 
+	 * @param i1
+	 *            the first argument to check
+	 * @param i2
+	 *            the second argument
+	 * @return the larger of i1 and i2.
+	 */
+	public static int max(int i1, int i2) {
+		return i1 > i2 ? i1 : i2;
+	}
+
+	/**
+	 * Answers the most positive (i.e. closest to positive infinity) of the two
+	 * arguments.
+	 * 
+	 * @param l1
+	 *            the first argument to check
+	 * @param l2
+	 *            the second argument
+	 * @return the larger of l1 and l2.
+	 */
+	public static long max(long l1, long l2) {
+		return l1 > l2 ? l1 : l2;
+	}
+
+	/**
+	 * Answers the most negative (i.e. closest to negative infinity) of the two
+	 * arguments.
+	 * 
+	 * @param d1
+	 *            the first argument to check
+	 * @param d2
+	 *            the second argument
+	 * @return the smaller of d1 and d2.
+	 */
+	public static double min(double d1, double d2) {
+		if (d1 > d2)
+			return d2;
+		if (d1 < d2)
+			return d1;
+		/* if either arg is NaN, return NaN */
+		if (d1 != d2)
+			return Double.NaN;
+		/* min( +0.0,-0.0) == -0.0 */
+		if (d1 == 0.0
+				&& ((Double.doubleToLongBits(d1) | Double.doubleToLongBits(d2)) & 0x8000000000000000l) != 0)
+			return 0.0 * (-1.0);
+		return d1;
+	}
+
+	/**
+	 * Answers the most negative (i.e. closest to negative infinity) of the two
+	 * arguments.
+	 * 
+	 * @param f1
+	 *            the first argument to check
+	 * @param f2
+	 *            the second argument
+	 * @return the smaller of f1 and f2.
+	 */
+	public static float min(float f1, float f2) {
+		if (f1 > f2)
+			return f2;
+		if (f1 < f2)
+			return f1;
+		/* if either arg is NaN, return NaN */
+		if (f1 != f2)
+			return Float.NaN;
+		/* min( +0.0,-0.0) == -0.0 */
+		if (f1 == 0.0f
+				&& ((Float.floatToIntBits(f1) | Float.floatToIntBits(f2)) & 0x80000000) != 0)
+			return 0.0f * (-1.0f);
+		return f1;
+	}
+
+	/**
+	 * Answers the most negative (i.e. closest to negative infinity) of the two
+	 * arguments.
+	 * 
+	 * @param i1
+	 *            the first argument to check
+	 * @param i2
+	 *            the second argument
+	 * @return the smaller of i1 and i2.
+	 */
+	public static int min(int i1, int i2) {
+		return i1 < i2 ? i1 : i2;
+	}
+
+	/**
+	 * Answers the most negative (i.e. closest to negative infinity) of the two
+	 * arguments.
+	 * 
+	 * @param l1
+	 *            the first argument to check
+	 * @param l2
+	 *            the second argument
+	 * @return the smaller of l1 and l2.
+	 */
+	public static long min(long l1, long l2) {
+		return l1 < l2 ? l1 : l2;
+	}
+
+	/**
+	 * Answers the closest double approximation of the result of raising the
+	 * first argument to the power of the second.
+	 * 
+	 * @param d1
+	 *            the base of the operation.
+	 * @param d2
+	 *            the exponent of the operation.
+	 * @return d1 to the power of d2
+	 */
+	public static native double pow(double d1, double d2);
+
+	/**
+	 * Returns a pseudo-random number between 0.0 and 1.0.
+	 * 
+	 * @return a pseudo-random number
+	 */
+	public static double random() {
+		if (random == null)
+			random = new Random();
+		return random.nextDouble();
+	}
+
+	/**
+	 * Answers the double conversion of the result of rounding the argument to
+	 * an integer.
+	 * 
+	 * @param d
+	 *            the value to be converted
+	 * @return the closest integer to the argument (as a double).
+	 */
+	public static native double rint(double d);
+
+	/**
+	 * Answers the result of rounding the argument to an integer.
+	 * 
+	 * @param d
+	 *            the value to be converted
+	 * @return the closest integer to the argument.
+	 */
+	public static long round(double d) {
+		// check for NaN
+		if (d != d)
+			return 0L;
+		return (long) Math.floor(d + 0.5d);
+	}
+
+	/**
+	 * Answers the result of rounding the argument to an integer.
+	 * 
+	 * @param f
+	 *            the value to be converted
+	 * @return the closest integer to the argument.
+	 */
+	public static int round(float f) {
+		// check for NaN
+		if (f != f)
+			return 0;
+		return (int) Math.floor(f + 0.5f);
+	}
+
+	/**
+	 * Answers the closest double approximation of the sine of the argument
+	 * 
+	 * @param d
+	 *            the value to compute sin of
+	 * @return the sine of the argument.
+	 */
+	public static native double sin(double d);
+
+	/**
+	 * Answers the closest double approximation of the square root of the
+	 * argument
+	 * 
+	 * @param d
+	 *            the value to compute sqrt of
+	 * @return the square root of the argument.
+	 */
+	public static native double sqrt(double d);
+
+	/**
+	 * Answers the closest double approximation of the tangent of the argument
+	 * 
+	 * @param d
+	 *            the value to compute tan of
+	 * @return the tangent of the argument.
+	 */
+	public static native double tan(double d);
+
+	/**
+	 * Returns the measure in degrees of the supplied radian angle
+	 * 
+	 * @param angrad
+	 *            an angle in radians
+	 * @return the degree measure of the angle.
+	 */
+	public static double toDegrees(double angrad) {
+		return angrad * 180d / PI;
+	}
+
+	/**
+	 * Returns the measure in radians of the supplied degree angle
+	 * 
+	 * @param angdeg
+	 *            an angle in degrees
+	 * @return the radian measure of the angle.
+	 */
+	public static double toRadians(double angdeg) {
+		return angdeg / 180d * PI;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StringBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StringBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StringBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StringBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,1084 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Arrays;
+
+/**
+ * StringBuffer is a variable size contiguous indexable array of characters. The
+ * length of the StringBuffer is the number of characters it contains. The
+ * capacity of the StringBuffer is the number of characters it can hold.
+ * <p>
+ * Characters may be inserted at any position up to the length of the
+ * StringBuffer, increasing the length of the StringBuffer. Characters at any
+ * position in the StringBuffer may be replaced, which does not affect the
+ * StringBuffer length.
+ * <p>
+ * The capacity of a StringBuffer may be specified when the StringBuffer is
+ * created. If the capacity of the StringBuffer is exceeded, the capacity is
+ * increased.
+ * 
+ * @see String
+ */
+public final class StringBuffer implements Serializable, CharSequence {
+	
+	static final long serialVersionUID = 3388685877147921107L;
+
+	private static final int INITIAL_SIZE = 16;
+
+	private int count;
+
+	private boolean shared;
+
+	private char[] value;
+
+	/**
+	 * Constructs a new StringBuffer using the default capacity.
+	 */
+	public StringBuffer() {
+		this(INITIAL_SIZE);
+	}
+
+	/**
+	 * Constructs a new StringBuffer using the specified capacity.
+	 * 
+	 * @param capacity
+	 *            the initial capacity
+	 */
+	public StringBuffer(int capacity) {
+		count = 0;
+		shared = false;
+		value = new char[capacity];
+	}
+
+	/**
+	 * Constructs a new StringBuffer containing the characters in the specified
+	 * string and the default capacity.
+	 * 
+	 * @param string
+	 *            the string content with which to initialize the new
+	 *            <code>StringBuffer</code> instance
+	 * @exception NullPointerException
+	 *                on supplying a <code>null</code> value of
+	 *                <code>string</code>
+	 */
+	public StringBuffer(String string) {
+		count = string.length();
+		shared = false;
+		value = new char[count + INITIAL_SIZE];
+		string.getChars(0, count, value, 0);
+	}
+
+	/**
+	 * Adds the character array to the end of this StringBuffer.
+	 * 
+	 * @param chars
+	 *            the character array
+	 * @return this StringBuffer
+	 * 
+	 * @exception NullPointerException
+	 *                when chars is null
+	 */
+	public synchronized StringBuffer append(char chars[]) {
+		int newSize = count + chars.length;
+		if (newSize > value.length) {
+			ensureCapacityImpl(newSize);
+		} else if (shared) {
+			value = (char[]) value.clone();
+			shared = false;
+		}
+		System.arraycopy(chars, 0, value, count, chars.length);
+		count = newSize;
+		return this;
+	}
+
+	/**
+	 * Adds the specified sequence of characters to the end of this
+	 * StringBuffer.
+	 * 
+	 * @param chars
+	 *            a character array
+	 * @param start
+	 *            the starting offset
+	 * @param length
+	 *            the number of characters
+	 * @return this StringBuffer
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>length < 0, start < 0</code> or
+	 *                <code>start + length > chars.length</code>
+	 * @exception NullPointerException
+	 *                when chars is null
+	 */
+	public synchronized StringBuffer append(char chars[], int start, int length) {
+		// start + length could overflow, start/length maybe MaxInt
+		if (start >= 0 && 0 <= length && length <= chars.length - start) {
+			int newSize = count + length;
+			if (newSize > value.length) {
+				ensureCapacityImpl(newSize);
+			} else if (shared) {
+				value = (char[]) value.clone();
+				shared = false;
+			}
+			System.arraycopy(chars, start, value, count, length);
+			count = newSize;
+			return this;
+		}
+		throw new StringIndexOutOfBoundsException();
+	}
+
+	/**
+	 * Adds the specified character to the end of this StringBuffer.
+	 * 
+	 * @param ch
+	 *            a character
+	 * @return this StringBuffer
+	 */
+	public synchronized StringBuffer append(char ch) {
+		if (count >= value.length) {
+			ensureCapacityImpl(count + 1);
+		}
+		if (shared) {
+			value = (char[]) value.clone();
+			shared = false;
+		}
+		value[count] = ch;
+		count++;
+		return this;
+	}
+
+	/**
+	 * Adds the string representation of the specified double to the end of this
+	 * StringBuffer.
+	 * 
+	 * @param d
+	 *            the double
+	 * @return this StringBuffer
+	 */
+	public StringBuffer append(double d) {
+		return append(String.valueOf(d));
+	}
+
+	/**
+	 * Adds the string representation of the specified float to the end of this
+	 * StringBuffer.
+	 * 
+	 * @param f
+	 *            the float
+	 * @return this StringBuffer
+	 */
+	public StringBuffer append(float f) {
+		return append(String.valueOf(f));
+	}
+
+	/**
+	 * Adds the string representation of the specified integer to the end of
+	 * this StringBuffer.
+	 * 
+	 * @param value
+	 *            the integer
+	 * @return this StringBuffer
+	 */
+	public StringBuffer append(int i) {
+		return append(Integer.toString(i));
+	}
+
+	/**
+	 * Adds the string representation of the specified long to the end of this
+	 * StringBuffer.
+	 * 
+	 * @param l
+	 *            the long
+	 * @return this StringBuffer
+	 */
+	public StringBuffer append(long l) {
+		return append(Long.toString(l));
+	}
+
+	/**
+	 * Adds the string representation of the specified object to the end of this
+	 * StringBuffer.
+	 * 
+	 * @param obj
+	 *            the object
+	 * @return this StringBuffer
+	 */
+	public StringBuffer append(Object obj) {
+		return append(String.valueOf(obj));
+	}
+
+	/**
+	 * Adds the specified string to the end of this StringBuffer.
+	 * 
+	 * @param string
+	 *            the string
+	 * @return this StringBuffer
+	 */
+	public synchronized StringBuffer append(String string) {
+		if (string == null)
+			string = String.valueOf(string);
+		int adding = string.length();
+		int newSize = count + adding;
+		if (newSize > value.length) {
+			ensureCapacityImpl(newSize);
+		} else if (shared) {
+			value = (char[]) value.clone();
+			shared = false;
+		}
+		string.getChars(0, adding, value, count);
+		count = newSize;
+		return this;
+	}
+
+	/**
+	 * Adds the string representation of the specified boolean to the end of
+	 * this StringBuffer.
+	 * 
+	 * @param b
+	 *            the boolean
+	 * @return this StringBuffer
+	 */
+	public StringBuffer append(boolean b) {
+		return append(String.valueOf(b));
+	}
+
+	/**
+	 * Answers the number of characters this StringBuffer can hold without
+	 * growing.
+	 * 
+	 * @return the capacity of this StringBuffer
+	 * 
+	 * @see #ensureCapacity
+	 * @see #length
+	 */
+	public int capacity() {
+		return value.length;
+	}
+
+	/**
+	 * Answers the character at the specified offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the zero-based index in this StringBuffer
+	 * @return the character at the index
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index >= length()</code>
+	 */
+	public synchronized char charAt(int index) {
+		try {
+			if (index < count)
+				return value[index];
+		} catch (IndexOutOfBoundsException e) {
+		}
+		throw new StringIndexOutOfBoundsException(index);
+	}
+
+	/**
+	 * Deletes a range of characters.
+	 * 
+	 * @param start
+	 *            the offset of the first character
+	 * @param end
+	 *            the offset one past the last character
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>start < 0, start > end</code> or
+	 *                <code>end > length()</code>
+	 */
+	public synchronized StringBuffer delete(int start, int end) {
+		if (start >= 0) {
+			if (end > count)
+				end = count;
+			if (end > start) {
+				int length = count - end;
+				if (length > 0) {
+					try {
+						if (!shared) {
+							System.arraycopy(value, end, value, start, length);
+						} else {
+							char[] newData = new char[value.length];
+							System.arraycopy(value, 0, newData, 0, start);
+							System
+									.arraycopy(value, end, newData, start,
+											length);
+							value = newData;
+							shared = false;
+						}
+					} catch (IndexOutOfBoundsException e) {
+						throw new StringIndexOutOfBoundsException();
+					}
+				}
+				count -= end - start;
+				return this;
+			}
+			if (start == end)
+				return this;
+		}
+		throw new StringIndexOutOfBoundsException();
+	}
+
+	/**
+	 * Deletes a single character
+	 * 
+	 * @param location
+	 *            the offset of the character to delete
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>location < 0</code> or
+	 *                <code>location >= length()</code>
+	 */
+	public synchronized StringBuffer deleteCharAt(int location) {
+		if (0 <= location && location < count) {
+			int length = count - location - 1;
+			if (length > 0) {
+				try {
+					if (!shared) {
+						System.arraycopy(value, location + 1, value, location,
+								length);
+					} else {
+						char[] newData = new char[value.length];
+						System.arraycopy(value, 0, newData, 0, location);
+						System.arraycopy(value, location + 1, newData,
+								location, length);
+						value = newData;
+						shared = false;
+					}
+				} catch (IndexOutOfBoundsException e) {
+					throw new StringIndexOutOfBoundsException(location);
+				}
+			}
+			count--;
+			return this;
+		}
+		throw new StringIndexOutOfBoundsException(location);
+	}
+
+	/**
+	 * Ensures that this StringBuffer can hold the specified number of
+	 * characters without growing.
+	 * 
+	 * @param min
+	 *            the minimum number of elements that this StringBuffer will
+	 *            hold before growing
+	 */
+	public synchronized void ensureCapacity(int min) {
+		if (min > value.length)
+			ensureCapacityImpl(min);
+	}
+
+	private void ensureCapacityImpl(int min) {
+		int twice = (value.length << 1) + 2;
+		char[] newData = new char[min > twice ? min : twice];
+		System.arraycopy(value, 0, newData, 0, count);
+		value = newData;
+		shared = false;
+	}
+
+	/**
+	 * Copies the specified characters in this StringBuffer to the character
+	 * array starting at the specified offset in the character array.
+	 * 
+	 * @param start
+	 *            the starting offset of characters to copy
+	 * @param end
+	 *            the ending offset of characters to copy
+	 * @param buffer
+	 *            the destination character array
+	 * @param index
+	 *            the starting offset in the character array
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>start < 0, end > length(),
+	 *				start > end, index < 0, end - start > buffer.length - index</code>
+	 * @exception NullPointerException
+	 *                when buffer is null
+	 */
+	public synchronized void getChars(int start, int end, char[] buffer,
+			int index) {
+		// NOTE last character not copied!
+		try {
+			if (start <= count && end <= count) {
+				System.arraycopy(value, start, buffer, index, end - start);
+				return;
+			}
+		} catch (IndexOutOfBoundsException e) {
+		}
+		throw new StringIndexOutOfBoundsException();
+	}
+
+	/**
+	 * Inserts the character array at the specified offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the index at which to insert
+	 * @param chars
+	 *            the character array to insert
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index > length()</code>
+	 * @exception NullPointerException
+	 *                when chars is null
+	 */
+	public synchronized StringBuffer insert(int index, char[] chars) {
+		if (0 <= index && index <= count) {
+			move(chars.length, index);
+			System.arraycopy(chars, 0, value, index, chars.length);
+			count += chars.length;
+			return this;
+		}
+		throw new StringIndexOutOfBoundsException(index);
+	}
+
+	/**
+	 * Inserts the specified sequence of characters at the specified offset in
+	 * this StringBuffer.
+	 * 
+	 * @param index
+	 *            the index at which to insert
+	 * @param chars
+	 *            a character array
+	 * @param start
+	 *            the starting offset
+	 * @param length
+	 *            the number of characters
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>length < 0, start < 0,</code>
+	 *				<code>start + length > chars.length, index < 0</code>
+	 *                or <code>index > length()</code>
+	 * @exception NullPointerException
+	 *                when chars is null
+	 */
+	public synchronized StringBuffer insert(int index, char chars[], int start,
+			int length) {
+		if (0 <= index && index <= count) {
+			// start + length could overflow, start/length maybe MaxInt
+			if (start >= 0 && 0 <= length && length <= chars.length - start) {
+				move(length, index);
+				System.arraycopy(chars, start, value, index, length);
+				count += length;
+				return this;
+			}
+			throw new StringIndexOutOfBoundsException();
+		}
+		throw new StringIndexOutOfBoundsException(index);
+	}
+
+	/**
+	 * Inserts the character at the specified offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the index at which to insert
+	 * @param ch
+	 *            the character to insert
+	 * @return this StringBuffer
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index > length()</code>
+	 */
+	public synchronized StringBuffer insert(int index, char ch) {
+		if (0 <= index && index <= count) {
+			move(1, index);
+			value[index] = ch;
+			count++;
+			return this;
+		}
+		throw new StringIndexOutOfBoundsException(index);
+	}
+
+	/**
+	 * Inserts the string representation of the specified double at the
+	 * specified offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the index at which to insert
+	 * @param d
+	 *            the double to insert
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index > length()</code>
+	 */
+	public StringBuffer insert(int index, double d) {
+		return insert(index, String.valueOf(d));
+	}
+
+	/**
+	 * Inserts the string representation of the specified float at the specified
+	 * offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the index at which to insert
+	 * @param f
+	 *            the float to insert
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index > length()</code>
+	 */
+	public StringBuffer insert(int index, float f) {
+		return insert(index, String.valueOf(f));
+	}
+
+	/**
+	 * Inserts the string representation of the specified integer at the
+	 * specified offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the index at which to insert
+	 * @param i
+	 *            the integer to insert
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index > length()</code>
+	 */
+	public StringBuffer insert(int index, int i) {
+		return insert(index, Integer.toString(i));
+	}
+
+	/**
+	 * Inserts the string representation of the specified long at the specified
+	 * offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the index at which to insert
+	 * @param l
+	 *            the long to insert
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index > length()</code>
+	 */
+	public StringBuffer insert(int index, long l) {
+		return insert(index, Long.toString(l));
+	}
+
+	/**
+	 * Inserts the string representation of the specified object at the
+	 * specified offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the index at which to insert
+	 * @param obj
+	 *            the object to insert
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index > length()</code>
+	 */
+	public StringBuffer insert(int index, Object obj) {
+		return insert(index, String.valueOf(obj));
+	}
+
+	/**
+	 * Inserts the string at the specified offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the index at which to insert
+	 * @param string
+	 *            the string to insert
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index > length()</code>
+	 */
+	public synchronized StringBuffer insert(int index, String string) {
+		if (0 <= index && index <= count) {
+			if (string == null)
+				string = String.valueOf(string);
+			int min = string.length();
+			move(min, index);
+			string.getChars(0, min, value, index);
+			count += min;
+			return this;
+		}
+		throw new StringIndexOutOfBoundsException(index);
+	}
+
+	/**
+	 * Inserts the string representation of the specified boolean at the
+	 * specified offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the index at which to insert
+	 * @param b
+	 *            the boolean to insert
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index > length()</code>
+	 */
+	public StringBuffer insert(int index, boolean b) {
+		return insert(index, String.valueOf(b));
+	}
+
+	/**
+	 * Answers the size of this StringBuffer.
+	 * 
+	 * @return the number of characters in this StringBuffer
+	 */
+	public int length() {
+		return count;
+	}
+
+	private void move(int size, int index) {
+		int newSize;
+		if (value.length - count >= size) {
+			if (!shared) {
+				System.arraycopy(value, index, value, index + size, count
+						- index); // index == count case is no-op
+				return;
+			}
+			newSize = value.length;
+		} else {
+			int a = count + size, b = (value.length << 1) + 2;
+			newSize = a > b ? a : b;
+		}
+
+		char[] newData = new char[newSize];
+		System.arraycopy(value, 0, newData, 0, index);
+		// index == count case is no-op
+		System.arraycopy(value, index, newData, index + size, count - index); 
+		value = newData;
+		shared = false;
+	}
+
+	/**
+	 * Replace a range of characters with the characters in the specified
+	 * String.
+	 * 
+	 * @param start
+	 *            the offset of the first character
+	 * @param end
+	 *            the offset one past the last character
+	 * @param string
+	 *            a String
+	 * @return this StringBuffer
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>start < 0</code> or <code>start > end</code>
+	 */
+	public synchronized StringBuffer replace(int start, int end, String string) {
+		if (start >= 0) {
+			if (end > count)
+				end = count;
+			if (end > start) {
+				int stringLength = string.length();
+				int diff = end - start - stringLength;
+				if (diff > 0) { // replacing with fewer characters
+					if (!shared) {
+						 // index == count case is no-op
+						System.arraycopy(value, end, value, start
+								+ stringLength, count - end);
+					} else {
+						char[] newData = new char[value.length];
+						System.arraycopy(value, 0, newData, 0, start);
+						// index == count case is no-op
+						System.arraycopy(value, end, newData, start
+								+ stringLength, count - end);
+						value = newData;
+						shared = false;
+					}
+				} else if (diff < 0) {
+					// replacing with more characters...need some room
+					move(-diff, end);
+				} else if (shared) {
+					value = (char[]) value.clone();
+					shared = false;
+				}
+				string.getChars(0, stringLength, value, start);
+				count -= diff;
+				return this;
+			}
+			if (start == end) {
+				if (string == null)
+					throw new NullPointerException();
+				return insert(start, string);
+			}
+		}
+		throw new StringIndexOutOfBoundsException();
+	}
+
+	/**
+	 * Reverses the order of characters in this StringBuffer.
+	 * 
+	 * @return this StringBuffer
+	 */
+	public synchronized StringBuffer reverse() {
+		if (count < 2) {
+			return this;
+		}
+		if (!shared) {
+			for (int i = 0, end = count, mid = count / 2; i < mid; i++) {
+				char temp = value[--end];
+				value[end] = value[i];
+				value[i] = temp;
+			}
+		} else {
+			char[] newData = new char[value.length];
+			for (int i = 0, end = count; i < count; i++) {
+				newData[--end] = value[i];
+			}
+			value = newData;
+			shared = false;
+		}
+		return this;
+	}
+
+	/**
+	 * Sets the character at the specified offset in this StringBuffer.
+	 * 
+	 * @param index
+	 *            the zero-based index in this StringBuffer
+	 * @param ch
+	 *            the character
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>index < 0</code> or
+	 *                <code>index >= length()</code>
+	 */
+	public synchronized void setCharAt(int index, char ch) {
+		if (shared) {
+			value = (char[]) value.clone();
+			shared = false;
+		}
+		if (0 <= index && index < count)
+			value[index] = ch;
+		else
+			throw new StringIndexOutOfBoundsException(index);
+	}
+
+	/**
+	 * Sets the length of this StringBuffer to the specified length. If there
+	 * are more than length characters in this StringBuffer, the characters at
+	 * end are lost. If there are less than length characters in the
+	 * StringBuffer, the additional characters are set to <code>\\u0000</code>.
+	 * 
+	 * @param length
+	 *            the new length of this StringBuffer
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>length < 0</code>
+	 * 
+	 * @see #length
+	 */
+	public synchronized void setLength(int length) {
+		if (length > value.length)
+			ensureCapacityImpl(length);
+		if (count > length) {
+			if (!shared) {
+				// NOTE: delete & replace do not void characters orphaned at the
+				// end
+				try {
+					Arrays.fill(value, length, count, (char) 0);
+				} catch (ArrayIndexOutOfBoundsException e) {
+					throw new IndexOutOfBoundsException();
+				}
+			} else {
+				char[] newData = new char[value.length];
+				if (length > 0) {
+					System.arraycopy(value, 0, newData, 0, length);
+				}
+				value = newData;
+				shared = false;
+			}
+		}
+		count = length;
+	}
+
+	/**
+	 * Copies a range of characters into a new String.
+	 * 
+	 * @param start
+	 *            the offset of the first character
+	 * @return a new String containing the characters from start to the end of
+	 *         the string
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>start < 0</code> or
+	 *                <code>start > length()</code>
+	 */
+	public synchronized String substring(int start) {
+		if (0 <= start && start <= count) {
+			shared = true;
+			return new String(start, count - start, value);
+		}
+		throw new StringIndexOutOfBoundsException(start);
+	}
+
+	/**
+	 * Copies a range of characters into a new String.
+	 * 
+	 * @param start
+	 *            the offset of the first character
+	 * @param end
+	 *            the offset one past the last character
+	 * @return a new String containing the characters from start to end - 1
+	 * 
+	 * @exception StringIndexOutOfBoundsException
+	 *                when <code>start < 0, start > end</code> or
+	 *                <code>end > length()</code>
+	 */
+	public synchronized String substring(int start, int end) {
+		if (0 <= start && start <= end && end <= count) {
+			shared = true;
+			return new String(value, start, end - start);
+		}
+		throw new StringIndexOutOfBoundsException();
+	}
+
+	/**
+	 * Answers the contents of this StringBuffer.
+	 * 
+	 * @return a String containing the characters in this StringBuffer
+	 */
+	public synchronized String toString() {
+		if (count >= 256 && count <= (value.length >> 1))
+			return new String(value, 0, count);
+		shared = true;
+		return new String(0, count, value);
+	}
+
+	/*
+	 * Return the underlying buffer and set the shared flag.
+	 * 
+	 */
+	char[] shareValue() {
+		shared = true;
+		return value;
+	}
+
+	private synchronized void writeObject(ObjectOutputStream stream)
+			throws IOException {
+		stream.defaultWriteObject();
+	}
+
+	private void readObject(ObjectInputStream stream) throws IOException,
+			ClassNotFoundException {
+		stream.defaultReadObject();
+		if (count > value.length)
+			throw new InvalidObjectException(com.ibm.oti.util.Msg
+					.getString("K0199"));
+		shared = false;
+	}
+
+	/**
+	 * Adds the specified StringBuffer to the end of this StringBuffer.
+	 * 
+	 * @param sbuffer
+	 *            the StringBuffer
+	 * @return this StringBuffer
+	 * 
+	 * @since 1.4
+	 */
+	public synchronized StringBuffer append(StringBuffer sbuffer) {
+		if (sbuffer == null)
+			return append((String) null);
+		synchronized (sbuffer) {
+			int adding = sbuffer.count;
+			int newSize = count + adding;
+			if (newSize > value.length) {
+				ensureCapacityImpl(newSize);
+			} else if (shared) {
+				value = (char[]) value.clone();
+				shared = false;
+			}
+			System.arraycopy(sbuffer.value, 0, value, count, adding);
+			count = newSize;
+		}
+		return this;
+	}
+
+	/**
+	 * Copies a range of characters into a new String.
+	 * 
+	 * @param start
+	 *            the offset of the first character
+	 * @param end
+	 *            the offset one past the last character
+	 * @return a new String containing the characters from start to end - 1
+	 * 
+	 * @exception IndexOutOfBoundsException
+	 *                when <code>start < 0, start > end</code> or
+	 *                <code>end > length()</code>
+	 * 
+	 * @since 1.4
+	 */
+	public CharSequence subSequence(int start, int end) {
+		return substring(start, end);
+	}
+
+	/**
+	 * Searches in this StringBuffer for the first index of the specified
+	 * character. The search for the character starts at the beginning and moves
+	 * towards the end.
+	 * 
+	 * 
+	 * @param string
+	 *            the string to find
+	 * @return the index in this StringBuffer of the specified character, -1 if
+	 *         the character isn't found
+	 * 
+	 * @see #lastIndexOf(String)
+	 * 
+	 * @since 1.4
+	 */
+	public int indexOf(String string) {
+		return indexOf(string, 0);
+	}
+
+	/**
+	 * Searches in this StringBuffer for the index of the specified character.
+	 * The search for the character starts at the specified offset and moves
+	 * towards the end.
+	 * 
+	 * @param subString
+	 *            the string to find
+	 * @param start
+	 *            the starting offset
+	 * @return the index in this StringBuffer of the specified character, -1 if
+	 *         the character isn't found
+	 * 
+	 * @see #lastIndexOf(String,int)
+	 * 
+	 * @since 1.4
+	 */
+	public synchronized int indexOf(String subString, int start) {
+		if (start < 0)
+			start = 0;
+		int subCount = subString.length();
+		if (subCount > 0) {
+			if (subCount + start > count)
+				return -1;
+			char firstChar = subString.charAt(0);
+			while (true) {
+				int i = start;
+				boolean found = false;
+				for (; i < count; i++)
+					if (value[i] == firstChar) {
+						found = true;
+						break;
+					}
+				if (!found || subCount + i > count)
+					return -1; // handles subCount > count || start >= count
+				int o1 = i, o2 = 0;
+				while (++o2 < subCount && value[++o1] == subString.charAt(o2)) {
+					// Intentionally empty
+				}
+				if (o2 == subCount)
+					return i;
+				start = i + 1;
+			}
+		}
+		return (start < count || start == 0) ? start : count;
+	}
+
+	/**
+	 * Searches in this StringBuffer for the last index of the specified
+	 * character. The search for the character starts at the end and moves
+	 * towards the beginning.
+	 * 
+	 * @param string
+	 *            the string to find
+	 * @return the index in this StringBuffer of the specified character, -1 if
+	 *         the character isn't found
+	 * 
+	 * @see #indexOf(String)
+	 * 
+	 * @since 1.4
+	 */
+	public synchronized int lastIndexOf(String string) {
+		return lastIndexOf(string, count);
+	}
+
+	/**
+	 * Searches in this StringBuffer for the index of the specified character.
+	 * The search for the character starts at the specified offset and moves
+	 * towards the beginning.
+	 * 
+	 * @param subString
+	 *            the string to find
+	 * @param start
+	 *            the starting offset
+	 * @return the index in this StringBuffer of the specified character, -1 if
+	 *         the character isn't found
+	 * 
+	 * @see #indexOf(String,int)
+	 * 
+	 * @since 1.4
+	 */
+	public synchronized int lastIndexOf(String subString, int start) {
+		int subCount = subString.length();
+		if (subCount <= count && start >= 0) {
+			if (subCount > 0) {
+				if (start > count - subCount)
+					start = count - subCount; // count and subCount are both
+												// >= 1
+				char firstChar = subString.charAt(0);
+				while (true) {
+					int i = start;
+					boolean found = false;
+					for (; i >= 0; --i)
+						if (value[i] == firstChar) {
+							found = true;
+							break;
+						}
+					if (!found)
+						return -1;
+					int o1 = i, o2 = 0;
+					while (++o2 < subCount
+							&& value[++o1] == subString.charAt(o2)) {
+						// Intentionally empty
+					}
+					if (o2 == subCount)
+						return i;
+					start = i - 1;
+				}
+			}
+			return start < count ? start : count;
+		}
+		return -1;
+	}
+
+	/*
+	 * Returns the character array for this StringBuffer.
+	 */
+	char[] getValue() {
+		return value;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StringIndexOutOfBoundsException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StringIndexOutOfBoundsException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StringIndexOutOfBoundsException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/StringIndexOutOfBoundsException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,57 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+import com.ibm.oti.util.Msg;
+
+/**
+ * This runtime exception is thrown when the a String is indexed with a value
+ * less than zero, or greater than or equal to the size of the array.
+ */
+
+public class StringIndexOutOfBoundsException extends IndexOutOfBoundsException {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public StringIndexOutOfBoundsException() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * (which is based on the argument which is the index which failed) filled
+	 * in.
+	 * 
+	 * @param index
+	 *            int the index which is out of bounds
+	 */
+	public StringIndexOutOfBoundsException(int index) {
+		super(Msg.getString("K0055", index));
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public StringIndexOutOfBoundsException(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ThreadDeath.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ThreadDeath.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ThreadDeath.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ThreadDeath.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,32 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * ThreadDeath is thrown when a thread stops executing. It is used to aid in the
+ * orderly unrolling of the thread's stack (eg. cleanup of monitors).
+ */
+public class ThreadDeath extends Error {
+
+	/**
+	 * Constructs a new instance of this class. Note that in the case of
+	 * ThreadDeath, the walkback may <em>not</em> be filled in a way which
+	 * allows a stack trace to be printed.
+	 */
+	public ThreadDeath() {
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ThreadLocal.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ThreadLocal.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ThreadLocal.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ThreadLocal.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,56 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * A ThreadLocal is a variable that has a per-thread value. Different Threads
+ * may reference the same ThreadLocal object, but the values they observe will
+ * not be <code>==</code>. This provides Thread local storage.
+ * 
+ * @see java.lang.Thread
+ */
+public class ThreadLocal {
+	/**
+	 * Constructs a new ThreadLocal object
+	 */
+	public ThreadLocal() {
+		super();
+	}
+
+	/**
+	 * Return the value of this variable under
+	 * <code>Thread.currentThread()</code>
+	 */
+	public Object get() {
+		return Thread.currentThread().getThreadLocal(this);
+	}
+
+	/**
+	 * Return the initial value of this variable under
+	 * <code>Thread.currentThread()</code>
+	 */
+	protected Object initialValue() {
+		return null;
+	}
+
+	/**
+	 * Set the value of this variable under <code>Thread.currentThread()</code>
+	 */
+	public void set(Object value) {
+		Thread.currentThread().setThreadLocal(this, value);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnknownError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnknownError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnknownError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnknownError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,42 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This error is thrown when the virtual machine must throw an error which does
+ * not match any known exceptional condition.
+ */
+public class UnknownError extends VirtualMachineError {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public UnknownError() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public UnknownError(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsatisfiedLinkError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsatisfiedLinkError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsatisfiedLinkError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsatisfiedLinkError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,42 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This error is thrown when an attempt is made to invoke a native for which an
+ * implementation could not be found.
+ */
+public class UnsatisfiedLinkError extends LinkageError {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public UnsatisfiedLinkError() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public UnsatisfiedLinkError(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsupportedClassVersionError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsupportedClassVersionError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsupportedClassVersionError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsupportedClassVersionError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,43 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This error is thrown when an attempt is made to load a class with a format
+ * version that is not supported by the VM.
+ */
+
+public class UnsupportedClassVersionError extends ClassFormatError {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public UnsupportedClassVersionError() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public UnsupportedClassVersionError(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsupportedOperationException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsupportedOperationException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsupportedOperationException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/UnsupportedOperationException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,40 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This runtime exception is thrown when an unsupported operation is attempted.
+ */
+public class UnsupportedOperationException extends RuntimeException {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public UnsupportedOperationException() {
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public UnsupportedOperationException(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/VerifyError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/VerifyError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/VerifyError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/VerifyError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,42 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This error is thrown when the VM notices that an attempt is made to load a
+ * class which does not pass the class verification phase.
+ */
+public class VerifyError extends LinkageError {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public VerifyError() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public VerifyError(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/VirtualMachineError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/VirtualMachineError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/VirtualMachineError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/VirtualMachineError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,44 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This class is the superclass of all classes which represent errors that occur
+ * during the operation of the virtual machine.
+ * 
+ * @see Error
+ */
+public abstract class VirtualMachineError extends Error {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public VirtualMachineError() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public VirtualMachineError(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Void.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Void.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Void.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/Void.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,44 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang;
+
+
+/**
+ * This class is a placeholder class for the Java keyword <code>void</code>
+ */
+public final class Void extends Object {
+	/**
+	 * The java.lang.Class that represents this class.
+	 */
+	public static final Class TYPE;
+	// Note: This can't be set to "void.class", since *that* is
+	// defined to be "java.lang.Void.TYPE";
+
+	static {
+		Class voidType = null;
+		try {
+			java.lang.reflect.Method method = Runnable.class.getMethod("run",
+					new Class[0]);
+			voidType = method.getReturnType();
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+		TYPE = voidType;
+	}
+
+	private Void() {
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ref/ReferenceQueue.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ref/ReferenceQueue.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ref/ReferenceQueue.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/ref/ReferenceQueue.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,158 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang.ref;
+
+
+/**
+ * The implementation of this class is provided. The non-public implementation
+ * details are documented so the vm vendor can use the implementation.
+ * 
+ * ReferenceQueue is the container on which reference objects are enqueued when
+ * their reachability type is detected for the referent.
+ * 
+ * @since JDK1.2
+ */
+public class ReferenceQueue extends Object {
+	private Reference[] references;
+
+	private int head, tail;
+
+	private boolean empty;
+
+	static private final int DEFAULT_QUEUE_SIZE = 128;
+
+	/**
+	 * Returns the next available reference from the queue if one is enqueued,
+	 * null otherwise. Does not wait for a reference to become available.
+	 * 
+	 * @return Reference next available Reference or NULL.
+	 */
+	public Reference poll() {
+		Reference ref;
+
+		synchronized (this) {
+			if (empty) {
+				return null;
+			}
+			ref = references[head++];
+			ref.dequeue();
+			if (head == references.length) {
+				head = 0;
+			}
+			if (head == tail) {
+				empty = true;
+			}
+		}
+		return ref;
+	}
+
+	/**
+	 * Return the next available enqueued reference on the queue, blocking
+	 * indefinately until one is available.
+	 * 
+	 * @return Reference a Reference object if one is available, null otherwise.
+	 * @exception InterruptedException
+	 *                to interrupt the wait.
+	 */
+	public Reference remove() throws InterruptedException {
+		return remove(0L);
+	}
+
+	/**
+	 * Return the next available enqueued reference on the queue, blocking up to
+	 * the time given until one is available. Return null if no reference became
+	 * available.
+	 * 
+	 * @param timeout
+	 *            maximum time spent waiting for a reference object to become
+	 *            available.
+	 * @return Reference a Reference object if one is available, null otherwise.
+	 * @exception IllegalArgumentException
+	 *                if the wait period is negative. InterruptedException to
+	 *                interrupt the wait.
+	 */
+	public Reference remove(long timeout) throws IllegalArgumentException,
+			InterruptedException {
+		if (timeout < 0) {
+			throw new IllegalArgumentException();
+		}
+
+		Reference ref;
+		synchronized (this) {
+			if (empty) {
+				wait(timeout);
+				if (empty) {
+					return null;
+				}
+			}
+			ref = references[head++];
+			ref.dequeue();
+			if (head == references.length) {
+				head = 0;
+			}
+			if (head == tail) {
+				empty = true;
+			} else {
+				notifyAll();
+			}
+		}
+		return ref;
+	}
+
+	/**
+	 * Enqueue the reference object on the receiver.
+	 * 
+	 * @param reference
+	 *            reference object to be enqueued.
+	 * @return boolean true if reference is enqueued. false if reference failed
+	 *         to enqueue.
+	 */
+	boolean enqueue(Reference reference) {
+		synchronized (this) {
+			if (!empty && head == tail) {
+				/* Queue is full - grow */
+				int newQueueSize = (int) (references.length * 1.10);
+				Reference newQueue[] = new Reference[newQueueSize];
+				System.arraycopy(references, head, newQueue, 0,
+						references.length - head);
+				if (tail > 0) {
+					System.arraycopy(references, 0, newQueue, references.length
+							- head, tail);
+				}
+				head = 0;
+				tail = references.length;
+				references = newQueue;
+			}
+			references[tail++] = reference;
+			if (tail == references.length) {
+				tail = 0;
+			}
+			empty = false;
+			notifyAll();
+		}
+		return true;
+	}
+
+	/**
+	 * Constructs a new instance of this class.
+	 */
+	public ReferenceQueue() {
+		references = new Reference[DEFAULT_QUEUE_SIZE];
+		head = 0;
+		tail = 0;
+		empty = true;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/InvocationHandler.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/InvocationHandler.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/InvocationHandler.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/InvocationHandler.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,48 @@
+/* Copyright 2001, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang.reflect;
+
+
+/**
+ * Implementors of this interface decode and dispatch methods sent to proxy
+ * instances.
+ * 
+ * @see Proxy
+ */
+public interface InvocationHandler {
+	/**
+	 * Return the result of decoding and dispatching the method which was
+	 * originally sent to the proxy instance.
+	 * 
+	 * @param proxy
+	 *            the proxy instance which was the receiver of the method.
+	 * @param method
+	 *            the Method invoked on the proxy instance.
+	 * @param args
+	 *            an array of objects containing the parameters passed to the
+	 *            method, or null if no arguments are expected. primitive types
+	 *            are wrapped in the appropriate class.
+	 * @return the result of executing the method
+	 * 
+	 * @throws Throwable
+	 *             if an exception was thrown by the invoked method. The
+	 *             exception must match one of the declared exception types for
+	 *             the invoked method or any unchecked exception type. If not
+	 *             then an UndeclaredThrowableException is thrown.
+	 */
+	public Object invoke(Object proxy, Method method, Object[] args)
+			throws Throwable;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/InvocationTargetException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/InvocationTargetException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/InvocationTargetException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/lang/reflect/InvocationTargetException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,82 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.lang.reflect;
+
+
+/**
+ * This class provides a wrapper for an exception thrown by a Method or
+ * Constructor invocation.
+ * 
+ * @see java.lang.reflect.Method#invoke
+ * @see java.lang.reflect.Constructor#newInstance
+ */
+public class InvocationTargetException extends Exception {
+
+	static final long serialVersionUID = 4085088731926701167L;
+
+	private Throwable target;
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	protected InvocationTargetException() {
+		super((Throwable) null);
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and target
+	 * exception filled in.
+	 * 
+	 * @param exception
+	 *            Throwable The exception which occurred while running the
+	 *            Method or Constructor.
+	 */
+	public InvocationTargetException(Throwable exception) {
+		super(null, exception);
+		target = exception;
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback, target
+	 * exception and message filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 * @param exception
+	 *            Throwable The exception which occurred while running the
+	 *            Method or Constructor.
+	 */
+	public InvocationTargetException(Throwable exception, String detailMessage) {
+		super(detailMessage, exception);
+		target = exception;
+	}
+
+	/**
+	 * Answers the exception which caused the receiver to be thrown.
+	 */
+	public Throwable getTargetException() {
+		return target;
+	}
+
+	/**
+	 * Answers the cause of this Throwable, or null if there is no cause.
+	 * 
+	 * @return Throwable The receiver's cause.
+	 */
+	public Throwable getCause() {
+		return target;
+	}
+}