# HG changeset patch # User Jaroslav Tulach # Date 1348893514 -7200 # Node ID 94c1a17117f3b37dbbfdb88b08a28f6873a95a4a # Parent 0a115f1c6f3c70458fc479ae82b4d7fcdeb7e95a More classes that could not be found diff -r 0a115f1c6f3c -r 94c1a17117f3 emul/src/main/java/java/lang/CharSequence.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/src/main/java/java/lang/CharSequence.java Sat Sep 29 06:38:34 2012 +0200 @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + + +/** + * A CharSequence is a readable sequence of char values. This + * interface provides uniform, read-only access to many different kinds of + * char sequences. + * A char value represents a character in the Basic + * Multilingual Plane (BMP) or a surrogate. Refer to Unicode Character Representation for details. + * + *

This interface does not refine the general contracts of the {@link + * java.lang.Object#equals(java.lang.Object) equals} and {@link + * java.lang.Object#hashCode() hashCode} methods. The result of comparing two + * objects that implement CharSequence is therefore, in general, + * undefined. Each object may be implemented by a different class, and there + * is no guarantee that each class will be capable of testing its instances + * for equality with those of the other. It is therefore inappropriate to use + * arbitrary CharSequence instances as elements in a set or as keys in + * a map.

+ * + * @author Mike McCloskey + * @since 1.4 + * @spec JSR-51 + */ + +public interface CharSequence { + + /** + * Returns the length of this character sequence. The length is the number + * of 16-bit chars in the sequence.

+ * + * @return the number of chars in this sequence + */ + int length(); + + /** + * Returns the char value at the specified index. An index ranges from zero + * to length() - 1. The first char value of the sequence is at + * index zero, the next at index one, and so on, as for array + * indexing.

+ * + *

If the char value specified by the index is a + * surrogate, the surrogate + * value is returned. + * + * @param index the index of the char value to be returned + * + * @return the specified char value + * + * @throws IndexOutOfBoundsException + * if the index argument is negative or not less than + * length() + */ + char charAt(int index); + + /** + * Returns a new CharSequence that is a subsequence of this sequence. + * The subsequence starts with the char value at the specified index and + * ends with the char value at index end - 1. The length + * (in chars) of the + * returned sequence is end - start, so if start == end + * then an empty sequence is returned.

+ * + * @param start the start index, inclusive + * @param end the end index, exclusive + * + * @return the specified subsequence + * + * @throws IndexOutOfBoundsException + * if start or end are negative, + * if end is greater than length(), + * or if start is greater than end + */ + CharSequence subSequence(int start, int end); + + /** + * Returns a string containing the characters in this sequence in the same + * order as this sequence. The length of the string will be the length of + * this sequence.

+ * + * @return a string consisting of exactly this sequence of characters + */ + public String toString(); + +} diff -r 0a115f1c6f3c -r 94c1a17117f3 emul/src/main/java/java/lang/Comparable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/src/main/java/java/lang/Comparable.java Sat Sep 29 06:38:34 2012 +0200 @@ -0,0 +1,138 @@ +/* + * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; +import java.util.*; + +/** + * This interface imposes a total ordering on the objects of each class that + * implements it. This ordering is referred to as the class's natural + * ordering, and the class's compareTo method is referred to as + * its natural comparison method.

+ * + * Lists (and arrays) of objects that implement this interface can be sorted + * automatically by {@link Collections#sort(List) Collections.sort} (and + * {@link Arrays#sort(Object[]) Arrays.sort}). Objects that implement this + * interface can be used as keys in a {@linkplain SortedMap sorted map} or as + * elements in a {@linkplain SortedSet sorted set}, without the need to + * specify a {@linkplain Comparator comparator}.

+ * + * The natural ordering for a class C is said to be consistent + * with equals if and only if e1.compareTo(e2) == 0 has + * the same boolean value as e1.equals(e2) for every + * e1 and e2 of class C. Note that null + * is not an instance of any class, and e.compareTo(null) should + * throw a NullPointerException even though e.equals(null) + * returns false.

+ * + * It is strongly recommended (though not required) that natural orderings be + * consistent with equals. This is so because sorted sets (and sorted maps) + * without explicit comparators behave "strangely" when they are used with + * elements (or keys) whose natural ordering is inconsistent with equals. In + * particular, such a sorted set (or sorted map) violates the general contract + * for set (or map), which is defined in terms of the equals + * method.

+ * + * For example, if one adds two keys a and b such that + * (!a.equals(b) && a.compareTo(b) == 0) to a sorted + * set that does not use an explicit comparator, the second add + * operation returns false (and the size of the sorted set does not increase) + * because a and b are equivalent from the sorted set's + * perspective.

+ * + * Virtually all Java core classes that implement Comparable have natural + * orderings that are consistent with equals. One exception is + * java.math.BigDecimal, whose natural ordering equates + * BigDecimal objects with equal values and different precisions + * (such as 4.0 and 4.00).

+ * + * For the mathematically inclined, the relation that defines + * the natural ordering on a given class C is:

+ *       {(x, y) such that x.compareTo(y) <= 0}.
+ * 
The quotient for this total order is:
+ *       {(x, y) such that x.compareTo(y) == 0}.
+ * 
+ * + * It follows immediately from the contract for compareTo that the + * quotient is an equivalence relation on C, and that the + * natural ordering is a total order on C. When we say that a + * class's natural ordering is consistent with equals, we mean that the + * quotient for the natural ordering is the equivalence relation defined by + * the class's {@link Object#equals(Object) equals(Object)} method:
+ *     {(x, y) such that x.equals(y)}. 

+ * + * This interface is a member of the + * + * Java Collections Framework. + * + * @param the type of objects that this object may be compared to + * + * @author Josh Bloch + * @see java.util.Comparator + * @since 1.2 + */ + +public interface Comparable { + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * + *

The implementor must ensure sgn(x.compareTo(y)) == + * -sgn(y.compareTo(x)) for all x and y. (This + * implies that x.compareTo(y) must throw an exception iff + * y.compareTo(x) throws an exception.) + * + *

The implementor must also ensure that the relation is transitive: + * (x.compareTo(y)>0 && y.compareTo(z)>0) implies + * x.compareTo(z)>0. + * + *

Finally, the implementor must ensure that x.compareTo(y)==0 + * implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for + * all z. + * + *

It is strongly recommended, but not strictly required that + * (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any + * class that implements the Comparable interface and violates + * this condition should clearly indicate this fact. The recommended + * language is "Note: this class has a natural ordering that is + * inconsistent with equals." + * + *

In the foregoing description, the notation + * sgn(expression) designates the mathematical + * signum function, which is defined to return one of -1, + * 0, or 1 according to whether the value of + * expression is negative, zero or positive. + * + * @param o the object to be compared. + * @return a negative integer, zero, or a positive integer as this object + * is less than, equal to, or greater than the specified object. + * + * @throws NullPointerException if the specified object is null + * @throws ClassCastException if the specified object's type prevents it + * from being compared to this object. + */ + public int compareTo(T o); +} diff -r 0a115f1c6f3c -r 94c1a17117f3 emul/src/main/java/java/lang/Deprecated.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/src/main/java/java/lang/Deprecated.java Sat Sep 29 06:38:34 2012 +0200 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +import java.lang.annotation.*; +import static java.lang.annotation.ElementType.*; + +/** + * A program element annotated @Deprecated is one that programmers + * are discouraged from using, typically because it is dangerous, + * or because a better alternative exists. Compilers warn when a + * deprecated program element is used or overridden in non-deprecated code. + * + * @author Neal Gafter + * @since 1.5 + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE}) +public @interface Deprecated { +} diff -r 0a115f1c6f3c -r 94c1a17117f3 emul/src/main/java/java/lang/Exception.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/src/main/java/java/lang/Exception.java Sat Sep 29 06:38:34 2012 +0200 @@ -0,0 +1,124 @@ +/* + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +/** + * The class {@code Exception} and its subclasses are a form of + * {@code Throwable} that indicates conditions that a reasonable + * application might want to catch. + * + *

The class {@code Exception} and any subclasses that are not also + * subclasses of {@link RuntimeException} are checked + * exceptions. Checked exceptions need to be declared in a + * method or constructor's {@code throws} clause if they can be thrown + * by the execution of the method or constructor and propagate outside + * the method or constructor boundary. + * + * @author Frank Yellin + * @see java.lang.Error + * @jls 11.2 Compile-Time Checking of Exceptions + * @since JDK1.0 + */ +public class Exception extends Throwable { + static final long serialVersionUID = -3387516993124229948L; + + /** + * Constructs a new exception with {@code null} as its detail message. + * The cause is not initialized, and may subsequently be initialized by a + * call to {@link #initCause}. + */ + public Exception() { + super(); + } + + /** + * Constructs a new exception with the specified detail message. The + * cause is not initialized, and may subsequently be initialized by + * a call to {@link #initCause}. + * + * @param message the detail message. The detail message is saved for + * later retrieval by the {@link #getMessage()} method. + */ + public Exception(String message) { + super(message); + } + + /** + * Constructs a new exception with the specified detail message and + * cause.

Note that the detail message associated with + * {@code cause} is not automatically incorporated in + * this exception's detail message. + * + * @param message the detail message (which is saved for later retrieval + * by the {@link #getMessage()} method). + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A null value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.4 + */ + public Exception(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructs a new exception with the specified cause and a detail + * message of (cause==null ? null : cause.toString()) (which + * typically contains the class and detail message of cause). + * This constructor is useful for exceptions that are little more than + * wrappers for other throwables (for example, {@link + * java.security.PrivilegedActionException}). + * + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A null value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.4 + */ + public Exception(Throwable cause) { + super(cause); + } + + /** + * Constructs a new exception with the specified detail message, + * cause, suppression enabled or disabled, and writable stack + * trace enabled or disabled. + * + * @param message the detail message. + * @param cause the cause. (A {@code null} value is permitted, + * and indicates that the cause is nonexistent or unknown.) + * @param enableSuppression whether or not suppression is enabled + * or disabled + * @param writableStackTrace whether or not the stack trace should + * be writable + * @since 1.7 + */ + protected Exception(String message, Throwable cause, + boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff -r 0a115f1c6f3c -r 94c1a17117f3 emul/src/main/java/java/lang/RuntimeException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/src/main/java/java/lang/RuntimeException.java Sat Sep 29 06:38:34 2012 +0200 @@ -0,0 +1,119 @@ +/* + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +/** + * {@code RuntimeException} is the superclass of those + * exceptions that can be thrown during the normal operation of the + * Java Virtual Machine. + * + *

{@code RuntimeException} and its subclasses are unchecked + * exceptions. Unchecked exceptions do not need to be + * declared in a method or constructor's {@code throws} clause if they + * can be thrown by the execution of the method or constructor and + * propagate outside the method or constructor boundary. + * + * @author Frank Yellin + * @jls 11.2 Compile-Time Checking of Exceptions + * @since JDK1.0 + */ +public class RuntimeException extends Exception { + static final long serialVersionUID = -7034897190745766939L; + + /** Constructs a new runtime exception with {@code null} as its + * detail message. The cause is not initialized, and may subsequently be + * initialized by a call to {@link #initCause}. + */ + public RuntimeException() { + super(); + } + + /** Constructs a new runtime exception with the specified detail message. + * The cause is not initialized, and may subsequently be initialized by a + * call to {@link #initCause}. + * + * @param message the detail message. The detail message is saved for + * later retrieval by the {@link #getMessage()} method. + */ + public RuntimeException(String message) { + super(message); + } + + /** + * Constructs a new runtime exception with the specified detail message and + * cause.

Note that the detail message associated with + * {@code cause} is not automatically incorporated in + * this runtime exception's detail message. + * + * @param message the detail message (which is saved for later retrieval + * by the {@link #getMessage()} method). + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A null value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.4 + */ + public RuntimeException(String message, Throwable cause) { + super(message, cause); + } + + /** Constructs a new runtime exception with the specified cause and a + * detail message of (cause==null ? null : cause.toString()) + * (which typically contains the class and detail message of + * cause). This constructor is useful for runtime exceptions + * that are little more than wrappers for other throwables. + * + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A null value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + * @since 1.4 + */ + public RuntimeException(Throwable cause) { + super(cause); + } + + /** + * Constructs a new runtime exception with the specified detail + * message, cause, suppression enabled or disabled, and writable + * stack trace enabled or disabled. + * + * @param message the detail message. + * @param cause the cause. (A {@code null} value is permitted, + * and indicates that the cause is nonexistent or unknown.) + * @param enableSuppression whether or not suppression is enabled + * or disabled + * @param writableStackTrace whether or not the stack trace should + * be writable + * + * @since 1.7 + */ + protected RuntimeException(String message, Throwable cause, + boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff -r 0a115f1c6f3c -r 94c1a17117f3 emul/src/main/java/java/lang/StackTraceElement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/src/main/java/java/lang/StackTraceElement.java Sat Sep 29 06:38:34 2012 +0200 @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +import java.util.Objects; + +/** + * An element in a stack trace, as returned by {@link + * Throwable#getStackTrace()}. Each element represents a single stack frame. + * All stack frames except for the one at the top of the stack represent + * a method invocation. The frame at the top of the stack represents the + * execution point at which the stack trace was generated. Typically, + * this is the point at which the throwable corresponding to the stack trace + * was created. + * + * @since 1.4 + * @author Josh Bloch + */ +public final class StackTraceElement implements java.io.Serializable { + // Normally initialized by VM (public constructor added in 1.5) + private String declaringClass; + private String methodName; + private String fileName; + private int lineNumber; + + /** + * Creates a stack trace element representing the specified execution + * point. + * + * @param declaringClass the fully qualified name of the class containing + * the execution point represented by the stack trace element + * @param methodName the name of the method containing the execution point + * represented by the stack trace element + * @param fileName the name of the file containing the execution point + * represented by the stack trace element, or {@code null} if + * this information is unavailable + * @param lineNumber the line number of the source line containing the + * execution point represented by this stack trace element, or + * a negative number if this information is unavailable. A value + * of -2 indicates that the method containing the execution point + * is a native method + * @throws NullPointerException if {@code declaringClass} or + * {@code methodName} is null + * @since 1.5 + */ + public StackTraceElement(String declaringClass, String methodName, + String fileName, int lineNumber) { + this.declaringClass = Objects.requireNonNull(declaringClass, "Declaring class is null"); + this.methodName = Objects.requireNonNull(methodName, "Method name is null"); + this.fileName = fileName; + this.lineNumber = lineNumber; + } + + /** + * Returns the name of the source file containing the execution point + * represented by this stack trace element. Generally, this corresponds + * to the {@code SourceFile} attribute of the relevant {@code class} + * file (as per The Java Virtual Machine Specification, Section + * 4.7.7). In some systems, the name may refer to some source code unit + * other than a file, such as an entry in source repository. + * + * @return the name of the file containing the execution point + * represented by this stack trace element, or {@code null} if + * this information is unavailable. + */ + public String getFileName() { + return fileName; + } + + /** + * Returns the line number of the source line containing the execution + * point represented by this stack trace element. Generally, this is + * derived from the {@code LineNumberTable} attribute of the relevant + * {@code class} file (as per The Java Virtual Machine + * Specification, Section 4.7.8). + * + * @return the line number of the source line containing the execution + * point represented by this stack trace element, or a negative + * number if this information is unavailable. + */ + public int getLineNumber() { + return lineNumber; + } + + /** + * Returns the fully qualified name of the class containing the + * execution point represented by this stack trace element. + * + * @return the fully qualified name of the {@code Class} containing + * the execution point represented by this stack trace element. + */ + public String getClassName() { + return declaringClass; + } + + /** + * Returns the name of the method containing the execution point + * represented by this stack trace element. If the execution point is + * contained in an instance or class initializer, this method will return + * the appropriate special method name, {@code } or + * {@code }, as per Section 3.9 of The Java Virtual + * Machine Specification. + * + * @return the name of the method containing the execution point + * represented by this stack trace element. + */ + public String getMethodName() { + return methodName; + } + + /** + * Returns true if the method containing the execution point + * represented by this stack trace element is a native method. + * + * @return {@code true} if the method containing the execution point + * represented by this stack trace element is a native method. + */ + public boolean isNativeMethod() { + return lineNumber == -2; + } + + /** + * Returns a string representation of this stack trace element. The + * format of this string depends on the implementation, but the following + * examples may be regarded as typical: + *

+ * @see Throwable#printStackTrace() + */ + public String toString() { + return getClassName() + "." + methodName + + (isNativeMethod() ? "(Native Method)" : + (fileName != null && lineNumber >= 0 ? + "(" + fileName + ":" + lineNumber + ")" : + (fileName != null ? "("+fileName+")" : "(Unknown Source)"))); + } + + /** + * Returns true if the specified object is another + * {@code StackTraceElement} instance representing the same execution + * point as this instance. Two stack trace elements {@code a} and + * {@code b} are equal if and only if: + *
+     *     equals(a.getFileName(), b.getFileName()) &&
+     *     a.getLineNumber() == b.getLineNumber()) &&
+     *     equals(a.getClassName(), b.getClassName()) &&
+     *     equals(a.getMethodName(), b.getMethodName())
+     * 
+ * where {@code equals} has the semantics of {@link + * java.util.Objects#equals(Object, Object) Objects.equals}. + * + * @param obj the object to be compared with this stack trace element. + * @return true if the specified object is another + * {@code StackTraceElement} instance representing the same + * execution point as this instance. + */ + public boolean equals(Object obj) { + if (obj==this) + return true; + if (!(obj instanceof StackTraceElement)) + return false; + StackTraceElement e = (StackTraceElement)obj; + return e.declaringClass.equals(declaringClass) && + e.lineNumber == lineNumber && + Objects.equals(methodName, e.methodName) && + Objects.equals(fileName, e.fileName); + } + + /** + * Returns a hash code value for this stack trace element. + */ + public int hashCode() { + int result = 31*declaringClass.hashCode() + methodName.hashCode(); + result = 31*result + Objects.hashCode(fileName); + result = 31*result + lineNumber; + return result; + } + + private static final long serialVersionUID = 6992337162326171013L; +} diff -r 0a115f1c6f3c -r 94c1a17117f3 emul/src/main/java/java/lang/StringBuffer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/src/main/java/java/lang/StringBuffer.java Sat Sep 29 06:38:34 2012 +0200 @@ -0,0 +1,605 @@ +/* + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + + +/** + * A thread-safe, mutable sequence of characters. + * A string buffer is like a {@link String}, but can be modified. At any + * point in time it contains some particular sequence of characters, but + * the length and content of the sequence can be changed through certain + * method calls. + *

+ * String buffers are safe for use by multiple threads. The methods + * are synchronized where necessary so that all the operations on any + * particular instance behave as if they occur in some serial order + * that is consistent with the order of the method calls made by each of + * the individual threads involved. + *

+ * The principal operations on a StringBuffer are the + * append and insert methods, which are + * overloaded so as to accept data of any type. Each effectively + * converts a given datum to a string and then appends or inserts the + * characters of that string to the string buffer. The + * append method always adds these characters at the end + * of the buffer; the insert method adds the characters at + * a specified point. + *

+ * For example, if z refers to a string buffer object + * whose current contents are "start", then + * the method call z.append("le") would cause the string + * buffer to contain "startle", whereas + * z.insert(4, "le") would alter the string buffer to + * contain "starlet". + *

+ * In general, if sb refers to an instance of a StringBuffer, + * then sb.append(x) has the same effect as + * sb.insert(sb.length(), x). + *

+ * Whenever an operation occurs involving a source sequence (such as + * appending or inserting from a source sequence) this class synchronizes + * only on the string buffer performing the operation, not on the source. + *

+ * Every string buffer has a capacity. As long as the length of the + * character sequence contained in the string buffer does not exceed + * the capacity, it is not necessary to allocate a new internal + * buffer array. If the internal buffer overflows, it is + * automatically made larger. + * + * As of release JDK 5, this class has been supplemented with an equivalent + * class designed for use by a single thread, {@link StringBuilder}. The + * StringBuilder class should generally be used in preference to + * this one, as it supports all of the same operations but it is faster, as + * it performs no synchronization. + * + * @author Arthur van Hoff + * @see java.lang.StringBuilder + * @see java.lang.String + * @since JDK1.0 + */ + public final class StringBuffer + extends AbstractStringBuilder + implements java.io.Serializable, CharSequence +{ + + /** use serialVersionUID from JDK 1.0.2 for interoperability */ + static final long serialVersionUID = 3388685877147921107L; + + /** + * Constructs a string buffer with no characters in it and an + * initial capacity of 16 characters. + */ + public StringBuffer() { + super(16); + } + + /** + * Constructs a string buffer with no characters in it and + * the specified initial capacity. + * + * @param capacity the initial capacity. + * @exception NegativeArraySizeException if the capacity + * argument is less than 0. + */ + public StringBuffer(int capacity) { + super(capacity); + } + + /** + * Constructs a string buffer initialized to the contents of the + * specified string. The initial capacity of the string buffer is + * 16 plus the length of the string argument. + * + * @param str the initial contents of the buffer. + * @exception NullPointerException if str is null + */ + public StringBuffer(String str) { + super(str.length() + 16); + append(str); + } + + /** + * Constructs a string buffer that contains the same characters + * as the specified CharSequence. The initial capacity of + * the string buffer is 16 plus the length of the + * CharSequence argument. + *

+ * If the length of the specified CharSequence is + * less than or equal to zero, then an empty buffer of capacity + * 16 is returned. + * + * @param seq the sequence to copy. + * @exception NullPointerException if seq is null + * @since 1.5 + */ + public StringBuffer(CharSequence seq) { + this(seq.length() + 16); + append(seq); + } + + public synchronized int length() { + return count; + } + + public synchronized int capacity() { + return value.length; + } + + + public synchronized void ensureCapacity(int minimumCapacity) { + if (minimumCapacity > value.length) { + expandCapacity(minimumCapacity); + } + } + + /** + * @since 1.5 + */ + public synchronized void trimToSize() { + super.trimToSize(); + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + * @see #length() + */ + public synchronized void setLength(int newLength) { + super.setLength(newLength); + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + * @see #length() + */ + public synchronized char charAt(int index) { + if ((index < 0) || (index >= count)) + throw new StringIndexOutOfBoundsException(index); + return value[index]; + } + + /** + * @since 1.5 + */ + public synchronized int codePointAt(int index) { + return super.codePointAt(index); + } + + /** + * @since 1.5 + */ + public synchronized int codePointBefore(int index) { + return super.codePointBefore(index); + } + + /** + * @since 1.5 + */ + public synchronized int codePointCount(int beginIndex, int endIndex) { + return super.codePointCount(beginIndex, endIndex); + } + + /** + * @since 1.5 + */ + public synchronized int offsetByCodePoints(int index, int codePointOffset) { + return super.offsetByCodePoints(index, codePointOffset); + } + + /** + * @throws NullPointerException {@inheritDoc} + * @throws IndexOutOfBoundsException {@inheritDoc} + */ + public synchronized void getChars(int srcBegin, int srcEnd, char[] dst, + int dstBegin) + { + super.getChars(srcBegin, srcEnd, dst, dstBegin); + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + * @see #length() + */ + public synchronized void setCharAt(int index, char ch) { + if ((index < 0) || (index >= count)) + throw new StringIndexOutOfBoundsException(index); + value[index] = ch; + } + + public synchronized StringBuffer append(Object obj) { + super.append(String.valueOf(obj)); + return this; + } + + public synchronized StringBuffer append(String str) { + super.append(str); + return this; + } + + /** + * Appends the specified StringBuffer to this sequence. + *

+ * The characters of the StringBuffer argument are appended, + * in order, to the contents of this StringBuffer, increasing the + * length of this StringBuffer by the length of the argument. + * If sb is null, then the four characters + * "null" are appended to this StringBuffer. + *

+ * Let n be the length of the old character sequence, the one + * contained in the StringBuffer just prior to execution of the + * append method. Then the character at index k in + * the new character sequence is equal to the character at index k + * in the old character sequence, if k is less than n; + * otherwise, it is equal to the character at index k-n in the + * argument sb. + *

+ * This method synchronizes on this (the destination) + * object but does not synchronize on the source (sb). + * + * @param sb the StringBuffer to append. + * @return a reference to this object. + * @since 1.4 + */ + public synchronized StringBuffer append(StringBuffer sb) { + super.append(sb); + return this; + } + + + /** + * Appends the specified CharSequence to this + * sequence. + *

+ * The characters of the CharSequence argument are appended, + * in order, increasing the length of this sequence by the length of the + * argument. + * + *

The result of this method is exactly the same as if it were an + * invocation of this.append(s, 0, s.length()); + * + *

This method synchronizes on this (the destination) + * object but does not synchronize on the source (s). + * + *

If s is null, then the four characters + * "null" are appended. + * + * @param s the CharSequence to append. + * @return a reference to this object. + * @since 1.5 + */ + public StringBuffer append(CharSequence s) { + // Note, synchronization achieved via other invocations + if (s == null) + s = "null"; + if (s instanceof String) + return this.append((String)s); + if (s instanceof StringBuffer) + return this.append((StringBuffer)s); + return this.append(s, 0, s.length()); + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + * @since 1.5 + */ + public synchronized StringBuffer append(CharSequence s, int start, int end) + { + super.append(s, start, end); + return this; + } + + public synchronized StringBuffer append(char[] str) { + super.append(str); + return this; + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + */ + public synchronized StringBuffer append(char[] str, int offset, int len) { + super.append(str, offset, len); + return this; + } + + public synchronized StringBuffer append(boolean b) { + super.append(b); + return this; + } + + public synchronized StringBuffer append(char c) { + super.append(c); + return this; + } + + public synchronized StringBuffer append(int i) { + super.append(i); + return this; + } + + /** + * @since 1.5 + */ + public synchronized StringBuffer appendCodePoint(int codePoint) { + super.appendCodePoint(codePoint); + return this; + } + + public synchronized StringBuffer append(long lng) { + super.append(lng); + return this; + } + + public synchronized StringBuffer append(float f) { + super.append(f); + return this; + } + + public synchronized StringBuffer append(double d) { + super.append(d); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + * @since 1.2 + */ + public synchronized StringBuffer delete(int start, int end) { + super.delete(start, end); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + * @since 1.2 + */ + public synchronized StringBuffer deleteCharAt(int index) { + super.deleteCharAt(index); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + * @since 1.2 + */ + public synchronized StringBuffer replace(int start, int end, String str) { + super.replace(start, end, str); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + * @since 1.2 + */ + public synchronized String substring(int start) { + return substring(start, count); + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + * @since 1.4 + */ + public synchronized CharSequence subSequence(int start, int end) { + return super.substring(start, end); + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + * @since 1.2 + */ + public synchronized String substring(int start, int end) { + return super.substring(start, end); + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + * @since 1.2 + */ + public synchronized StringBuffer insert(int index, char[] str, int offset, + int len) + { + super.insert(index, str, offset, len); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public synchronized StringBuffer insert(int offset, Object obj) { + super.insert(offset, String.valueOf(obj)); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public synchronized StringBuffer insert(int offset, String str) { + super.insert(offset, str); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public synchronized StringBuffer insert(int offset, char[] str) { + super.insert(offset, str); + return this; + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + * @since 1.5 + */ + public StringBuffer insert(int dstOffset, CharSequence s) { + // Note, synchronization achieved via other invocations + if (s == null) + s = "null"; + if (s instanceof String) + return this.insert(dstOffset, (String)s); + return this.insert(dstOffset, s, 0, s.length()); + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + * @since 1.5 + */ + public synchronized StringBuffer insert(int dstOffset, CharSequence s, + int start, int end) + { + super.insert(dstOffset, s, start, end); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuffer insert(int offset, boolean b) { + return insert(offset, String.valueOf(b)); + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + */ + public synchronized StringBuffer insert(int offset, char c) { + super.insert(offset, c); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuffer insert(int offset, int i) { + return insert(offset, String.valueOf(i)); + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuffer insert(int offset, long l) { + return insert(offset, String.valueOf(l)); + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuffer insert(int offset, float f) { + return insert(offset, String.valueOf(f)); + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuffer insert(int offset, double d) { + return insert(offset, String.valueOf(d)); + } + + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.4 + */ + public int indexOf(String str) { + return indexOf(str, 0); + } + + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.4 + */ + public synchronized int indexOf(String str, int fromIndex) { + return String.indexOf(value, 0, count, + str.toCharArray(), 0, str.length(), fromIndex); + } + + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.4 + */ + public int lastIndexOf(String str) { + // Note, synchronization achieved via other invocations + return lastIndexOf(str, count); + } + + /** + * @throws NullPointerException {@inheritDoc} + * @since 1.4 + */ + public synchronized int lastIndexOf(String str, int fromIndex) { + return String.lastIndexOf(value, 0, count, + str.toCharArray(), 0, str.length(), fromIndex); + } + + /** + * @since JDK1.0.2 + */ + public synchronized StringBuffer reverse() { + super.reverse(); + return this; + } + + public synchronized String toString() { + return new String(value, 0, count); + } + + /** + * Serializable fields for StringBuffer. + * + * @serialField value char[] + * The backing character array of this StringBuffer. + * @serialField count int + * The number of characters in this StringBuffer. + * @serialField shared boolean + * A flag indicating whether the backing array is shared. + * The value is ignored upon deserialization. + */ + private static final java.io.ObjectStreamField[] serialPersistentFields = + { + new java.io.ObjectStreamField("value", char[].class), + new java.io.ObjectStreamField("count", Integer.TYPE), + new java.io.ObjectStreamField("shared", Boolean.TYPE), + }; + + /** + * readObject is called to restore the state of the StringBuffer from + * a stream. + */ + private synchronized void writeObject(java.io.ObjectOutputStream s) + throws java.io.IOException { + java.io.ObjectOutputStream.PutField fields = s.putFields(); + fields.put("value", value); + fields.put("count", count); + fields.put("shared", false); + s.writeFields(); + } + + /** + * readObject is called to restore the state of the StringBuffer from + * a stream. + */ + private void readObject(java.io.ObjectInputStream s) + throws java.io.IOException, ClassNotFoundException { + java.io.ObjectInputStream.GetField fields = s.readFields(); + value = (char[])fields.get("value", null); + count = fields.get("count", 0); + } +} diff -r 0a115f1c6f3c -r 94c1a17117f3 emul/src/main/java/java/lang/StringBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emul/src/main/java/java/lang/StringBuilder.java Sat Sep 29 06:38:34 2012 +0200 @@ -0,0 +1,437 @@ +/* + * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + + +/** + * A mutable sequence of characters. This class provides an API compatible + * with StringBuffer, but with no guarantee of synchronization. + * This class is designed for use as a drop-in replacement for + * StringBuffer in places where the string buffer was being + * used by a single thread (as is generally the case). Where possible, + * it is recommended that this class be used in preference to + * StringBuffer as it will be faster under most implementations. + * + *

The principal operations on a StringBuilder are the + * append and insert methods, which are + * overloaded so as to accept data of any type. Each effectively + * converts a given datum to a string and then appends or inserts the + * characters of that string to the string builder. The + * append method always adds these characters at the end + * of the builder; the insert method adds the characters at + * a specified point. + *

+ * For example, if z refers to a string builder object + * whose current contents are "start", then + * the method call z.append("le") would cause the string + * builder to contain "startle", whereas + * z.insert(4, "le") would alter the string builder to + * contain "starlet". + *

+ * In general, if sb refers to an instance of a StringBuilder, + * then sb.append(x) has the same effect as + * sb.insert(sb.length(), x). + * + * Every string builder has a capacity. As long as the length of the + * character sequence contained in the string builder does not exceed + * the capacity, it is not necessary to allocate a new internal + * buffer. If the internal buffer overflows, it is automatically made larger. + * + *

Instances of StringBuilder are not safe for + * use by multiple threads. If such synchronization is required then it is + * recommended that {@link java.lang.StringBuffer} be used. + * + * @author Michael McCloskey + * @see java.lang.StringBuffer + * @see java.lang.String + * @since 1.5 + */ +public final class StringBuilder + extends AbstractStringBuilder + implements java.io.Serializable, CharSequence +{ + + /** use serialVersionUID for interoperability */ + static final long serialVersionUID = 4383685877147921099L; + + /** + * Constructs a string builder with no characters in it and an + * initial capacity of 16 characters. + */ + public StringBuilder() { + super(16); + } + + /** + * Constructs a string builder with no characters in it and an + * initial capacity specified by the capacity argument. + * + * @param capacity the initial capacity. + * @throws NegativeArraySizeException if the capacity + * argument is less than 0. + */ + public StringBuilder(int capacity) { + super(capacity); + } + + /** + * Constructs a string builder initialized to the contents of the + * specified string. The initial capacity of the string builder is + * 16 plus the length of the string argument. + * + * @param str the initial contents of the buffer. + * @throws NullPointerException if str is null + */ + public StringBuilder(String str) { + super(str.length() + 16); + append(str); + } + + /** + * Constructs a string builder that contains the same characters + * as the specified CharSequence. The initial capacity of + * the string builder is 16 plus the length of the + * CharSequence argument. + * + * @param seq the sequence to copy. + * @throws NullPointerException if seq is null + */ + public StringBuilder(CharSequence seq) { + this(seq.length() + 16); + append(seq); + } + + public StringBuilder append(Object obj) { + return append(String.valueOf(obj)); + } + + public StringBuilder append(String str) { + super.append(str); + return this; + } + + // Appends the specified string builder to this sequence. + private StringBuilder append(StringBuilder sb) { + if (sb == null) + return append("null"); + int len = sb.length(); + int newcount = count + len; + if (newcount > value.length) + expandCapacity(newcount); + sb.getChars(0, len, value, count); + count = newcount; + return this; + } + + /** + * Appends the specified StringBuffer to this sequence. + *

+ * The characters of the StringBuffer argument are appended, + * in order, to this sequence, increasing the + * length of this sequence by the length of the argument. + * If sb is null, then the four characters + * "null" are appended to this sequence. + *

+ * Let n be the length of this character sequence just prior to + * execution of the append method. Then the character at index + * k in the new character sequence is equal to the character at + * index k in the old character sequence, if k is less than + * n; otherwise, it is equal to the character at index k-n + * in the argument sb. + * + * @param sb the StringBuffer to append. + * @return a reference to this object. + */ + public StringBuilder append(StringBuffer sb) { + super.append(sb); + return this; + } + + /** + */ + public StringBuilder append(CharSequence s) { + if (s == null) + s = "null"; + if (s instanceof String) + return this.append((String)s); + if (s instanceof StringBuffer) + return this.append((StringBuffer)s); + if (s instanceof StringBuilder) + return this.append((StringBuilder)s); + return this.append(s, 0, s.length()); + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder append(CharSequence s, int start, int end) { + super.append(s, start, end); + return this; + } + + public StringBuilder append(char[] str) { + super.append(str); + return this; + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder append(char[] str, int offset, int len) { + super.append(str, offset, len); + return this; + } + + public StringBuilder append(boolean b) { + super.append(b); + return this; + } + + public StringBuilder append(char c) { + super.append(c); + return this; + } + + public StringBuilder append(int i) { + super.append(i); + return this; + } + + public StringBuilder append(long lng) { + super.append(lng); + return this; + } + + public StringBuilder append(float f) { + super.append(f); + return this; + } + + public StringBuilder append(double d) { + super.append(d); + return this; + } + + /** + * @since 1.5 + */ + public StringBuilder appendCodePoint(int codePoint) { + super.appendCodePoint(codePoint); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder delete(int start, int end) { + super.delete(start, end); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder deleteCharAt(int index) { + super.deleteCharAt(index); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder replace(int start, int end, String str) { + super.replace(start, end, str); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int index, char[] str, int offset, + int len) + { + super.insert(index, str, offset, len); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int offset, Object obj) { + return insert(offset, String.valueOf(obj)); + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int offset, String str) { + super.insert(offset, str); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int offset, char[] str) { + super.insert(offset, str); + return this; + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int dstOffset, CharSequence s) { + if (s == null) + s = "null"; + if (s instanceof String) + return this.insert(dstOffset, (String)s); + return this.insert(dstOffset, s, 0, s.length()); + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int dstOffset, CharSequence s, + int start, int end) + { + super.insert(dstOffset, s, start, end); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int offset, boolean b) { + super.insert(offset, b); + return this; + } + + /** + * @throws IndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int offset, char c) { + super.insert(offset, c); + return this; + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int offset, int i) { + return insert(offset, String.valueOf(i)); + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int offset, long l) { + return insert(offset, String.valueOf(l)); + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int offset, float f) { + return insert(offset, String.valueOf(f)); + } + + /** + * @throws StringIndexOutOfBoundsException {@inheritDoc} + */ + public StringBuilder insert(int offset, double d) { + return insert(offset, String.valueOf(d)); + } + + /** + * @throws NullPointerException {@inheritDoc} + */ + public int indexOf(String str) { + return indexOf(str, 0); + } + + /** + * @throws NullPointerException {@inheritDoc} + */ + public int indexOf(String str, int fromIndex) { + return String.indexOf(value, 0, count, + str.toCharArray(), 0, str.length(), fromIndex); + } + + /** + * @throws NullPointerException {@inheritDoc} + */ + public int lastIndexOf(String str) { + return lastIndexOf(str, count); + } + + /** + * @throws NullPointerException {@inheritDoc} + */ + public int lastIndexOf(String str, int fromIndex) { + return String.lastIndexOf(value, 0, count, + str.toCharArray(), 0, str.length(), fromIndex); + } + + public StringBuilder reverse() { + super.reverse(); + return this; + } + + public String toString() { + // Create a copy, don't share the array + return new String(value, 0, count); + } + + /** + * Save the state of the StringBuilder instance to a stream + * (that is, serialize it). + * + * @serialData the number of characters currently stored in the string + * builder (int), followed by the characters in the + * string builder (char[]). The length of the + * char array may be greater than the number of + * characters currently stored in the string builder, in which + * case extra characters are ignored. + */ + private void writeObject(java.io.ObjectOutputStream s) + throws java.io.IOException { + s.defaultWriteObject(); + s.writeInt(count); + s.writeObject(value); + } + + /** + * readObject is called to restore the state of the StringBuffer from + * a stream. + */ + private void readObject(java.io.ObjectInputStream s) + throws java.io.IOException, ClassNotFoundException { + s.defaultReadObject(); + count = s.readInt(); + value = (char[]) s.readObject(); + } + +}