1.1 --- a/benchmarks/matrix-multiplication/pom.xml Wed Jan 23 20:16:48 2013 +0100
1.2 +++ b/benchmarks/matrix-multiplication/pom.xml Wed Jan 23 20:39:23 2013 +0100
1.3 @@ -31,7 +31,7 @@
1.4 <dependencies>
1.5 <dependency>
1.6 <groupId>org.apidesign.bck2brwsr</groupId>
1.7 - <artifactId>emul</artifactId>
1.8 + <artifactId>emul.mini</artifactId>
1.9 <version>0.3-SNAPSHOT</version>
1.10 </dependency>
1.11 <dependency>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/emul/mini/pom.xml Wed Jan 23 20:39:23 2013 +0100
2.3 @@ -0,0 +1,42 @@
2.4 +<?xml version="1.0"?>
2.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
2.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2.7 + <modelVersion>4.0.0</modelVersion>
2.8 + <parent>
2.9 + <groupId>org.apidesign.bck2brwsr</groupId>
2.10 + <artifactId>emul.pom</artifactId>
2.11 + <version>0.3-SNAPSHOT</version>
2.12 + </parent>
2.13 + <groupId>org.apidesign.bck2brwsr</groupId>
2.14 + <artifactId>emul.mini</artifactId>
2.15 + <version>0.3-SNAPSHOT</version>
2.16 + <name>Minimal API Profile</name>
2.17 + <url>http://maven.apache.org</url>
2.18 + <properties>
2.19 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2.20 + </properties>
2.21 + <dependencies>
2.22 + <dependency>
2.23 + <groupId>org.apidesign.bck2brwsr</groupId>
2.24 + <artifactId>core</artifactId>
2.25 + <version>0.3-SNAPSHOT</version>
2.26 + <type>jar</type>
2.27 + </dependency>
2.28 + </dependencies>
2.29 + <build>
2.30 + <plugins>
2.31 + <plugin>
2.32 + <groupId>org.apache.maven.plugins</groupId>
2.33 + <artifactId>maven-compiler-plugin</artifactId>
2.34 + <version>2.5.1</version>
2.35 + <configuration>
2.36 + <compilerArguments>
2.37 + <bootclasspath>netbeans.ignore.jdk.bootsclasspath</bootclasspath>
2.38 + </compilerArguments>
2.39 + <source>1.7</source>
2.40 + <target>1.7</target>
2.41 + </configuration>
2.42 + </plugin>
2.43 + </plugins>
2.44 + </build>
2.45 +</project>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/emul/mini/src/main/java/java/io/ByteArrayInputStream.java Wed Jan 23 20:39:23 2013 +0100
3.3 @@ -0,0 +1,283 @@
3.4 +/*
3.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3.7 + *
3.8 + * This code is free software; you can redistribute it and/or modify it
3.9 + * under the terms of the GNU General Public License version 2 only, as
3.10 + * published by the Free Software Foundation. Oracle designates this
3.11 + * particular file as subject to the "Classpath" exception as provided
3.12 + * by Oracle in the LICENSE file that accompanied this code.
3.13 + *
3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3.17 + * version 2 for more details (a copy is included in the LICENSE file that
3.18 + * accompanied this code).
3.19 + *
3.20 + * You should have received a copy of the GNU General Public License version
3.21 + * 2 along with this work; if not, write to the Free Software Foundation,
3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3.23 + *
3.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3.25 + * or visit www.oracle.com if you need additional information or have any
3.26 + * questions.
3.27 + */
3.28 +
3.29 +package java.io;
3.30 +
3.31 +/**
3.32 + * A <code>ByteArrayInputStream</code> contains
3.33 + * an internal buffer that contains bytes that
3.34 + * may be read from the stream. An internal
3.35 + * counter keeps track of the next byte to
3.36 + * be supplied by the <code>read</code> method.
3.37 + * <p>
3.38 + * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
3.39 + * this class can be called after the stream has been closed without
3.40 + * generating an <tt>IOException</tt>.
3.41 + *
3.42 + * @author Arthur van Hoff
3.43 + * @see java.io.StringBufferInputStream
3.44 + * @since JDK1.0
3.45 + */
3.46 +public
3.47 +class ByteArrayInputStream extends InputStream {
3.48 +
3.49 + /**
3.50 + * An array of bytes that was provided
3.51 + * by the creator of the stream. Elements <code>buf[0]</code>
3.52 + * through <code>buf[count-1]</code> are the
3.53 + * only bytes that can ever be read from the
3.54 + * stream; element <code>buf[pos]</code> is
3.55 + * the next byte to be read.
3.56 + */
3.57 + protected byte buf[];
3.58 +
3.59 + /**
3.60 + * The index of the next character to read from the input stream buffer.
3.61 + * This value should always be nonnegative
3.62 + * and not larger than the value of <code>count</code>.
3.63 + * The next byte to be read from the input stream buffer
3.64 + * will be <code>buf[pos]</code>.
3.65 + */
3.66 + protected int pos;
3.67 +
3.68 + /**
3.69 + * The currently marked position in the stream.
3.70 + * ByteArrayInputStream objects are marked at position zero by
3.71 + * default when constructed. They may be marked at another
3.72 + * position within the buffer by the <code>mark()</code> method.
3.73 + * The current buffer position is set to this point by the
3.74 + * <code>reset()</code> method.
3.75 + * <p>
3.76 + * If no mark has been set, then the value of mark is the offset
3.77 + * passed to the constructor (or 0 if the offset was not supplied).
3.78 + *
3.79 + * @since JDK1.1
3.80 + */
3.81 + protected int mark = 0;
3.82 +
3.83 + /**
3.84 + * The index one greater than the last valid character in the input
3.85 + * stream buffer.
3.86 + * This value should always be nonnegative
3.87 + * and not larger than the length of <code>buf</code>.
3.88 + * It is one greater than the position of
3.89 + * the last byte within <code>buf</code> that
3.90 + * can ever be read from the input stream buffer.
3.91 + */
3.92 + protected int count;
3.93 +
3.94 + /**
3.95 + * Creates a <code>ByteArrayInputStream</code>
3.96 + * so that it uses <code>buf</code> as its
3.97 + * buffer array.
3.98 + * The buffer array is not copied.
3.99 + * The initial value of <code>pos</code>
3.100 + * is <code>0</code> and the initial value
3.101 + * of <code>count</code> is the length of
3.102 + * <code>buf</code>.
3.103 + *
3.104 + * @param buf the input buffer.
3.105 + */
3.106 + public ByteArrayInputStream(byte buf[]) {
3.107 + this.buf = buf;
3.108 + this.pos = 0;
3.109 + this.count = buf.length;
3.110 + }
3.111 +
3.112 + /**
3.113 + * Creates <code>ByteArrayInputStream</code>
3.114 + * that uses <code>buf</code> as its
3.115 + * buffer array. The initial value of <code>pos</code>
3.116 + * is <code>offset</code> and the initial value
3.117 + * of <code>count</code> is the minimum of <code>offset+length</code>
3.118 + * and <code>buf.length</code>.
3.119 + * The buffer array is not copied. The buffer's mark is
3.120 + * set to the specified offset.
3.121 + *
3.122 + * @param buf the input buffer.
3.123 + * @param offset the offset in the buffer of the first byte to read.
3.124 + * @param length the maximum number of bytes to read from the buffer.
3.125 + */
3.126 + public ByteArrayInputStream(byte buf[], int offset, int length) {
3.127 + this.buf = buf;
3.128 + this.pos = offset;
3.129 + this.count = Math.min(offset + length, buf.length);
3.130 + this.mark = offset;
3.131 + }
3.132 +
3.133 + /**
3.134 + * Reads the next byte of data from this input stream. The value
3.135 + * byte is returned as an <code>int</code> in the range
3.136 + * <code>0</code> to <code>255</code>. If no byte is available
3.137 + * because the end of the stream has been reached, the value
3.138 + * <code>-1</code> is returned.
3.139 + * <p>
3.140 + * This <code>read</code> method
3.141 + * cannot block.
3.142 + *
3.143 + * @return the next byte of data, or <code>-1</code> if the end of the
3.144 + * stream has been reached.
3.145 + */
3.146 + public synchronized int read() {
3.147 + return (pos < count) ? (buf[pos++] & 0xff) : -1;
3.148 + }
3.149 +
3.150 + /**
3.151 + * Reads up to <code>len</code> bytes of data into an array of bytes
3.152 + * from this input stream.
3.153 + * If <code>pos</code> equals <code>count</code>,
3.154 + * then <code>-1</code> is returned to indicate
3.155 + * end of file. Otherwise, the number <code>k</code>
3.156 + * of bytes read is equal to the smaller of
3.157 + * <code>len</code> and <code>count-pos</code>.
3.158 + * If <code>k</code> is positive, then bytes
3.159 + * <code>buf[pos]</code> through <code>buf[pos+k-1]</code>
3.160 + * are copied into <code>b[off]</code> through
3.161 + * <code>b[off+k-1]</code> in the manner performed
3.162 + * by <code>System.arraycopy</code>. The
3.163 + * value <code>k</code> is added into <code>pos</code>
3.164 + * and <code>k</code> is returned.
3.165 + * <p>
3.166 + * This <code>read</code> method cannot block.
3.167 + *
3.168 + * @param b the buffer into which the data is read.
3.169 + * @param off the start offset in the destination array <code>b</code>
3.170 + * @param len the maximum number of bytes read.
3.171 + * @return the total number of bytes read into the buffer, or
3.172 + * <code>-1</code> if there is no more data because the end of
3.173 + * the stream has been reached.
3.174 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
3.175 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
3.176 + * <code>len</code> is negative, or <code>len</code> is greater than
3.177 + * <code>b.length - off</code>
3.178 + */
3.179 + public synchronized int read(byte b[], int off, int len) {
3.180 + if (b == null) {
3.181 + throw new NullPointerException();
3.182 + } else if (off < 0 || len < 0 || len > b.length - off) {
3.183 + throw new IndexOutOfBoundsException();
3.184 + }
3.185 +
3.186 + if (pos >= count) {
3.187 + return -1;
3.188 + }
3.189 +
3.190 + int avail = count - pos;
3.191 + if (len > avail) {
3.192 + len = avail;
3.193 + }
3.194 + if (len <= 0) {
3.195 + return 0;
3.196 + }
3.197 + PushbackInputStream.arraycopy(buf, pos, b, off, len);
3.198 + pos += len;
3.199 + return len;
3.200 + }
3.201 +
3.202 + /**
3.203 + * Skips <code>n</code> bytes of input from this input stream. Fewer
3.204 + * bytes might be skipped if the end of the input stream is reached.
3.205 + * The actual number <code>k</code>
3.206 + * of bytes to be skipped is equal to the smaller
3.207 + * of <code>n</code> and <code>count-pos</code>.
3.208 + * The value <code>k</code> is added into <code>pos</code>
3.209 + * and <code>k</code> is returned.
3.210 + *
3.211 + * @param n the number of bytes to be skipped.
3.212 + * @return the actual number of bytes skipped.
3.213 + */
3.214 + public synchronized long skip(long n) {
3.215 + long k = count - pos;
3.216 + if (n < k) {
3.217 + k = n < 0 ? 0 : n;
3.218 + }
3.219 +
3.220 + pos += k;
3.221 + return k;
3.222 + }
3.223 +
3.224 + /**
3.225 + * Returns the number of remaining bytes that can be read (or skipped over)
3.226 + * from this input stream.
3.227 + * <p>
3.228 + * The value returned is <code>count - pos</code>,
3.229 + * which is the number of bytes remaining to be read from the input buffer.
3.230 + *
3.231 + * @return the number of remaining bytes that can be read (or skipped
3.232 + * over) from this input stream without blocking.
3.233 + */
3.234 + public synchronized int available() {
3.235 + return count - pos;
3.236 + }
3.237 +
3.238 + /**
3.239 + * Tests if this <code>InputStream</code> supports mark/reset. The
3.240 + * <code>markSupported</code> method of <code>ByteArrayInputStream</code>
3.241 + * always returns <code>true</code>.
3.242 + *
3.243 + * @since JDK1.1
3.244 + */
3.245 + public boolean markSupported() {
3.246 + return true;
3.247 + }
3.248 +
3.249 + /**
3.250 + * Set the current marked position in the stream.
3.251 + * ByteArrayInputStream objects are marked at position zero by
3.252 + * default when constructed. They may be marked at another
3.253 + * position within the buffer by this method.
3.254 + * <p>
3.255 + * If no mark has been set, then the value of the mark is the
3.256 + * offset passed to the constructor (or 0 if the offset was not
3.257 + * supplied).
3.258 + *
3.259 + * <p> Note: The <code>readAheadLimit</code> for this class
3.260 + * has no meaning.
3.261 + *
3.262 + * @since JDK1.1
3.263 + */
3.264 + public void mark(int readAheadLimit) {
3.265 + mark = pos;
3.266 + }
3.267 +
3.268 + /**
3.269 + * Resets the buffer to the marked position. The marked position
3.270 + * is 0 unless another position was marked or an offset was specified
3.271 + * in the constructor.
3.272 + */
3.273 + public synchronized void reset() {
3.274 + pos = mark;
3.275 + }
3.276 +
3.277 + /**
3.278 + * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
3.279 + * this class can be called after the stream has been closed without
3.280 + * generating an <tt>IOException</tt>.
3.281 + * <p>
3.282 + */
3.283 + public void close() throws IOException {
3.284 + }
3.285 +
3.286 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/emul/mini/src/main/java/java/io/Closeable.java Wed Jan 23 20:39:23 2013 +0100
4.3 @@ -0,0 +1,48 @@
4.4 +/*
4.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4.7 + *
4.8 + * This code is free software; you can redistribute it and/or modify it
4.9 + * under the terms of the GNU General Public License version 2 only, as
4.10 + * published by the Free Software Foundation. Oracle designates this
4.11 + * particular file as subject to the "Classpath" exception as provided
4.12 + * by Oracle in the LICENSE file that accompanied this code.
4.13 + *
4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4.17 + * version 2 for more details (a copy is included in the LICENSE file that
4.18 + * accompanied this code).
4.19 + *
4.20 + * You should have received a copy of the GNU General Public License version
4.21 + * 2 along with this work; if not, write to the Free Software Foundation,
4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4.23 + *
4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4.25 + * or visit www.oracle.com if you need additional information or have any
4.26 + * questions.
4.27 + */
4.28 +
4.29 +package java.io;
4.30 +
4.31 +import java.io.IOException;
4.32 +
4.33 +/**
4.34 + * A {@code Closeable} is a source or destination of data that can be closed.
4.35 + * The close method is invoked to release resources that the object is
4.36 + * holding (such as open files).
4.37 + *
4.38 + * @since 1.5
4.39 + */
4.40 +
4.41 +public interface Closeable extends AutoCloseable {
4.42 +
4.43 + /**
4.44 + * Closes this stream and releases any system resources associated
4.45 + * with it. If the stream is already closed then invoking this
4.46 + * method has no effect.
4.47 + *
4.48 + * @throws IOException if an I/O error occurs
4.49 + */
4.50 + public void close() throws IOException;
4.51 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/emul/mini/src/main/java/java/io/DataInput.java Wed Jan 23 20:39:23 2013 +0100
5.3 @@ -0,0 +1,635 @@
5.4 +/*
5.5 + * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.7 + *
5.8 + * This code is free software; you can redistribute it and/or modify it
5.9 + * under the terms of the GNU General Public License version 2 only, as
5.10 + * published by the Free Software Foundation. Oracle designates this
5.11 + * particular file as subject to the "Classpath" exception as provided
5.12 + * by Oracle in the LICENSE file that accompanied this code.
5.13 + *
5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5.17 + * version 2 for more details (a copy is included in the LICENSE file that
5.18 + * accompanied this code).
5.19 + *
5.20 + * You should have received a copy of the GNU General Public License version
5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5.23 + *
5.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5.25 + * or visit www.oracle.com if you need additional information or have any
5.26 + * questions.
5.27 + */
5.28 +
5.29 +package java.io;
5.30 +
5.31 +/**
5.32 + * The <code>DataInput</code> interface provides
5.33 + * for reading bytes from a binary stream and
5.34 + * reconstructing from them data in any of
5.35 + * the Java primitive types. There is also
5.36 + * a
5.37 + * facility for reconstructing a <code>String</code>
5.38 + * from data in
5.39 + * <a href="#modified-utf-8">modified UTF-8</a>
5.40 + * format.
5.41 + * <p>
5.42 + * It is generally true of all the reading
5.43 + * routines in this interface that if end of
5.44 + * file is reached before the desired number
5.45 + * of bytes has been read, an <code>EOFException</code>
5.46 + * (which is a kind of <code>IOException</code>)
5.47 + * is thrown. If any byte cannot be read for
5.48 + * any reason other than end of file, an <code>IOException</code>
5.49 + * other than <code>EOFException</code> is
5.50 + * thrown. In particular, an <code>IOException</code>
5.51 + * may be thrown if the input stream has been
5.52 + * closed.
5.53 + *
5.54 + * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
5.55 + * <p>
5.56 + * Implementations of the DataInput and DataOutput interfaces represent
5.57 + * Unicode strings in a format that is a slight modification of UTF-8.
5.58 + * (For information regarding the standard UTF-8 format, see section
5.59 + * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
5.60 + * 4.0</i>).
5.61 + * Note that in the following tables, the most significant bit appears in the
5.62 + * far left-hand column.
5.63 + * <p>
5.64 + * All characters in the range <code>'\u0001'</code> to
5.65 + * <code>'\u007F'</code> are represented by a single byte:
5.66 + *
5.67 + * <blockquote>
5.68 + * <table border="1" cellspacing="0" cellpadding="8" width="50%"
5.69 + * summary="Bit values and bytes">
5.70 + * <tr>
5.71 + * <td></td>
5.72 + * <th id="bit">Bit Values</th>
5.73 + * </tr>
5.74 + * <tr>
5.75 + * <th id="byte1">Byte 1</th>
5.76 + * <td>
5.77 + * <table border="1" cellspacing="0" width="100%">
5.78 + * <tr>
5.79 + * <td width="12%"><center>0</center>
5.80 + * <td colspan="7"><center>bits 6-0</center>
5.81 + * </tr>
5.82 + * </table>
5.83 + * </td>
5.84 + * </tr>
5.85 + * </table>
5.86 + * </blockquote>
5.87 + *
5.88 + * <p>
5.89 + * The null character <code>'\u0000'</code> and characters in the
5.90 + * range <code>'\u0080'</code> to <code>'\u07FF'</code> are
5.91 + * represented by a pair of bytes:
5.92 + *
5.93 + * <blockquote>
5.94 + * <table border="1" cellspacing="0" cellpadding="8" width="50%"
5.95 + * summary="Bit values and bytes">
5.96 + * <tr>
5.97 + * <td></td>
5.98 + * <th id="bit">Bit Values</th>
5.99 + * </tr>
5.100 + * <tr>
5.101 + * <th id="byte1">Byte 1</th>
5.102 + * <td>
5.103 + * <table border="1" cellspacing="0" width="100%">
5.104 + * <tr>
5.105 + * <td width="12%"><center>1</center>
5.106 + * <td width="13%"><center>1</center>
5.107 + * <td width="12%"><center>0</center>
5.108 + * <td colspan="5"><center>bits 10-6</center>
5.109 + * </tr>
5.110 + * </table>
5.111 + * </td>
5.112 + * </tr>
5.113 + * <tr>
5.114 + * <th id="byte2">Byte 2</th>
5.115 + * <td>
5.116 + * <table border="1" cellspacing="0" width="100%">
5.117 + * <tr>
5.118 + * <td width="12%"><center>1</center>
5.119 + * <td width="13%"><center>0</center>
5.120 + * <td colspan="6"><center>bits 5-0</center>
5.121 + * </tr>
5.122 + * </table>
5.123 + * </td>
5.124 + * </tr>
5.125 + * </table>
5.126 + * </blockquote>
5.127 + *
5.128 + * <br>
5.129 + * <code>char</code> values in the range <code>'\u0800'</code> to
5.130 + * <code>'\uFFFF'</code> are represented by three bytes:
5.131 + *
5.132 + * <blockquote>
5.133 + * <table border="1" cellspacing="0" cellpadding="8" width="50%"
5.134 + * summary="Bit values and bytes">
5.135 + * <tr>
5.136 + * <td></td>
5.137 + * <th id="bit">Bit Values</th>
5.138 + * </tr>
5.139 + * <tr>
5.140 + * <th id="byte1">Byte 1</th>
5.141 + * <td>
5.142 + * <table border="1" cellspacing="0" width="100%">
5.143 + * <tr>
5.144 + * <td width="12%"><center>1</center>
5.145 + * <td width="13%"><center>1</center>
5.146 + * <td width="12%"><center>1</center>
5.147 + * <td width="13%"><center>0</center>
5.148 + * <td colspan="4"><center>bits 15-12</center>
5.149 + * </tr>
5.150 + * </table>
5.151 + * </td>
5.152 + * </tr>
5.153 + * <tr>
5.154 + * <th id="byte2">Byte 2</th>
5.155 + * <td>
5.156 + * <table border="1" cellspacing="0" width="100%">
5.157 + * <tr>
5.158 + * <td width="12%"><center>1</center>
5.159 + * <td width="13%"><center>0</center>
5.160 + * <td colspan="6"><center>bits 11-6</center>
5.161 + * </tr>
5.162 + * </table>
5.163 + * </td>
5.164 + * </tr>
5.165 + * <tr>
5.166 + * <th id="byte3">Byte 3</th>
5.167 + * <td>
5.168 + * <table border="1" cellspacing="0" width="100%">
5.169 + * <tr>
5.170 + * <td width="12%"><center>1</center>
5.171 + * <td width="13%"><center>0</center>
5.172 + * <td colspan="6"><center>bits 5-0</center>
5.173 + * </tr>
5.174 + * </table>
5.175 + * </td>
5.176 + * </tr>
5.177 + * </table>
5.178 + * </blockquote>
5.179 + *
5.180 + * <p>
5.181 + * The differences between this format and the
5.182 + * standard UTF-8 format are the following:
5.183 + * <ul>
5.184 + * <li>The null byte <code>'\u0000'</code> is encoded in 2-byte format
5.185 + * rather than 1-byte, so that the encoded strings never have
5.186 + * embedded nulls.
5.187 + * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
5.188 + * <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
5.189 + * are represented in the form of surrogate pairs.
5.190 + * </ul>
5.191 + * @author Frank Yellin
5.192 + * @see java.io.DataInputStream
5.193 + * @see java.io.DataOutput
5.194 + * @since JDK1.0
5.195 + */
5.196 +public
5.197 +interface DataInput {
5.198 + /**
5.199 + * Reads some bytes from an input
5.200 + * stream and stores them into the buffer
5.201 + * array <code>b</code>. The number of bytes
5.202 + * read is equal
5.203 + * to the length of <code>b</code>.
5.204 + * <p>
5.205 + * This method blocks until one of the
5.206 + * following conditions occurs:<p>
5.207 + * <ul>
5.208 + * <li><code>b.length</code>
5.209 + * bytes of input data are available, in which
5.210 + * case a normal return is made.
5.211 + *
5.212 + * <li>End of
5.213 + * file is detected, in which case an <code>EOFException</code>
5.214 + * is thrown.
5.215 + *
5.216 + * <li>An I/O error occurs, in
5.217 + * which case an <code>IOException</code> other
5.218 + * than <code>EOFException</code> is thrown.
5.219 + * </ul>
5.220 + * <p>
5.221 + * If <code>b</code> is <code>null</code>,
5.222 + * a <code>NullPointerException</code> is thrown.
5.223 + * If <code>b.length</code> is zero, then
5.224 + * no bytes are read. Otherwise, the first
5.225 + * byte read is stored into element <code>b[0]</code>,
5.226 + * the next one into <code>b[1]</code>, and
5.227 + * so on.
5.228 + * If an exception is thrown from
5.229 + * this method, then it may be that some but
5.230 + * not all bytes of <code>b</code> have been
5.231 + * updated with data from the input stream.
5.232 + *
5.233 + * @param b the buffer into which the data is read.
5.234 + * @exception EOFException if this stream reaches the end before reading
5.235 + * all the bytes.
5.236 + * @exception IOException if an I/O error occurs.
5.237 + */
5.238 + void readFully(byte b[]) throws IOException;
5.239 +
5.240 + /**
5.241 + *
5.242 + * Reads <code>len</code>
5.243 + * bytes from
5.244 + * an input stream.
5.245 + * <p>
5.246 + * This method
5.247 + * blocks until one of the following conditions
5.248 + * occurs:<p>
5.249 + * <ul>
5.250 + * <li><code>len</code> bytes
5.251 + * of input data are available, in which case
5.252 + * a normal return is made.
5.253 + *
5.254 + * <li>End of file
5.255 + * is detected, in which case an <code>EOFException</code>
5.256 + * is thrown.
5.257 + *
5.258 + * <li>An I/O error occurs, in
5.259 + * which case an <code>IOException</code> other
5.260 + * than <code>EOFException</code> is thrown.
5.261 + * </ul>
5.262 + * <p>
5.263 + * If <code>b</code> is <code>null</code>,
5.264 + * a <code>NullPointerException</code> is thrown.
5.265 + * If <code>off</code> is negative, or <code>len</code>
5.266 + * is negative, or <code>off+len</code> is
5.267 + * greater than the length of the array <code>b</code>,
5.268 + * then an <code>IndexOutOfBoundsException</code>
5.269 + * is thrown.
5.270 + * If <code>len</code> is zero,
5.271 + * then no bytes are read. Otherwise, the first
5.272 + * byte read is stored into element <code>b[off]</code>,
5.273 + * the next one into <code>b[off+1]</code>,
5.274 + * and so on. The number of bytes read is,
5.275 + * at most, equal to <code>len</code>.
5.276 + *
5.277 + * @param b the buffer into which the data is read.
5.278 + * @param off an int specifying the offset into the data.
5.279 + * @param len an int specifying the number of bytes to read.
5.280 + * @exception EOFException if this stream reaches the end before reading
5.281 + * all the bytes.
5.282 + * @exception IOException if an I/O error occurs.
5.283 + */
5.284 + void readFully(byte b[], int off, int len) throws IOException;
5.285 +
5.286 + /**
5.287 + * Makes an attempt to skip over
5.288 + * <code>n</code> bytes
5.289 + * of data from the input
5.290 + * stream, discarding the skipped bytes. However,
5.291 + * it may skip
5.292 + * over some smaller number of
5.293 + * bytes, possibly zero. This may result from
5.294 + * any of a
5.295 + * number of conditions; reaching
5.296 + * end of file before <code>n</code> bytes
5.297 + * have been skipped is
5.298 + * only one possibility.
5.299 + * This method never throws an <code>EOFException</code>.
5.300 + * The actual
5.301 + * number of bytes skipped is returned.
5.302 + *
5.303 + * @param n the number of bytes to be skipped.
5.304 + * @return the number of bytes actually skipped.
5.305 + * @exception IOException if an I/O error occurs.
5.306 + */
5.307 + int skipBytes(int n) throws IOException;
5.308 +
5.309 + /**
5.310 + * Reads one input byte and returns
5.311 + * <code>true</code> if that byte is nonzero,
5.312 + * <code>false</code> if that byte is zero.
5.313 + * This method is suitable for reading
5.314 + * the byte written by the <code>writeBoolean</code>
5.315 + * method of interface <code>DataOutput</code>.
5.316 + *
5.317 + * @return the <code>boolean</code> value read.
5.318 + * @exception EOFException if this stream reaches the end before reading
5.319 + * all the bytes.
5.320 + * @exception IOException if an I/O error occurs.
5.321 + */
5.322 + boolean readBoolean() throws IOException;
5.323 +
5.324 + /**
5.325 + * Reads and returns one input byte.
5.326 + * The byte is treated as a signed value in
5.327 + * the range <code>-128</code> through <code>127</code>,
5.328 + * inclusive.
5.329 + * This method is suitable for
5.330 + * reading the byte written by the <code>writeByte</code>
5.331 + * method of interface <code>DataOutput</code>.
5.332 + *
5.333 + * @return the 8-bit value read.
5.334 + * @exception EOFException if this stream reaches the end before reading
5.335 + * all the bytes.
5.336 + * @exception IOException if an I/O error occurs.
5.337 + */
5.338 + byte readByte() throws IOException;
5.339 +
5.340 + /**
5.341 + * Reads one input byte, zero-extends
5.342 + * it to type <code>int</code>, and returns
5.343 + * the result, which is therefore in the range
5.344 + * <code>0</code>
5.345 + * through <code>255</code>.
5.346 + * This method is suitable for reading
5.347 + * the byte written by the <code>writeByte</code>
5.348 + * method of interface <code>DataOutput</code>
5.349 + * if the argument to <code>writeByte</code>
5.350 + * was intended to be a value in the range
5.351 + * <code>0</code> through <code>255</code>.
5.352 + *
5.353 + * @return the unsigned 8-bit value read.
5.354 + * @exception EOFException if this stream reaches the end before reading
5.355 + * all the bytes.
5.356 + * @exception IOException if an I/O error occurs.
5.357 + */
5.358 + int readUnsignedByte() throws IOException;
5.359 +
5.360 + /**
5.361 + * Reads two input bytes and returns
5.362 + * a <code>short</code> value. Let <code>a</code>
5.363 + * be the first byte read and <code>b</code>
5.364 + * be the second byte. The value
5.365 + * returned
5.366 + * is:
5.367 + * <p><pre><code>(short)((a << 8) | (b & 0xff))
5.368 + * </code></pre>
5.369 + * This method
5.370 + * is suitable for reading the bytes written
5.371 + * by the <code>writeShort</code> method of
5.372 + * interface <code>DataOutput</code>.
5.373 + *
5.374 + * @return the 16-bit value read.
5.375 + * @exception EOFException if this stream reaches the end before reading
5.376 + * all the bytes.
5.377 + * @exception IOException if an I/O error occurs.
5.378 + */
5.379 + short readShort() throws IOException;
5.380 +
5.381 + /**
5.382 + * Reads two input bytes and returns
5.383 + * an <code>int</code> value in the range <code>0</code>
5.384 + * through <code>65535</code>. Let <code>a</code>
5.385 + * be the first byte read and
5.386 + * <code>b</code>
5.387 + * be the second byte. The value returned is:
5.388 + * <p><pre><code>(((a & 0xff) << 8) | (b & 0xff))
5.389 + * </code></pre>
5.390 + * This method is suitable for reading the bytes
5.391 + * written by the <code>writeShort</code> method
5.392 + * of interface <code>DataOutput</code> if
5.393 + * the argument to <code>writeShort</code>
5.394 + * was intended to be a value in the range
5.395 + * <code>0</code> through <code>65535</code>.
5.396 + *
5.397 + * @return the unsigned 16-bit value read.
5.398 + * @exception EOFException if this stream reaches the end before reading
5.399 + * all the bytes.
5.400 + * @exception IOException if an I/O error occurs.
5.401 + */
5.402 + int readUnsignedShort() throws IOException;
5.403 +
5.404 + /**
5.405 + * Reads two input bytes and returns a <code>char</code> value.
5.406 + * Let <code>a</code>
5.407 + * be the first byte read and <code>b</code>
5.408 + * be the second byte. The value
5.409 + * returned is:
5.410 + * <p><pre><code>(char)((a << 8) | (b & 0xff))
5.411 + * </code></pre>
5.412 + * This method
5.413 + * is suitable for reading bytes written by
5.414 + * the <code>writeChar</code> method of interface
5.415 + * <code>DataOutput</code>.
5.416 + *
5.417 + * @return the <code>char</code> value read.
5.418 + * @exception EOFException if this stream reaches the end before reading
5.419 + * all the bytes.
5.420 + * @exception IOException if an I/O error occurs.
5.421 + */
5.422 + char readChar() throws IOException;
5.423 +
5.424 + /**
5.425 + * Reads four input bytes and returns an
5.426 + * <code>int</code> value. Let <code>a-d</code>
5.427 + * be the first through fourth bytes read. The value returned is:
5.428 + * <p><pre>
5.429 + * <code>
5.430 + * (((a & 0xff) << 24) | ((b & 0xff) << 16) |
5.431 + *  ((c & 0xff) << 8) | (d & 0xff))
5.432 + * </code></pre>
5.433 + * This method is suitable
5.434 + * for reading bytes written by the <code>writeInt</code>
5.435 + * method of interface <code>DataOutput</code>.
5.436 + *
5.437 + * @return the <code>int</code> value read.
5.438 + * @exception EOFException if this stream reaches the end before reading
5.439 + * all the bytes.
5.440 + * @exception IOException if an I/O error occurs.
5.441 + */
5.442 + int readInt() throws IOException;
5.443 +
5.444 + /**
5.445 + * Reads eight input bytes and returns
5.446 + * a <code>long</code> value. Let <code>a-h</code>
5.447 + * be the first through eighth bytes read.
5.448 + * The value returned is:
5.449 + * <p><pre> <code>
5.450 + * (((long)(a & 0xff) << 56) |
5.451 + * ((long)(b & 0xff) << 48) |
5.452 + * ((long)(c & 0xff) << 40) |
5.453 + * ((long)(d & 0xff) << 32) |
5.454 + * ((long)(e & 0xff) << 24) |
5.455 + * ((long)(f & 0xff) << 16) |
5.456 + * ((long)(g & 0xff) << 8) |
5.457 + * ((long)(h & 0xff)))
5.458 + * </code></pre>
5.459 + * <p>
5.460 + * This method is suitable
5.461 + * for reading bytes written by the <code>writeLong</code>
5.462 + * method of interface <code>DataOutput</code>.
5.463 + *
5.464 + * @return the <code>long</code> value read.
5.465 + * @exception EOFException if this stream reaches the end before reading
5.466 + * all the bytes.
5.467 + * @exception IOException if an I/O error occurs.
5.468 + */
5.469 + long readLong() throws IOException;
5.470 +
5.471 + /**
5.472 + * Reads four input bytes and returns
5.473 + * a <code>float</code> value. It does this
5.474 + * by first constructing an <code>int</code>
5.475 + * value in exactly the manner
5.476 + * of the <code>readInt</code>
5.477 + * method, then converting this <code>int</code>
5.478 + * value to a <code>float</code> in
5.479 + * exactly the manner of the method <code>Float.intBitsToFloat</code>.
5.480 + * This method is suitable for reading
5.481 + * bytes written by the <code>writeFloat</code>
5.482 + * method of interface <code>DataOutput</code>.
5.483 + *
5.484 + * @return the <code>float</code> value read.
5.485 + * @exception EOFException if this stream reaches the end before reading
5.486 + * all the bytes.
5.487 + * @exception IOException if an I/O error occurs.
5.488 + */
5.489 + float readFloat() throws IOException;
5.490 +
5.491 + /**
5.492 + * Reads eight input bytes and returns
5.493 + * a <code>double</code> value. It does this
5.494 + * by first constructing a <code>long</code>
5.495 + * value in exactly the manner
5.496 + * of the <code>readlong</code>
5.497 + * method, then converting this <code>long</code>
5.498 + * value to a <code>double</code> in exactly
5.499 + * the manner of the method <code>Double.longBitsToDouble</code>.
5.500 + * This method is suitable for reading
5.501 + * bytes written by the <code>writeDouble</code>
5.502 + * method of interface <code>DataOutput</code>.
5.503 + *
5.504 + * @return the <code>double</code> value read.
5.505 + * @exception EOFException if this stream reaches the end before reading
5.506 + * all the bytes.
5.507 + * @exception IOException if an I/O error occurs.
5.508 + */
5.509 + double readDouble() throws IOException;
5.510 +
5.511 + /**
5.512 + * Reads the next line of text from the input stream.
5.513 + * It reads successive bytes, converting
5.514 + * each byte separately into a character,
5.515 + * until it encounters a line terminator or
5.516 + * end of
5.517 + * file; the characters read are then
5.518 + * returned as a <code>String</code>. Note
5.519 + * that because this
5.520 + * method processes bytes,
5.521 + * it does not support input of the full Unicode
5.522 + * character set.
5.523 + * <p>
5.524 + * If end of file is encountered
5.525 + * before even one byte can be read, then <code>null</code>
5.526 + * is returned. Otherwise, each byte that is
5.527 + * read is converted to type <code>char</code>
5.528 + * by zero-extension. If the character <code>'\n'</code>
5.529 + * is encountered, it is discarded and reading
5.530 + * ceases. If the character <code>'\r'</code>
5.531 + * is encountered, it is discarded and, if
5.532 + * the following byte converts  to the
5.533 + * character <code>'\n'</code>, then that is
5.534 + * discarded also; reading then ceases. If
5.535 + * end of file is encountered before either
5.536 + * of the characters <code>'\n'</code> and
5.537 + * <code>'\r'</code> is encountered, reading
5.538 + * ceases. Once reading has ceased, a <code>String</code>
5.539 + * is returned that contains all the characters
5.540 + * read and not discarded, taken in order.
5.541 + * Note that every character in this string
5.542 + * will have a value less than <code>\u0100</code>,
5.543 + * that is, <code>(char)256</code>.
5.544 + *
5.545 + * @return the next line of text from the input stream,
5.546 + * or <CODE>null</CODE> if the end of file is
5.547 + * encountered before a byte can be read.
5.548 + * @exception IOException if an I/O error occurs.
5.549 + */
5.550 + String readLine() throws IOException;
5.551 +
5.552 + /**
5.553 + * Reads in a string that has been encoded using a
5.554 + * <a href="#modified-utf-8">modified UTF-8</a>
5.555 + * format.
5.556 + * The general contract of <code>readUTF</code>
5.557 + * is that it reads a representation of a Unicode
5.558 + * character string encoded in modified
5.559 + * UTF-8 format; this string of characters
5.560 + * is then returned as a <code>String</code>.
5.561 + * <p>
5.562 + * First, two bytes are read and used to
5.563 + * construct an unsigned 16-bit integer in
5.564 + * exactly the manner of the <code>readUnsignedShort</code>
5.565 + * method . This integer value is called the
5.566 + * <i>UTF length</i> and specifies the number
5.567 + * of additional bytes to be read. These bytes
5.568 + * are then converted to characters by considering
5.569 + * them in groups. The length of each group
5.570 + * is computed from the value of the first
5.571 + * byte of the group. The byte following a
5.572 + * group, if any, is the first byte of the
5.573 + * next group.
5.574 + * <p>
5.575 + * If the first byte of a group
5.576 + * matches the bit pattern <code>0xxxxxxx</code>
5.577 + * (where <code>x</code> means "may be <code>0</code>
5.578 + * or <code>1</code>"), then the group consists
5.579 + * of just that byte. The byte is zero-extended
5.580 + * to form a character.
5.581 + * <p>
5.582 + * If the first byte
5.583 + * of a group matches the bit pattern <code>110xxxxx</code>,
5.584 + * then the group consists of that byte <code>a</code>
5.585 + * and a second byte <code>b</code>. If there
5.586 + * is no byte <code>b</code> (because byte
5.587 + * <code>a</code> was the last of the bytes
5.588 + * to be read), or if byte <code>b</code> does
5.589 + * not match the bit pattern <code>10xxxxxx</code>,
5.590 + * then a <code>UTFDataFormatException</code>
5.591 + * is thrown. Otherwise, the group is converted
5.592 + * to the character:<p>
5.593 + * <pre><code>(char)(((a& 0x1F) << 6) | (b & 0x3F))
5.594 + * </code></pre>
5.595 + * If the first byte of a group
5.596 + * matches the bit pattern <code>1110xxxx</code>,
5.597 + * then the group consists of that byte <code>a</code>
5.598 + * and two more bytes <code>b</code> and <code>c</code>.
5.599 + * If there is no byte <code>c</code> (because
5.600 + * byte <code>a</code> was one of the last
5.601 + * two of the bytes to be read), or either
5.602 + * byte <code>b</code> or byte <code>c</code>
5.603 + * does not match the bit pattern <code>10xxxxxx</code>,
5.604 + * then a <code>UTFDataFormatException</code>
5.605 + * is thrown. Otherwise, the group is converted
5.606 + * to the character:<p>
5.607 + * <pre><code>
5.608 + * (char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F))
5.609 + * </code></pre>
5.610 + * If the first byte of a group matches the
5.611 + * pattern <code>1111xxxx</code> or the pattern
5.612 + * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
5.613 + * is thrown.
5.614 + * <p>
5.615 + * If end of file is encountered
5.616 + * at any time during this entire process,
5.617 + * then an <code>EOFException</code> is thrown.
5.618 + * <p>
5.619 + * After every group has been converted to
5.620 + * a character by this process, the characters
5.621 + * are gathered, in the same order in which
5.622 + * their corresponding groups were read from
5.623 + * the input stream, to form a <code>String</code>,
5.624 + * which is returned.
5.625 + * <p>
5.626 + * The <code>writeUTF</code>
5.627 + * method of interface <code>DataOutput</code>
5.628 + * may be used to write data that is suitable
5.629 + * for reading by this method.
5.630 + * @return a Unicode string.
5.631 + * @exception EOFException if this stream reaches the end
5.632 + * before reading all the bytes.
5.633 + * @exception IOException if an I/O error occurs.
5.634 + * @exception UTFDataFormatException if the bytes do not represent a
5.635 + * valid modified UTF-8 encoding of a string.
5.636 + */
5.637 + String readUTF() throws IOException;
5.638 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/emul/mini/src/main/java/java/io/DataInputStream.java Wed Jan 23 20:39:23 2013 +0100
6.3 @@ -0,0 +1,704 @@
6.4 +/*
6.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6.7 + *
6.8 + * This code is free software; you can redistribute it and/or modify it
6.9 + * under the terms of the GNU General Public License version 2 only, as
6.10 + * published by the Free Software Foundation. Oracle designates this
6.11 + * particular file as subject to the "Classpath" exception as provided
6.12 + * by Oracle in the LICENSE file that accompanied this code.
6.13 + *
6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6.17 + * version 2 for more details (a copy is included in the LICENSE file that
6.18 + * accompanied this code).
6.19 + *
6.20 + * You should have received a copy of the GNU General Public License version
6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6.23 + *
6.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6.25 + * or visit www.oracle.com if you need additional information or have any
6.26 + * questions.
6.27 + */
6.28 +
6.29 +package java.io;
6.30 +
6.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
6.32 +
6.33 +/**
6.34 + * A data input stream lets an application read primitive Java data
6.35 + * types from an underlying input stream in a machine-independent
6.36 + * way. An application uses a data output stream to write data that
6.37 + * can later be read by a data input stream.
6.38 + * <p>
6.39 + * DataInputStream is not necessarily safe for multithreaded access.
6.40 + * Thread safety is optional and is the responsibility of users of
6.41 + * methods in this class.
6.42 + *
6.43 + * @author Arthur van Hoff
6.44 + * @see java.io.DataOutputStream
6.45 + * @since JDK1.0
6.46 + */
6.47 +public
6.48 +class DataInputStream extends FilterInputStream implements DataInput {
6.49 +
6.50 + /**
6.51 + * Creates a DataInputStream that uses the specified
6.52 + * underlying InputStream.
6.53 + *
6.54 + * @param in the specified input stream
6.55 + */
6.56 + public DataInputStream(InputStream in) {
6.57 + super(in);
6.58 + }
6.59 +
6.60 + /**
6.61 + * working arrays initialized on demand by readUTF
6.62 + */
6.63 + private byte bytearr[] = new byte[80];
6.64 + private char chararr[] = new char[80];
6.65 +
6.66 + /**
6.67 + * Reads some number of bytes from the contained input stream and
6.68 + * stores them into the buffer array <code>b</code>. The number of
6.69 + * bytes actually read is returned as an integer. This method blocks
6.70 + * until input data is available, end of file is detected, or an
6.71 + * exception is thrown.
6.72 + *
6.73 + * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
6.74 + * thrown. If the length of <code>b</code> is zero, then no bytes are
6.75 + * read and <code>0</code> is returned; otherwise, there is an attempt
6.76 + * to read at least one byte. If no byte is available because the
6.77 + * stream is at end of file, the value <code>-1</code> is returned;
6.78 + * otherwise, at least one byte is read and stored into <code>b</code>.
6.79 + *
6.80 + * <p>The first byte read is stored into element <code>b[0]</code>, the
6.81 + * next one into <code>b[1]</code>, and so on. The number of bytes read
6.82 + * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
6.83 + * be the number of bytes actually read; these bytes will be stored in
6.84 + * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
6.85 + * elements <code>b[k]</code> through <code>b[b.length-1]</code>
6.86 + * unaffected.
6.87 + *
6.88 + * <p>The <code>read(b)</code> method has the same effect as:
6.89 + * <blockquote><pre>
6.90 + * read(b, 0, b.length)
6.91 + * </pre></blockquote>
6.92 + *
6.93 + * @param b the buffer into which the data is read.
6.94 + * @return the total number of bytes read into the buffer, or
6.95 + * <code>-1</code> if there is no more data because the end
6.96 + * of the stream has been reached.
6.97 + * @exception IOException if the first byte cannot be read for any reason
6.98 + * other than end of file, the stream has been closed and the underlying
6.99 + * input stream does not support reading after close, or another I/O
6.100 + * error occurs.
6.101 + * @see java.io.FilterInputStream#in
6.102 + * @see java.io.InputStream#read(byte[], int, int)
6.103 + */
6.104 + public final int read(byte b[]) throws IOException {
6.105 + return in.read(b, 0, b.length);
6.106 + }
6.107 +
6.108 + /**
6.109 + * Reads up to <code>len</code> bytes of data from the contained
6.110 + * input stream into an array of bytes. An attempt is made to read
6.111 + * as many as <code>len</code> bytes, but a smaller number may be read,
6.112 + * possibly zero. The number of bytes actually read is returned as an
6.113 + * integer.
6.114 + *
6.115 + * <p> This method blocks until input data is available, end of file is
6.116 + * detected, or an exception is thrown.
6.117 + *
6.118 + * <p> If <code>len</code> is zero, then no bytes are read and
6.119 + * <code>0</code> is returned; otherwise, there is an attempt to read at
6.120 + * least one byte. If no byte is available because the stream is at end of
6.121 + * file, the value <code>-1</code> is returned; otherwise, at least one
6.122 + * byte is read and stored into <code>b</code>.
6.123 + *
6.124 + * <p> The first byte read is stored into element <code>b[off]</code>, the
6.125 + * next one into <code>b[off+1]</code>, and so on. The number of bytes read
6.126 + * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
6.127 + * bytes actually read; these bytes will be stored in elements
6.128 + * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
6.129 + * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
6.130 + * <code>b[off+len-1]</code> unaffected.
6.131 + *
6.132 + * <p> In every case, elements <code>b[0]</code> through
6.133 + * <code>b[off]</code> and elements <code>b[off+len]</code> through
6.134 + * <code>b[b.length-1]</code> are unaffected.
6.135 + *
6.136 + * @param b the buffer into which the data is read.
6.137 + * @param off the start offset in the destination array <code>b</code>
6.138 + * @param len the maximum number of bytes read.
6.139 + * @return the total number of bytes read into the buffer, or
6.140 + * <code>-1</code> if there is no more data because the end
6.141 + * of the stream has been reached.
6.142 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
6.143 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
6.144 + * <code>len</code> is negative, or <code>len</code> is greater than
6.145 + * <code>b.length - off</code>
6.146 + * @exception IOException if the first byte cannot be read for any reason
6.147 + * other than end of file, the stream has been closed and the underlying
6.148 + * input stream does not support reading after close, or another I/O
6.149 + * error occurs.
6.150 + * @see java.io.FilterInputStream#in
6.151 + * @see java.io.InputStream#read(byte[], int, int)
6.152 + */
6.153 + public final int read(byte b[], int off, int len) throws IOException {
6.154 + return in.read(b, off, len);
6.155 + }
6.156 +
6.157 + /**
6.158 + * See the general contract of the <code>readFully</code>
6.159 + * method of <code>DataInput</code>.
6.160 + * <p>
6.161 + * Bytes
6.162 + * for this operation are read from the contained
6.163 + * input stream.
6.164 + *
6.165 + * @param b the buffer into which the data is read.
6.166 + * @exception EOFException if this input stream reaches the end before
6.167 + * reading all the bytes.
6.168 + * @exception IOException the stream has been closed and the contained
6.169 + * input stream does not support reading after close, or
6.170 + * another I/O error occurs.
6.171 + * @see java.io.FilterInputStream#in
6.172 + */
6.173 + public final void readFully(byte b[]) throws IOException {
6.174 + readFully(b, 0, b.length);
6.175 + }
6.176 +
6.177 + /**
6.178 + * See the general contract of the <code>readFully</code>
6.179 + * method of <code>DataInput</code>.
6.180 + * <p>
6.181 + * Bytes
6.182 + * for this operation are read from the contained
6.183 + * input stream.
6.184 + *
6.185 + * @param b the buffer into which the data is read.
6.186 + * @param off the start offset of the data.
6.187 + * @param len the number of bytes to read.
6.188 + * @exception EOFException if this input stream reaches the end before
6.189 + * reading all the bytes.
6.190 + * @exception IOException the stream has been closed and the contained
6.191 + * input stream does not support reading after close, or
6.192 + * another I/O error occurs.
6.193 + * @see java.io.FilterInputStream#in
6.194 + */
6.195 + public final void readFully(byte b[], int off, int len) throws IOException {
6.196 + if (len < 0)
6.197 + throw new IndexOutOfBoundsException();
6.198 + int n = 0;
6.199 + while (n < len) {
6.200 + int count = in.read(b, off + n, len - n);
6.201 + if (count < 0)
6.202 + throw new EOFException();
6.203 + n += count;
6.204 + }
6.205 + }
6.206 +
6.207 + /**
6.208 + * See the general contract of the <code>skipBytes</code>
6.209 + * method of <code>DataInput</code>.
6.210 + * <p>
6.211 + * Bytes for this operation are read from the contained
6.212 + * input stream.
6.213 + *
6.214 + * @param n the number of bytes to be skipped.
6.215 + * @return the actual number of bytes skipped.
6.216 + * @exception IOException if the contained input stream does not support
6.217 + * seek, or the stream has been closed and
6.218 + * the contained input stream does not support
6.219 + * reading after close, or another I/O error occurs.
6.220 + */
6.221 + public final int skipBytes(int n) throws IOException {
6.222 + int total = 0;
6.223 + int cur = 0;
6.224 +
6.225 + while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
6.226 + total += cur;
6.227 + }
6.228 +
6.229 + return total;
6.230 + }
6.231 +
6.232 + /**
6.233 + * See the general contract of the <code>readBoolean</code>
6.234 + * method of <code>DataInput</code>.
6.235 + * <p>
6.236 + * Bytes for this operation are read from the contained
6.237 + * input stream.
6.238 + *
6.239 + * @return the <code>boolean</code> value read.
6.240 + * @exception EOFException if this input stream has reached the end.
6.241 + * @exception IOException the stream has been closed and the contained
6.242 + * input stream does not support reading after close, or
6.243 + * another I/O error occurs.
6.244 + * @see java.io.FilterInputStream#in
6.245 + */
6.246 + public final boolean readBoolean() throws IOException {
6.247 + int ch = in.read();
6.248 + if (ch < 0)
6.249 + throw new EOFException();
6.250 + return (ch != 0);
6.251 + }
6.252 +
6.253 + /**
6.254 + * See the general contract of the <code>readByte</code>
6.255 + * method of <code>DataInput</code>.
6.256 + * <p>
6.257 + * Bytes
6.258 + * for this operation are read from the contained
6.259 + * input stream.
6.260 + *
6.261 + * @return the next byte of this input stream as a signed 8-bit
6.262 + * <code>byte</code>.
6.263 + * @exception EOFException if this input stream has reached the end.
6.264 + * @exception IOException the stream has been closed and the contained
6.265 + * input stream does not support reading after close, or
6.266 + * another I/O error occurs.
6.267 + * @see java.io.FilterInputStream#in
6.268 + */
6.269 + public final byte readByte() throws IOException {
6.270 + int ch = in.read();
6.271 + if (ch < 0)
6.272 + throw new EOFException();
6.273 + return (byte)(ch);
6.274 + }
6.275 +
6.276 + /**
6.277 + * See the general contract of the <code>readUnsignedByte</code>
6.278 + * method of <code>DataInput</code>.
6.279 + * <p>
6.280 + * Bytes
6.281 + * for this operation are read from the contained
6.282 + * input stream.
6.283 + *
6.284 + * @return the next byte of this input stream, interpreted as an
6.285 + * unsigned 8-bit number.
6.286 + * @exception EOFException if this input stream has reached the end.
6.287 + * @exception IOException the stream has been closed and the contained
6.288 + * input stream does not support reading after close, or
6.289 + * another I/O error occurs.
6.290 + * @see java.io.FilterInputStream#in
6.291 + */
6.292 + public final int readUnsignedByte() throws IOException {
6.293 + int ch = in.read();
6.294 + if (ch < 0)
6.295 + throw new EOFException();
6.296 + return ch;
6.297 + }
6.298 +
6.299 + /**
6.300 + * See the general contract of the <code>readShort</code>
6.301 + * method of <code>DataInput</code>.
6.302 + * <p>
6.303 + * Bytes
6.304 + * for this operation are read from the contained
6.305 + * input stream.
6.306 + *
6.307 + * @return the next two bytes of this input stream, interpreted as a
6.308 + * signed 16-bit number.
6.309 + * @exception EOFException if this input stream reaches the end before
6.310 + * reading two bytes.
6.311 + * @exception IOException the stream has been closed and the contained
6.312 + * input stream does not support reading after close, or
6.313 + * another I/O error occurs.
6.314 + * @see java.io.FilterInputStream#in
6.315 + */
6.316 + public final short readShort() throws IOException {
6.317 + int ch1 = in.read();
6.318 + int ch2 = in.read();
6.319 + if ((ch1 | ch2) < 0)
6.320 + throw new EOFException();
6.321 + return (short)((ch1 << 8) + (ch2 << 0));
6.322 + }
6.323 +
6.324 + /**
6.325 + * See the general contract of the <code>readUnsignedShort</code>
6.326 + * method of <code>DataInput</code>.
6.327 + * <p>
6.328 + * Bytes
6.329 + * for this operation are read from the contained
6.330 + * input stream.
6.331 + *
6.332 + * @return the next two bytes of this input stream, interpreted as an
6.333 + * unsigned 16-bit integer.
6.334 + * @exception EOFException if this input stream reaches the end before
6.335 + * reading two bytes.
6.336 + * @exception IOException the stream has been closed and the contained
6.337 + * input stream does not support reading after close, or
6.338 + * another I/O error occurs.
6.339 + * @see java.io.FilterInputStream#in
6.340 + */
6.341 + public final int readUnsignedShort() throws IOException {
6.342 + int ch1 = in.read();
6.343 + int ch2 = in.read();
6.344 + if ((ch1 | ch2) < 0)
6.345 + throw new EOFException();
6.346 + return (ch1 << 8) + (ch2 << 0);
6.347 + }
6.348 +
6.349 + /**
6.350 + * See the general contract of the <code>readChar</code>
6.351 + * method of <code>DataInput</code>.
6.352 + * <p>
6.353 + * Bytes
6.354 + * for this operation are read from the contained
6.355 + * input stream.
6.356 + *
6.357 + * @return the next two bytes of this input stream, interpreted as a
6.358 + * <code>char</code>.
6.359 + * @exception EOFException if this input stream reaches the end before
6.360 + * reading two bytes.
6.361 + * @exception IOException the stream has been closed and the contained
6.362 + * input stream does not support reading after close, or
6.363 + * another I/O error occurs.
6.364 + * @see java.io.FilterInputStream#in
6.365 + */
6.366 + public final char readChar() throws IOException {
6.367 + int ch1 = in.read();
6.368 + int ch2 = in.read();
6.369 + if ((ch1 | ch2) < 0)
6.370 + throw new EOFException();
6.371 + return (char)((ch1 << 8) + (ch2 << 0));
6.372 + }
6.373 +
6.374 + /**
6.375 + * See the general contract of the <code>readInt</code>
6.376 + * method of <code>DataInput</code>.
6.377 + * <p>
6.378 + * Bytes
6.379 + * for this operation are read from the contained
6.380 + * input stream.
6.381 + *
6.382 + * @return the next four bytes of this input stream, interpreted as an
6.383 + * <code>int</code>.
6.384 + * @exception EOFException if this input stream reaches the end before
6.385 + * reading four bytes.
6.386 + * @exception IOException the stream has been closed and the contained
6.387 + * input stream does not support reading after close, or
6.388 + * another I/O error occurs.
6.389 + * @see java.io.FilterInputStream#in
6.390 + */
6.391 + public final int readInt() throws IOException {
6.392 + int ch1 = in.read();
6.393 + int ch2 = in.read();
6.394 + int ch3 = in.read();
6.395 + int ch4 = in.read();
6.396 + if ((ch1 | ch2 | ch3 | ch4) < 0)
6.397 + throw new EOFException();
6.398 + return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
6.399 + }
6.400 +
6.401 + private byte readBuffer[] = new byte[8];
6.402 +
6.403 + /**
6.404 + * See the general contract of the <code>readLong</code>
6.405 + * method of <code>DataInput</code>.
6.406 + * <p>
6.407 + * Bytes
6.408 + * for this operation are read from the contained
6.409 + * input stream.
6.410 + *
6.411 + * @return the next eight bytes of this input stream, interpreted as a
6.412 + * <code>long</code>.
6.413 + * @exception EOFException if this input stream reaches the end before
6.414 + * reading eight bytes.
6.415 + * @exception IOException the stream has been closed and the contained
6.416 + * input stream does not support reading after close, or
6.417 + * another I/O error occurs.
6.418 + * @see java.io.FilterInputStream#in
6.419 + */
6.420 + public final long readLong() throws IOException {
6.421 + readFully(readBuffer, 0, 8);
6.422 + return (((long)readBuffer[0] << 56) +
6.423 + ((long)(readBuffer[1] & 255) << 48) +
6.424 + ((long)(readBuffer[2] & 255) << 40) +
6.425 + ((long)(readBuffer[3] & 255) << 32) +
6.426 + ((long)(readBuffer[4] & 255) << 24) +
6.427 + ((readBuffer[5] & 255) << 16) +
6.428 + ((readBuffer[6] & 255) << 8) +
6.429 + ((readBuffer[7] & 255) << 0));
6.430 + }
6.431 +
6.432 + /**
6.433 + * See the general contract of the <code>readFloat</code>
6.434 + * method of <code>DataInput</code>.
6.435 + * <p>
6.436 + * Bytes
6.437 + * for this operation are read from the contained
6.438 + * input stream.
6.439 + *
6.440 + * @return the next four bytes of this input stream, interpreted as a
6.441 + * <code>float</code>.
6.442 + * @exception EOFException if this input stream reaches the end before
6.443 + * reading four bytes.
6.444 + * @exception IOException the stream has been closed and the contained
6.445 + * input stream does not support reading after close, or
6.446 + * another I/O error occurs.
6.447 + * @see java.io.DataInputStream#readInt()
6.448 + * @see java.lang.Float#intBitsToFloat(int)
6.449 + */
6.450 + public final float readFloat() throws IOException {
6.451 + return Float.intBitsToFloat(readInt());
6.452 + }
6.453 +
6.454 + /**
6.455 + * See the general contract of the <code>readDouble</code>
6.456 + * method of <code>DataInput</code>.
6.457 + * <p>
6.458 + * Bytes
6.459 + * for this operation are read from the contained
6.460 + * input stream.
6.461 + *
6.462 + * @return the next eight bytes of this input stream, interpreted as a
6.463 + * <code>double</code>.
6.464 + * @exception EOFException if this input stream reaches the end before
6.465 + * reading eight bytes.
6.466 + * @exception IOException the stream has been closed and the contained
6.467 + * input stream does not support reading after close, or
6.468 + * another I/O error occurs.
6.469 + * @see java.io.DataInputStream#readLong()
6.470 + * @see java.lang.Double#longBitsToDouble(long)
6.471 + */
6.472 + public final double readDouble() throws IOException {
6.473 + int hi = readInt();
6.474 + int low = readInt();
6.475 + return toDouble(hi, low);
6.476 + }
6.477 +
6.478 + @JavaScriptBody(args={ "hi", "low" },
6.479 + body=
6.480 + "if (low == 0) {\n"
6.481 + + " if (hi === 0x7ff00000) return Number.POSITIVE_INFINITY;\n"
6.482 + + " if (hi === 0xfff00000) return Number.NEGATIVE_INFINITY;\n"
6.483 + + "}\n"
6.484 + + "if (hi >= 0x7ff00000 && hi <= 0x7fffffff) return Number.NaN;\n"
6.485 + + "if (hi >= 0xfff00000 && hi <= 0xffffffff) return Number.NaN;\n"
6.486 + + "var s = (hi & 0x80000000) === 0 ? 1 : -1;\n"
6.487 + + "var e = (hi >> 20) & 0x7ff;\n"
6.488 + + "var to32 = low >> 0;\n"
6.489 + + "if (e === 0) {\n"
6.490 + + " if (to32 & 0x80000000) {\n"
6.491 + + " hi = hi << 1 + 1; low = low << 1;\n"
6.492 + + " } else {\n"
6.493 + + " hi = hi << 1; low = low << 1;\n"
6.494 + + " }\n"
6.495 + + "} else {\n"
6.496 + + " hi = (hi & 0xfffff) | 0x100000;\n"
6.497 + + "}\n"
6.498 + + "to32 = low >> 0;\n"
6.499 + + "var m = Math.pow(2.0, 32) * hi + to32;\n"
6.500 + + "var r = s * m * Math.pow(2.0, e - 1075);\n"
6.501 + + "//throw 'exp: ' + e + ' sign: ' + s + ' hi:' + hi + ' low: ' + low + ' m: ' + m + ' r: ' + r;\n"
6.502 + + "return r;\n"
6.503 + )
6.504 + private static double toDouble(int hi, int low) {
6.505 + long both = hi;
6.506 + both = (both << 32) & low;
6.507 + return Double.doubleToLongBits(both);
6.508 + }
6.509 +
6.510 + private char lineBuffer[];
6.511 +
6.512 + /**
6.513 + * See the general contract of the <code>readLine</code>
6.514 + * method of <code>DataInput</code>.
6.515 + * <p>
6.516 + * Bytes
6.517 + * for this operation are read from the contained
6.518 + * input stream.
6.519 + *
6.520 + * @deprecated This method does not properly convert bytes to characters.
6.521 + * As of JDK 1.1, the preferred way to read lines of text is via the
6.522 + * <code>BufferedReader.readLine()</code> method. Programs that use the
6.523 + * <code>DataInputStream</code> class to read lines can be converted to use
6.524 + * the <code>BufferedReader</code> class by replacing code of the form:
6.525 + * <blockquote><pre>
6.526 + * DataInputStream d = new DataInputStream(in);
6.527 + * </pre></blockquote>
6.528 + * with:
6.529 + * <blockquote><pre>
6.530 + * BufferedReader d
6.531 + * = new BufferedReader(new InputStreamReader(in));
6.532 + * </pre></blockquote>
6.533 + *
6.534 + * @return the next line of text from this input stream.
6.535 + * @exception IOException if an I/O error occurs.
6.536 + * @see java.io.BufferedReader#readLine()
6.537 + * @see java.io.FilterInputStream#in
6.538 + */
6.539 + @Deprecated
6.540 + public final String readLine() throws IOException {
6.541 + char buf[] = lineBuffer;
6.542 +
6.543 + if (buf == null) {
6.544 + buf = lineBuffer = new char[128];
6.545 + }
6.546 +
6.547 + int room = buf.length;
6.548 + int offset = 0;
6.549 + int c;
6.550 +
6.551 +loop: while (true) {
6.552 + switch (c = in.read()) {
6.553 + case -1:
6.554 + case '\n':
6.555 + break loop;
6.556 +
6.557 + case '\r':
6.558 + int c2 = in.read();
6.559 + if ((c2 != '\n') && (c2 != -1)) {
6.560 + if (!(in instanceof PushbackInputStream)) {
6.561 + this.in = new PushbackInputStream(in);
6.562 + }
6.563 + ((PushbackInputStream)in).unread(c2);
6.564 + }
6.565 + break loop;
6.566 +
6.567 + default:
6.568 + if (--room < 0) {
6.569 + buf = new char[offset + 128];
6.570 + room = buf.length - offset - 1;
6.571 + arraycopy(lineBuffer, 0, buf, 0, offset);
6.572 + lineBuffer = buf;
6.573 + }
6.574 + buf[offset++] = (char) c;
6.575 + break;
6.576 + }
6.577 + }
6.578 + if ((c == -1) && (offset == 0)) {
6.579 + return null;
6.580 + }
6.581 + return String.copyValueOf(buf, 0, offset);
6.582 + }
6.583 +
6.584 + /**
6.585 + * See the general contract of the <code>readUTF</code>
6.586 + * method of <code>DataInput</code>.
6.587 + * <p>
6.588 + * Bytes
6.589 + * for this operation are read from the contained
6.590 + * input stream.
6.591 + *
6.592 + * @return a Unicode string.
6.593 + * @exception EOFException if this input stream reaches the end before
6.594 + * reading all the bytes.
6.595 + * @exception IOException the stream has been closed and the contained
6.596 + * input stream does not support reading after close, or
6.597 + * another I/O error occurs.
6.598 + * @exception UTFDataFormatException if the bytes do not represent a valid
6.599 + * modified UTF-8 encoding of a string.
6.600 + * @see java.io.DataInputStream#readUTF(java.io.DataInput)
6.601 + */
6.602 + public final String readUTF() throws IOException {
6.603 + return readUTF(this);
6.604 + }
6.605 +
6.606 + /**
6.607 + * Reads from the
6.608 + * stream <code>in</code> a representation
6.609 + * of a Unicode character string encoded in
6.610 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
6.611 + * this string of characters is then returned as a <code>String</code>.
6.612 + * The details of the modified UTF-8 representation
6.613 + * are exactly the same as for the <code>readUTF</code>
6.614 + * method of <code>DataInput</code>.
6.615 + *
6.616 + * @param in a data input stream.
6.617 + * @return a Unicode string.
6.618 + * @exception EOFException if the input stream reaches the end
6.619 + * before all the bytes.
6.620 + * @exception IOException the stream has been closed and the contained
6.621 + * input stream does not support reading after close, or
6.622 + * another I/O error occurs.
6.623 + * @exception UTFDataFormatException if the bytes do not represent a
6.624 + * valid modified UTF-8 encoding of a Unicode string.
6.625 + * @see java.io.DataInputStream#readUnsignedShort()
6.626 + */
6.627 + public final static String readUTF(DataInput in) throws IOException {
6.628 + int utflen = in.readUnsignedShort();
6.629 + byte[] bytearr = null;
6.630 + char[] chararr = null;
6.631 + if (in instanceof DataInputStream) {
6.632 + DataInputStream dis = (DataInputStream)in;
6.633 + if (dis.bytearr.length < utflen){
6.634 + dis.bytearr = new byte[utflen*2];
6.635 + dis.chararr = new char[utflen*2];
6.636 + }
6.637 + chararr = dis.chararr;
6.638 + bytearr = dis.bytearr;
6.639 + } else {
6.640 + bytearr = new byte[utflen];
6.641 + chararr = new char[utflen];
6.642 + }
6.643 +
6.644 + int c, char2, char3;
6.645 + int count = 0;
6.646 + int chararr_count=0;
6.647 +
6.648 + in.readFully(bytearr, 0, utflen);
6.649 +
6.650 + while (count < utflen) {
6.651 + c = (int) bytearr[count] & 0xff;
6.652 + if (c > 127) break;
6.653 + count++;
6.654 + chararr[chararr_count++]=(char)c;
6.655 + }
6.656 +
6.657 + while (count < utflen) {
6.658 + c = (int) bytearr[count] & 0xff;
6.659 + switch (c >> 4) {
6.660 + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
6.661 + /* 0xxxxxxx*/
6.662 + count++;
6.663 + chararr[chararr_count++]=(char)c;
6.664 + break;
6.665 + case 12: case 13:
6.666 + /* 110x xxxx 10xx xxxx*/
6.667 + count += 2;
6.668 + if (count > utflen)
6.669 + throw new UTFDataFormatException(
6.670 + "malformed input: partial character at end");
6.671 + char2 = (int) bytearr[count-1];
6.672 + if ((char2 & 0xC0) != 0x80)
6.673 + throw new UTFDataFormatException(
6.674 + "malformed input around byte " + count);
6.675 + chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
6.676 + (char2 & 0x3F));
6.677 + break;
6.678 + case 14:
6.679 + /* 1110 xxxx 10xx xxxx 10xx xxxx */
6.680 + count += 3;
6.681 + if (count > utflen)
6.682 + throw new UTFDataFormatException(
6.683 + "malformed input: partial character at end");
6.684 + char2 = (int) bytearr[count-2];
6.685 + char3 = (int) bytearr[count-1];
6.686 + if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
6.687 + throw new UTFDataFormatException(
6.688 + "malformed input around byte " + (count-1));
6.689 + chararr[chararr_count++]=(char)(((c & 0x0F) << 12) |
6.690 + ((char2 & 0x3F) << 6) |
6.691 + ((char3 & 0x3F) << 0));
6.692 + break;
6.693 + default:
6.694 + /* 10xx xxxx, 1111 xxxx */
6.695 + throw new UTFDataFormatException(
6.696 + "malformed input around byte " + count);
6.697 + }
6.698 + }
6.699 + // The number of chars produced may be less than utflen
6.700 + return new String(chararr, 0, chararr_count);
6.701 + }
6.702 + static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
6.703 + while (count-- > 0) {
6.704 + dst[dstBegin++] = value[srcBegin++];
6.705 + }
6.706 + }
6.707 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/emul/mini/src/main/java/java/io/EOFException.java Wed Jan 23 20:39:23 2013 +0100
7.3 @@ -0,0 +1,65 @@
7.4 +/*
7.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7.7 + *
7.8 + * This code is free software; you can redistribute it and/or modify it
7.9 + * under the terms of the GNU General Public License version 2 only, as
7.10 + * published by the Free Software Foundation. Oracle designates this
7.11 + * particular file as subject to the "Classpath" exception as provided
7.12 + * by Oracle in the LICENSE file that accompanied this code.
7.13 + *
7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7.17 + * version 2 for more details (a copy is included in the LICENSE file that
7.18 + * accompanied this code).
7.19 + *
7.20 + * You should have received a copy of the GNU General Public License version
7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7.23 + *
7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7.25 + * or visit www.oracle.com if you need additional information or have any
7.26 + * questions.
7.27 + */
7.28 +
7.29 +package java.io;
7.30 +
7.31 +/**
7.32 + * Signals that an end of file or end of stream has been reached
7.33 + * unexpectedly during input.
7.34 + * <p>
7.35 + * This exception is mainly used by data input streams to signal end of
7.36 + * stream. Note that many other input operations return a special value on
7.37 + * end of stream rather than throwing an exception.
7.38 + * <p>
7.39 + *
7.40 + * @author Frank Yellin
7.41 + * @see java.io.DataInputStream
7.42 + * @see java.io.IOException
7.43 + * @since JDK1.0
7.44 + */
7.45 +public
7.46 +class EOFException extends IOException {
7.47 + private static final long serialVersionUID = 6433858223774886977L;
7.48 +
7.49 + /**
7.50 + * Constructs an <code>EOFException</code> with <code>null</code>
7.51 + * as its error detail message.
7.52 + */
7.53 + public EOFException() {
7.54 + super();
7.55 + }
7.56 +
7.57 + /**
7.58 + * Constructs an <code>EOFException</code> with the specified detail
7.59 + * message. The string <code>s</code> may later be retrieved by the
7.60 + * <code>{@link java.lang.Throwable#getMessage}</code> method of class
7.61 + * <code>java.lang.Throwable</code>.
7.62 + *
7.63 + * @param s the detail message.
7.64 + */
7.65 + public EOFException(String s) {
7.66 + super(s);
7.67 + }
7.68 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/emul/mini/src/main/java/java/io/FilterInputStream.java Wed Jan 23 20:39:23 2013 +0100
8.3 @@ -0,0 +1,245 @@
8.4 +/*
8.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8.7 + *
8.8 + * This code is free software; you can redistribute it and/or modify it
8.9 + * under the terms of the GNU General Public License version 2 only, as
8.10 + * published by the Free Software Foundation. Oracle designates this
8.11 + * particular file as subject to the "Classpath" exception as provided
8.12 + * by Oracle in the LICENSE file that accompanied this code.
8.13 + *
8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8.17 + * version 2 for more details (a copy is included in the LICENSE file that
8.18 + * accompanied this code).
8.19 + *
8.20 + * You should have received a copy of the GNU General Public License version
8.21 + * 2 along with this work; if not, write to the Free Software Foundation,
8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8.23 + *
8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8.25 + * or visit www.oracle.com if you need additional information or have any
8.26 + * questions.
8.27 + */
8.28 +
8.29 +package java.io;
8.30 +
8.31 +/**
8.32 + * A <code>FilterInputStream</code> contains
8.33 + * some other input stream, which it uses as
8.34 + * its basic source of data, possibly transforming
8.35 + * the data along the way or providing additional
8.36 + * functionality. The class <code>FilterInputStream</code>
8.37 + * itself simply overrides all methods of
8.38 + * <code>InputStream</code> with versions that
8.39 + * pass all requests to the contained input
8.40 + * stream. Subclasses of <code>FilterInputStream</code>
8.41 + * may further override some of these methods
8.42 + * and may also provide additional methods
8.43 + * and fields.
8.44 + *
8.45 + * @author Jonathan Payne
8.46 + * @since JDK1.0
8.47 + */
8.48 +public
8.49 +class FilterInputStream extends InputStream {
8.50 + /**
8.51 + * The input stream to be filtered.
8.52 + */
8.53 + protected volatile InputStream in;
8.54 +
8.55 + /**
8.56 + * Creates a <code>FilterInputStream</code>
8.57 + * by assigning the argument <code>in</code>
8.58 + * to the field <code>this.in</code> so as
8.59 + * to remember it for later use.
8.60 + *
8.61 + * @param in the underlying input stream, or <code>null</code> if
8.62 + * this instance is to be created without an underlying stream.
8.63 + */
8.64 + protected FilterInputStream(InputStream in) {
8.65 + this.in = in;
8.66 + }
8.67 +
8.68 + /**
8.69 + * Reads the next byte of data from this input stream. The value
8.70 + * byte is returned as an <code>int</code> in the range
8.71 + * <code>0</code> to <code>255</code>. If no byte is available
8.72 + * because the end of the stream has been reached, the value
8.73 + * <code>-1</code> is returned. This method blocks until input data
8.74 + * is available, the end of the stream is detected, or an exception
8.75 + * is thrown.
8.76 + * <p>
8.77 + * This method
8.78 + * simply performs <code>in.read()</code> and returns the result.
8.79 + *
8.80 + * @return the next byte of data, or <code>-1</code> if the end of the
8.81 + * stream is reached.
8.82 + * @exception IOException if an I/O error occurs.
8.83 + * @see java.io.FilterInputStream#in
8.84 + */
8.85 + public int read() throws IOException {
8.86 + return in.read();
8.87 + }
8.88 +
8.89 + /**
8.90 + * Reads up to <code>byte.length</code> bytes of data from this
8.91 + * input stream into an array of bytes. This method blocks until some
8.92 + * input is available.
8.93 + * <p>
8.94 + * This method simply performs the call
8.95 + * <code>read(b, 0, b.length)</code> and returns
8.96 + * the result. It is important that it does
8.97 + * <i>not</i> do <code>in.read(b)</code> instead;
8.98 + * certain subclasses of <code>FilterInputStream</code>
8.99 + * depend on the implementation strategy actually
8.100 + * used.
8.101 + *
8.102 + * @param b the buffer into which the data is read.
8.103 + * @return the total number of bytes read into the buffer, or
8.104 + * <code>-1</code> if there is no more data because the end of
8.105 + * the stream has been reached.
8.106 + * @exception IOException if an I/O error occurs.
8.107 + * @see java.io.FilterInputStream#read(byte[], int, int)
8.108 + */
8.109 + public int read(byte b[]) throws IOException {
8.110 + return read(b, 0, b.length);
8.111 + }
8.112 +
8.113 + /**
8.114 + * Reads up to <code>len</code> bytes of data from this input stream
8.115 + * into an array of bytes. If <code>len</code> is not zero, the method
8.116 + * blocks until some input is available; otherwise, no
8.117 + * bytes are read and <code>0</code> is returned.
8.118 + * <p>
8.119 + * This method simply performs <code>in.read(b, off, len)</code>
8.120 + * and returns the result.
8.121 + *
8.122 + * @param b the buffer into which the data is read.
8.123 + * @param off the start offset in the destination array <code>b</code>
8.124 + * @param len the maximum number of bytes read.
8.125 + * @return the total number of bytes read into the buffer, or
8.126 + * <code>-1</code> if there is no more data because the end of
8.127 + * the stream has been reached.
8.128 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
8.129 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
8.130 + * <code>len</code> is negative, or <code>len</code> is greater than
8.131 + * <code>b.length - off</code>
8.132 + * @exception IOException if an I/O error occurs.
8.133 + * @see java.io.FilterInputStream#in
8.134 + */
8.135 + public int read(byte b[], int off, int len) throws IOException {
8.136 + return in.read(b, off, len);
8.137 + }
8.138 +
8.139 + /**
8.140 + * Skips over and discards <code>n</code> bytes of data from the
8.141 + * input stream. The <code>skip</code> method may, for a variety of
8.142 + * reasons, end up skipping over some smaller number of bytes,
8.143 + * possibly <code>0</code>. The actual number of bytes skipped is
8.144 + * returned.
8.145 + * <p>
8.146 + * This method simply performs <code>in.skip(n)</code>.
8.147 + *
8.148 + * @param n the number of bytes to be skipped.
8.149 + * @return the actual number of bytes skipped.
8.150 + * @exception IOException if the stream does not support seek,
8.151 + * or if some other I/O error occurs.
8.152 + */
8.153 + public long skip(long n) throws IOException {
8.154 + return in.skip(n);
8.155 + }
8.156 +
8.157 + /**
8.158 + * Returns an estimate of the number of bytes that can be read (or
8.159 + * skipped over) from this input stream without blocking by the next
8.160 + * caller of a method for this input stream. The next caller might be
8.161 + * the same thread or another thread. A single read or skip of this
8.162 + * many bytes will not block, but may read or skip fewer bytes.
8.163 + * <p>
8.164 + * This method returns the result of {@link #in in}.available().
8.165 + *
8.166 + * @return an estimate of the number of bytes that can be read (or skipped
8.167 + * over) from this input stream without blocking.
8.168 + * @exception IOException if an I/O error occurs.
8.169 + */
8.170 + public int available() throws IOException {
8.171 + return in.available();
8.172 + }
8.173 +
8.174 + /**
8.175 + * Closes this input stream and releases any system resources
8.176 + * associated with the stream.
8.177 + * This
8.178 + * method simply performs <code>in.close()</code>.
8.179 + *
8.180 + * @exception IOException if an I/O error occurs.
8.181 + * @see java.io.FilterInputStream#in
8.182 + */
8.183 + public void close() throws IOException {
8.184 + in.close();
8.185 + }
8.186 +
8.187 + /**
8.188 + * Marks the current position in this input stream. A subsequent
8.189 + * call to the <code>reset</code> method repositions this stream at
8.190 + * the last marked position so that subsequent reads re-read the same bytes.
8.191 + * <p>
8.192 + * The <code>readlimit</code> argument tells this input stream to
8.193 + * allow that many bytes to be read before the mark position gets
8.194 + * invalidated.
8.195 + * <p>
8.196 + * This method simply performs <code>in.mark(readlimit)</code>.
8.197 + *
8.198 + * @param readlimit the maximum limit of bytes that can be read before
8.199 + * the mark position becomes invalid.
8.200 + * @see java.io.FilterInputStream#in
8.201 + * @see java.io.FilterInputStream#reset()
8.202 + */
8.203 + public synchronized void mark(int readlimit) {
8.204 + in.mark(readlimit);
8.205 + }
8.206 +
8.207 + /**
8.208 + * Repositions this stream to the position at the time the
8.209 + * <code>mark</code> method was last called on this input stream.
8.210 + * <p>
8.211 + * This method
8.212 + * simply performs <code>in.reset()</code>.
8.213 + * <p>
8.214 + * Stream marks are intended to be used in
8.215 + * situations where you need to read ahead a little to see what's in
8.216 + * the stream. Often this is most easily done by invoking some
8.217 + * general parser. If the stream is of the type handled by the
8.218 + * parse, it just chugs along happily. If the stream is not of
8.219 + * that type, the parser should toss an exception when it fails.
8.220 + * If this happens within readlimit bytes, it allows the outer
8.221 + * code to reset the stream and try another parser.
8.222 + *
8.223 + * @exception IOException if the stream has not been marked or if the
8.224 + * mark has been invalidated.
8.225 + * @see java.io.FilterInputStream#in
8.226 + * @see java.io.FilterInputStream#mark(int)
8.227 + */
8.228 + public synchronized void reset() throws IOException {
8.229 + in.reset();
8.230 + }
8.231 +
8.232 + /**
8.233 + * Tests if this input stream supports the <code>mark</code>
8.234 + * and <code>reset</code> methods.
8.235 + * This method
8.236 + * simply performs <code>in.markSupported()</code>.
8.237 + *
8.238 + * @return <code>true</code> if this stream type supports the
8.239 + * <code>mark</code> and <code>reset</code> method;
8.240 + * <code>false</code> otherwise.
8.241 + * @see java.io.FilterInputStream#in
8.242 + * @see java.io.InputStream#mark(int)
8.243 + * @see java.io.InputStream#reset()
8.244 + */
8.245 + public boolean markSupported() {
8.246 + return in.markSupported();
8.247 + }
8.248 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/emul/mini/src/main/java/java/io/IOException.java Wed Jan 23 20:39:23 2013 +0100
9.3 @@ -0,0 +1,101 @@
9.4 +/*
9.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9.7 + *
9.8 + * This code is free software; you can redistribute it and/or modify it
9.9 + * under the terms of the GNU General Public License version 2 only, as
9.10 + * published by the Free Software Foundation. Oracle designates this
9.11 + * particular file as subject to the "Classpath" exception as provided
9.12 + * by Oracle in the LICENSE file that accompanied this code.
9.13 + *
9.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
9.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9.17 + * version 2 for more details (a copy is included in the LICENSE file that
9.18 + * accompanied this code).
9.19 + *
9.20 + * You should have received a copy of the GNU General Public License version
9.21 + * 2 along with this work; if not, write to the Free Software Foundation,
9.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9.23 + *
9.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9.25 + * or visit www.oracle.com if you need additional information or have any
9.26 + * questions.
9.27 + */
9.28 +
9.29 +package java.io;
9.30 +
9.31 +/**
9.32 + * Signals that an I/O exception of some sort has occurred. This
9.33 + * class is the general class of exceptions produced by failed or
9.34 + * interrupted I/O operations.
9.35 + *
9.36 + * @author unascribed
9.37 + * @see java.io.InputStream
9.38 + * @see java.io.OutputStream
9.39 + * @since JDK1.0
9.40 + */
9.41 +public
9.42 +class IOException extends Exception {
9.43 + static final long serialVersionUID = 7818375828146090155L;
9.44 +
9.45 + /**
9.46 + * Constructs an {@code IOException} with {@code null}
9.47 + * as its error detail message.
9.48 + */
9.49 + public IOException() {
9.50 + super();
9.51 + }
9.52 +
9.53 + /**
9.54 + * Constructs an {@code IOException} with the specified detail message.
9.55 + *
9.56 + * @param message
9.57 + * The detail message (which is saved for later retrieval
9.58 + * by the {@link #getMessage()} method)
9.59 + */
9.60 + public IOException(String message) {
9.61 + super(message);
9.62 + }
9.63 +
9.64 + /**
9.65 + * Constructs an {@code IOException} with the specified detail message
9.66 + * and cause.
9.67 + *
9.68 + * <p> Note that the detail message associated with {@code cause} is
9.69 + * <i>not</i> automatically incorporated into this exception's detail
9.70 + * message.
9.71 + *
9.72 + * @param message
9.73 + * The detail message (which is saved for later retrieval
9.74 + * by the {@link #getMessage()} method)
9.75 + *
9.76 + * @param cause
9.77 + * The cause (which is saved for later retrieval by the
9.78 + * {@link #getCause()} method). (A null value is permitted,
9.79 + * and indicates that the cause is nonexistent or unknown.)
9.80 + *
9.81 + * @since 1.6
9.82 + */
9.83 + public IOException(String message, Throwable cause) {
9.84 + super(message, cause);
9.85 + }
9.86 +
9.87 + /**
9.88 + * Constructs an {@code IOException} with the specified cause and a
9.89 + * detail message of {@code (cause==null ? null : cause.toString())}
9.90 + * (which typically contains the class and detail message of {@code cause}).
9.91 + * This constructor is useful for IO exceptions that are little more
9.92 + * than wrappers for other throwables.
9.93 + *
9.94 + * @param cause
9.95 + * The cause (which is saved for later retrieval by the
9.96 + * {@link #getCause()} method). (A null value is permitted,
9.97 + * and indicates that the cause is nonexistent or unknown.)
9.98 + *
9.99 + * @since 1.6
9.100 + */
9.101 + public IOException(Throwable cause) {
9.102 + super(cause);
9.103 + }
9.104 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/emul/mini/src/main/java/java/io/InputStream.java Wed Jan 23 20:39:23 2013 +0100
10.3 @@ -0,0 +1,370 @@
10.4 +/*
10.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10.7 + *
10.8 + * This code is free software; you can redistribute it and/or modify it
10.9 + * under the terms of the GNU General Public License version 2 only, as
10.10 + * published by the Free Software Foundation. Oracle designates this
10.11 + * particular file as subject to the "Classpath" exception as provided
10.12 + * by Oracle in the LICENSE file that accompanied this code.
10.13 + *
10.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
10.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10.17 + * version 2 for more details (a copy is included in the LICENSE file that
10.18 + * accompanied this code).
10.19 + *
10.20 + * You should have received a copy of the GNU General Public License version
10.21 + * 2 along with this work; if not, write to the Free Software Foundation,
10.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10.23 + *
10.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
10.25 + * or visit www.oracle.com if you need additional information or have any
10.26 + * questions.
10.27 + */
10.28 +
10.29 +package java.io;
10.30 +
10.31 +/**
10.32 + * This abstract class is the superclass of all classes representing
10.33 + * an input stream of bytes.
10.34 + *
10.35 + * <p> Applications that need to define a subclass of <code>InputStream</code>
10.36 + * must always provide a method that returns the next byte of input.
10.37 + *
10.38 + * @author Arthur van Hoff
10.39 + * @see java.io.BufferedInputStream
10.40 + * @see java.io.ByteArrayInputStream
10.41 + * @see java.io.DataInputStream
10.42 + * @see java.io.FilterInputStream
10.43 + * @see java.io.InputStream#read()
10.44 + * @see java.io.OutputStream
10.45 + * @see java.io.PushbackInputStream
10.46 + * @since JDK1.0
10.47 + */
10.48 +public abstract class InputStream implements Closeable {
10.49 +
10.50 + // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
10.51 + private static final int SKIP_BUFFER_SIZE = 2048;
10.52 + // skipBuffer is initialized in skip(long), if needed.
10.53 + private static byte[] skipBuffer;
10.54 +
10.55 + /**
10.56 + * Reads the next byte of data from the input stream. The value byte is
10.57 + * returned as an <code>int</code> in the range <code>0</code> to
10.58 + * <code>255</code>. If no byte is available because the end of the stream
10.59 + * has been reached, the value <code>-1</code> is returned. This method
10.60 + * blocks until input data is available, the end of the stream is detected,
10.61 + * or an exception is thrown.
10.62 + *
10.63 + * <p> A subclass must provide an implementation of this method.
10.64 + *
10.65 + * @return the next byte of data, or <code>-1</code> if the end of the
10.66 + * stream is reached.
10.67 + * @exception IOException if an I/O error occurs.
10.68 + */
10.69 + public abstract int read() throws IOException;
10.70 +
10.71 + /**
10.72 + * Reads some number of bytes from the input stream and stores them into
10.73 + * the buffer array <code>b</code>. The number of bytes actually read is
10.74 + * returned as an integer. This method blocks until input data is
10.75 + * available, end of file is detected, or an exception is thrown.
10.76 + *
10.77 + * <p> If the length of <code>b</code> is zero, then no bytes are read and
10.78 + * <code>0</code> is returned; otherwise, there is an attempt to read at
10.79 + * least one byte. If no byte is available because the stream is at the
10.80 + * end of the file, the value <code>-1</code> is returned; otherwise, at
10.81 + * least one byte is read and stored into <code>b</code>.
10.82 + *
10.83 + * <p> The first byte read is stored into element <code>b[0]</code>, the
10.84 + * next one into <code>b[1]</code>, and so on. The number of bytes read is,
10.85 + * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
10.86 + * number of bytes actually read; these bytes will be stored in elements
10.87 + * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
10.88 + * leaving elements <code>b[</code><i>k</i><code>]</code> through
10.89 + * <code>b[b.length-1]</code> unaffected.
10.90 + *
10.91 + * <p> The <code>read(b)</code> method for class <code>InputStream</code>
10.92 + * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
10.93 + *
10.94 + * @param b the buffer into which the data is read.
10.95 + * @return the total number of bytes read into the buffer, or
10.96 + * <code>-1</code> if there is no more data because the end of
10.97 + * the stream has been reached.
10.98 + * @exception IOException If the first byte cannot be read for any reason
10.99 + * other than the end of the file, if the input stream has been closed, or
10.100 + * if some other I/O error occurs.
10.101 + * @exception NullPointerException if <code>b</code> is <code>null</code>.
10.102 + * @see java.io.InputStream#read(byte[], int, int)
10.103 + */
10.104 + public int read(byte b[]) throws IOException {
10.105 + return read(b, 0, b.length);
10.106 + }
10.107 +
10.108 + /**
10.109 + * Reads up to <code>len</code> bytes of data from the input stream into
10.110 + * an array of bytes. An attempt is made to read as many as
10.111 + * <code>len</code> bytes, but a smaller number may be read.
10.112 + * The number of bytes actually read is returned as an integer.
10.113 + *
10.114 + * <p> This method blocks until input data is available, end of file is
10.115 + * detected, or an exception is thrown.
10.116 + *
10.117 + * <p> If <code>len</code> is zero, then no bytes are read and
10.118 + * <code>0</code> is returned; otherwise, there is an attempt to read at
10.119 + * least one byte. If no byte is available because the stream is at end of
10.120 + * file, the value <code>-1</code> is returned; otherwise, at least one
10.121 + * byte is read and stored into <code>b</code>.
10.122 + *
10.123 + * <p> The first byte read is stored into element <code>b[off]</code>, the
10.124 + * next one into <code>b[off+1]</code>, and so on. The number of bytes read
10.125 + * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
10.126 + * bytes actually read; these bytes will be stored in elements
10.127 + * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
10.128 + * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
10.129 + * <code>b[off+len-1]</code> unaffected.
10.130 + *
10.131 + * <p> In every case, elements <code>b[0]</code> through
10.132 + * <code>b[off]</code> and elements <code>b[off+len]</code> through
10.133 + * <code>b[b.length-1]</code> are unaffected.
10.134 + *
10.135 + * <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
10.136 + * for class <code>InputStream</code> simply calls the method
10.137 + * <code>read()</code> repeatedly. If the first such call results in an
10.138 + * <code>IOException</code>, that exception is returned from the call to
10.139 + * the <code>read(b,</code> <code>off,</code> <code>len)</code> method. If
10.140 + * any subsequent call to <code>read()</code> results in a
10.141 + * <code>IOException</code>, the exception is caught and treated as if it
10.142 + * were end of file; the bytes read up to that point are stored into
10.143 + * <code>b</code> and the number of bytes read before the exception
10.144 + * occurred is returned. The default implementation of this method blocks
10.145 + * until the requested amount of input data <code>len</code> has been read,
10.146 + * end of file is detected, or an exception is thrown. Subclasses are encouraged
10.147 + * to provide a more efficient implementation of this method.
10.148 + *
10.149 + * @param b the buffer into which the data is read.
10.150 + * @param off the start offset in array <code>b</code>
10.151 + * at which the data is written.
10.152 + * @param len the maximum number of bytes to read.
10.153 + * @return the total number of bytes read into the buffer, or
10.154 + * <code>-1</code> if there is no more data because the end of
10.155 + * the stream has been reached.
10.156 + * @exception IOException If the first byte cannot be read for any reason
10.157 + * other than end of file, or if the input stream has been closed, or if
10.158 + * some other I/O error occurs.
10.159 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
10.160 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
10.161 + * <code>len</code> is negative, or <code>len</code> is greater than
10.162 + * <code>b.length - off</code>
10.163 + * @see java.io.InputStream#read()
10.164 + */
10.165 + public int read(byte b[], int off, int len) throws IOException {
10.166 + if (b == null) {
10.167 + throw new NullPointerException();
10.168 + } else if (off < 0 || len < 0 || len > b.length - off) {
10.169 + throw new IndexOutOfBoundsException();
10.170 + } else if (len == 0) {
10.171 + return 0;
10.172 + }
10.173 +
10.174 + int c = read();
10.175 + if (c == -1) {
10.176 + return -1;
10.177 + }
10.178 + b[off] = (byte)c;
10.179 +
10.180 + int i = 1;
10.181 + try {
10.182 + for (; i < len ; i++) {
10.183 + c = read();
10.184 + if (c == -1) {
10.185 + break;
10.186 + }
10.187 + b[off + i] = (byte)c;
10.188 + }
10.189 + } catch (IOException ee) {
10.190 + }
10.191 + return i;
10.192 + }
10.193 +
10.194 + /**
10.195 + * Skips over and discards <code>n</code> bytes of data from this input
10.196 + * stream. The <code>skip</code> method may, for a variety of reasons, end
10.197 + * up skipping over some smaller number of bytes, possibly <code>0</code>.
10.198 + * This may result from any of a number of conditions; reaching end of file
10.199 + * before <code>n</code> bytes have been skipped is only one possibility.
10.200 + * The actual number of bytes skipped is returned. If <code>n</code> is
10.201 + * negative, no bytes are skipped.
10.202 + *
10.203 + * <p> The <code>skip</code> method of this class creates a
10.204 + * byte array and then repeatedly reads into it until <code>n</code> bytes
10.205 + * have been read or the end of the stream has been reached. Subclasses are
10.206 + * encouraged to provide a more efficient implementation of this method.
10.207 + * For instance, the implementation may depend on the ability to seek.
10.208 + *
10.209 + * @param n the number of bytes to be skipped.
10.210 + * @return the actual number of bytes skipped.
10.211 + * @exception IOException if the stream does not support seek,
10.212 + * or if some other I/O error occurs.
10.213 + */
10.214 + public long skip(long n) throws IOException {
10.215 +
10.216 + long remaining = n;
10.217 + int nr;
10.218 + if (skipBuffer == null)
10.219 + skipBuffer = new byte[SKIP_BUFFER_SIZE];
10.220 +
10.221 + byte[] localSkipBuffer = skipBuffer;
10.222 +
10.223 + if (n <= 0) {
10.224 + return 0;
10.225 + }
10.226 +
10.227 + while (remaining > 0) {
10.228 + nr = read(localSkipBuffer, 0,
10.229 + (int) Math.min(SKIP_BUFFER_SIZE, remaining));
10.230 + if (nr < 0) {
10.231 + break;
10.232 + }
10.233 + remaining -= nr;
10.234 + }
10.235 +
10.236 + return n - remaining;
10.237 + }
10.238 +
10.239 + /**
10.240 + * Returns an estimate of the number of bytes that can be read (or
10.241 + * skipped over) from this input stream without blocking by the next
10.242 + * invocation of a method for this input stream. The next invocation
10.243 + * might be the same thread or another thread. A single read or skip of this
10.244 + * many bytes will not block, but may read or skip fewer bytes.
10.245 + *
10.246 + * <p> Note that while some implementations of {@code InputStream} will return
10.247 + * the total number of bytes in the stream, many will not. It is
10.248 + * never correct to use the return value of this method to allocate
10.249 + * a buffer intended to hold all data in this stream.
10.250 + *
10.251 + * <p> A subclass' implementation of this method may choose to throw an
10.252 + * {@link IOException} if this input stream has been closed by
10.253 + * invoking the {@link #close()} method.
10.254 + *
10.255 + * <p> The {@code available} method for class {@code InputStream} always
10.256 + * returns {@code 0}.
10.257 + *
10.258 + * <p> This method should be overridden by subclasses.
10.259 + *
10.260 + * @return an estimate of the number of bytes that can be read (or skipped
10.261 + * over) from this input stream without blocking or {@code 0} when
10.262 + * it reaches the end of the input stream.
10.263 + * @exception IOException if an I/O error occurs.
10.264 + */
10.265 + public int available() throws IOException {
10.266 + return 0;
10.267 + }
10.268 +
10.269 + /**
10.270 + * Closes this input stream and releases any system resources associated
10.271 + * with the stream.
10.272 + *
10.273 + * <p> The <code>close</code> method of <code>InputStream</code> does
10.274 + * nothing.
10.275 + *
10.276 + * @exception IOException if an I/O error occurs.
10.277 + */
10.278 + public void close() throws IOException {}
10.279 +
10.280 + /**
10.281 + * Marks the current position in this input stream. A subsequent call to
10.282 + * the <code>reset</code> method repositions this stream at the last marked
10.283 + * position so that subsequent reads re-read the same bytes.
10.284 + *
10.285 + * <p> The <code>readlimit</code> arguments tells this input stream to
10.286 + * allow that many bytes to be read before the mark position gets
10.287 + * invalidated.
10.288 + *
10.289 + * <p> The general contract of <code>mark</code> is that, if the method
10.290 + * <code>markSupported</code> returns <code>true</code>, the stream somehow
10.291 + * remembers all the bytes read after the call to <code>mark</code> and
10.292 + * stands ready to supply those same bytes again if and whenever the method
10.293 + * <code>reset</code> is called. However, the stream is not required to
10.294 + * remember any data at all if more than <code>readlimit</code> bytes are
10.295 + * read from the stream before <code>reset</code> is called.
10.296 + *
10.297 + * <p> Marking a closed stream should not have any effect on the stream.
10.298 + *
10.299 + * <p> The <code>mark</code> method of <code>InputStream</code> does
10.300 + * nothing.
10.301 + *
10.302 + * @param readlimit the maximum limit of bytes that can be read before
10.303 + * the mark position becomes invalid.
10.304 + * @see java.io.InputStream#reset()
10.305 + */
10.306 + public synchronized void mark(int readlimit) {}
10.307 +
10.308 + /**
10.309 + * Repositions this stream to the position at the time the
10.310 + * <code>mark</code> method was last called on this input stream.
10.311 + *
10.312 + * <p> The general contract of <code>reset</code> is:
10.313 + *
10.314 + * <p><ul>
10.315 + *
10.316 + * <li> If the method <code>markSupported</code> returns
10.317 + * <code>true</code>, then:
10.318 + *
10.319 + * <ul><li> If the method <code>mark</code> has not been called since
10.320 + * the stream was created, or the number of bytes read from the stream
10.321 + * since <code>mark</code> was last called is larger than the argument
10.322 + * to <code>mark</code> at that last call, then an
10.323 + * <code>IOException</code> might be thrown.
10.324 + *
10.325 + * <li> If such an <code>IOException</code> is not thrown, then the
10.326 + * stream is reset to a state such that all the bytes read since the
10.327 + * most recent call to <code>mark</code> (or since the start of the
10.328 + * file, if <code>mark</code> has not been called) will be resupplied
10.329 + * to subsequent callers of the <code>read</code> method, followed by
10.330 + * any bytes that otherwise would have been the next input data as of
10.331 + * the time of the call to <code>reset</code>. </ul>
10.332 + *
10.333 + * <li> If the method <code>markSupported</code> returns
10.334 + * <code>false</code>, then:
10.335 + *
10.336 + * <ul><li> The call to <code>reset</code> may throw an
10.337 + * <code>IOException</code>.
10.338 + *
10.339 + * <li> If an <code>IOException</code> is not thrown, then the stream
10.340 + * is reset to a fixed state that depends on the particular type of the
10.341 + * input stream and how it was created. The bytes that will be supplied
10.342 + * to subsequent callers of the <code>read</code> method depend on the
10.343 + * particular type of the input stream. </ul></ul>
10.344 + *
10.345 + * <p>The method <code>reset</code> for class <code>InputStream</code>
10.346 + * does nothing except throw an <code>IOException</code>.
10.347 + *
10.348 + * @exception IOException if this stream has not been marked or if the
10.349 + * mark has been invalidated.
10.350 + * @see java.io.InputStream#mark(int)
10.351 + * @see java.io.IOException
10.352 + */
10.353 + public synchronized void reset() throws IOException {
10.354 + throw new IOException("mark/reset not supported");
10.355 + }
10.356 +
10.357 + /**
10.358 + * Tests if this input stream supports the <code>mark</code> and
10.359 + * <code>reset</code> methods. Whether or not <code>mark</code> and
10.360 + * <code>reset</code> are supported is an invariant property of a
10.361 + * particular input stream instance. The <code>markSupported</code> method
10.362 + * of <code>InputStream</code> returns <code>false</code>.
10.363 + *
10.364 + * @return <code>true</code> if this stream instance supports the mark
10.365 + * and reset methods; <code>false</code> otherwise.
10.366 + * @see java.io.InputStream#mark(int)
10.367 + * @see java.io.InputStream#reset()
10.368 + */
10.369 + public boolean markSupported() {
10.370 + return false;
10.371 + }
10.372 +
10.373 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/emul/mini/src/main/java/java/io/PushbackInputStream.java Wed Jan 23 20:39:23 2013 +0100
11.3 @@ -0,0 +1,388 @@
11.4 +/*
11.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11.7 + *
11.8 + * This code is free software; you can redistribute it and/or modify it
11.9 + * under the terms of the GNU General Public License version 2 only, as
11.10 + * published by the Free Software Foundation. Oracle designates this
11.11 + * particular file as subject to the "Classpath" exception as provided
11.12 + * by Oracle in the LICENSE file that accompanied this code.
11.13 + *
11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11.17 + * version 2 for more details (a copy is included in the LICENSE file that
11.18 + * accompanied this code).
11.19 + *
11.20 + * You should have received a copy of the GNU General Public License version
11.21 + * 2 along with this work; if not, write to the Free Software Foundation,
11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
11.23 + *
11.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
11.25 + * or visit www.oracle.com if you need additional information or have any
11.26 + * questions.
11.27 + */
11.28 +
11.29 +package java.io;
11.30 +
11.31 +/**
11.32 + * A <code>PushbackInputStream</code> adds
11.33 + * functionality to another input stream, namely
11.34 + * the ability to "push back" or "unread"
11.35 + * one byte. This is useful in situations where
11.36 + * it is convenient for a fragment of code
11.37 + * to read an indefinite number of data bytes
11.38 + * that are delimited by a particular byte
11.39 + * value; after reading the terminating byte,
11.40 + * the code fragment can "unread" it, so that
11.41 + * the next read operation on the input stream
11.42 + * will reread the byte that was pushed back.
11.43 + * For example, bytes representing the characters
11.44 + * constituting an identifier might be terminated
11.45 + * by a byte representing an operator character;
11.46 + * a method whose job is to read just an identifier
11.47 + * can read until it sees the operator and
11.48 + * then push the operator back to be re-read.
11.49 + *
11.50 + * @author David Connelly
11.51 + * @author Jonathan Payne
11.52 + * @since JDK1.0
11.53 + */
11.54 +public
11.55 +class PushbackInputStream extends FilterInputStream {
11.56 + /**
11.57 + * The pushback buffer.
11.58 + * @since JDK1.1
11.59 + */
11.60 + protected byte[] buf;
11.61 +
11.62 + /**
11.63 + * The position within the pushback buffer from which the next byte will
11.64 + * be read. When the buffer is empty, <code>pos</code> is equal to
11.65 + * <code>buf.length</code>; when the buffer is full, <code>pos</code> is
11.66 + * equal to zero.
11.67 + *
11.68 + * @since JDK1.1
11.69 + */
11.70 + protected int pos;
11.71 +
11.72 + /**
11.73 + * Check to make sure that this stream has not been closed
11.74 + */
11.75 + private void ensureOpen() throws IOException {
11.76 + if (in == null)
11.77 + throw new IOException("Stream closed");
11.78 + }
11.79 +
11.80 + /**
11.81 + * Creates a <code>PushbackInputStream</code>
11.82 + * with a pushback buffer of the specified <code>size</code>,
11.83 + * and saves its argument, the input stream
11.84 + * <code>in</code>, for later use. Initially,
11.85 + * there is no pushed-back byte (the field
11.86 + * <code>pushBack</code> is initialized to
11.87 + * <code>-1</code>).
11.88 + *
11.89 + * @param in the input stream from which bytes will be read.
11.90 + * @param size the size of the pushback buffer.
11.91 + * @exception IllegalArgumentException if size is <= 0
11.92 + * @since JDK1.1
11.93 + */
11.94 + public PushbackInputStream(InputStream in, int size) {
11.95 + super(in);
11.96 + if (size <= 0) {
11.97 + throw new IllegalArgumentException("size <= 0");
11.98 + }
11.99 + this.buf = new byte[size];
11.100 + this.pos = size;
11.101 + }
11.102 +
11.103 + /**
11.104 + * Creates a <code>PushbackInputStream</code>
11.105 + * and saves its argument, the input stream
11.106 + * <code>in</code>, for later use. Initially,
11.107 + * there is no pushed-back byte (the field
11.108 + * <code>pushBack</code> is initialized to
11.109 + * <code>-1</code>).
11.110 + *
11.111 + * @param in the input stream from which bytes will be read.
11.112 + */
11.113 + public PushbackInputStream(InputStream in) {
11.114 + this(in, 1);
11.115 + }
11.116 +
11.117 + /**
11.118 + * Reads the next byte of data from this input stream. The value
11.119 + * byte is returned as an <code>int</code> in the range
11.120 + * <code>0</code> to <code>255</code>. If no byte is available
11.121 + * because the end of the stream has been reached, the value
11.122 + * <code>-1</code> is returned. This method blocks until input data
11.123 + * is available, the end of the stream is detected, or an exception
11.124 + * is thrown.
11.125 + *
11.126 + * <p> This method returns the most recently pushed-back byte, if there is
11.127 + * one, and otherwise calls the <code>read</code> method of its underlying
11.128 + * input stream and returns whatever value that method returns.
11.129 + *
11.130 + * @return the next byte of data, or <code>-1</code> if the end of the
11.131 + * stream has been reached.
11.132 + * @exception IOException if this input stream has been closed by
11.133 + * invoking its {@link #close()} method,
11.134 + * or an I/O error occurs.
11.135 + * @see java.io.InputStream#read()
11.136 + */
11.137 + public int read() throws IOException {
11.138 + ensureOpen();
11.139 + if (pos < buf.length) {
11.140 + return buf[pos++] & 0xff;
11.141 + }
11.142 + return super.read();
11.143 + }
11.144 +
11.145 + /**
11.146 + * Reads up to <code>len</code> bytes of data from this input stream into
11.147 + * an array of bytes. This method first reads any pushed-back bytes; after
11.148 + * that, if fewer than <code>len</code> bytes have been read then it
11.149 + * reads from the underlying input stream. If <code>len</code> is not zero, the method
11.150 + * blocks until at least 1 byte of input is available; otherwise, no
11.151 + * bytes are read and <code>0</code> is returned.
11.152 + *
11.153 + * @param b the buffer into which the data is read.
11.154 + * @param off the start offset in the destination array <code>b</code>
11.155 + * @param len the maximum number of bytes read.
11.156 + * @return the total number of bytes read into the buffer, or
11.157 + * <code>-1</code> if there is no more data because the end of
11.158 + * the stream has been reached.
11.159 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
11.160 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
11.161 + * <code>len</code> is negative, or <code>len</code> is greater than
11.162 + * <code>b.length - off</code>
11.163 + * @exception IOException if this input stream has been closed by
11.164 + * invoking its {@link #close()} method,
11.165 + * or an I/O error occurs.
11.166 + * @see java.io.InputStream#read(byte[], int, int)
11.167 + */
11.168 + public int read(byte[] b, int off, int len) throws IOException {
11.169 + ensureOpen();
11.170 + if (b == null) {
11.171 + throw new NullPointerException();
11.172 + } else if (off < 0 || len < 0 || len > b.length - off) {
11.173 + throw new IndexOutOfBoundsException();
11.174 + } else if (len == 0) {
11.175 + return 0;
11.176 + }
11.177 +
11.178 + int avail = buf.length - pos;
11.179 + if (avail > 0) {
11.180 + if (len < avail) {
11.181 + avail = len;
11.182 + }
11.183 + arraycopy(buf, pos, b, off, avail);
11.184 + pos += avail;
11.185 + off += avail;
11.186 + len -= avail;
11.187 + }
11.188 + if (len > 0) {
11.189 + len = super.read(b, off, len);
11.190 + if (len == -1) {
11.191 + return avail == 0 ? -1 : avail;
11.192 + }
11.193 + return avail + len;
11.194 + }
11.195 + return avail;
11.196 + }
11.197 +
11.198 + /**
11.199 + * Pushes back a byte by copying it to the front of the pushback buffer.
11.200 + * After this method returns, the next byte to be read will have the value
11.201 + * <code>(byte)b</code>.
11.202 + *
11.203 + * @param b the <code>int</code> value whose low-order
11.204 + * byte is to be pushed back.
11.205 + * @exception IOException If there is not enough room in the pushback
11.206 + * buffer for the byte, or this input stream has been closed by
11.207 + * invoking its {@link #close()} method.
11.208 + */
11.209 + public void unread(int b) throws IOException {
11.210 + ensureOpen();
11.211 + if (pos == 0) {
11.212 + throw new IOException("Push back buffer is full");
11.213 + }
11.214 + buf[--pos] = (byte)b;
11.215 + }
11.216 +
11.217 + /**
11.218 + * Pushes back a portion of an array of bytes by copying it to the front
11.219 + * of the pushback buffer. After this method returns, the next byte to be
11.220 + * read will have the value <code>b[off]</code>, the byte after that will
11.221 + * have the value <code>b[off+1]</code>, and so forth.
11.222 + *
11.223 + * @param b the byte array to push back.
11.224 + * @param off the start offset of the data.
11.225 + * @param len the number of bytes to push back.
11.226 + * @exception IOException If there is not enough room in the pushback
11.227 + * buffer for the specified number of bytes,
11.228 + * or this input stream has been closed by
11.229 + * invoking its {@link #close()} method.
11.230 + * @since JDK1.1
11.231 + */
11.232 + public void unread(byte[] b, int off, int len) throws IOException {
11.233 + ensureOpen();
11.234 + if (len > pos) {
11.235 + throw new IOException("Push back buffer is full");
11.236 + }
11.237 + pos -= len;
11.238 + arraycopy(b, off, buf, pos, len);
11.239 + }
11.240 +
11.241 + /**
11.242 + * Pushes back an array of bytes by copying it to the front of the
11.243 + * pushback buffer. After this method returns, the next byte to be read
11.244 + * will have the value <code>b[0]</code>, the byte after that will have the
11.245 + * value <code>b[1]</code>, and so forth.
11.246 + *
11.247 + * @param b the byte array to push back
11.248 + * @exception IOException If there is not enough room in the pushback
11.249 + * buffer for the specified number of bytes,
11.250 + * or this input stream has been closed by
11.251 + * invoking its {@link #close()} method.
11.252 + * @since JDK1.1
11.253 + */
11.254 + public void unread(byte[] b) throws IOException {
11.255 + unread(b, 0, b.length);
11.256 + }
11.257 +
11.258 + /**
11.259 + * Returns an estimate of the number of bytes that can be read (or
11.260 + * skipped over) from this input stream without blocking by the next
11.261 + * invocation of a method for this input stream. The next invocation might be
11.262 + * the same thread or another thread. A single read or skip of this
11.263 + * many bytes will not block, but may read or skip fewer bytes.
11.264 + *
11.265 + * <p> The method returns the sum of the number of bytes that have been
11.266 + * pushed back and the value returned by {@link
11.267 + * java.io.FilterInputStream#available available}.
11.268 + *
11.269 + * @return the number of bytes that can be read (or skipped over) from
11.270 + * the input stream without blocking.
11.271 + * @exception IOException if this input stream has been closed by
11.272 + * invoking its {@link #close()} method,
11.273 + * or an I/O error occurs.
11.274 + * @see java.io.FilterInputStream#in
11.275 + * @see java.io.InputStream#available()
11.276 + */
11.277 + public int available() throws IOException {
11.278 + ensureOpen();
11.279 + int n = buf.length - pos;
11.280 + int avail = super.available();
11.281 + return n > (Integer.MAX_VALUE - avail)
11.282 + ? Integer.MAX_VALUE
11.283 + : n + avail;
11.284 + }
11.285 +
11.286 + /**
11.287 + * Skips over and discards <code>n</code> bytes of data from this
11.288 + * input stream. The <code>skip</code> method may, for a variety of
11.289 + * reasons, end up skipping over some smaller number of bytes,
11.290 + * possibly zero. If <code>n</code> is negative, no bytes are skipped.
11.291 + *
11.292 + * <p> The <code>skip</code> method of <code>PushbackInputStream</code>
11.293 + * first skips over the bytes in the pushback buffer, if any. It then
11.294 + * calls the <code>skip</code> method of the underlying input stream if
11.295 + * more bytes need to be skipped. The actual number of bytes skipped
11.296 + * is returned.
11.297 + *
11.298 + * @param n {@inheritDoc}
11.299 + * @return {@inheritDoc}
11.300 + * @exception IOException if the stream does not support seek,
11.301 + * or the stream has been closed by
11.302 + * invoking its {@link #close()} method,
11.303 + * or an I/O error occurs.
11.304 + * @see java.io.FilterInputStream#in
11.305 + * @see java.io.InputStream#skip(long n)
11.306 + * @since 1.2
11.307 + */
11.308 + public long skip(long n) throws IOException {
11.309 + ensureOpen();
11.310 + if (n <= 0) {
11.311 + return 0;
11.312 + }
11.313 +
11.314 + long pskip = buf.length - pos;
11.315 + if (pskip > 0) {
11.316 + if (n < pskip) {
11.317 + pskip = n;
11.318 + }
11.319 + pos += pskip;
11.320 + n -= pskip;
11.321 + }
11.322 + if (n > 0) {
11.323 + pskip += super.skip(n);
11.324 + }
11.325 + return pskip;
11.326 + }
11.327 +
11.328 + /**
11.329 + * Tests if this input stream supports the <code>mark</code> and
11.330 + * <code>reset</code> methods, which it does not.
11.331 + *
11.332 + * @return <code>false</code>, since this class does not support the
11.333 + * <code>mark</code> and <code>reset</code> methods.
11.334 + * @see java.io.InputStream#mark(int)
11.335 + * @see java.io.InputStream#reset()
11.336 + */
11.337 + public boolean markSupported() {
11.338 + return false;
11.339 + }
11.340 +
11.341 + /**
11.342 + * Marks the current position in this input stream.
11.343 + *
11.344 + * <p> The <code>mark</code> method of <code>PushbackInputStream</code>
11.345 + * does nothing.
11.346 + *
11.347 + * @param readlimit the maximum limit of bytes that can be read before
11.348 + * the mark position becomes invalid.
11.349 + * @see java.io.InputStream#reset()
11.350 + */
11.351 + public synchronized void mark(int readlimit) {
11.352 + }
11.353 +
11.354 + /**
11.355 + * Repositions this stream to the position at the time the
11.356 + * <code>mark</code> method was last called on this input stream.
11.357 + *
11.358 + * <p> The method <code>reset</code> for class
11.359 + * <code>PushbackInputStream</code> does nothing except throw an
11.360 + * <code>IOException</code>.
11.361 + *
11.362 + * @exception IOException if this method is invoked.
11.363 + * @see java.io.InputStream#mark(int)
11.364 + * @see java.io.IOException
11.365 + */
11.366 + public synchronized void reset() throws IOException {
11.367 + throw new IOException("mark/reset not supported");
11.368 + }
11.369 +
11.370 + /**
11.371 + * Closes this input stream and releases any system resources
11.372 + * associated with the stream.
11.373 + * Once the stream has been closed, further read(), unread(),
11.374 + * available(), reset(), or skip() invocations will throw an IOException.
11.375 + * Closing a previously closed stream has no effect.
11.376 + *
11.377 + * @exception IOException if an I/O error occurs.
11.378 + */
11.379 + public synchronized void close() throws IOException {
11.380 + if (in == null)
11.381 + return;
11.382 + in.close();
11.383 + in = null;
11.384 + buf = null;
11.385 + }
11.386 + static void arraycopy(byte[] value, int srcBegin, byte[] dst, int dstBegin, int count) {
11.387 + while (count-- > 0) {
11.388 + dst[dstBegin++] = value[srcBegin++];
11.389 + }
11.390 + }
11.391 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/emul/mini/src/main/java/java/io/Serializable.java Wed Jan 23 20:39:23 2013 +0100
12.3 @@ -0,0 +1,170 @@
12.4 +/*
12.5 + * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12.7 + *
12.8 + * This code is free software; you can redistribute it and/or modify it
12.9 + * under the terms of the GNU General Public License version 2 only, as
12.10 + * published by the Free Software Foundation. Oracle designates this
12.11 + * particular file as subject to the "Classpath" exception as provided
12.12 + * by Oracle in the LICENSE file that accompanied this code.
12.13 + *
12.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
12.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12.17 + * version 2 for more details (a copy is included in the LICENSE file that
12.18 + * accompanied this code).
12.19 + *
12.20 + * You should have received a copy of the GNU General Public License version
12.21 + * 2 along with this work; if not, write to the Free Software Foundation,
12.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
12.23 + *
12.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
12.25 + * or visit www.oracle.com if you need additional information or have any
12.26 + * questions.
12.27 + */
12.28 +
12.29 +package java.io;
12.30 +
12.31 +/**
12.32 + * Serializability of a class is enabled by the class implementing the
12.33 + * java.io.Serializable interface. Classes that do not implement this
12.34 + * interface will not have any of their state serialized or
12.35 + * deserialized. All subtypes of a serializable class are themselves
12.36 + * serializable. The serialization interface has no methods or fields
12.37 + * and serves only to identify the semantics of being serializable. <p>
12.38 + *
12.39 + * To allow subtypes of non-serializable classes to be serialized, the
12.40 + * subtype may assume responsibility for saving and restoring the
12.41 + * state of the supertype's public, protected, and (if accessible)
12.42 + * package fields. The subtype may assume this responsibility only if
12.43 + * the class it extends has an accessible no-arg constructor to
12.44 + * initialize the class's state. It is an error to declare a class
12.45 + * Serializable if this is not the case. The error will be detected at
12.46 + * runtime. <p>
12.47 + *
12.48 + * During deserialization, the fields of non-serializable classes will
12.49 + * be initialized using the public or protected no-arg constructor of
12.50 + * the class. A no-arg constructor must be accessible to the subclass
12.51 + * that is serializable. The fields of serializable subclasses will
12.52 + * be restored from the stream. <p>
12.53 + *
12.54 + * When traversing a graph, an object may be encountered that does not
12.55 + * support the Serializable interface. In this case the
12.56 + * NotSerializableException will be thrown and will identify the class
12.57 + * of the non-serializable object. <p>
12.58 + *
12.59 + * Classes that require special handling during the serialization and
12.60 + * deserialization process must implement special methods with these exact
12.61 + * signatures: <p>
12.62 + *
12.63 + * <PRE>
12.64 + * private void writeObject(java.io.ObjectOutputStream out)
12.65 + * throws IOException
12.66 + * private void readObject(java.io.ObjectInputStream in)
12.67 + * throws IOException, ClassNotFoundException;
12.68 + * private void readObjectNoData()
12.69 + * throws ObjectStreamException;
12.70 + * </PRE>
12.71 + *
12.72 + * <p>The writeObject method is responsible for writing the state of the
12.73 + * object for its particular class so that the corresponding
12.74 + * readObject method can restore it. The default mechanism for saving
12.75 + * the Object's fields can be invoked by calling
12.76 + * out.defaultWriteObject. The method does not need to concern
12.77 + * itself with the state belonging to its superclasses or subclasses.
12.78 + * State is saved by writing the individual fields to the
12.79 + * ObjectOutputStream using the writeObject method or by using the
12.80 + * methods for primitive data types supported by DataOutput.
12.81 + *
12.82 + * <p>The readObject method is responsible for reading from the stream and
12.83 + * restoring the classes fields. It may call in.defaultReadObject to invoke
12.84 + * the default mechanism for restoring the object's non-static and
12.85 + * non-transient fields. The defaultReadObject method uses information in
12.86 + * the stream to assign the fields of the object saved in the stream with the
12.87 + * correspondingly named fields in the current object. This handles the case
12.88 + * when the class has evolved to add new fields. The method does not need to
12.89 + * concern itself with the state belonging to its superclasses or subclasses.
12.90 + * State is saved by writing the individual fields to the
12.91 + * ObjectOutputStream using the writeObject method or by using the
12.92 + * methods for primitive data types supported by DataOutput.
12.93 + *
12.94 + * <p>The readObjectNoData method is responsible for initializing the state of
12.95 + * the object for its particular class in the event that the serialization
12.96 + * stream does not list the given class as a superclass of the object being
12.97 + * deserialized. This may occur in cases where the receiving party uses a
12.98 + * different version of the deserialized instance's class than the sending
12.99 + * party, and the receiver's version extends classes that are not extended by
12.100 + * the sender's version. This may also occur if the serialization stream has
12.101 + * been tampered; hence, readObjectNoData is useful for initializing
12.102 + * deserialized objects properly despite a "hostile" or incomplete source
12.103 + * stream.
12.104 + *
12.105 + * <p>Serializable classes that need to designate an alternative object to be
12.106 + * used when writing an object to the stream should implement this
12.107 + * special method with the exact signature: <p>
12.108 + *
12.109 + * <PRE>
12.110 + * ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
12.111 + * </PRE><p>
12.112 + *
12.113 + * This writeReplace method is invoked by serialization if the method
12.114 + * exists and it would be accessible from a method defined within the
12.115 + * class of the object being serialized. Thus, the method can have private,
12.116 + * protected and package-private access. Subclass access to this method
12.117 + * follows java accessibility rules. <p>
12.118 + *
12.119 + * Classes that need to designate a replacement when an instance of it
12.120 + * is read from the stream should implement this special method with the
12.121 + * exact signature.<p>
12.122 + *
12.123 + * <PRE>
12.124 + * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
12.125 + * </PRE><p>
12.126 + *
12.127 + * This readResolve method follows the same invocation rules and
12.128 + * accessibility rules as writeReplace.<p>
12.129 + *
12.130 + * The serialization runtime associates with each serializable class a version
12.131 + * number, called a serialVersionUID, which is used during deserialization to
12.132 + * verify that the sender and receiver of a serialized object have loaded
12.133 + * classes for that object that are compatible with respect to serialization.
12.134 + * If the receiver has loaded a class for the object that has a different
12.135 + * serialVersionUID than that of the corresponding sender's class, then
12.136 + * deserialization will result in an {@link InvalidClassException}. A
12.137 + * serializable class can declare its own serialVersionUID explicitly by
12.138 + * declaring a field named <code>"serialVersionUID"</code> that must be static,
12.139 + * final, and of type <code>long</code>:<p>
12.140 + *
12.141 + * <PRE>
12.142 + * ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
12.143 + * </PRE>
12.144 + *
12.145 + * If a serializable class does not explicitly declare a serialVersionUID, then
12.146 + * the serialization runtime will calculate a default serialVersionUID value
12.147 + * for that class based on various aspects of the class, as described in the
12.148 + * Java(TM) Object Serialization Specification. However, it is <em>strongly
12.149 + * recommended</em> that all serializable classes explicitly declare
12.150 + * serialVersionUID values, since the default serialVersionUID computation is
12.151 + * highly sensitive to class details that may vary depending on compiler
12.152 + * implementations, and can thus result in unexpected
12.153 + * <code>InvalidClassException</code>s during deserialization. Therefore, to
12.154 + * guarantee a consistent serialVersionUID value across different java compiler
12.155 + * implementations, a serializable class must declare an explicit
12.156 + * serialVersionUID value. It is also strongly advised that explicit
12.157 + * serialVersionUID declarations use the <code>private</code> modifier where
12.158 + * possible, since such declarations apply only to the immediately declaring
12.159 + * class--serialVersionUID fields are not useful as inherited members. Array
12.160 + * classes cannot declare an explicit serialVersionUID, so they always have
12.161 + * the default computed value, but the requirement for matching
12.162 + * serialVersionUID values is waived for array classes.
12.163 + *
12.164 + * @author unascribed
12.165 + * @see java.io.ObjectOutputStream
12.166 + * @see java.io.ObjectInputStream
12.167 + * @see java.io.ObjectOutput
12.168 + * @see java.io.ObjectInput
12.169 + * @see java.io.Externalizable
12.170 + * @since JDK1.1
12.171 + */
12.172 +public interface Serializable {
12.173 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/emul/mini/src/main/java/java/io/UTFDataFormatException.java Wed Jan 23 20:39:23 2013 +0100
13.3 @@ -0,0 +1,69 @@
13.4 +/*
13.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13.7 + *
13.8 + * This code is free software; you can redistribute it and/or modify it
13.9 + * under the terms of the GNU General Public License version 2 only, as
13.10 + * published by the Free Software Foundation. Oracle designates this
13.11 + * particular file as subject to the "Classpath" exception as provided
13.12 + * by Oracle in the LICENSE file that accompanied this code.
13.13 + *
13.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
13.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13.17 + * version 2 for more details (a copy is included in the LICENSE file that
13.18 + * accompanied this code).
13.19 + *
13.20 + * You should have received a copy of the GNU General Public License version
13.21 + * 2 along with this work; if not, write to the Free Software Foundation,
13.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
13.23 + *
13.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
13.25 + * or visit www.oracle.com if you need additional information or have any
13.26 + * questions.
13.27 + */
13.28 +
13.29 +package java.io;
13.30 +
13.31 +/**
13.32 + * Signals that a malformed string in
13.33 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
13.34 + * format has been read in a data
13.35 + * input stream or by any class that implements the data input
13.36 + * interface.
13.37 + * See the
13.38 + * <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
13.39 + * class description for the format in
13.40 + * which modified UTF-8 strings are read and written.
13.41 + *
13.42 + * @author Frank Yellin
13.43 + * @see java.io.DataInput
13.44 + * @see java.io.DataInputStream#readUTF(java.io.DataInput)
13.45 + * @see java.io.IOException
13.46 + * @since JDK1.0
13.47 + */
13.48 +public
13.49 +class UTFDataFormatException extends IOException {
13.50 + private static final long serialVersionUID = 420743449228280612L;
13.51 +
13.52 + /**
13.53 + * Constructs a <code>UTFDataFormatException</code> with
13.54 + * <code>null</code> as its error detail message.
13.55 + */
13.56 + public UTFDataFormatException() {
13.57 + super();
13.58 + }
13.59 +
13.60 + /**
13.61 + * Constructs a <code>UTFDataFormatException</code> with the
13.62 + * specified detail message. The string <code>s</code> can be
13.63 + * retrieved later by the
13.64 + * <code>{@link java.lang.Throwable#getMessage}</code>
13.65 + * method of class <code>java.lang.Throwable</code>.
13.66 + *
13.67 + * @param s the detail message.
13.68 + */
13.69 + public UTFDataFormatException(String s) {
13.70 + super(s);
13.71 + }
13.72 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/emul/mini/src/main/java/java/io/UnsupportedEncodingException.java Wed Jan 23 20:39:23 2013 +0100
14.3 @@ -0,0 +1,52 @@
14.4 +/*
14.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14.7 + *
14.8 + * This code is free software; you can redistribute it and/or modify it
14.9 + * under the terms of the GNU General Public License version 2 only, as
14.10 + * published by the Free Software Foundation. Oracle designates this
14.11 + * particular file as subject to the "Classpath" exception as provided
14.12 + * by Oracle in the LICENSE file that accompanied this code.
14.13 + *
14.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
14.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14.17 + * version 2 for more details (a copy is included in the LICENSE file that
14.18 + * accompanied this code).
14.19 + *
14.20 + * You should have received a copy of the GNU General Public License version
14.21 + * 2 along with this work; if not, write to the Free Software Foundation,
14.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14.23 + *
14.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
14.25 + * or visit www.oracle.com if you need additional information or have any
14.26 + * questions.
14.27 + */
14.28 +package java.io;
14.29 +
14.30 +/**
14.31 + * The Character Encoding is not supported.
14.32 + *
14.33 + * @author Asmus Freytag
14.34 + * @since JDK1.1
14.35 + */
14.36 +public class UnsupportedEncodingException
14.37 + extends IOException
14.38 +{
14.39 + private static final long serialVersionUID = -4274276298326136670L;
14.40 +
14.41 + /**
14.42 + * Constructs an UnsupportedEncodingException without a detail message.
14.43 + */
14.44 + public UnsupportedEncodingException() {
14.45 + super();
14.46 + }
14.47 +
14.48 + /**
14.49 + * Constructs an UnsupportedEncodingException with a detail message.
14.50 + * @param s Describes the reason for the exception.
14.51 + */
14.52 + public UnsupportedEncodingException(String s) {
14.53 + super(s);
14.54 + }
14.55 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/emul/mini/src/main/java/java/lang/AbstractStringBuilder.java Wed Jan 23 20:39:23 2013 +0100
15.3 @@ -0,0 +1,1424 @@
15.4 +/*
15.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
15.7 + *
15.8 + * This code is free software; you can redistribute it and/or modify it
15.9 + * under the terms of the GNU General Public License version 2 only, as
15.10 + * published by the Free Software Foundation. Oracle designates this
15.11 + * particular file as subject to the "Classpath" exception as provided
15.12 + * by Oracle in the LICENSE file that accompanied this code.
15.13 + *
15.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
15.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15.17 + * version 2 for more details (a copy is included in the LICENSE file that
15.18 + * accompanied this code).
15.19 + *
15.20 + * You should have received a copy of the GNU General Public License version
15.21 + * 2 along with this work; if not, write to the Free Software Foundation,
15.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15.23 + *
15.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
15.25 + * or visit www.oracle.com if you need additional information or have any
15.26 + * questions.
15.27 + */
15.28 +
15.29 +package java.lang;
15.30 +
15.31 +/**
15.32 + * A mutable sequence of characters.
15.33 + * <p>
15.34 + * Implements a modifiable string. At any point in time it contains some
15.35 + * particular sequence of characters, but the length and content of the
15.36 + * sequence can be changed through certain method calls.
15.37 + *
15.38 + * @author Michael McCloskey
15.39 + * @author Martin Buchholz
15.40 + * @author Ulf Zibis
15.41 + * @since 1.5
15.42 + */
15.43 +abstract class AbstractStringBuilder implements Appendable, CharSequence {
15.44 + /**
15.45 + * The value is used for character storage.
15.46 + */
15.47 + char[] value;
15.48 +
15.49 + /**
15.50 + * The count is the number of characters used.
15.51 + */
15.52 + int count;
15.53 +
15.54 + /**
15.55 + * This no-arg constructor is necessary for serialization of subclasses.
15.56 + */
15.57 + AbstractStringBuilder() {
15.58 + }
15.59 +
15.60 + /**
15.61 + * Creates an AbstractStringBuilder of the specified capacity.
15.62 + */
15.63 + AbstractStringBuilder(int capacity) {
15.64 + value = new char[capacity];
15.65 + }
15.66 +
15.67 + /**
15.68 + * Returns the length (character count).
15.69 + *
15.70 + * @return the length of the sequence of characters currently
15.71 + * represented by this object
15.72 + */
15.73 + public int length() {
15.74 + return count;
15.75 + }
15.76 +
15.77 + /**
15.78 + * Returns the current capacity. The capacity is the amount of storage
15.79 + * available for newly inserted characters, beyond which an allocation
15.80 + * will occur.
15.81 + *
15.82 + * @return the current capacity
15.83 + */
15.84 + public int capacity() {
15.85 + return value.length;
15.86 + }
15.87 +
15.88 + /**
15.89 + * Ensures that the capacity is at least equal to the specified minimum.
15.90 + * If the current capacity is less than the argument, then a new internal
15.91 + * array is allocated with greater capacity. The new capacity is the
15.92 + * larger of:
15.93 + * <ul>
15.94 + * <li>The <code>minimumCapacity</code> argument.
15.95 + * <li>Twice the old capacity, plus <code>2</code>.
15.96 + * </ul>
15.97 + * If the <code>minimumCapacity</code> argument is nonpositive, this
15.98 + * method takes no action and simply returns.
15.99 + *
15.100 + * @param minimumCapacity the minimum desired capacity.
15.101 + */
15.102 + public void ensureCapacity(int minimumCapacity) {
15.103 + if (minimumCapacity > 0)
15.104 + ensureCapacityInternal(minimumCapacity);
15.105 + }
15.106 +
15.107 + /**
15.108 + * This method has the same contract as ensureCapacity, but is
15.109 + * never synchronized.
15.110 + */
15.111 + private void ensureCapacityInternal(int minimumCapacity) {
15.112 + // overflow-conscious code
15.113 + if (minimumCapacity - value.length > 0)
15.114 + expandCapacity(minimumCapacity);
15.115 + }
15.116 +
15.117 + /**
15.118 + * This implements the expansion semantics of ensureCapacity with no
15.119 + * size check or synchronization.
15.120 + */
15.121 + void expandCapacity(int minimumCapacity) {
15.122 + int newCapacity = value.length * 2 + 2;
15.123 + if (newCapacity - minimumCapacity < 0)
15.124 + newCapacity = minimumCapacity;
15.125 + if (newCapacity < 0) {
15.126 + if (minimumCapacity < 0) // overflow
15.127 + throw new OutOfMemoryError();
15.128 + newCapacity = Integer.MAX_VALUE;
15.129 + }
15.130 + value = copyOf(value, newCapacity);
15.131 + }
15.132 +
15.133 + /**
15.134 + * Attempts to reduce storage used for the character sequence.
15.135 + * If the buffer is larger than necessary to hold its current sequence of
15.136 + * characters, then it may be resized to become more space efficient.
15.137 + * Calling this method may, but is not required to, affect the value
15.138 + * returned by a subsequent call to the {@link #capacity()} method.
15.139 + */
15.140 + public void trimToSize() {
15.141 + if (count < value.length) {
15.142 + value = copyOf(value, count);
15.143 + }
15.144 + }
15.145 +
15.146 + /**
15.147 + * Sets the length of the character sequence.
15.148 + * The sequence is changed to a new character sequence
15.149 + * whose length is specified by the argument. For every nonnegative
15.150 + * index <i>k</i> less than <code>newLength</code>, the character at
15.151 + * index <i>k</i> in the new character sequence is the same as the
15.152 + * character at index <i>k</i> in the old sequence if <i>k</i> is less
15.153 + * than the length of the old character sequence; otherwise, it is the
15.154 + * null character <code>'\u0000'</code>.
15.155 + *
15.156 + * In other words, if the <code>newLength</code> argument is less than
15.157 + * the current length, the length is changed to the specified length.
15.158 + * <p>
15.159 + * If the <code>newLength</code> argument is greater than or equal
15.160 + * to the current length, sufficient null characters
15.161 + * (<code>'\u0000'</code>) are appended so that
15.162 + * length becomes the <code>newLength</code> argument.
15.163 + * <p>
15.164 + * The <code>newLength</code> argument must be greater than or equal
15.165 + * to <code>0</code>.
15.166 + *
15.167 + * @param newLength the new length
15.168 + * @throws IndexOutOfBoundsException if the
15.169 + * <code>newLength</code> argument is negative.
15.170 + */
15.171 + public void setLength(int newLength) {
15.172 + if (newLength < 0)
15.173 + throw new StringIndexOutOfBoundsException(newLength);
15.174 + ensureCapacityInternal(newLength);
15.175 +
15.176 + if (count < newLength) {
15.177 + for (; count < newLength; count++)
15.178 + value[count] = '\0';
15.179 + } else {
15.180 + count = newLength;
15.181 + }
15.182 + }
15.183 +
15.184 + /**
15.185 + * Returns the <code>char</code> value in this sequence at the specified index.
15.186 + * The first <code>char</code> value is at index <code>0</code>, the next at index
15.187 + * <code>1</code>, and so on, as in array indexing.
15.188 + * <p>
15.189 + * The index argument must be greater than or equal to
15.190 + * <code>0</code>, and less than the length of this sequence.
15.191 + *
15.192 + * <p>If the <code>char</code> value specified by the index is a
15.193 + * <a href="Character.html#unicode">surrogate</a>, the surrogate
15.194 + * value is returned.
15.195 + *
15.196 + * @param index the index of the desired <code>char</code> value.
15.197 + * @return the <code>char</code> value at the specified index.
15.198 + * @throws IndexOutOfBoundsException if <code>index</code> is
15.199 + * negative or greater than or equal to <code>length()</code>.
15.200 + */
15.201 + public char charAt(int index) {
15.202 + if ((index < 0) || (index >= count))
15.203 + throw new StringIndexOutOfBoundsException(index);
15.204 + return value[index];
15.205 + }
15.206 +
15.207 + /**
15.208 + * Returns the character (Unicode code point) at the specified
15.209 + * index. The index refers to <code>char</code> values
15.210 + * (Unicode code units) and ranges from <code>0</code> to
15.211 + * {@link #length()}<code> - 1</code>.
15.212 + *
15.213 + * <p> If the <code>char</code> value specified at the given index
15.214 + * is in the high-surrogate range, the following index is less
15.215 + * than the length of this sequence, and the
15.216 + * <code>char</code> value at the following index is in the
15.217 + * low-surrogate range, then the supplementary code point
15.218 + * corresponding to this surrogate pair is returned. Otherwise,
15.219 + * the <code>char</code> value at the given index is returned.
15.220 + *
15.221 + * @param index the index to the <code>char</code> values
15.222 + * @return the code point value of the character at the
15.223 + * <code>index</code>
15.224 + * @exception IndexOutOfBoundsException if the <code>index</code>
15.225 + * argument is negative or not less than the length of this
15.226 + * sequence.
15.227 + */
15.228 + public int codePointAt(int index) {
15.229 + if ((index < 0) || (index >= count)) {
15.230 + throw new StringIndexOutOfBoundsException(index);
15.231 + }
15.232 + return Character.codePointAt(value, index);
15.233 + }
15.234 +
15.235 + /**
15.236 + * Returns the character (Unicode code point) before the specified
15.237 + * index. The index refers to <code>char</code> values
15.238 + * (Unicode code units) and ranges from <code>1</code> to {@link
15.239 + * #length()}.
15.240 + *
15.241 + * <p> If the <code>char</code> value at <code>(index - 1)</code>
15.242 + * is in the low-surrogate range, <code>(index - 2)</code> is not
15.243 + * negative, and the <code>char</code> value at <code>(index -
15.244 + * 2)</code> is in the high-surrogate range, then the
15.245 + * supplementary code point value of the surrogate pair is
15.246 + * returned. If the <code>char</code> value at <code>index -
15.247 + * 1</code> is an unpaired low-surrogate or a high-surrogate, the
15.248 + * surrogate value is returned.
15.249 + *
15.250 + * @param index the index following the code point that should be returned
15.251 + * @return the Unicode code point value before the given index.
15.252 + * @exception IndexOutOfBoundsException if the <code>index</code>
15.253 + * argument is less than 1 or greater than the length
15.254 + * of this sequence.
15.255 + */
15.256 + public int codePointBefore(int index) {
15.257 + int i = index - 1;
15.258 + if ((i < 0) || (i >= count)) {
15.259 + throw new StringIndexOutOfBoundsException(index);
15.260 + }
15.261 + return Character.codePointBefore(value, index);
15.262 + }
15.263 +
15.264 + /**
15.265 + * Returns the number of Unicode code points in the specified text
15.266 + * range of this sequence. The text range begins at the specified
15.267 + * <code>beginIndex</code> and extends to the <code>char</code> at
15.268 + * index <code>endIndex - 1</code>. Thus the length (in
15.269 + * <code>char</code>s) of the text range is
15.270 + * <code>endIndex-beginIndex</code>. Unpaired surrogates within
15.271 + * this sequence count as one code point each.
15.272 + *
15.273 + * @param beginIndex the index to the first <code>char</code> of
15.274 + * the text range.
15.275 + * @param endIndex the index after the last <code>char</code> of
15.276 + * the text range.
15.277 + * @return the number of Unicode code points in the specified text
15.278 + * range
15.279 + * @exception IndexOutOfBoundsException if the
15.280 + * <code>beginIndex</code> is negative, or <code>endIndex</code>
15.281 + * is larger than the length of this sequence, or
15.282 + * <code>beginIndex</code> is larger than <code>endIndex</code>.
15.283 + */
15.284 + public int codePointCount(int beginIndex, int endIndex) {
15.285 + if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
15.286 + throw new IndexOutOfBoundsException();
15.287 + }
15.288 + return Character.codePointCountImpl(value, beginIndex, endIndex-beginIndex);
15.289 + }
15.290 +
15.291 + /**
15.292 + * Returns the index within this sequence that is offset from the
15.293 + * given <code>index</code> by <code>codePointOffset</code> code
15.294 + * points. Unpaired surrogates within the text range given by
15.295 + * <code>index</code> and <code>codePointOffset</code> count as
15.296 + * one code point each.
15.297 + *
15.298 + * @param index the index to be offset
15.299 + * @param codePointOffset the offset in code points
15.300 + * @return the index within this sequence
15.301 + * @exception IndexOutOfBoundsException if <code>index</code>
15.302 + * is negative or larger then the length of this sequence,
15.303 + * or if <code>codePointOffset</code> is positive and the subsequence
15.304 + * starting with <code>index</code> has fewer than
15.305 + * <code>codePointOffset</code> code points,
15.306 + * or if <code>codePointOffset</code> is negative and the subsequence
15.307 + * before <code>index</code> has fewer than the absolute value of
15.308 + * <code>codePointOffset</code> code points.
15.309 + */
15.310 + public int offsetByCodePoints(int index, int codePointOffset) {
15.311 + if (index < 0 || index > count) {
15.312 + throw new IndexOutOfBoundsException();
15.313 + }
15.314 + return Character.offsetByCodePointsImpl(value, 0, count,
15.315 + index, codePointOffset);
15.316 + }
15.317 +
15.318 + /**
15.319 + * Characters are copied from this sequence into the
15.320 + * destination character array <code>dst</code>. The first character to
15.321 + * be copied is at index <code>srcBegin</code>; the last character to
15.322 + * be copied is at index <code>srcEnd-1</code>. The total number of
15.323 + * characters to be copied is <code>srcEnd-srcBegin</code>. The
15.324 + * characters are copied into the subarray of <code>dst</code> starting
15.325 + * at index <code>dstBegin</code> and ending at index:
15.326 + * <p><blockquote><pre>
15.327 + * dstbegin + (srcEnd-srcBegin) - 1
15.328 + * </pre></blockquote>
15.329 + *
15.330 + * @param srcBegin start copying at this offset.
15.331 + * @param srcEnd stop copying at this offset.
15.332 + * @param dst the array to copy the data into.
15.333 + * @param dstBegin offset into <code>dst</code>.
15.334 + * @throws NullPointerException if <code>dst</code> is
15.335 + * <code>null</code>.
15.336 + * @throws IndexOutOfBoundsException if any of the following is true:
15.337 + * <ul>
15.338 + * <li><code>srcBegin</code> is negative
15.339 + * <li><code>dstBegin</code> is negative
15.340 + * <li>the <code>srcBegin</code> argument is greater than
15.341 + * the <code>srcEnd</code> argument.
15.342 + * <li><code>srcEnd</code> is greater than
15.343 + * <code>this.length()</code>.
15.344 + * <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
15.345 + * <code>dst.length</code>
15.346 + * </ul>
15.347 + */
15.348 + public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
15.349 + {
15.350 + if (srcBegin < 0)
15.351 + throw new StringIndexOutOfBoundsException(srcBegin);
15.352 + if ((srcEnd < 0) || (srcEnd > count))
15.353 + throw new StringIndexOutOfBoundsException(srcEnd);
15.354 + if (srcBegin > srcEnd)
15.355 + throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
15.356 + arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
15.357 + }
15.358 +
15.359 + /**
15.360 + * The character at the specified index is set to <code>ch</code>. This
15.361 + * sequence is altered to represent a new character sequence that is
15.362 + * identical to the old character sequence, except that it contains the
15.363 + * character <code>ch</code> at position <code>index</code>.
15.364 + * <p>
15.365 + * The index argument must be greater than or equal to
15.366 + * <code>0</code>, and less than the length of this sequence.
15.367 + *
15.368 + * @param index the index of the character to modify.
15.369 + * @param ch the new character.
15.370 + * @throws IndexOutOfBoundsException if <code>index</code> is
15.371 + * negative or greater than or equal to <code>length()</code>.
15.372 + */
15.373 + public void setCharAt(int index, char ch) {
15.374 + if ((index < 0) || (index >= count))
15.375 + throw new StringIndexOutOfBoundsException(index);
15.376 + value[index] = ch;
15.377 + }
15.378 +
15.379 + /**
15.380 + * Appends the string representation of the {@code Object} argument.
15.381 + * <p>
15.382 + * The overall effect is exactly as if the argument were converted
15.383 + * to a string by the method {@link String#valueOf(Object)},
15.384 + * and the characters of that string were then
15.385 + * {@link #append(String) appended} to this character sequence.
15.386 + *
15.387 + * @param obj an {@code Object}.
15.388 + * @return a reference to this object.
15.389 + */
15.390 + public AbstractStringBuilder append(Object obj) {
15.391 + return append(String.valueOf(obj));
15.392 + }
15.393 +
15.394 + /**
15.395 + * Appends the specified string to this character sequence.
15.396 + * <p>
15.397 + * The characters of the {@code String} argument are appended, in
15.398 + * order, increasing the length of this sequence by the length of the
15.399 + * argument. If {@code str} is {@code null}, then the four
15.400 + * characters {@code "null"} are appended.
15.401 + * <p>
15.402 + * Let <i>n</i> be the length of this character sequence just prior to
15.403 + * execution of the {@code append} method. Then the character at
15.404 + * index <i>k</i> in the new character sequence is equal to the character
15.405 + * at index <i>k</i> in the old character sequence, if <i>k</i> is less
15.406 + * than <i>n</i>; otherwise, it is equal to the character at index
15.407 + * <i>k-n</i> in the argument {@code str}.
15.408 + *
15.409 + * @param str a string.
15.410 + * @return a reference to this object.
15.411 + */
15.412 + public AbstractStringBuilder append(String str) {
15.413 + if (str == null) str = "null";
15.414 + int len = str.length();
15.415 + ensureCapacityInternal(count + len);
15.416 + str.getChars(0, len, value, count);
15.417 + count += len;
15.418 + return this;
15.419 + }
15.420 +
15.421 + // Documentation in subclasses because of synchro difference
15.422 + public AbstractStringBuilder append(StringBuffer sb) {
15.423 + if (sb == null)
15.424 + return append("null");
15.425 + int len = sb.length();
15.426 + ensureCapacityInternal(count + len);
15.427 + sb.getChars(0, len, value, count);
15.428 + count += len;
15.429 + return this;
15.430 + }
15.431 +
15.432 + // Documentation in subclasses because of synchro difference
15.433 + public AbstractStringBuilder append(CharSequence s) {
15.434 + if (s == null)
15.435 + s = "null";
15.436 + if (s instanceof String)
15.437 + return this.append((String)s);
15.438 + if (s instanceof StringBuffer)
15.439 + return this.append((StringBuffer)s);
15.440 + return this.append(s, 0, s.length());
15.441 + }
15.442 +
15.443 + /**
15.444 + * Appends a subsequence of the specified {@code CharSequence} to this
15.445 + * sequence.
15.446 + * <p>
15.447 + * Characters of the argument {@code s}, starting at
15.448 + * index {@code start}, are appended, in order, to the contents of
15.449 + * this sequence up to the (exclusive) index {@code end}. The length
15.450 + * of this sequence is increased by the value of {@code end - start}.
15.451 + * <p>
15.452 + * Let <i>n</i> be the length of this character sequence just prior to
15.453 + * execution of the {@code append} method. Then the character at
15.454 + * index <i>k</i> in this character sequence becomes equal to the
15.455 + * character at index <i>k</i> in this sequence, if <i>k</i> is less than
15.456 + * <i>n</i>; otherwise, it is equal to the character at index
15.457 + * <i>k+start-n</i> in the argument {@code s}.
15.458 + * <p>
15.459 + * If {@code s} is {@code null}, then this method appends
15.460 + * characters as if the s parameter was a sequence containing the four
15.461 + * characters {@code "null"}.
15.462 + *
15.463 + * @param s the sequence to append.
15.464 + * @param start the starting index of the subsequence to be appended.
15.465 + * @param end the end index of the subsequence to be appended.
15.466 + * @return a reference to this object.
15.467 + * @throws IndexOutOfBoundsException if
15.468 + * {@code start} is negative, or
15.469 + * {@code start} is greater than {@code end} or
15.470 + * {@code end} is greater than {@code s.length()}
15.471 + */
15.472 + public AbstractStringBuilder append(CharSequence s, int start, int end) {
15.473 + if (s == null)
15.474 + s = "null";
15.475 + if ((start < 0) || (start > end) || (end > s.length()))
15.476 + throw new IndexOutOfBoundsException(
15.477 + "start " + start + ", end " + end + ", s.length() "
15.478 + + s.length());
15.479 + int len = end - start;
15.480 + ensureCapacityInternal(count + len);
15.481 + for (int i = start, j = count; i < end; i++, j++)
15.482 + value[j] = s.charAt(i);
15.483 + count += len;
15.484 + return this;
15.485 + }
15.486 +
15.487 + /**
15.488 + * Appends the string representation of the {@code char} array
15.489 + * argument to this sequence.
15.490 + * <p>
15.491 + * The characters of the array argument are appended, in order, to
15.492 + * the contents of this sequence. The length of this sequence
15.493 + * increases by the length of the argument.
15.494 + * <p>
15.495 + * The overall effect is exactly as if the argument were converted
15.496 + * to a string by the method {@link String#valueOf(char[])},
15.497 + * and the characters of that string were then
15.498 + * {@link #append(String) appended} to this character sequence.
15.499 + *
15.500 + * @param str the characters to be appended.
15.501 + * @return a reference to this object.
15.502 + */
15.503 + public AbstractStringBuilder append(char[] str) {
15.504 + int len = str.length;
15.505 + ensureCapacityInternal(count + len);
15.506 + arraycopy(str, 0, value, count, len);
15.507 + count += len;
15.508 + return this;
15.509 + }
15.510 +
15.511 + /**
15.512 + * Appends the string representation of a subarray of the
15.513 + * {@code char} array argument to this sequence.
15.514 + * <p>
15.515 + * Characters of the {@code char} array {@code str}, starting at
15.516 + * index {@code offset}, are appended, in order, to the contents
15.517 + * of this sequence. The length of this sequence increases
15.518 + * by the value of {@code len}.
15.519 + * <p>
15.520 + * The overall effect is exactly as if the arguments were converted
15.521 + * to a string by the method {@link String#valueOf(char[],int,int)},
15.522 + * and the characters of that string were then
15.523 + * {@link #append(String) appended} to this character sequence.
15.524 + *
15.525 + * @param str the characters to be appended.
15.526 + * @param offset the index of the first {@code char} to append.
15.527 + * @param len the number of {@code char}s to append.
15.528 + * @return a reference to this object.
15.529 + * @throws IndexOutOfBoundsException
15.530 + * if {@code offset < 0} or {@code len < 0}
15.531 + * or {@code offset+len > str.length}
15.532 + */
15.533 + public AbstractStringBuilder append(char str[], int offset, int len) {
15.534 + if (len > 0) // let arraycopy report AIOOBE for len < 0
15.535 + ensureCapacityInternal(count + len);
15.536 + arraycopy(str, offset, value, count, len);
15.537 + count += len;
15.538 + return this;
15.539 + }
15.540 +
15.541 + /**
15.542 + * Appends the string representation of the {@code boolean}
15.543 + * argument to the sequence.
15.544 + * <p>
15.545 + * The overall effect is exactly as if the argument were converted
15.546 + * to a string by the method {@link String#valueOf(boolean)},
15.547 + * and the characters of that string were then
15.548 + * {@link #append(String) appended} to this character sequence.
15.549 + *
15.550 + * @param b a {@code boolean}.
15.551 + * @return a reference to this object.
15.552 + */
15.553 + public AbstractStringBuilder append(boolean b) {
15.554 + if (b) {
15.555 + ensureCapacityInternal(count + 4);
15.556 + value[count++] = 't';
15.557 + value[count++] = 'r';
15.558 + value[count++] = 'u';
15.559 + value[count++] = 'e';
15.560 + } else {
15.561 + ensureCapacityInternal(count + 5);
15.562 + value[count++] = 'f';
15.563 + value[count++] = 'a';
15.564 + value[count++] = 'l';
15.565 + value[count++] = 's';
15.566 + value[count++] = 'e';
15.567 + }
15.568 + return this;
15.569 + }
15.570 +
15.571 + /**
15.572 + * Appends the string representation of the {@code char}
15.573 + * argument to this sequence.
15.574 + * <p>
15.575 + * The argument is appended to the contents of this sequence.
15.576 + * The length of this sequence increases by {@code 1}.
15.577 + * <p>
15.578 + * The overall effect is exactly as if the argument were converted
15.579 + * to a string by the method {@link String#valueOf(char)},
15.580 + * and the character in that string were then
15.581 + * {@link #append(String) appended} to this character sequence.
15.582 + *
15.583 + * @param c a {@code char}.
15.584 + * @return a reference to this object.
15.585 + */
15.586 + public AbstractStringBuilder append(char c) {
15.587 + ensureCapacityInternal(count + 1);
15.588 + value[count++] = c;
15.589 + return this;
15.590 + }
15.591 +
15.592 + /**
15.593 + * Appends the string representation of the {@code int}
15.594 + * argument to this sequence.
15.595 + * <p>
15.596 + * The overall effect is exactly as if the argument were converted
15.597 + * to a string by the method {@link String#valueOf(int)},
15.598 + * and the characters of that string were then
15.599 + * {@link #append(String) appended} to this character sequence.
15.600 + *
15.601 + * @param i an {@code int}.
15.602 + * @return a reference to this object.
15.603 + */
15.604 + public AbstractStringBuilder append(int i) {
15.605 + return append(Integer.toString(i));
15.606 + }
15.607 +
15.608 + /**
15.609 + * Appends the string representation of the {@code long}
15.610 + * argument to this sequence.
15.611 + * <p>
15.612 + * The overall effect is exactly as if the argument were converted
15.613 + * to a string by the method {@link String#valueOf(long)},
15.614 + * and the characters of that string were then
15.615 + * {@link #append(String) appended} to this character sequence.
15.616 + *
15.617 + * @param l a {@code long}.
15.618 + * @return a reference to this object.
15.619 + */
15.620 + public AbstractStringBuilder append(long l) {
15.621 + if (l == Long.MIN_VALUE) {
15.622 + append("-9223372036854775808");
15.623 + return this;
15.624 + }
15.625 + int appendedLength = (l < 0) ? Long.stringSize(-l) + 1
15.626 + : Long.stringSize(l);
15.627 + int spaceNeeded = count + appendedLength;
15.628 + ensureCapacityInternal(spaceNeeded);
15.629 + Long.getChars(l, spaceNeeded, value);
15.630 + count = spaceNeeded;
15.631 + return this;
15.632 + }
15.633 +
15.634 + /**
15.635 + * Appends the string representation of the {@code float}
15.636 + * argument to this sequence.
15.637 + * <p>
15.638 + * The overall effect is exactly as if the argument were converted
15.639 + * to a string by the method {@link String#valueOf(float)},
15.640 + * and the characters of that string were then
15.641 + * {@link #append(String) appended} to this character sequence.
15.642 + *
15.643 + * @param f a {@code float}.
15.644 + * @return a reference to this object.
15.645 + */
15.646 + public AbstractStringBuilder append(float f) {
15.647 + return append(Float.toString(f));
15.648 + }
15.649 +
15.650 + /**
15.651 + * Appends the string representation of the {@code double}
15.652 + * argument to this sequence.
15.653 + * <p>
15.654 + * The overall effect is exactly as if the argument were converted
15.655 + * to a string by the method {@link String#valueOf(double)},
15.656 + * and the characters of that string were then
15.657 + * {@link #append(String) appended} to this character sequence.
15.658 + *
15.659 + * @param d a {@code double}.
15.660 + * @return a reference to this object.
15.661 + */
15.662 + public AbstractStringBuilder append(double d) {
15.663 + return append(Double.toString(d));
15.664 + }
15.665 +
15.666 + /**
15.667 + * Removes the characters in a substring of this sequence.
15.668 + * The substring begins at the specified {@code start} and extends to
15.669 + * the character at index {@code end - 1} or to the end of the
15.670 + * sequence if no such character exists. If
15.671 + * {@code start} is equal to {@code end}, no changes are made.
15.672 + *
15.673 + * @param start The beginning index, inclusive.
15.674 + * @param end The ending index, exclusive.
15.675 + * @return This object.
15.676 + * @throws StringIndexOutOfBoundsException if {@code start}
15.677 + * is negative, greater than {@code length()}, or
15.678 + * greater than {@code end}.
15.679 + */
15.680 + public AbstractStringBuilder delete(int start, int end) {
15.681 + if (start < 0)
15.682 + throw new StringIndexOutOfBoundsException(start);
15.683 + if (end > count)
15.684 + end = count;
15.685 + if (start > end)
15.686 + throw new StringIndexOutOfBoundsException();
15.687 + int len = end - start;
15.688 + if (len > 0) {
15.689 + arraycopy(value, start+len, value, start, count-end);
15.690 + count -= len;
15.691 + }
15.692 + return this;
15.693 + }
15.694 +
15.695 + /**
15.696 + * Appends the string representation of the {@code codePoint}
15.697 + * argument to this sequence.
15.698 + *
15.699 + * <p> The argument is appended to the contents of this sequence.
15.700 + * The length of this sequence increases by
15.701 + * {@link Character#charCount(int) Character.charCount(codePoint)}.
15.702 + *
15.703 + * <p> The overall effect is exactly as if the argument were
15.704 + * converted to a {@code char} array by the method
15.705 + * {@link Character#toChars(int)} and the character in that array
15.706 + * were then {@link #append(char[]) appended} to this character
15.707 + * sequence.
15.708 + *
15.709 + * @param codePoint a Unicode code point
15.710 + * @return a reference to this object.
15.711 + * @exception IllegalArgumentException if the specified
15.712 + * {@code codePoint} isn't a valid Unicode code point
15.713 + */
15.714 + public AbstractStringBuilder appendCodePoint(int codePoint) {
15.715 + final int count = this.count;
15.716 +
15.717 + if (Character.isBmpCodePoint(codePoint)) {
15.718 + ensureCapacityInternal(count + 1);
15.719 + value[count] = (char) codePoint;
15.720 + this.count = count + 1;
15.721 + } else if (Character.isValidCodePoint(codePoint)) {
15.722 + ensureCapacityInternal(count + 2);
15.723 + Character.toSurrogates(codePoint, value, count);
15.724 + this.count = count + 2;
15.725 + } else {
15.726 + throw new IllegalArgumentException();
15.727 + }
15.728 + return this;
15.729 + }
15.730 +
15.731 + /**
15.732 + * Removes the <code>char</code> at the specified position in this
15.733 + * sequence. This sequence is shortened by one <code>char</code>.
15.734 + *
15.735 + * <p>Note: If the character at the given index is a supplementary
15.736 + * character, this method does not remove the entire character. If
15.737 + * correct handling of supplementary characters is required,
15.738 + * determine the number of <code>char</code>s to remove by calling
15.739 + * <code>Character.charCount(thisSequence.codePointAt(index))</code>,
15.740 + * where <code>thisSequence</code> is this sequence.
15.741 + *
15.742 + * @param index Index of <code>char</code> to remove
15.743 + * @return This object.
15.744 + * @throws StringIndexOutOfBoundsException if the <code>index</code>
15.745 + * is negative or greater than or equal to
15.746 + * <code>length()</code>.
15.747 + */
15.748 + public AbstractStringBuilder deleteCharAt(int index) {
15.749 + if ((index < 0) || (index >= count))
15.750 + throw new StringIndexOutOfBoundsException(index);
15.751 + arraycopy(value, index+1, value, index, count-index-1);
15.752 + count--;
15.753 + return this;
15.754 + }
15.755 +
15.756 + /**
15.757 + * Replaces the characters in a substring of this sequence
15.758 + * with characters in the specified <code>String</code>. The substring
15.759 + * begins at the specified <code>start</code> and extends to the character
15.760 + * at index <code>end - 1</code> or to the end of the
15.761 + * sequence if no such character exists. First the
15.762 + * characters in the substring are removed and then the specified
15.763 + * <code>String</code> is inserted at <code>start</code>. (This
15.764 + * sequence will be lengthened to accommodate the
15.765 + * specified String if necessary.)
15.766 + *
15.767 + * @param start The beginning index, inclusive.
15.768 + * @param end The ending index, exclusive.
15.769 + * @param str String that will replace previous contents.
15.770 + * @return This object.
15.771 + * @throws StringIndexOutOfBoundsException if <code>start</code>
15.772 + * is negative, greater than <code>length()</code>, or
15.773 + * greater than <code>end</code>.
15.774 + */
15.775 + public AbstractStringBuilder replace(int start, int end, String str) {
15.776 + if (start < 0)
15.777 + throw new StringIndexOutOfBoundsException(start);
15.778 + if (start > count)
15.779 + throw new StringIndexOutOfBoundsException("start > length()");
15.780 + if (start > end)
15.781 + throw new StringIndexOutOfBoundsException("start > end");
15.782 +
15.783 + if (end > count)
15.784 + end = count;
15.785 + int len = str.length();
15.786 + int newCount = count + len - (end - start);
15.787 + ensureCapacityInternal(newCount);
15.788 +
15.789 + arraycopy(value, end, value, start + len, count - end);
15.790 + str.getChars(value, start);
15.791 + count = newCount;
15.792 + return this;
15.793 + }
15.794 +
15.795 + /**
15.796 + * Returns a new <code>String</code> that contains a subsequence of
15.797 + * characters currently contained in this character sequence. The
15.798 + * substring begins at the specified index and extends to the end of
15.799 + * this sequence.
15.800 + *
15.801 + * @param start The beginning index, inclusive.
15.802 + * @return The new string.
15.803 + * @throws StringIndexOutOfBoundsException if <code>start</code> is
15.804 + * less than zero, or greater than the length of this object.
15.805 + */
15.806 + public String substring(int start) {
15.807 + return substring(start, count);
15.808 + }
15.809 +
15.810 + /**
15.811 + * Returns a new character sequence that is a subsequence of this sequence.
15.812 + *
15.813 + * <p> An invocation of this method of the form
15.814 + *
15.815 + * <blockquote><pre>
15.816 + * sb.subSequence(begin, end)</pre></blockquote>
15.817 + *
15.818 + * behaves in exactly the same way as the invocation
15.819 + *
15.820 + * <blockquote><pre>
15.821 + * sb.substring(begin, end)</pre></blockquote>
15.822 + *
15.823 + * This method is provided so that this class can
15.824 + * implement the {@link CharSequence} interface. </p>
15.825 + *
15.826 + * @param start the start index, inclusive.
15.827 + * @param end the end index, exclusive.
15.828 + * @return the specified subsequence.
15.829 + *
15.830 + * @throws IndexOutOfBoundsException
15.831 + * if <tt>start</tt> or <tt>end</tt> are negative,
15.832 + * if <tt>end</tt> is greater than <tt>length()</tt>,
15.833 + * or if <tt>start</tt> is greater than <tt>end</tt>
15.834 + * @spec JSR-51
15.835 + */
15.836 + public CharSequence subSequence(int start, int end) {
15.837 + return substring(start, end);
15.838 + }
15.839 +
15.840 + /**
15.841 + * Returns a new <code>String</code> that contains a subsequence of
15.842 + * characters currently contained in this sequence. The
15.843 + * substring begins at the specified <code>start</code> and
15.844 + * extends to the character at index <code>end - 1</code>.
15.845 + *
15.846 + * @param start The beginning index, inclusive.
15.847 + * @param end The ending index, exclusive.
15.848 + * @return The new string.
15.849 + * @throws StringIndexOutOfBoundsException if <code>start</code>
15.850 + * or <code>end</code> are negative or greater than
15.851 + * <code>length()</code>, or <code>start</code> is
15.852 + * greater than <code>end</code>.
15.853 + */
15.854 + public String substring(int start, int end) {
15.855 + if (start < 0)
15.856 + throw new StringIndexOutOfBoundsException(start);
15.857 + if (end > count)
15.858 + throw new StringIndexOutOfBoundsException(end);
15.859 + if (start > end)
15.860 + throw new StringIndexOutOfBoundsException(end - start);
15.861 + return new String(value, start, end - start);
15.862 + }
15.863 +
15.864 + /**
15.865 + * Inserts the string representation of a subarray of the {@code str}
15.866 + * array argument into this sequence. The subarray begins at the
15.867 + * specified {@code offset} and extends {@code len} {@code char}s.
15.868 + * The characters of the subarray are inserted into this sequence at
15.869 + * the position indicated by {@code index}. The length of this
15.870 + * sequence increases by {@code len} {@code char}s.
15.871 + *
15.872 + * @param index position at which to insert subarray.
15.873 + * @param str A {@code char} array.
15.874 + * @param offset the index of the first {@code char} in subarray to
15.875 + * be inserted.
15.876 + * @param len the number of {@code char}s in the subarray to
15.877 + * be inserted.
15.878 + * @return This object
15.879 + * @throws StringIndexOutOfBoundsException if {@code index}
15.880 + * is negative or greater than {@code length()}, or
15.881 + * {@code offset} or {@code len} are negative, or
15.882 + * {@code (offset+len)} is greater than
15.883 + * {@code str.length}.
15.884 + */
15.885 + public AbstractStringBuilder insert(int index, char[] str, int offset,
15.886 + int len)
15.887 + {
15.888 + if ((index < 0) || (index > length()))
15.889 + throw new StringIndexOutOfBoundsException(index);
15.890 + if ((offset < 0) || (len < 0) || (offset > str.length - len))
15.891 + throw new StringIndexOutOfBoundsException(
15.892 + "offset " + offset + ", len " + len + ", str.length "
15.893 + + str.length);
15.894 + ensureCapacityInternal(count + len);
15.895 + arraycopy(value, index, value, index + len, count - index);
15.896 + arraycopy(str, offset, value, index, len);
15.897 + count += len;
15.898 + return this;
15.899 + }
15.900 +
15.901 + /**
15.902 + * Inserts the string representation of the {@code Object}
15.903 + * argument into this character sequence.
15.904 + * <p>
15.905 + * The overall effect is exactly as if the second argument were
15.906 + * converted to a string by the method {@link String#valueOf(Object)},
15.907 + * and the characters of that string were then
15.908 + * {@link #insert(int,String) inserted} into this character
15.909 + * sequence at the indicated offset.
15.910 + * <p>
15.911 + * The {@code offset} argument must be greater than or equal to
15.912 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.913 + * of this sequence.
15.914 + *
15.915 + * @param offset the offset.
15.916 + * @param obj an {@code Object}.
15.917 + * @return a reference to this object.
15.918 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.919 + */
15.920 + public AbstractStringBuilder insert(int offset, Object obj) {
15.921 + return insert(offset, String.valueOf(obj));
15.922 + }
15.923 +
15.924 + /**
15.925 + * Inserts the string into this character sequence.
15.926 + * <p>
15.927 + * The characters of the {@code String} argument are inserted, in
15.928 + * order, into this sequence at the indicated offset, moving up any
15.929 + * characters originally above that position and increasing the length
15.930 + * of this sequence by the length of the argument. If
15.931 + * {@code str} is {@code null}, then the four characters
15.932 + * {@code "null"} are inserted into this sequence.
15.933 + * <p>
15.934 + * The character at index <i>k</i> in the new character sequence is
15.935 + * equal to:
15.936 + * <ul>
15.937 + * <li>the character at index <i>k</i> in the old character sequence, if
15.938 + * <i>k</i> is less than {@code offset}
15.939 + * <li>the character at index <i>k</i>{@code -offset} in the
15.940 + * argument {@code str}, if <i>k</i> is not less than
15.941 + * {@code offset} but is less than {@code offset+str.length()}
15.942 + * <li>the character at index <i>k</i>{@code -str.length()} in the
15.943 + * old character sequence, if <i>k</i> is not less than
15.944 + * {@code offset+str.length()}
15.945 + * </ul><p>
15.946 + * The {@code offset} argument must be greater than or equal to
15.947 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.948 + * of this sequence.
15.949 + *
15.950 + * @param offset the offset.
15.951 + * @param str a string.
15.952 + * @return a reference to this object.
15.953 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.954 + */
15.955 + public AbstractStringBuilder insert(int offset, String str) {
15.956 + if ((offset < 0) || (offset > length()))
15.957 + throw new StringIndexOutOfBoundsException(offset);
15.958 + if (str == null)
15.959 + str = "null";
15.960 + int len = str.length();
15.961 + ensureCapacityInternal(count + len);
15.962 + arraycopy(value, offset, value, offset + len, count - offset);
15.963 + str.getChars(value, offset);
15.964 + count += len;
15.965 + return this;
15.966 + }
15.967 +
15.968 + /**
15.969 + * Inserts the string representation of the {@code char} array
15.970 + * argument into this sequence.
15.971 + * <p>
15.972 + * The characters of the array argument are inserted into the
15.973 + * contents of this sequence at the position indicated by
15.974 + * {@code offset}. The length of this sequence increases by
15.975 + * the length of the argument.
15.976 + * <p>
15.977 + * The overall effect is exactly as if the second argument were
15.978 + * converted to a string by the method {@link String#valueOf(char[])},
15.979 + * and the characters of that string were then
15.980 + * {@link #insert(int,String) inserted} into this character
15.981 + * sequence at the indicated offset.
15.982 + * <p>
15.983 + * The {@code offset} argument must be greater than or equal to
15.984 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.985 + * of this sequence.
15.986 + *
15.987 + * @param offset the offset.
15.988 + * @param str a character array.
15.989 + * @return a reference to this object.
15.990 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.991 + */
15.992 + public AbstractStringBuilder insert(int offset, char[] str) {
15.993 + if ((offset < 0) || (offset > length()))
15.994 + throw new StringIndexOutOfBoundsException(offset);
15.995 + int len = str.length;
15.996 + ensureCapacityInternal(count + len);
15.997 + arraycopy(value, offset, value, offset + len, count - offset);
15.998 + arraycopy(str, 0, value, offset, len);
15.999 + count += len;
15.1000 + return this;
15.1001 + }
15.1002 +
15.1003 + /**
15.1004 + * Inserts the specified {@code CharSequence} into this sequence.
15.1005 + * <p>
15.1006 + * The characters of the {@code CharSequence} argument are inserted,
15.1007 + * in order, into this sequence at the indicated offset, moving up
15.1008 + * any characters originally above that position and increasing the length
15.1009 + * of this sequence by the length of the argument s.
15.1010 + * <p>
15.1011 + * The result of this method is exactly the same as if it were an
15.1012 + * invocation of this object's
15.1013 + * {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length())
15.1014 + * method.
15.1015 + *
15.1016 + * <p>If {@code s} is {@code null}, then the four characters
15.1017 + * {@code "null"} are inserted into this sequence.
15.1018 + *
15.1019 + * @param dstOffset the offset.
15.1020 + * @param s the sequence to be inserted
15.1021 + * @return a reference to this object.
15.1022 + * @throws IndexOutOfBoundsException if the offset is invalid.
15.1023 + */
15.1024 + public AbstractStringBuilder insert(int dstOffset, CharSequence s) {
15.1025 + if (s == null)
15.1026 + s = "null";
15.1027 + if (s instanceof String)
15.1028 + return this.insert(dstOffset, (String)s);
15.1029 + return this.insert(dstOffset, s, 0, s.length());
15.1030 + }
15.1031 +
15.1032 + /**
15.1033 + * Inserts a subsequence of the specified {@code CharSequence} into
15.1034 + * this sequence.
15.1035 + * <p>
15.1036 + * The subsequence of the argument {@code s} specified by
15.1037 + * {@code start} and {@code end} are inserted,
15.1038 + * in order, into this sequence at the specified destination offset, moving
15.1039 + * up any characters originally above that position. The length of this
15.1040 + * sequence is increased by {@code end - start}.
15.1041 + * <p>
15.1042 + * The character at index <i>k</i> in this sequence becomes equal to:
15.1043 + * <ul>
15.1044 + * <li>the character at index <i>k</i> in this sequence, if
15.1045 + * <i>k</i> is less than {@code dstOffset}
15.1046 + * <li>the character at index <i>k</i>{@code +start-dstOffset} in
15.1047 + * the argument {@code s}, if <i>k</i> is greater than or equal to
15.1048 + * {@code dstOffset} but is less than {@code dstOffset+end-start}
15.1049 + * <li>the character at index <i>k</i>{@code -(end-start)} in this
15.1050 + * sequence, if <i>k</i> is greater than or equal to
15.1051 + * {@code dstOffset+end-start}
15.1052 + * </ul><p>
15.1053 + * The {@code dstOffset} argument must be greater than or equal to
15.1054 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1055 + * of this sequence.
15.1056 + * <p>The start argument must be nonnegative, and not greater than
15.1057 + * {@code end}.
15.1058 + * <p>The end argument must be greater than or equal to
15.1059 + * {@code start}, and less than or equal to the length of s.
15.1060 + *
15.1061 + * <p>If {@code s} is {@code null}, then this method inserts
15.1062 + * characters as if the s parameter was a sequence containing the four
15.1063 + * characters {@code "null"}.
15.1064 + *
15.1065 + * @param dstOffset the offset in this sequence.
15.1066 + * @param s the sequence to be inserted.
15.1067 + * @param start the starting index of the subsequence to be inserted.
15.1068 + * @param end the end index of the subsequence to be inserted.
15.1069 + * @return a reference to this object.
15.1070 + * @throws IndexOutOfBoundsException if {@code dstOffset}
15.1071 + * is negative or greater than {@code this.length()}, or
15.1072 + * {@code start} or {@code end} are negative, or
15.1073 + * {@code start} is greater than {@code end} or
15.1074 + * {@code end} is greater than {@code s.length()}
15.1075 + */
15.1076 + public AbstractStringBuilder insert(int dstOffset, CharSequence s,
15.1077 + int start, int end) {
15.1078 + if (s == null)
15.1079 + s = "null";
15.1080 + if ((dstOffset < 0) || (dstOffset > this.length()))
15.1081 + throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
15.1082 + if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
15.1083 + throw new IndexOutOfBoundsException(
15.1084 + "start " + start + ", end " + end + ", s.length() "
15.1085 + + s.length());
15.1086 + int len = end - start;
15.1087 + ensureCapacityInternal(count + len);
15.1088 + arraycopy(value, dstOffset, value, dstOffset + len,
15.1089 + count - dstOffset);
15.1090 + for (int i=start; i<end; i++)
15.1091 + value[dstOffset++] = s.charAt(i);
15.1092 + count += len;
15.1093 + return this;
15.1094 + }
15.1095 +
15.1096 + /**
15.1097 + * Inserts the string representation of the {@code boolean}
15.1098 + * argument into this sequence.
15.1099 + * <p>
15.1100 + * The overall effect is exactly as if the second argument were
15.1101 + * converted to a string by the method {@link String#valueOf(boolean)},
15.1102 + * and the characters of that string were then
15.1103 + * {@link #insert(int,String) inserted} into this character
15.1104 + * sequence at the indicated offset.
15.1105 + * <p>
15.1106 + * The {@code offset} argument must be greater than or equal to
15.1107 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1108 + * of this sequence.
15.1109 + *
15.1110 + * @param offset the offset.
15.1111 + * @param b a {@code boolean}.
15.1112 + * @return a reference to this object.
15.1113 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.1114 + */
15.1115 + public AbstractStringBuilder insert(int offset, boolean b) {
15.1116 + return insert(offset, String.valueOf(b));
15.1117 + }
15.1118 +
15.1119 + /**
15.1120 + * Inserts the string representation of the {@code char}
15.1121 + * argument into this sequence.
15.1122 + * <p>
15.1123 + * The overall effect is exactly as if the second argument were
15.1124 + * converted to a string by the method {@link String#valueOf(char)},
15.1125 + * and the character in that string were then
15.1126 + * {@link #insert(int,String) inserted} into this character
15.1127 + * sequence at the indicated offset.
15.1128 + * <p>
15.1129 + * The {@code offset} argument must be greater than or equal to
15.1130 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1131 + * of this sequence.
15.1132 + *
15.1133 + * @param offset the offset.
15.1134 + * @param c a {@code char}.
15.1135 + * @return a reference to this object.
15.1136 + * @throws IndexOutOfBoundsException if the offset is invalid.
15.1137 + */
15.1138 + public AbstractStringBuilder insert(int offset, char c) {
15.1139 + ensureCapacityInternal(count + 1);
15.1140 + arraycopy(value, offset, value, offset + 1, count - offset);
15.1141 + value[offset] = c;
15.1142 + count += 1;
15.1143 + return this;
15.1144 + }
15.1145 +
15.1146 + /**
15.1147 + * Inserts the string representation of the second {@code int}
15.1148 + * argument into this sequence.
15.1149 + * <p>
15.1150 + * The overall effect is exactly as if the second argument were
15.1151 + * converted to a string by the method {@link String#valueOf(int)},
15.1152 + * and the characters of that string were then
15.1153 + * {@link #insert(int,String) inserted} into this character
15.1154 + * sequence at the indicated offset.
15.1155 + * <p>
15.1156 + * The {@code offset} argument must be greater than or equal to
15.1157 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1158 + * of this sequence.
15.1159 + *
15.1160 + * @param offset the offset.
15.1161 + * @param i an {@code int}.
15.1162 + * @return a reference to this object.
15.1163 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.1164 + */
15.1165 + public AbstractStringBuilder insert(int offset, int i) {
15.1166 + return insert(offset, String.valueOf(i));
15.1167 + }
15.1168 +
15.1169 + /**
15.1170 + * Inserts the string representation of the {@code long}
15.1171 + * argument into this sequence.
15.1172 + * <p>
15.1173 + * The overall effect is exactly as if the second argument were
15.1174 + * converted to a string by the method {@link String#valueOf(long)},
15.1175 + * and the characters of that string were then
15.1176 + * {@link #insert(int,String) inserted} into this character
15.1177 + * sequence at the indicated offset.
15.1178 + * <p>
15.1179 + * The {@code offset} argument must be greater than or equal to
15.1180 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1181 + * of this sequence.
15.1182 + *
15.1183 + * @param offset the offset.
15.1184 + * @param l a {@code long}.
15.1185 + * @return a reference to this object.
15.1186 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.1187 + */
15.1188 + public AbstractStringBuilder insert(int offset, long l) {
15.1189 + return insert(offset, String.valueOf(l));
15.1190 + }
15.1191 +
15.1192 + /**
15.1193 + * Inserts the string representation of the {@code float}
15.1194 + * argument into this sequence.
15.1195 + * <p>
15.1196 + * The overall effect is exactly as if the second argument were
15.1197 + * converted to a string by the method {@link String#valueOf(float)},
15.1198 + * and the characters of that string were then
15.1199 + * {@link #insert(int,String) inserted} into this character
15.1200 + * sequence at the indicated offset.
15.1201 + * <p>
15.1202 + * The {@code offset} argument must be greater than or equal to
15.1203 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1204 + * of this sequence.
15.1205 + *
15.1206 + * @param offset the offset.
15.1207 + * @param f a {@code float}.
15.1208 + * @return a reference to this object.
15.1209 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.1210 + */
15.1211 + public AbstractStringBuilder insert(int offset, float f) {
15.1212 + return insert(offset, String.valueOf(f));
15.1213 + }
15.1214 +
15.1215 + /**
15.1216 + * Inserts the string representation of the {@code double}
15.1217 + * argument into this sequence.
15.1218 + * <p>
15.1219 + * The overall effect is exactly as if the second argument were
15.1220 + * converted to a string by the method {@link String#valueOf(double)},
15.1221 + * and the characters of that string were then
15.1222 + * {@link #insert(int,String) inserted} into this character
15.1223 + * sequence at the indicated offset.
15.1224 + * <p>
15.1225 + * The {@code offset} argument must be greater than or equal to
15.1226 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1227 + * of this sequence.
15.1228 + *
15.1229 + * @param offset the offset.
15.1230 + * @param d a {@code double}.
15.1231 + * @return a reference to this object.
15.1232 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.1233 + */
15.1234 + public AbstractStringBuilder insert(int offset, double d) {
15.1235 + return insert(offset, String.valueOf(d));
15.1236 + }
15.1237 +
15.1238 + /**
15.1239 + * Returns the index within this string of the first occurrence of the
15.1240 + * specified substring. The integer returned is the smallest value
15.1241 + * <i>k</i> such that:
15.1242 + * <blockquote><pre>
15.1243 + * this.toString().startsWith(str, <i>k</i>)
15.1244 + * </pre></blockquote>
15.1245 + * is <code>true</code>.
15.1246 + *
15.1247 + * @param str any string.
15.1248 + * @return if the string argument occurs as a substring within this
15.1249 + * object, then the index of the first character of the first
15.1250 + * such substring is returned; if it does not occur as a
15.1251 + * substring, <code>-1</code> is returned.
15.1252 + * @throws java.lang.NullPointerException if <code>str</code> is
15.1253 + * <code>null</code>.
15.1254 + */
15.1255 + public int indexOf(String str) {
15.1256 + return indexOf(str, 0);
15.1257 + }
15.1258 +
15.1259 + /**
15.1260 + * Returns the index within this string of the first occurrence of the
15.1261 + * specified substring, starting at the specified index. The integer
15.1262 + * returned is the smallest value <tt>k</tt> for which:
15.1263 + * <blockquote><pre>
15.1264 + * k >= Math.min(fromIndex, str.length()) &&
15.1265 + * this.toString().startsWith(str, k)
15.1266 + * </pre></blockquote>
15.1267 + * If no such value of <i>k</i> exists, then -1 is returned.
15.1268 + *
15.1269 + * @param str the substring for which to search.
15.1270 + * @param fromIndex the index from which to start the search.
15.1271 + * @return the index within this string of the first occurrence of the
15.1272 + * specified substring, starting at the specified index.
15.1273 + * @throws java.lang.NullPointerException if <code>str</code> is
15.1274 + * <code>null</code>.
15.1275 + */
15.1276 + public int indexOf(String str, int fromIndex) {
15.1277 + return toString().indexOf(str, fromIndex);
15.1278 + }
15.1279 +
15.1280 + /**
15.1281 + * Returns the index within this string of the rightmost occurrence
15.1282 + * of the specified substring. The rightmost empty string "" is
15.1283 + * considered to occur at the index value <code>this.length()</code>.
15.1284 + * The returned index is the largest value <i>k</i> such that
15.1285 + * <blockquote><pre>
15.1286 + * this.toString().startsWith(str, k)
15.1287 + * </pre></blockquote>
15.1288 + * is true.
15.1289 + *
15.1290 + * @param str the substring to search for.
15.1291 + * @return if the string argument occurs one or more times as a substring
15.1292 + * within this object, then the index of the first character of
15.1293 + * the last such substring is returned. If it does not occur as
15.1294 + * a substring, <code>-1</code> is returned.
15.1295 + * @throws java.lang.NullPointerException if <code>str</code> is
15.1296 + * <code>null</code>.
15.1297 + */
15.1298 + public int lastIndexOf(String str) {
15.1299 + return lastIndexOf(str, count);
15.1300 + }
15.1301 +
15.1302 + /**
15.1303 + * Returns the index within this string of the last occurrence of the
15.1304 + * specified substring. The integer returned is the largest value <i>k</i>
15.1305 + * such that:
15.1306 + * <blockquote><pre>
15.1307 + * k <= Math.min(fromIndex, str.length()) &&
15.1308 + * this.toString().startsWith(str, k)
15.1309 + * </pre></blockquote>
15.1310 + * If no such value of <i>k</i> exists, then -1 is returned.
15.1311 + *
15.1312 + * @param str the substring to search for.
15.1313 + * @param fromIndex the index to start the search from.
15.1314 + * @return the index within this sequence of the last occurrence of the
15.1315 + * specified substring.
15.1316 + * @throws java.lang.NullPointerException if <code>str</code> is
15.1317 + * <code>null</code>.
15.1318 + */
15.1319 + public int lastIndexOf(String str, int fromIndex) {
15.1320 + return String.lastIndexOf(value, 0, count,
15.1321 + str.toCharArray(), 0, str.length(), fromIndex);
15.1322 + }
15.1323 +
15.1324 + /**
15.1325 + * Causes this character sequence to be replaced by the reverse of
15.1326 + * the sequence. If there are any surrogate pairs included in the
15.1327 + * sequence, these are treated as single characters for the
15.1328 + * reverse operation. Thus, the order of the high-low surrogates
15.1329 + * is never reversed.
15.1330 + *
15.1331 + * Let <i>n</i> be the character length of this character sequence
15.1332 + * (not the length in <code>char</code> values) just prior to
15.1333 + * execution of the <code>reverse</code> method. Then the
15.1334 + * character at index <i>k</i> in the new character sequence is
15.1335 + * equal to the character at index <i>n-k-1</i> in the old
15.1336 + * character sequence.
15.1337 + *
15.1338 + * <p>Note that the reverse operation may result in producing
15.1339 + * surrogate pairs that were unpaired low-surrogates and
15.1340 + * high-surrogates before the operation. For example, reversing
15.1341 + * "\uDC00\uD800" produces "\uD800\uDC00" which is
15.1342 + * a valid surrogate pair.
15.1343 + *
15.1344 + * @return a reference to this object.
15.1345 + */
15.1346 + public AbstractStringBuilder reverse() {
15.1347 + boolean hasSurrogate = false;
15.1348 + int n = count - 1;
15.1349 + for (int j = (n-1) >> 1; j >= 0; --j) {
15.1350 + char temp = value[j];
15.1351 + char temp2 = value[n - j];
15.1352 + if (!hasSurrogate) {
15.1353 + hasSurrogate = (temp >= Character.MIN_SURROGATE && temp <= Character.MAX_SURROGATE)
15.1354 + || (temp2 >= Character.MIN_SURROGATE && temp2 <= Character.MAX_SURROGATE);
15.1355 + }
15.1356 + value[j] = temp2;
15.1357 + value[n - j] = temp;
15.1358 + }
15.1359 + if (hasSurrogate) {
15.1360 + // Reverse back all valid surrogate pairs
15.1361 + for (int i = 0; i < count - 1; i++) {
15.1362 + char c2 = value[i];
15.1363 + if (Character.isLowSurrogate(c2)) {
15.1364 + char c1 = value[i + 1];
15.1365 + if (Character.isHighSurrogate(c1)) {
15.1366 + value[i++] = c1;
15.1367 + value[i] = c2;
15.1368 + }
15.1369 + }
15.1370 + }
15.1371 + }
15.1372 + return this;
15.1373 + }
15.1374 +
15.1375 + /**
15.1376 + * Returns a string representing the data in this sequence.
15.1377 + * A new <code>String</code> object is allocated and initialized to
15.1378 + * contain the character sequence currently represented by this
15.1379 + * object. This <code>String</code> is then returned. Subsequent
15.1380 + * changes to this sequence do not affect the contents of the
15.1381 + * <code>String</code>.
15.1382 + *
15.1383 + * @return a string representation of this sequence of characters.
15.1384 + */
15.1385 + public abstract String toString();
15.1386 +
15.1387 + /**
15.1388 + * Needed by <tt>String</tt> for the contentEquals method.
15.1389 + */
15.1390 + final char[] getValue() {
15.1391 + return value;
15.1392 + }
15.1393 +
15.1394 + static char[] copyOfRange(char[] original, int from, int to) {
15.1395 + int newLength = to - from;
15.1396 + if (newLength < 0) {
15.1397 + throw new IllegalArgumentException(from + " > " + to);
15.1398 + }
15.1399 + char[] copy = new char[newLength];
15.1400 + arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
15.1401 + return copy;
15.1402 + }
15.1403 +
15.1404 + static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
15.1405 + if (srcBegin < dstBegin) {
15.1406 + while (count-- > 0) {
15.1407 + dst[dstBegin + count] = value[srcBegin + count];
15.1408 + }
15.1409 + } else {
15.1410 + while (count-- > 0) {
15.1411 + dst[dstBegin++] = value[srcBegin++];
15.1412 + }
15.1413 + }
15.1414 + }
15.1415 +
15.1416 + // access system property
15.1417 + static String getProperty(String nm) {
15.1418 + return null;
15.1419 + }
15.1420 +
15.1421 + static char[] copyOf(char[] original, int newLength) {
15.1422 + char[] copy = new char[newLength];
15.1423 + arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
15.1424 + return copy;
15.1425 + }
15.1426 +
15.1427 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/emul/mini/src/main/java/java/lang/Appendable.java Wed Jan 23 20:39:23 2013 +0100
16.3 @@ -0,0 +1,121 @@
16.4 +/*
16.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
16.7 + *
16.8 + * This code is free software; you can redistribute it and/or modify it
16.9 + * under the terms of the GNU General Public License version 2 only, as
16.10 + * published by the Free Software Foundation. Oracle designates this
16.11 + * particular file as subject to the "Classpath" exception as provided
16.12 + * by Oracle in the LICENSE file that accompanied this code.
16.13 + *
16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16.17 + * version 2 for more details (a copy is included in the LICENSE file that
16.18 + * accompanied this code).
16.19 + *
16.20 + * You should have received a copy of the GNU General Public License version
16.21 + * 2 along with this work; if not, write to the Free Software Foundation,
16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16.23 + *
16.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
16.25 + * or visit www.oracle.com if you need additional information or have any
16.26 + * questions.
16.27 + */
16.28 +
16.29 +package java.lang;
16.30 +
16.31 +import java.io.IOException;
16.32 +
16.33 +/**
16.34 + * An object to which <tt>char</tt> sequences and values can be appended. The
16.35 + * <tt>Appendable</tt> interface must be implemented by any class whose
16.36 + * instances are intended to receive formatted output from a {@link
16.37 + * java.util.Formatter}.
16.38 + *
16.39 + * <p> The characters to be appended should be valid Unicode characters as
16.40 + * described in <a href="Character.html#unicode">Unicode Character
16.41 + * Representation</a>. Note that supplementary characters may be composed of
16.42 + * multiple 16-bit <tt>char</tt> values.
16.43 + *
16.44 + * <p> Appendables are not necessarily safe for multithreaded access. Thread
16.45 + * safety is the responsibility of classes that extend and implement this
16.46 + * interface.
16.47 + *
16.48 + * <p> Since this interface may be implemented by existing classes
16.49 + * with different styles of error handling there is no guarantee that
16.50 + * errors will be propagated to the invoker.
16.51 + *
16.52 + * @since 1.5
16.53 + */
16.54 +public interface Appendable {
16.55 +
16.56 + /**
16.57 + * Appends the specified character sequence to this <tt>Appendable</tt>.
16.58 + *
16.59 + * <p> Depending on which class implements the character sequence
16.60 + * <tt>csq</tt>, the entire sequence may not be appended. For
16.61 + * instance, if <tt>csq</tt> is a {@link java.nio.CharBuffer} then
16.62 + * the subsequence to append is defined by the buffer's position and limit.
16.63 + *
16.64 + * @param csq
16.65 + * The character sequence to append. If <tt>csq</tt> is
16.66 + * <tt>null</tt>, then the four characters <tt>"null"</tt> are
16.67 + * appended to this Appendable.
16.68 + *
16.69 + * @return A reference to this <tt>Appendable</tt>
16.70 + *
16.71 + * @throws IOException
16.72 + * If an I/O error occurs
16.73 + */
16.74 + Appendable append(CharSequence csq) throws IOException;
16.75 +
16.76 + /**
16.77 + * Appends a subsequence of the specified character sequence to this
16.78 + * <tt>Appendable</tt>.
16.79 + *
16.80 + * <p> An invocation of this method of the form <tt>out.append(csq, start,
16.81 + * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
16.82 + * exactly the same way as the invocation
16.83 + *
16.84 + * <pre>
16.85 + * out.append(csq.subSequence(start, end)) </pre>
16.86 + *
16.87 + * @param csq
16.88 + * The character sequence from which a subsequence will be
16.89 + * appended. If <tt>csq</tt> is <tt>null</tt>, then characters
16.90 + * will be appended as if <tt>csq</tt> contained the four
16.91 + * characters <tt>"null"</tt>.
16.92 + *
16.93 + * @param start
16.94 + * The index of the first character in the subsequence
16.95 + *
16.96 + * @param end
16.97 + * The index of the character following the last character in the
16.98 + * subsequence
16.99 + *
16.100 + * @return A reference to this <tt>Appendable</tt>
16.101 + *
16.102 + * @throws IndexOutOfBoundsException
16.103 + * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
16.104 + * is greater than <tt>end</tt>, or <tt>end</tt> is greater than
16.105 + * <tt>csq.length()</tt>
16.106 + *
16.107 + * @throws IOException
16.108 + * If an I/O error occurs
16.109 + */
16.110 + Appendable append(CharSequence csq, int start, int end) throws IOException;
16.111 +
16.112 + /**
16.113 + * Appends the specified character to this <tt>Appendable</tt>.
16.114 + *
16.115 + * @param c
16.116 + * The character to append
16.117 + *
16.118 + * @return A reference to this <tt>Appendable</tt>
16.119 + *
16.120 + * @throws IOException
16.121 + * If an I/O error occurs
16.122 + */
16.123 + Appendable append(char c) throws IOException;
16.124 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/emul/mini/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java Wed Jan 23 20:39:23 2013 +0100
17.3 @@ -0,0 +1,67 @@
17.4 +/*
17.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17.7 + *
17.8 + * This code is free software; you can redistribute it and/or modify it
17.9 + * under the terms of the GNU General Public License version 2 only, as
17.10 + * published by the Free Software Foundation. Oracle designates this
17.11 + * particular file as subject to the "Classpath" exception as provided
17.12 + * by Oracle in the LICENSE file that accompanied this code.
17.13 + *
17.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
17.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17.17 + * version 2 for more details (a copy is included in the LICENSE file that
17.18 + * accompanied this code).
17.19 + *
17.20 + * You should have received a copy of the GNU General Public License version
17.21 + * 2 along with this work; if not, write to the Free Software Foundation,
17.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17.23 + *
17.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
17.25 + * or visit www.oracle.com if you need additional information or have any
17.26 + * questions.
17.27 + */
17.28 +
17.29 +package java.lang;
17.30 +
17.31 +/**
17.32 + * Thrown to indicate that an array has been accessed with an
17.33 + * illegal index. The index is either negative or greater than or
17.34 + * equal to the size of the array.
17.35 + *
17.36 + * @author unascribed
17.37 + * @since JDK1.0
17.38 + */
17.39 +public
17.40 +class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
17.41 + private static final long serialVersionUID = -5116101128118950844L;
17.42 +
17.43 + /**
17.44 + * Constructs an <code>ArrayIndexOutOfBoundsException</code> with no
17.45 + * detail message.
17.46 + */
17.47 + public ArrayIndexOutOfBoundsException() {
17.48 + super();
17.49 + }
17.50 +
17.51 + /**
17.52 + * Constructs a new <code>ArrayIndexOutOfBoundsException</code>
17.53 + * class with an argument indicating the illegal index.
17.54 + *
17.55 + * @param index the illegal index.
17.56 + */
17.57 + public ArrayIndexOutOfBoundsException(int index) {
17.58 + super("Array index out of range: " + index);
17.59 + }
17.60 +
17.61 + /**
17.62 + * Constructs an <code>ArrayIndexOutOfBoundsException</code> class
17.63 + * with the specified detail message.
17.64 + *
17.65 + * @param s the detail message.
17.66 + */
17.67 + public ArrayIndexOutOfBoundsException(String s) {
17.68 + super(s);
17.69 + }
17.70 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/emul/mini/src/main/java/java/lang/AssertionError.java Wed Jan 23 20:39:23 2013 +0100
18.3 @@ -0,0 +1,167 @@
18.4 +/*
18.5 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
18.7 + *
18.8 + * This code is free software; you can redistribute it and/or modify it
18.9 + * under the terms of the GNU General Public License version 2 only, as
18.10 + * published by the Free Software Foundation. Oracle designates this
18.11 + * particular file as subject to the "Classpath" exception as provided
18.12 + * by Oracle in the LICENSE file that accompanied this code.
18.13 + *
18.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
18.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18.17 + * version 2 for more details (a copy is included in the LICENSE file that
18.18 + * accompanied this code).
18.19 + *
18.20 + * You should have received a copy of the GNU General Public License version
18.21 + * 2 along with this work; if not, write to the Free Software Foundation,
18.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18.23 + *
18.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
18.25 + * or visit www.oracle.com if you need additional information or have any
18.26 + * questions.
18.27 + */
18.28 +
18.29 +package java.lang;
18.30 +
18.31 +/**
18.32 + * Thrown to indicate that an assertion has failed.
18.33 + *
18.34 + * <p>The seven one-argument public constructors provided by this
18.35 + * class ensure that the assertion error returned by the invocation:
18.36 + * <pre>
18.37 + * new AssertionError(<i>expression</i>)
18.38 + * </pre>
18.39 + * has as its detail message the <i>string conversion</i> of
18.40 + * <i>expression</i> (as defined in section 15.18.1.1 of
18.41 + * <cite>The Java™ Language Specification</cite>),
18.42 + * regardless of the type of <i>expression</i>.
18.43 + *
18.44 + * @since 1.4
18.45 + */
18.46 +public class AssertionError extends Error {
18.47 + private static final long serialVersionUID = -5013299493970297370L;
18.48 +
18.49 + /**
18.50 + * Constructs an AssertionError with no detail message.
18.51 + */
18.52 + public AssertionError() {
18.53 + }
18.54 +
18.55 + /**
18.56 + * This internal constructor does no processing on its string argument,
18.57 + * even if it is a null reference. The public constructors will
18.58 + * never call this constructor with a null argument.
18.59 + */
18.60 + private AssertionError(String detailMessage) {
18.61 + super(detailMessage);
18.62 + }
18.63 +
18.64 + /**
18.65 + * Constructs an AssertionError with its detail message derived
18.66 + * from the specified object, which is converted to a string as
18.67 + * defined in section 15.18.1.1 of
18.68 + * <cite>The Java™ Language Specification</cite>.
18.69 + *<p>
18.70 + * If the specified object is an instance of {@code Throwable}, it
18.71 + * becomes the <i>cause</i> of the newly constructed assertion error.
18.72 + *
18.73 + * @param detailMessage value to be used in constructing detail message
18.74 + * @see Throwable#getCause()
18.75 + */
18.76 + public AssertionError(Object detailMessage) {
18.77 + this("" + detailMessage);
18.78 + if (detailMessage instanceof Throwable)
18.79 + initCause((Throwable) detailMessage);
18.80 + }
18.81 +
18.82 + /**
18.83 + * Constructs an AssertionError with its detail message derived
18.84 + * from the specified <code>boolean</code>, which is converted to
18.85 + * a string as defined in section 15.18.1.1 of
18.86 + * <cite>The Java™ Language Specification</cite>.
18.87 + *
18.88 + * @param detailMessage value to be used in constructing detail message
18.89 + */
18.90 + public AssertionError(boolean detailMessage) {
18.91 + this("" + detailMessage);
18.92 + }
18.93 +
18.94 + /**
18.95 + * Constructs an AssertionError with its detail message derived
18.96 + * from the specified <code>char</code>, which is converted to a
18.97 + * string as defined in section 15.18.1.1 of
18.98 + * <cite>The Java™ Language Specification</cite>.
18.99 + *
18.100 + * @param detailMessage value to be used in constructing detail message
18.101 + */
18.102 + public AssertionError(char detailMessage) {
18.103 + this("" + detailMessage);
18.104 + }
18.105 +
18.106 + /**
18.107 + * Constructs an AssertionError with its detail message derived
18.108 + * from the specified <code>int</code>, which is converted to a
18.109 + * string as defined in section 15.18.1.1 of
18.110 + * <cite>The Java™ Language Specification</cite>.
18.111 + *
18.112 + * @param detailMessage value to be used in constructing detail message
18.113 + */
18.114 + public AssertionError(int detailMessage) {
18.115 + this("" + detailMessage);
18.116 + }
18.117 +
18.118 + /**
18.119 + * Constructs an AssertionError with its detail message derived
18.120 + * from the specified <code>long</code>, which is converted to a
18.121 + * string as defined in section 15.18.1.1 of
18.122 + * <cite>The Java™ Language Specification</cite>.
18.123 + *
18.124 + * @param detailMessage value to be used in constructing detail message
18.125 + */
18.126 + public AssertionError(long detailMessage) {
18.127 + this("" + detailMessage);
18.128 + }
18.129 +
18.130 + /**
18.131 + * Constructs an AssertionError with its detail message derived
18.132 + * from the specified <code>float</code>, which is converted to a
18.133 + * string as defined in section 15.18.1.1 of
18.134 + * <cite>The Java™ Language Specification</cite>.
18.135 + *
18.136 + * @param detailMessage value to be used in constructing detail message
18.137 + */
18.138 + public AssertionError(float detailMessage) {
18.139 + this("" + detailMessage);
18.140 + }
18.141 +
18.142 + /**
18.143 + * Constructs an AssertionError with its detail message derived
18.144 + * from the specified <code>double</code>, which is converted to a
18.145 + * string as defined in section 15.18.1.1 of
18.146 + * <cite>The Java™ Language Specification</cite>.
18.147 + *
18.148 + * @param detailMessage value to be used in constructing detail message
18.149 + */
18.150 + public AssertionError(double detailMessage) {
18.151 + this("" + detailMessage);
18.152 + }
18.153 +
18.154 + /**
18.155 + * Constructs a new {@code AssertionError} with the specified
18.156 + * detail message and cause.
18.157 + *
18.158 + * <p>Note that the detail message associated with
18.159 + * {@code cause} is <i>not</i> automatically incorporated in
18.160 + * this error's detail message.
18.161 + *
18.162 + * @param message the detail message, may be {@code null}
18.163 + * @param cause the cause, may be {@code null}
18.164 + *
18.165 + * @since 1.7
18.166 + */
18.167 + public AssertionError(String message, Throwable cause) {
18.168 + super(message, cause);
18.169 + }
18.170 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/emul/mini/src/main/java/java/lang/AutoCloseable.java Wed Jan 23 20:39:23 2013 +0100
19.3 @@ -0,0 +1,72 @@
19.4 +/*
19.5 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
19.7 + *
19.8 + * This code is free software; you can redistribute it and/or modify it
19.9 + * under the terms of the GNU General Public License version 2 only, as
19.10 + * published by the Free Software Foundation. Oracle designates this
19.11 + * particular file as subject to the "Classpath" exception as provided
19.12 + * by Oracle in the LICENSE file that accompanied this code.
19.13 + *
19.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
19.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19.17 + * version 2 for more details (a copy is included in the LICENSE file that
19.18 + * accompanied this code).
19.19 + *
19.20 + * You should have received a copy of the GNU General Public License version
19.21 + * 2 along with this work; if not, write to the Free Software Foundation,
19.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19.23 + *
19.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19.25 + * or visit www.oracle.com if you need additional information or have any
19.26 + * questions.
19.27 + */
19.28 +
19.29 +package java.lang;
19.30 +
19.31 +/**
19.32 + * A resource that must be closed when it is no longer needed.
19.33 + *
19.34 + * @author Josh Bloch
19.35 + * @since 1.7
19.36 + */
19.37 +public interface AutoCloseable {
19.38 + /**
19.39 + * Closes this resource, relinquishing any underlying resources.
19.40 + * This method is invoked automatically on objects managed by the
19.41 + * {@code try}-with-resources statement.
19.42 + *
19.43 + * <p>While this interface method is declared to throw {@code
19.44 + * Exception}, implementers are <em>strongly</em> encouraged to
19.45 + * declare concrete implementations of the {@code close} method to
19.46 + * throw more specific exceptions, or to throw no exception at all
19.47 + * if the close operation cannot fail.
19.48 + *
19.49 + * <p><em>Implementers of this interface are also strongly advised
19.50 + * to not have the {@code close} method throw {@link
19.51 + * InterruptedException}.</em>
19.52 + *
19.53 + * This exception interacts with a thread's interrupted status,
19.54 + * and runtime misbehavior is likely to occur if an {@code
19.55 + * InterruptedException} is {@linkplain Throwable#addSuppressed
19.56 + * suppressed}.
19.57 + *
19.58 + * More generally, if it would cause problems for an
19.59 + * exception to be suppressed, the {@code AutoCloseable.close}
19.60 + * method should not throw it.
19.61 + *
19.62 + * <p>Note that unlike the {@link java.io.Closeable#close close}
19.63 + * method of {@link java.io.Closeable}, this {@code close} method
19.64 + * is <em>not</em> required to be idempotent. In other words,
19.65 + * calling this {@code close} method more than once may have some
19.66 + * visible side effect, unlike {@code Closeable.close} which is
19.67 + * required to have no effect if called more than once.
19.68 + *
19.69 + * However, implementers of this interface are strongly encouraged
19.70 + * to make their {@code close} methods idempotent.
19.71 + *
19.72 + * @throws Exception if this resource cannot be closed
19.73 + */
19.74 + void close() throws Exception;
19.75 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/emul/mini/src/main/java/java/lang/Boolean.java Wed Jan 23 20:39:23 2013 +0100
20.3 @@ -0,0 +1,282 @@
20.4 +/*
20.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
20.7 + *
20.8 + * This code is free software; you can redistribute it and/or modify it
20.9 + * under the terms of the GNU General Public License version 2 only, as
20.10 + * published by the Free Software Foundation. Oracle designates this
20.11 + * particular file as subject to the "Classpath" exception as provided
20.12 + * by Oracle in the LICENSE file that accompanied this code.
20.13 + *
20.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
20.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20.17 + * version 2 for more details (a copy is included in the LICENSE file that
20.18 + * accompanied this code).
20.19 + *
20.20 + * You should have received a copy of the GNU General Public License version
20.21 + * 2 along with this work; if not, write to the Free Software Foundation,
20.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20.23 + *
20.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20.25 + * or visit www.oracle.com if you need additional information or have any
20.26 + * questions.
20.27 + */
20.28 +
20.29 +package java.lang;
20.30 +
20.31 +/**
20.32 + * The Boolean class wraps a value of the primitive type
20.33 + * {@code boolean} in an object. An object of type
20.34 + * {@code Boolean} contains a single field whose type is
20.35 + * {@code boolean}.
20.36 + * <p>
20.37 + * In addition, this class provides many methods for
20.38 + * converting a {@code boolean} to a {@code String} and a
20.39 + * {@code String} to a {@code boolean}, as well as other
20.40 + * constants and methods useful when dealing with a
20.41 + * {@code boolean}.
20.42 + *
20.43 + * @author Arthur van Hoff
20.44 + * @since JDK1.0
20.45 + */
20.46 +public final class Boolean implements java.io.Serializable,
20.47 + Comparable<Boolean>
20.48 +{
20.49 + /**
20.50 + * The {@code Boolean} object corresponding to the primitive
20.51 + * value {@code true}.
20.52 + */
20.53 + public static final Boolean TRUE = new Boolean(true);
20.54 +
20.55 + /**
20.56 + * The {@code Boolean} object corresponding to the primitive
20.57 + * value {@code false}.
20.58 + */
20.59 + public static final Boolean FALSE = new Boolean(false);
20.60 +
20.61 + /**
20.62 + * The Class object representing the primitive type boolean.
20.63 + *
20.64 + * @since JDK1.1
20.65 + */
20.66 + public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean");
20.67 +
20.68 + /**
20.69 + * The value of the Boolean.
20.70 + *
20.71 + * @serial
20.72 + */
20.73 + private final boolean value;
20.74 +
20.75 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
20.76 + private static final long serialVersionUID = -3665804199014368530L;
20.77 +
20.78 + /**
20.79 + * Allocates a {@code Boolean} object representing the
20.80 + * {@code value} argument.
20.81 + *
20.82 + * <p><b>Note: It is rarely appropriate to use this constructor.
20.83 + * Unless a <i>new</i> instance is required, the static factory
20.84 + * {@link #valueOf(boolean)} is generally a better choice. It is
20.85 + * likely to yield significantly better space and time performance.</b>
20.86 + *
20.87 + * @param value the value of the {@code Boolean}.
20.88 + */
20.89 + public Boolean(boolean value) {
20.90 + this.value = value;
20.91 + }
20.92 +
20.93 + /**
20.94 + * Allocates a {@code Boolean} object representing the value
20.95 + * {@code true} if the string argument is not {@code null}
20.96 + * and is equal, ignoring case, to the string {@code "true"}.
20.97 + * Otherwise, allocate a {@code Boolean} object representing the
20.98 + * value {@code false}. Examples:<p>
20.99 + * {@code new Boolean("True")} produces a {@code Boolean} object
20.100 + * that represents {@code true}.<br>
20.101 + * {@code new Boolean("yes")} produces a {@code Boolean} object
20.102 + * that represents {@code false}.
20.103 + *
20.104 + * @param s the string to be converted to a {@code Boolean}.
20.105 + */
20.106 + public Boolean(String s) {
20.107 + this(toBoolean(s));
20.108 + }
20.109 +
20.110 + /**
20.111 + * Parses the string argument as a boolean. The {@code boolean}
20.112 + * returned represents the value {@code true} if the string argument
20.113 + * is not {@code null} and is equal, ignoring case, to the string
20.114 + * {@code "true"}. <p>
20.115 + * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
20.116 + * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
20.117 + *
20.118 + * @param s the {@code String} containing the boolean
20.119 + * representation to be parsed
20.120 + * @return the boolean represented by the string argument
20.121 + * @since 1.5
20.122 + */
20.123 + public static boolean parseBoolean(String s) {
20.124 + return toBoolean(s);
20.125 + }
20.126 +
20.127 + /**
20.128 + * Returns the value of this {@code Boolean} object as a boolean
20.129 + * primitive.
20.130 + *
20.131 + * @return the primitive {@code boolean} value of this object.
20.132 + */
20.133 + public boolean booleanValue() {
20.134 + return value;
20.135 + }
20.136 +
20.137 + /**
20.138 + * Returns a {@code Boolean} instance representing the specified
20.139 + * {@code boolean} value. If the specified {@code boolean} value
20.140 + * is {@code true}, this method returns {@code Boolean.TRUE};
20.141 + * if it is {@code false}, this method returns {@code Boolean.FALSE}.
20.142 + * If a new {@code Boolean} instance is not required, this method
20.143 + * should generally be used in preference to the constructor
20.144 + * {@link #Boolean(boolean)}, as this method is likely to yield
20.145 + * significantly better space and time performance.
20.146 + *
20.147 + * @param b a boolean value.
20.148 + * @return a {@code Boolean} instance representing {@code b}.
20.149 + * @since 1.4
20.150 + */
20.151 + public static Boolean valueOf(boolean b) {
20.152 + return (b ? TRUE : FALSE);
20.153 + }
20.154 +
20.155 + /**
20.156 + * Returns a {@code Boolean} with a value represented by the
20.157 + * specified string. The {@code Boolean} returned represents a
20.158 + * true value if the string argument is not {@code null}
20.159 + * and is equal, ignoring case, to the string {@code "true"}.
20.160 + *
20.161 + * @param s a string.
20.162 + * @return the {@code Boolean} value represented by the string.
20.163 + */
20.164 + public static Boolean valueOf(String s) {
20.165 + return toBoolean(s) ? TRUE : FALSE;
20.166 + }
20.167 +
20.168 + /**
20.169 + * Returns a {@code String} object representing the specified
20.170 + * boolean. If the specified boolean is {@code true}, then
20.171 + * the string {@code "true"} will be returned, otherwise the
20.172 + * string {@code "false"} will be returned.
20.173 + *
20.174 + * @param b the boolean to be converted
20.175 + * @return the string representation of the specified {@code boolean}
20.176 + * @since 1.4
20.177 + */
20.178 + public static String toString(boolean b) {
20.179 + return b ? "true" : "false";
20.180 + }
20.181 +
20.182 + /**
20.183 + * Returns a {@code String} object representing this Boolean's
20.184 + * value. If this object represents the value {@code true},
20.185 + * a string equal to {@code "true"} is returned. Otherwise, a
20.186 + * string equal to {@code "false"} is returned.
20.187 + *
20.188 + * @return a string representation of this object.
20.189 + */
20.190 + public String toString() {
20.191 + return value ? "true" : "false";
20.192 + }
20.193 +
20.194 + /**
20.195 + * Returns a hash code for this {@code Boolean} object.
20.196 + *
20.197 + * @return the integer {@code 1231} if this object represents
20.198 + * {@code true}; returns the integer {@code 1237} if this
20.199 + * object represents {@code false}.
20.200 + */
20.201 + public int hashCode() {
20.202 + return value ? 1231 : 1237;
20.203 + }
20.204 +
20.205 + /**
20.206 + * Returns {@code true} if and only if the argument is not
20.207 + * {@code null} and is a {@code Boolean} object that
20.208 + * represents the same {@code boolean} value as this object.
20.209 + *
20.210 + * @param obj the object to compare with.
20.211 + * @return {@code true} if the Boolean objects represent the
20.212 + * same value; {@code false} otherwise.
20.213 + */
20.214 + public boolean equals(Object obj) {
20.215 + if (obj instanceof Boolean) {
20.216 + return value == ((Boolean)obj).booleanValue();
20.217 + }
20.218 + return false;
20.219 + }
20.220 +
20.221 + /**
20.222 + * Returns {@code true} if and only if the system property
20.223 + * named by the argument exists and is equal to the string
20.224 + * {@code "true"}. (Beginning with version 1.0.2 of the
20.225 + * Java<small><sup>TM</sup></small> platform, the test of
20.226 + * this string is case insensitive.) A system property is accessible
20.227 + * through {@code getProperty}, a method defined by the
20.228 + * {@code System} class.
20.229 + * <p>
20.230 + * If there is no property with the specified name, or if the specified
20.231 + * name is empty or null, then {@code false} is returned.
20.232 + *
20.233 + * @param name the system property name.
20.234 + * @return the {@code boolean} value of the system property.
20.235 + * @see java.lang.System#getProperty(java.lang.String)
20.236 + * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
20.237 + */
20.238 + public static boolean getBoolean(String name) {
20.239 + boolean result = false;
20.240 + try {
20.241 + result = toBoolean(AbstractStringBuilder.getProperty(name));
20.242 + } catch (IllegalArgumentException e) {
20.243 + } catch (NullPointerException e) {
20.244 + }
20.245 + return result;
20.246 + }
20.247 +
20.248 + /**
20.249 + * Compares this {@code Boolean} instance with another.
20.250 + *
20.251 + * @param b the {@code Boolean} instance to be compared
20.252 + * @return zero if this object represents the same boolean value as the
20.253 + * argument; a positive value if this object represents true
20.254 + * and the argument represents false; and a negative value if
20.255 + * this object represents false and the argument represents true
20.256 + * @throws NullPointerException if the argument is {@code null}
20.257 + * @see Comparable
20.258 + * @since 1.5
20.259 + */
20.260 + public int compareTo(Boolean b) {
20.261 + return compare(this.value, b.value);
20.262 + }
20.263 +
20.264 + /**
20.265 + * Compares two {@code boolean} values.
20.266 + * The value returned is identical to what would be returned by:
20.267 + * <pre>
20.268 + * Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
20.269 + * </pre>
20.270 + *
20.271 + * @param x the first {@code boolean} to compare
20.272 + * @param y the second {@code boolean} to compare
20.273 + * @return the value {@code 0} if {@code x == y};
20.274 + * a value less than {@code 0} if {@code !x && y}; and
20.275 + * a value greater than {@code 0} if {@code x && !y}
20.276 + * @since 1.7
20.277 + */
20.278 + public static int compare(boolean x, boolean y) {
20.279 + return (x == y) ? 0 : (x ? 1 : -1);
20.280 + }
20.281 +
20.282 + private static boolean toBoolean(String name) {
20.283 + return ((name != null) && name.equalsIgnoreCase("true"));
20.284 + }
20.285 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
21.2 +++ b/emul/mini/src/main/java/java/lang/Byte.java Wed Jan 23 20:39:23 2013 +0100
21.3 @@ -0,0 +1,452 @@
21.4 +/*
21.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
21.7 + *
21.8 + * This code is free software; you can redistribute it and/or modify it
21.9 + * under the terms of the GNU General Public License version 2 only, as
21.10 + * published by the Free Software Foundation. Oracle designates this
21.11 + * particular file as subject to the "Classpath" exception as provided
21.12 + * by Oracle in the LICENSE file that accompanied this code.
21.13 + *
21.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
21.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21.17 + * version 2 for more details (a copy is included in the LICENSE file that
21.18 + * accompanied this code).
21.19 + *
21.20 + * You should have received a copy of the GNU General Public License version
21.21 + * 2 along with this work; if not, write to the Free Software Foundation,
21.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21.23 + *
21.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21.25 + * or visit www.oracle.com if you need additional information or have any
21.26 + * questions.
21.27 + */
21.28 +
21.29 +package java.lang;
21.30 +
21.31 +/**
21.32 + *
21.33 + * The {@code Byte} class wraps a value of primitive type {@code byte}
21.34 + * in an object. An object of type {@code Byte} contains a single
21.35 + * field whose type is {@code byte}.
21.36 + *
21.37 + * <p>In addition, this class provides several methods for converting
21.38 + * a {@code byte} to a {@code String} and a {@code String} to a {@code
21.39 + * byte}, as well as other constants and methods useful when dealing
21.40 + * with a {@code byte}.
21.41 + *
21.42 + * @author Nakul Saraiya
21.43 + * @author Joseph D. Darcy
21.44 + * @see java.lang.Number
21.45 + * @since JDK1.1
21.46 + */
21.47 +public final class Byte extends Number implements Comparable<Byte> {
21.48 +
21.49 + /**
21.50 + * A constant holding the minimum value a {@code byte} can
21.51 + * have, -2<sup>7</sup>.
21.52 + */
21.53 + public static final byte MIN_VALUE = -128;
21.54 +
21.55 + /**
21.56 + * A constant holding the maximum value a {@code byte} can
21.57 + * have, 2<sup>7</sup>-1.
21.58 + */
21.59 + public static final byte MAX_VALUE = 127;
21.60 +
21.61 + /**
21.62 + * The {@code Class} instance representing the primitive type
21.63 + * {@code byte}.
21.64 + */
21.65 + public static final Class<Byte> TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
21.66 +
21.67 + /**
21.68 + * Returns a new {@code String} object representing the
21.69 + * specified {@code byte}. The radix is assumed to be 10.
21.70 + *
21.71 + * @param b the {@code byte} to be converted
21.72 + * @return the string representation of the specified {@code byte}
21.73 + * @see java.lang.Integer#toString(int)
21.74 + */
21.75 + public static String toString(byte b) {
21.76 + return Integer.toString((int)b, 10);
21.77 + }
21.78 +
21.79 + private static class ByteCache {
21.80 + private ByteCache(){}
21.81 +
21.82 + static final Byte cache[] = new Byte[-(-128) + 127 + 1];
21.83 +
21.84 + static {
21.85 + for(int i = 0; i < cache.length; i++)
21.86 + cache[i] = new Byte((byte)(i - 128));
21.87 + }
21.88 + }
21.89 +
21.90 + /**
21.91 + * Returns a {@code Byte} instance representing the specified
21.92 + * {@code byte} value.
21.93 + * If a new {@code Byte} instance is not required, this method
21.94 + * should generally be used in preference to the constructor
21.95 + * {@link #Byte(byte)}, as this method is likely to yield
21.96 + * significantly better space and time performance since
21.97 + * all byte values are cached.
21.98 + *
21.99 + * @param b a byte value.
21.100 + * @return a {@code Byte} instance representing {@code b}.
21.101 + * @since 1.5
21.102 + */
21.103 + public static Byte valueOf(byte b) {
21.104 + final int offset = 128;
21.105 + return ByteCache.cache[(int)b + offset];
21.106 + }
21.107 +
21.108 + /**
21.109 + * Parses the string argument as a signed {@code byte} in the
21.110 + * radix specified by the second argument. The characters in the
21.111 + * string must all be digits, of the specified radix (as
21.112 + * determined by whether {@link java.lang.Character#digit(char,
21.113 + * int)} returns a nonnegative value) except that the first
21.114 + * character may be an ASCII minus sign {@code '-'}
21.115 + * (<code>'\u002D'</code>) to indicate a negative value or an
21.116 + * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
21.117 + * indicate a positive value. The resulting {@code byte} value is
21.118 + * returned.
21.119 + *
21.120 + * <p>An exception of type {@code NumberFormatException} is
21.121 + * thrown if any of the following situations occurs:
21.122 + * <ul>
21.123 + * <li> The first argument is {@code null} or is a string of
21.124 + * length zero.
21.125 + *
21.126 + * <li> The radix is either smaller than {@link
21.127 + * java.lang.Character#MIN_RADIX} or larger than {@link
21.128 + * java.lang.Character#MAX_RADIX}.
21.129 + *
21.130 + * <li> Any character of the string is not a digit of the
21.131 + * specified radix, except that the first character may be a minus
21.132 + * sign {@code '-'} (<code>'\u002D'</code>) or plus sign
21.133 + * {@code '+'} (<code>'\u002B'</code>) provided that the
21.134 + * string is longer than length 1.
21.135 + *
21.136 + * <li> The value represented by the string is not a value of type
21.137 + * {@code byte}.
21.138 + * </ul>
21.139 + *
21.140 + * @param s the {@code String} containing the
21.141 + * {@code byte}
21.142 + * representation to be parsed
21.143 + * @param radix the radix to be used while parsing {@code s}
21.144 + * @return the {@code byte} value represented by the string
21.145 + * argument in the specified radix
21.146 + * @throws NumberFormatException If the string does
21.147 + * not contain a parsable {@code byte}.
21.148 + */
21.149 + public static byte parseByte(String s, int radix)
21.150 + throws NumberFormatException {
21.151 + int i = Integer.parseInt(s, radix);
21.152 + if (i < MIN_VALUE || i > MAX_VALUE)
21.153 + throw new NumberFormatException(
21.154 + "Value out of range. Value:\"" + s + "\" Radix:" + radix);
21.155 + return (byte)i;
21.156 + }
21.157 +
21.158 + /**
21.159 + * Parses the string argument as a signed decimal {@code
21.160 + * byte}. The characters in the string must all be decimal digits,
21.161 + * except that the first character may be an ASCII minus sign
21.162 + * {@code '-'} (<code>'\u002D'</code>) to indicate a negative
21.163 + * value or an ASCII plus sign {@code '+'}
21.164 + * (<code>'\u002B'</code>) to indicate a positive value. The
21.165 + * resulting {@code byte} value is returned, exactly as if the
21.166 + * argument and the radix 10 were given as arguments to the {@link
21.167 + * #parseByte(java.lang.String, int)} method.
21.168 + *
21.169 + * @param s a {@code String} containing the
21.170 + * {@code byte} representation to be parsed
21.171 + * @return the {@code byte} value represented by the
21.172 + * argument in decimal
21.173 + * @throws NumberFormatException if the string does not
21.174 + * contain a parsable {@code byte}.
21.175 + */
21.176 + public static byte parseByte(String s) throws NumberFormatException {
21.177 + return parseByte(s, 10);
21.178 + }
21.179 +
21.180 + /**
21.181 + * Returns a {@code Byte} object holding the value
21.182 + * extracted from the specified {@code String} when parsed
21.183 + * with the radix given by the second argument. The first argument
21.184 + * is interpreted as representing a signed {@code byte} in
21.185 + * the radix specified by the second argument, exactly as if the
21.186 + * argument were given to the {@link #parseByte(java.lang.String,
21.187 + * int)} method. The result is a {@code Byte} object that
21.188 + * represents the {@code byte} value specified by the string.
21.189 + *
21.190 + * <p> In other words, this method returns a {@code Byte} object
21.191 + * equal to the value of:
21.192 + *
21.193 + * <blockquote>
21.194 + * {@code new Byte(Byte.parseByte(s, radix))}
21.195 + * </blockquote>
21.196 + *
21.197 + * @param s the string to be parsed
21.198 + * @param radix the radix to be used in interpreting {@code s}
21.199 + * @return a {@code Byte} object holding the value
21.200 + * represented by the string argument in the
21.201 + * specified radix.
21.202 + * @throws NumberFormatException If the {@code String} does
21.203 + * not contain a parsable {@code byte}.
21.204 + */
21.205 + public static Byte valueOf(String s, int radix)
21.206 + throws NumberFormatException {
21.207 + return valueOf(parseByte(s, radix));
21.208 + }
21.209 +
21.210 + /**
21.211 + * Returns a {@code Byte} object holding the value
21.212 + * given by the specified {@code String}. The argument is
21.213 + * interpreted as representing a signed decimal {@code byte},
21.214 + * exactly as if the argument were given to the {@link
21.215 + * #parseByte(java.lang.String)} method. The result is a
21.216 + * {@code Byte} object that represents the {@code byte}
21.217 + * value specified by the string.
21.218 + *
21.219 + * <p> In other words, this method returns a {@code Byte} object
21.220 + * equal to the value of:
21.221 + *
21.222 + * <blockquote>
21.223 + * {@code new Byte(Byte.parseByte(s))}
21.224 + * </blockquote>
21.225 + *
21.226 + * @param s the string to be parsed
21.227 + * @return a {@code Byte} object holding the value
21.228 + * represented by the string argument
21.229 + * @throws NumberFormatException If the {@code String} does
21.230 + * not contain a parsable {@code byte}.
21.231 + */
21.232 + public static Byte valueOf(String s) throws NumberFormatException {
21.233 + return valueOf(s, 10);
21.234 + }
21.235 +
21.236 + /**
21.237 + * Decodes a {@code String} into a {@code Byte}.
21.238 + * Accepts decimal, hexadecimal, and octal numbers given by
21.239 + * the following grammar:
21.240 + *
21.241 + * <blockquote>
21.242 + * <dl>
21.243 + * <dt><i>DecodableString:</i>
21.244 + * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
21.245 + * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
21.246 + * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
21.247 + * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
21.248 + * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
21.249 + * <p>
21.250 + * <dt><i>Sign:</i>
21.251 + * <dd>{@code -}
21.252 + * <dd>{@code +}
21.253 + * </dl>
21.254 + * </blockquote>
21.255 + *
21.256 + * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
21.257 + * are as defined in section 3.10.1 of
21.258 + * <cite>The Java™ Language Specification</cite>,
21.259 + * except that underscores are not accepted between digits.
21.260 + *
21.261 + * <p>The sequence of characters following an optional
21.262 + * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
21.263 + * "{@code #}", or leading zero) is parsed as by the {@code
21.264 + * Byte.parseByte} method with the indicated radix (10, 16, or 8).
21.265 + * This sequence of characters must represent a positive value or
21.266 + * a {@link NumberFormatException} will be thrown. The result is
21.267 + * negated if first character of the specified {@code String} is
21.268 + * the minus sign. No whitespace characters are permitted in the
21.269 + * {@code String}.
21.270 + *
21.271 + * @param nm the {@code String} to decode.
21.272 + * @return a {@code Byte} object holding the {@code byte}
21.273 + * value represented by {@code nm}
21.274 + * @throws NumberFormatException if the {@code String} does not
21.275 + * contain a parsable {@code byte}.
21.276 + * @see java.lang.Byte#parseByte(java.lang.String, int)
21.277 + */
21.278 + public static Byte decode(String nm) throws NumberFormatException {
21.279 + int i = Integer.decode(nm);
21.280 + if (i < MIN_VALUE || i > MAX_VALUE)
21.281 + throw new NumberFormatException(
21.282 + "Value " + i + " out of range from input " + nm);
21.283 + return valueOf((byte)i);
21.284 + }
21.285 +
21.286 + /**
21.287 + * The value of the {@code Byte}.
21.288 + *
21.289 + * @serial
21.290 + */
21.291 + private final byte value;
21.292 +
21.293 + /**
21.294 + * Constructs a newly allocated {@code Byte} object that
21.295 + * represents the specified {@code byte} value.
21.296 + *
21.297 + * @param value the value to be represented by the
21.298 + * {@code Byte}.
21.299 + */
21.300 + public Byte(byte value) {
21.301 + this.value = value;
21.302 + }
21.303 +
21.304 + /**
21.305 + * Constructs a newly allocated {@code Byte} object that
21.306 + * represents the {@code byte} value indicated by the
21.307 + * {@code String} parameter. The string is converted to a
21.308 + * {@code byte} value in exactly the manner used by the
21.309 + * {@code parseByte} method for radix 10.
21.310 + *
21.311 + * @param s the {@code String} to be converted to a
21.312 + * {@code Byte}
21.313 + * @throws NumberFormatException If the {@code String}
21.314 + * does not contain a parsable {@code byte}.
21.315 + * @see java.lang.Byte#parseByte(java.lang.String, int)
21.316 + */
21.317 + public Byte(String s) throws NumberFormatException {
21.318 + this.value = parseByte(s, 10);
21.319 + }
21.320 +
21.321 + /**
21.322 + * Returns the value of this {@code Byte} as a
21.323 + * {@code byte}.
21.324 + */
21.325 + public byte byteValue() {
21.326 + return value;
21.327 + }
21.328 +
21.329 + /**
21.330 + * Returns the value of this {@code Byte} as a
21.331 + * {@code short}.
21.332 + */
21.333 + public short shortValue() {
21.334 + return (short)value;
21.335 + }
21.336 +
21.337 + /**
21.338 + * Returns the value of this {@code Byte} as an
21.339 + * {@code int}.
21.340 + */
21.341 + public int intValue() {
21.342 + return (int)value;
21.343 + }
21.344 +
21.345 + /**
21.346 + * Returns the value of this {@code Byte} as a
21.347 + * {@code long}.
21.348 + */
21.349 + public long longValue() {
21.350 + return (long)value;
21.351 + }
21.352 +
21.353 + /**
21.354 + * Returns the value of this {@code Byte} as a
21.355 + * {@code float}.
21.356 + */
21.357 + public float floatValue() {
21.358 + return (float)value;
21.359 + }
21.360 +
21.361 + /**
21.362 + * Returns the value of this {@code Byte} as a
21.363 + * {@code double}.
21.364 + */
21.365 + public double doubleValue() {
21.366 + return (double)value;
21.367 + }
21.368 +
21.369 + /**
21.370 + * Returns a {@code String} object representing this
21.371 + * {@code Byte}'s value. The value is converted to signed
21.372 + * decimal representation and returned as a string, exactly as if
21.373 + * the {@code byte} value were given as an argument to the
21.374 + * {@link java.lang.Byte#toString(byte)} method.
21.375 + *
21.376 + * @return a string representation of the value of this object in
21.377 + * base 10.
21.378 + */
21.379 + public String toString() {
21.380 + return Integer.toString((int)value);
21.381 + }
21.382 +
21.383 + /**
21.384 + * Returns a hash code for this {@code Byte}; equal to the result
21.385 + * of invoking {@code intValue()}.
21.386 + *
21.387 + * @return a hash code value for this {@code Byte}
21.388 + */
21.389 + public int hashCode() {
21.390 + return (int)value;
21.391 + }
21.392 +
21.393 + /**
21.394 + * Compares this object to the specified object. The result is
21.395 + * {@code true} if and only if the argument is not
21.396 + * {@code null} and is a {@code Byte} object that
21.397 + * contains the same {@code byte} value as this object.
21.398 + *
21.399 + * @param obj the object to compare with
21.400 + * @return {@code true} if the objects are the same;
21.401 + * {@code false} otherwise.
21.402 + */
21.403 + public boolean equals(Object obj) {
21.404 + if (obj instanceof Byte) {
21.405 + return value == ((Byte)obj).byteValue();
21.406 + }
21.407 + return false;
21.408 + }
21.409 +
21.410 + /**
21.411 + * Compares two {@code Byte} objects numerically.
21.412 + *
21.413 + * @param anotherByte the {@code Byte} to be compared.
21.414 + * @return the value {@code 0} if this {@code Byte} is
21.415 + * equal to the argument {@code Byte}; a value less than
21.416 + * {@code 0} if this {@code Byte} is numerically less
21.417 + * than the argument {@code Byte}; and a value greater than
21.418 + * {@code 0} if this {@code Byte} is numerically
21.419 + * greater than the argument {@code Byte} (signed
21.420 + * comparison).
21.421 + * @since 1.2
21.422 + */
21.423 + public int compareTo(Byte anotherByte) {
21.424 + return compare(this.value, anotherByte.value);
21.425 + }
21.426 +
21.427 + /**
21.428 + * Compares two {@code byte} values numerically.
21.429 + * The value returned is identical to what would be returned by:
21.430 + * <pre>
21.431 + * Byte.valueOf(x).compareTo(Byte.valueOf(y))
21.432 + * </pre>
21.433 + *
21.434 + * @param x the first {@code byte} to compare
21.435 + * @param y the second {@code byte} to compare
21.436 + * @return the value {@code 0} if {@code x == y};
21.437 + * a value less than {@code 0} if {@code x < y}; and
21.438 + * a value greater than {@code 0} if {@code x > y}
21.439 + * @since 1.7
21.440 + */
21.441 + public static int compare(byte x, byte y) {
21.442 + return x - y;
21.443 + }
21.444 +
21.445 + /**
21.446 + * The number of bits used to represent a {@code byte} value in two's
21.447 + * complement binary form.
21.448 + *
21.449 + * @since 1.5
21.450 + */
21.451 + public static final int SIZE = 8;
21.452 +
21.453 + /** use serialVersionUID from JDK 1.1. for interoperability */
21.454 + private static final long serialVersionUID = -7183698231559129828L;
21.455 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
22.2 +++ b/emul/mini/src/main/java/java/lang/CharSequence.java Wed Jan 23 20:39:23 2013 +0100
22.3 @@ -0,0 +1,111 @@
22.4 +/*
22.5 + * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
22.7 + *
22.8 + * This code is free software; you can redistribute it and/or modify it
22.9 + * under the terms of the GNU General Public License version 2 only, as
22.10 + * published by the Free Software Foundation. Oracle designates this
22.11 + * particular file as subject to the "Classpath" exception as provided
22.12 + * by Oracle in the LICENSE file that accompanied this code.
22.13 + *
22.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
22.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22.17 + * version 2 for more details (a copy is included in the LICENSE file that
22.18 + * accompanied this code).
22.19 + *
22.20 + * You should have received a copy of the GNU General Public License version
22.21 + * 2 along with this work; if not, write to the Free Software Foundation,
22.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22.23 + *
22.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22.25 + * or visit www.oracle.com if you need additional information or have any
22.26 + * questions.
22.27 + */
22.28 +
22.29 +package java.lang;
22.30 +
22.31 +
22.32 +/**
22.33 + * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
22.34 + * interface provides uniform, read-only access to many different kinds of
22.35 + * <code>char</code> sequences.
22.36 + * A <code>char</code> value represents a character in the <i>Basic
22.37 + * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
22.38 + * href="Character.html#unicode">Unicode Character Representation</a> for details.
22.39 + *
22.40 + * <p> This interface does not refine the general contracts of the {@link
22.41 + * java.lang.Object#equals(java.lang.Object) equals} and {@link
22.42 + * java.lang.Object#hashCode() hashCode} methods. The result of comparing two
22.43 + * objects that implement <tt>CharSequence</tt> is therefore, in general,
22.44 + * undefined. Each object may be implemented by a different class, and there
22.45 + * is no guarantee that each class will be capable of testing its instances
22.46 + * for equality with those of the other. It is therefore inappropriate to use
22.47 + * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
22.48 + * a map. </p>
22.49 + *
22.50 + * @author Mike McCloskey
22.51 + * @since 1.4
22.52 + * @spec JSR-51
22.53 + */
22.54 +
22.55 +public interface CharSequence {
22.56 +
22.57 + /**
22.58 + * Returns the length of this character sequence. The length is the number
22.59 + * of 16-bit <code>char</code>s in the sequence.</p>
22.60 + *
22.61 + * @return the number of <code>char</code>s in this sequence
22.62 + */
22.63 + int length();
22.64 +
22.65 + /**
22.66 + * Returns the <code>char</code> value at the specified index. An index ranges from zero
22.67 + * to <tt>length() - 1</tt>. The first <code>char</code> value of the sequence is at
22.68 + * index zero, the next at index one, and so on, as for array
22.69 + * indexing. </p>
22.70 + *
22.71 + * <p>If the <code>char</code> value specified by the index is a
22.72 + * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
22.73 + * value is returned.
22.74 + *
22.75 + * @param index the index of the <code>char</code> value to be returned
22.76 + *
22.77 + * @return the specified <code>char</code> value
22.78 + *
22.79 + * @throws IndexOutOfBoundsException
22.80 + * if the <tt>index</tt> argument is negative or not less than
22.81 + * <tt>length()</tt>
22.82 + */
22.83 + char charAt(int index);
22.84 +
22.85 + /**
22.86 + * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
22.87 + * The subsequence starts with the <code>char</code> value at the specified index and
22.88 + * ends with the <code>char</code> value at index <tt>end - 1</tt>. The length
22.89 + * (in <code>char</code>s) of the
22.90 + * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
22.91 + * then an empty sequence is returned. </p>
22.92 + *
22.93 + * @param start the start index, inclusive
22.94 + * @param end the end index, exclusive
22.95 + *
22.96 + * @return the specified subsequence
22.97 + *
22.98 + * @throws IndexOutOfBoundsException
22.99 + * if <tt>start</tt> or <tt>end</tt> are negative,
22.100 + * if <tt>end</tt> is greater than <tt>length()</tt>,
22.101 + * or if <tt>start</tt> is greater than <tt>end</tt>
22.102 + */
22.103 + CharSequence subSequence(int start, int end);
22.104 +
22.105 + /**
22.106 + * Returns a string containing the characters in this sequence in the same
22.107 + * order as this sequence. The length of the string will be the length of
22.108 + * this sequence. </p>
22.109 + *
22.110 + * @return a string consisting of exactly this sequence of characters
22.111 + */
22.112 + public String toString();
22.113 +
22.114 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
23.2 +++ b/emul/mini/src/main/java/java/lang/Character.java Wed Jan 23 20:39:23 2013 +0100
23.3 @@ -0,0 +1,2382 @@
23.4 +/*
23.5 + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
23.7 + *
23.8 + * This code is free software; you can redistribute it and/or modify it
23.9 + * under the terms of the GNU General Public License version 2 only, as
23.10 + * published by the Free Software Foundation. Oracle designates this
23.11 + * particular file as subject to the "Classpath" exception as provided
23.12 + * by Oracle in the LICENSE file that accompanied this code.
23.13 + *
23.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
23.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23.17 + * version 2 for more details (a copy is included in the LICENSE file that
23.18 + * accompanied this code).
23.19 + *
23.20 + * You should have received a copy of the GNU General Public License version
23.21 + * 2 along with this work; if not, write to the Free Software Foundation,
23.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23.23 + *
23.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23.25 + * or visit www.oracle.com if you need additional information or have any
23.26 + * questions.
23.27 + */
23.28 +
23.29 +package java.lang;
23.30 +
23.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
23.32 +
23.33 +/**
23.34 + * The {@code Character} class wraps a value of the primitive
23.35 + * type {@code char} in an object. An object of type
23.36 + * {@code Character} contains a single field whose type is
23.37 + * {@code char}.
23.38 + * <p>
23.39 + * In addition, this class provides several methods for determining
23.40 + * a character's category (lowercase letter, digit, etc.) and for converting
23.41 + * characters from uppercase to lowercase and vice versa.
23.42 + * <p>
23.43 + * Character information is based on the Unicode Standard, version 6.0.0.
23.44 + * <p>
23.45 + * The methods and data of class {@code Character} are defined by
23.46 + * the information in the <i>UnicodeData</i> file that is part of the
23.47 + * Unicode Character Database maintained by the Unicode
23.48 + * Consortium. This file specifies various properties including name
23.49 + * and general category for every defined Unicode code point or
23.50 + * character range.
23.51 + * <p>
23.52 + * The file and its description are available from the Unicode Consortium at:
23.53 + * <ul>
23.54 + * <li><a href="http://www.unicode.org">http://www.unicode.org</a>
23.55 + * </ul>
23.56 + *
23.57 + * <h4><a name="unicode">Unicode Character Representations</a></h4>
23.58 + *
23.59 + * <p>The {@code char} data type (and therefore the value that a
23.60 + * {@code Character} object encapsulates) are based on the
23.61 + * original Unicode specification, which defined characters as
23.62 + * fixed-width 16-bit entities. The Unicode Standard has since been
23.63 + * changed to allow for characters whose representation requires more
23.64 + * than 16 bits. The range of legal <em>code point</em>s is now
23.65 + * U+0000 to U+10FFFF, known as <em>Unicode scalar value</em>.
23.66 + * (Refer to the <a
23.67 + * href="http://www.unicode.org/reports/tr27/#notation"><i>
23.68 + * definition</i></a> of the U+<i>n</i> notation in the Unicode
23.69 + * Standard.)
23.70 + *
23.71 + * <p><a name="BMP">The set of characters from U+0000 to U+FFFF is
23.72 + * sometimes referred to as the <em>Basic Multilingual Plane (BMP)</em>.
23.73 + * <a name="supplementary">Characters</a> whose code points are greater
23.74 + * than U+FFFF are called <em>supplementary character</em>s. The Java
23.75 + * platform uses the UTF-16 representation in {@code char} arrays and
23.76 + * in the {@code String} and {@code StringBuffer} classes. In
23.77 + * this representation, supplementary characters are represented as a pair
23.78 + * of {@code char} values, the first from the <em>high-surrogates</em>
23.79 + * range, (\uD800-\uDBFF), the second from the
23.80 + * <em>low-surrogates</em> range (\uDC00-\uDFFF).
23.81 + *
23.82 + * <p>A {@code char} value, therefore, represents Basic
23.83 + * Multilingual Plane (BMP) code points, including the surrogate
23.84 + * code points, or code units of the UTF-16 encoding. An
23.85 + * {@code int} value represents all Unicode code points,
23.86 + * including supplementary code points. The lower (least significant)
23.87 + * 21 bits of {@code int} are used to represent Unicode code
23.88 + * points and the upper (most significant) 11 bits must be zero.
23.89 + * Unless otherwise specified, the behavior with respect to
23.90 + * supplementary characters and surrogate {@code char} values is
23.91 + * as follows:
23.92 + *
23.93 + * <ul>
23.94 + * <li>The methods that only accept a {@code char} value cannot support
23.95 + * supplementary characters. They treat {@code char} values from the
23.96 + * surrogate ranges as undefined characters. For example,
23.97 + * {@code Character.isLetter('\u005CuD840')} returns {@code false}, even though
23.98 + * this specific value if followed by any low-surrogate value in a string
23.99 + * would represent a letter.
23.100 + *
23.101 + * <li>The methods that accept an {@code int} value support all
23.102 + * Unicode characters, including supplementary characters. For
23.103 + * example, {@code Character.isLetter(0x2F81A)} returns
23.104 + * {@code true} because the code point value represents a letter
23.105 + * (a CJK ideograph).
23.106 + * </ul>
23.107 + *
23.108 + * <p>In the Java SE API documentation, <em>Unicode code point</em> is
23.109 + * used for character values in the range between U+0000 and U+10FFFF,
23.110 + * and <em>Unicode code unit</em> is used for 16-bit
23.111 + * {@code char} values that are code units of the <em>UTF-16</em>
23.112 + * encoding. For more information on Unicode terminology, refer to the
23.113 + * <a href="http://www.unicode.org/glossary/">Unicode Glossary</a>.
23.114 + *
23.115 + * @author Lee Boynton
23.116 + * @author Guy Steele
23.117 + * @author Akira Tanaka
23.118 + * @author Martin Buchholz
23.119 + * @author Ulf Zibis
23.120 + * @since 1.0
23.121 + */
23.122 +public final
23.123 +class Character implements java.io.Serializable, Comparable<Character> {
23.124 + /**
23.125 + * The minimum radix available for conversion to and from strings.
23.126 + * The constant value of this field is the smallest value permitted
23.127 + * for the radix argument in radix-conversion methods such as the
23.128 + * {@code digit} method, the {@code forDigit} method, and the
23.129 + * {@code toString} method of class {@code Integer}.
23.130 + *
23.131 + * @see Character#digit(char, int)
23.132 + * @see Character#forDigit(int, int)
23.133 + * @see Integer#toString(int, int)
23.134 + * @see Integer#valueOf(String)
23.135 + */
23.136 + public static final int MIN_RADIX = 2;
23.137 +
23.138 + /**
23.139 + * The maximum radix available for conversion to and from strings.
23.140 + * The constant value of this field is the largest value permitted
23.141 + * for the radix argument in radix-conversion methods such as the
23.142 + * {@code digit} method, the {@code forDigit} method, and the
23.143 + * {@code toString} method of class {@code Integer}.
23.144 + *
23.145 + * @see Character#digit(char, int)
23.146 + * @see Character#forDigit(int, int)
23.147 + * @see Integer#toString(int, int)
23.148 + * @see Integer#valueOf(String)
23.149 + */
23.150 + public static final int MAX_RADIX = 36;
23.151 +
23.152 + /**
23.153 + * The constant value of this field is the smallest value of type
23.154 + * {@code char}, {@code '\u005Cu0000'}.
23.155 + *
23.156 + * @since 1.0.2
23.157 + */
23.158 + public static final char MIN_VALUE = '\u0000';
23.159 +
23.160 + /**
23.161 + * The constant value of this field is the largest value of type
23.162 + * {@code char}, {@code '\u005CuFFFF'}.
23.163 + *
23.164 + * @since 1.0.2
23.165 + */
23.166 + public static final char MAX_VALUE = '\uFFFF';
23.167 +
23.168 + /**
23.169 + * The {@code Class} instance representing the primitive type
23.170 + * {@code char}.
23.171 + *
23.172 + * @since 1.1
23.173 + */
23.174 + public static final Class<Character> TYPE = Class.getPrimitiveClass("char");
23.175 +
23.176 + /*
23.177 + * Normative general types
23.178 + */
23.179 +
23.180 + /*
23.181 + * General character types
23.182 + */
23.183 +
23.184 + /**
23.185 + * General category "Cn" in the Unicode specification.
23.186 + * @since 1.1
23.187 + */
23.188 + public static final byte UNASSIGNED = 0;
23.189 +
23.190 + /**
23.191 + * General category "Lu" in the Unicode specification.
23.192 + * @since 1.1
23.193 + */
23.194 + public static final byte UPPERCASE_LETTER = 1;
23.195 +
23.196 + /**
23.197 + * General category "Ll" in the Unicode specification.
23.198 + * @since 1.1
23.199 + */
23.200 + public static final byte LOWERCASE_LETTER = 2;
23.201 +
23.202 + /**
23.203 + * General category "Lt" in the Unicode specification.
23.204 + * @since 1.1
23.205 + */
23.206 + public static final byte TITLECASE_LETTER = 3;
23.207 +
23.208 + /**
23.209 + * General category "Lm" in the Unicode specification.
23.210 + * @since 1.1
23.211 + */
23.212 + public static final byte MODIFIER_LETTER = 4;
23.213 +
23.214 + /**
23.215 + * General category "Lo" in the Unicode specification.
23.216 + * @since 1.1
23.217 + */
23.218 + public static final byte OTHER_LETTER = 5;
23.219 +
23.220 + /**
23.221 + * General category "Mn" in the Unicode specification.
23.222 + * @since 1.1
23.223 + */
23.224 + public static final byte NON_SPACING_MARK = 6;
23.225 +
23.226 + /**
23.227 + * General category "Me" in the Unicode specification.
23.228 + * @since 1.1
23.229 + */
23.230 + public static final byte ENCLOSING_MARK = 7;
23.231 +
23.232 + /**
23.233 + * General category "Mc" in the Unicode specification.
23.234 + * @since 1.1
23.235 + */
23.236 + public static final byte COMBINING_SPACING_MARK = 8;
23.237 +
23.238 + /**
23.239 + * General category "Nd" in the Unicode specification.
23.240 + * @since 1.1
23.241 + */
23.242 + public static final byte DECIMAL_DIGIT_NUMBER = 9;
23.243 +
23.244 + /**
23.245 + * General category "Nl" in the Unicode specification.
23.246 + * @since 1.1
23.247 + */
23.248 + public static final byte LETTER_NUMBER = 10;
23.249 +
23.250 + /**
23.251 + * General category "No" in the Unicode specification.
23.252 + * @since 1.1
23.253 + */
23.254 + public static final byte OTHER_NUMBER = 11;
23.255 +
23.256 + /**
23.257 + * General category "Zs" in the Unicode specification.
23.258 + * @since 1.1
23.259 + */
23.260 + public static final byte SPACE_SEPARATOR = 12;
23.261 +
23.262 + /**
23.263 + * General category "Zl" in the Unicode specification.
23.264 + * @since 1.1
23.265 + */
23.266 + public static final byte LINE_SEPARATOR = 13;
23.267 +
23.268 + /**
23.269 + * General category "Zp" in the Unicode specification.
23.270 + * @since 1.1
23.271 + */
23.272 + public static final byte PARAGRAPH_SEPARATOR = 14;
23.273 +
23.274 + /**
23.275 + * General category "Cc" in the Unicode specification.
23.276 + * @since 1.1
23.277 + */
23.278 + public static final byte CONTROL = 15;
23.279 +
23.280 + /**
23.281 + * General category "Cf" in the Unicode specification.
23.282 + * @since 1.1
23.283 + */
23.284 + public static final byte FORMAT = 16;
23.285 +
23.286 + /**
23.287 + * General category "Co" in the Unicode specification.
23.288 + * @since 1.1
23.289 + */
23.290 + public static final byte PRIVATE_USE = 18;
23.291 +
23.292 + /**
23.293 + * General category "Cs" in the Unicode specification.
23.294 + * @since 1.1
23.295 + */
23.296 + public static final byte SURROGATE = 19;
23.297 +
23.298 + /**
23.299 + * General category "Pd" in the Unicode specification.
23.300 + * @since 1.1
23.301 + */
23.302 + public static final byte DASH_PUNCTUATION = 20;
23.303 +
23.304 + /**
23.305 + * General category "Ps" in the Unicode specification.
23.306 + * @since 1.1
23.307 + */
23.308 + public static final byte START_PUNCTUATION = 21;
23.309 +
23.310 + /**
23.311 + * General category "Pe" in the Unicode specification.
23.312 + * @since 1.1
23.313 + */
23.314 + public static final byte END_PUNCTUATION = 22;
23.315 +
23.316 + /**
23.317 + * General category "Pc" in the Unicode specification.
23.318 + * @since 1.1
23.319 + */
23.320 + public static final byte CONNECTOR_PUNCTUATION = 23;
23.321 +
23.322 + /**
23.323 + * General category "Po" in the Unicode specification.
23.324 + * @since 1.1
23.325 + */
23.326 + public static final byte OTHER_PUNCTUATION = 24;
23.327 +
23.328 + /**
23.329 + * General category "Sm" in the Unicode specification.
23.330 + * @since 1.1
23.331 + */
23.332 + public static final byte MATH_SYMBOL = 25;
23.333 +
23.334 + /**
23.335 + * General category "Sc" in the Unicode specification.
23.336 + * @since 1.1
23.337 + */
23.338 + public static final byte CURRENCY_SYMBOL = 26;
23.339 +
23.340 + /**
23.341 + * General category "Sk" in the Unicode specification.
23.342 + * @since 1.1
23.343 + */
23.344 + public static final byte MODIFIER_SYMBOL = 27;
23.345 +
23.346 + /**
23.347 + * General category "So" in the Unicode specification.
23.348 + * @since 1.1
23.349 + */
23.350 + public static final byte OTHER_SYMBOL = 28;
23.351 +
23.352 + /**
23.353 + * General category "Pi" in the Unicode specification.
23.354 + * @since 1.4
23.355 + */
23.356 + public static final byte INITIAL_QUOTE_PUNCTUATION = 29;
23.357 +
23.358 + /**
23.359 + * General category "Pf" in the Unicode specification.
23.360 + * @since 1.4
23.361 + */
23.362 + public static final byte FINAL_QUOTE_PUNCTUATION = 30;
23.363 +
23.364 + /**
23.365 + * Error flag. Use int (code point) to avoid confusion with U+FFFF.
23.366 + */
23.367 + static final int ERROR = 0xFFFFFFFF;
23.368 +
23.369 +
23.370 + /**
23.371 + * Undefined bidirectional character type. Undefined {@code char}
23.372 + * values have undefined directionality in the Unicode specification.
23.373 + * @since 1.4
23.374 + */
23.375 + public static final byte DIRECTIONALITY_UNDEFINED = -1;
23.376 +
23.377 + /**
23.378 + * Strong bidirectional character type "L" in the Unicode specification.
23.379 + * @since 1.4
23.380 + */
23.381 + public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0;
23.382 +
23.383 + /**
23.384 + * Strong bidirectional character type "R" in the Unicode specification.
23.385 + * @since 1.4
23.386 + */
23.387 + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1;
23.388 +
23.389 + /**
23.390 + * Strong bidirectional character type "AL" in the Unicode specification.
23.391 + * @since 1.4
23.392 + */
23.393 + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2;
23.394 +
23.395 + /**
23.396 + * Weak bidirectional character type "EN" in the Unicode specification.
23.397 + * @since 1.4
23.398 + */
23.399 + public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3;
23.400 +
23.401 + /**
23.402 + * Weak bidirectional character type "ES" in the Unicode specification.
23.403 + * @since 1.4
23.404 + */
23.405 + public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4;
23.406 +
23.407 + /**
23.408 + * Weak bidirectional character type "ET" in the Unicode specification.
23.409 + * @since 1.4
23.410 + */
23.411 + public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5;
23.412 +
23.413 + /**
23.414 + * Weak bidirectional character type "AN" in the Unicode specification.
23.415 + * @since 1.4
23.416 + */
23.417 + public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6;
23.418 +
23.419 + /**
23.420 + * Weak bidirectional character type "CS" in the Unicode specification.
23.421 + * @since 1.4
23.422 + */
23.423 + public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7;
23.424 +
23.425 + /**
23.426 + * Weak bidirectional character type "NSM" in the Unicode specification.
23.427 + * @since 1.4
23.428 + */
23.429 + public static final byte DIRECTIONALITY_NONSPACING_MARK = 8;
23.430 +
23.431 + /**
23.432 + * Weak bidirectional character type "BN" in the Unicode specification.
23.433 + * @since 1.4
23.434 + */
23.435 + public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9;
23.436 +
23.437 + /**
23.438 + * Neutral bidirectional character type "B" in the Unicode specification.
23.439 + * @since 1.4
23.440 + */
23.441 + public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10;
23.442 +
23.443 + /**
23.444 + * Neutral bidirectional character type "S" in the Unicode specification.
23.445 + * @since 1.4
23.446 + */
23.447 + public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11;
23.448 +
23.449 + /**
23.450 + * Neutral bidirectional character type "WS" in the Unicode specification.
23.451 + * @since 1.4
23.452 + */
23.453 + public static final byte DIRECTIONALITY_WHITESPACE = 12;
23.454 +
23.455 + /**
23.456 + * Neutral bidirectional character type "ON" in the Unicode specification.
23.457 + * @since 1.4
23.458 + */
23.459 + public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13;
23.460 +
23.461 + /**
23.462 + * Strong bidirectional character type "LRE" in the Unicode specification.
23.463 + * @since 1.4
23.464 + */
23.465 + public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14;
23.466 +
23.467 + /**
23.468 + * Strong bidirectional character type "LRO" in the Unicode specification.
23.469 + * @since 1.4
23.470 + */
23.471 + public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15;
23.472 +
23.473 + /**
23.474 + * Strong bidirectional character type "RLE" in the Unicode specification.
23.475 + * @since 1.4
23.476 + */
23.477 + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16;
23.478 +
23.479 + /**
23.480 + * Strong bidirectional character type "RLO" in the Unicode specification.
23.481 + * @since 1.4
23.482 + */
23.483 + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17;
23.484 +
23.485 + /**
23.486 + * Weak bidirectional character type "PDF" in the Unicode specification.
23.487 + * @since 1.4
23.488 + */
23.489 + public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;
23.490 +
23.491 + /**
23.492 + * The minimum value of a
23.493 + * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
23.494 + * Unicode high-surrogate code unit</a>
23.495 + * in the UTF-16 encoding, constant {@code '\u005CuD800'}.
23.496 + * A high-surrogate is also known as a <i>leading-surrogate</i>.
23.497 + *
23.498 + * @since 1.5
23.499 + */
23.500 + public static final char MIN_HIGH_SURROGATE = '\uD800';
23.501 +
23.502 + /**
23.503 + * The maximum value of a
23.504 + * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
23.505 + * Unicode high-surrogate code unit</a>
23.506 + * in the UTF-16 encoding, constant {@code '\u005CuDBFF'}.
23.507 + * A high-surrogate is also known as a <i>leading-surrogate</i>.
23.508 + *
23.509 + * @since 1.5
23.510 + */
23.511 + public static final char MAX_HIGH_SURROGATE = '\uDBFF';
23.512 +
23.513 + /**
23.514 + * The minimum value of a
23.515 + * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
23.516 + * Unicode low-surrogate code unit</a>
23.517 + * in the UTF-16 encoding, constant {@code '\u005CuDC00'}.
23.518 + * A low-surrogate is also known as a <i>trailing-surrogate</i>.
23.519 + *
23.520 + * @since 1.5
23.521 + */
23.522 + public static final char MIN_LOW_SURROGATE = '\uDC00';
23.523 +
23.524 + /**
23.525 + * The maximum value of a
23.526 + * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
23.527 + * Unicode low-surrogate code unit</a>
23.528 + * in the UTF-16 encoding, constant {@code '\u005CuDFFF'}.
23.529 + * A low-surrogate is also known as a <i>trailing-surrogate</i>.
23.530 + *
23.531 + * @since 1.5
23.532 + */
23.533 + public static final char MAX_LOW_SURROGATE = '\uDFFF';
23.534 +
23.535 + /**
23.536 + * The minimum value of a Unicode surrogate code unit in the
23.537 + * UTF-16 encoding, constant {@code '\u005CuD800'}.
23.538 + *
23.539 + * @since 1.5
23.540 + */
23.541 + public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
23.542 +
23.543 + /**
23.544 + * The maximum value of a Unicode surrogate code unit in the
23.545 + * UTF-16 encoding, constant {@code '\u005CuDFFF'}.
23.546 + *
23.547 + * @since 1.5
23.548 + */
23.549 + public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
23.550 +
23.551 + /**
23.552 + * The minimum value of a
23.553 + * <a href="http://www.unicode.org/glossary/#supplementary_code_point">
23.554 + * Unicode supplementary code point</a>, constant {@code U+10000}.
23.555 + *
23.556 + * @since 1.5
23.557 + */
23.558 + public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000;
23.559 +
23.560 + /**
23.561 + * The minimum value of a
23.562 + * <a href="http://www.unicode.org/glossary/#code_point">
23.563 + * Unicode code point</a>, constant {@code U+0000}.
23.564 + *
23.565 + * @since 1.5
23.566 + */
23.567 + public static final int MIN_CODE_POINT = 0x000000;
23.568 +
23.569 + /**
23.570 + * The maximum value of a
23.571 + * <a href="http://www.unicode.org/glossary/#code_point">
23.572 + * Unicode code point</a>, constant {@code U+10FFFF}.
23.573 + *
23.574 + * @since 1.5
23.575 + */
23.576 + public static final int MAX_CODE_POINT = 0X10FFFF;
23.577 +
23.578 +
23.579 + /**
23.580 + * Instances of this class represent particular subsets of the Unicode
23.581 + * character set. The only family of subsets defined in the
23.582 + * {@code Character} class is {@link Character.UnicodeBlock}.
23.583 + * Other portions of the Java API may define other subsets for their
23.584 + * own purposes.
23.585 + *
23.586 + * @since 1.2
23.587 + */
23.588 + public static class Subset {
23.589 +
23.590 + private String name;
23.591 +
23.592 + /**
23.593 + * Constructs a new {@code Subset} instance.
23.594 + *
23.595 + * @param name The name of this subset
23.596 + * @exception NullPointerException if name is {@code null}
23.597 + */
23.598 + protected Subset(String name) {
23.599 + if (name == null) {
23.600 + throw new NullPointerException("name");
23.601 + }
23.602 + this.name = name;
23.603 + }
23.604 +
23.605 + /**
23.606 + * Compares two {@code Subset} objects for equality.
23.607 + * This method returns {@code true} if and only if
23.608 + * {@code this} and the argument refer to the same
23.609 + * object; since this method is {@code final}, this
23.610 + * guarantee holds for all subclasses.
23.611 + */
23.612 + public final boolean equals(Object obj) {
23.613 + return (this == obj);
23.614 + }
23.615 +
23.616 + /**
23.617 + * Returns the standard hash code as defined by the
23.618 + * {@link Object#hashCode} method. This method
23.619 + * is {@code final} in order to ensure that the
23.620 + * {@code equals} and {@code hashCode} methods will
23.621 + * be consistent in all subclasses.
23.622 + */
23.623 + public final int hashCode() {
23.624 + return super.hashCode();
23.625 + }
23.626 +
23.627 + /**
23.628 + * Returns the name of this subset.
23.629 + */
23.630 + public final String toString() {
23.631 + return name;
23.632 + }
23.633 + }
23.634 +
23.635 + // See http://www.unicode.org/Public/UNIDATA/Blocks.txt
23.636 + // for the latest specification of Unicode Blocks.
23.637 +
23.638 +
23.639 + /**
23.640 + * The value of the {@code Character}.
23.641 + *
23.642 + * @serial
23.643 + */
23.644 + private final char value;
23.645 +
23.646 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
23.647 + private static final long serialVersionUID = 3786198910865385080L;
23.648 +
23.649 + /**
23.650 + * Constructs a newly allocated {@code Character} object that
23.651 + * represents the specified {@code char} value.
23.652 + *
23.653 + * @param value the value to be represented by the
23.654 + * {@code Character} object.
23.655 + */
23.656 + public Character(char value) {
23.657 + this.value = value;
23.658 + }
23.659 +
23.660 + private static class CharacterCache {
23.661 + private CharacterCache(){}
23.662 +
23.663 + static final Character cache[] = new Character[127 + 1];
23.664 +
23.665 + static {
23.666 + for (int i = 0; i < cache.length; i++)
23.667 + cache[i] = new Character((char)i);
23.668 + }
23.669 + }
23.670 +
23.671 + /**
23.672 + * Returns a <tt>Character</tt> instance representing the specified
23.673 + * <tt>char</tt> value.
23.674 + * If a new <tt>Character</tt> instance is not required, this method
23.675 + * should generally be used in preference to the constructor
23.676 + * {@link #Character(char)}, as this method is likely to yield
23.677 + * significantly better space and time performance by caching
23.678 + * frequently requested values.
23.679 + *
23.680 + * This method will always cache values in the range {@code
23.681 + * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
23.682 + * cache other values outside of this range.
23.683 + *
23.684 + * @param c a char value.
23.685 + * @return a <tt>Character</tt> instance representing <tt>c</tt>.
23.686 + * @since 1.5
23.687 + */
23.688 + public static Character valueOf(char c) {
23.689 + if (c <= 127) { // must cache
23.690 + return CharacterCache.cache[(int)c];
23.691 + }
23.692 + return new Character(c);
23.693 + }
23.694 +
23.695 + /**
23.696 + * Returns the value of this {@code Character} object.
23.697 + * @return the primitive {@code char} value represented by
23.698 + * this object.
23.699 + */
23.700 + public char charValue() {
23.701 + return value;
23.702 + }
23.703 +
23.704 + /**
23.705 + * Returns a hash code for this {@code Character}; equal to the result
23.706 + * of invoking {@code charValue()}.
23.707 + *
23.708 + * @return a hash code value for this {@code Character}
23.709 + */
23.710 + public int hashCode() {
23.711 + return (int)value;
23.712 + }
23.713 +
23.714 + /**
23.715 + * Compares this object against the specified object.
23.716 + * The result is {@code true} if and only if the argument is not
23.717 + * {@code null} and is a {@code Character} object that
23.718 + * represents the same {@code char} value as this object.
23.719 + *
23.720 + * @param obj the object to compare with.
23.721 + * @return {@code true} if the objects are the same;
23.722 + * {@code false} otherwise.
23.723 + */
23.724 + public boolean equals(Object obj) {
23.725 + if (obj instanceof Character) {
23.726 + return value == ((Character)obj).charValue();
23.727 + }
23.728 + return false;
23.729 + }
23.730 +
23.731 + /**
23.732 + * Returns a {@code String} object representing this
23.733 + * {@code Character}'s value. The result is a string of
23.734 + * length 1 whose sole component is the primitive
23.735 + * {@code char} value represented by this
23.736 + * {@code Character} object.
23.737 + *
23.738 + * @return a string representation of this object.
23.739 + */
23.740 + public String toString() {
23.741 + char buf[] = {value};
23.742 + return String.valueOf(buf);
23.743 + }
23.744 +
23.745 + /**
23.746 + * Returns a {@code String} object representing the
23.747 + * specified {@code char}. The result is a string of length
23.748 + * 1 consisting solely of the specified {@code char}.
23.749 + *
23.750 + * @param c the {@code char} to be converted
23.751 + * @return the string representation of the specified {@code char}
23.752 + * @since 1.4
23.753 + */
23.754 + public static String toString(char c) {
23.755 + return String.valueOf(c);
23.756 + }
23.757 +
23.758 + /**
23.759 + * Determines whether the specified code point is a valid
23.760 + * <a href="http://www.unicode.org/glossary/#code_point">
23.761 + * Unicode code point value</a>.
23.762 + *
23.763 + * @param codePoint the Unicode code point to be tested
23.764 + * @return {@code true} if the specified code point value is between
23.765 + * {@link #MIN_CODE_POINT} and
23.766 + * {@link #MAX_CODE_POINT} inclusive;
23.767 + * {@code false} otherwise.
23.768 + * @since 1.5
23.769 + */
23.770 + public static boolean isValidCodePoint(int codePoint) {
23.771 + // Optimized form of:
23.772 + // codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
23.773 + int plane = codePoint >>> 16;
23.774 + return plane < ((MAX_CODE_POINT + 1) >>> 16);
23.775 + }
23.776 +
23.777 + /**
23.778 + * Determines whether the specified character (Unicode code point)
23.779 + * is in the <a href="#BMP">Basic Multilingual Plane (BMP)</a>.
23.780 + * Such code points can be represented using a single {@code char}.
23.781 + *
23.782 + * @param codePoint the character (Unicode code point) to be tested
23.783 + * @return {@code true} if the specified code point is between
23.784 + * {@link #MIN_VALUE} and {@link #MAX_VALUE} inclusive;
23.785 + * {@code false} otherwise.
23.786 + * @since 1.7
23.787 + */
23.788 + public static boolean isBmpCodePoint(int codePoint) {
23.789 + return codePoint >>> 16 == 0;
23.790 + // Optimized form of:
23.791 + // codePoint >= MIN_VALUE && codePoint <= MAX_VALUE
23.792 + // We consistently use logical shift (>>>) to facilitate
23.793 + // additional runtime optimizations.
23.794 + }
23.795 +
23.796 + /**
23.797 + * Determines whether the specified character (Unicode code point)
23.798 + * is in the <a href="#supplementary">supplementary character</a> range.
23.799 + *
23.800 + * @param codePoint the character (Unicode code point) to be tested
23.801 + * @return {@code true} if the specified code point is between
23.802 + * {@link #MIN_SUPPLEMENTARY_CODE_POINT} and
23.803 + * {@link #MAX_CODE_POINT} inclusive;
23.804 + * {@code false} otherwise.
23.805 + * @since 1.5
23.806 + */
23.807 + public static boolean isSupplementaryCodePoint(int codePoint) {
23.808 + return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
23.809 + && codePoint < MAX_CODE_POINT + 1;
23.810 + }
23.811 +
23.812 + /**
23.813 + * Determines if the given {@code char} value is a
23.814 + * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
23.815 + * Unicode high-surrogate code unit</a>
23.816 + * (also known as <i>leading-surrogate code unit</i>).
23.817 + *
23.818 + * <p>Such values do not represent characters by themselves,
23.819 + * but are used in the representation of
23.820 + * <a href="#supplementary">supplementary characters</a>
23.821 + * in the UTF-16 encoding.
23.822 + *
23.823 + * @param ch the {@code char} value to be tested.
23.824 + * @return {@code true} if the {@code char} value is between
23.825 + * {@link #MIN_HIGH_SURROGATE} and
23.826 + * {@link #MAX_HIGH_SURROGATE} inclusive;
23.827 + * {@code false} otherwise.
23.828 + * @see Character#isLowSurrogate(char)
23.829 + * @see Character.UnicodeBlock#of(int)
23.830 + * @since 1.5
23.831 + */
23.832 + public static boolean isHighSurrogate(char ch) {
23.833 + // Help VM constant-fold; MAX_HIGH_SURROGATE + 1 == MIN_LOW_SURROGATE
23.834 + return ch >= MIN_HIGH_SURROGATE && ch < (MAX_HIGH_SURROGATE + 1);
23.835 + }
23.836 +
23.837 + /**
23.838 + * Determines if the given {@code char} value is a
23.839 + * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
23.840 + * Unicode low-surrogate code unit</a>
23.841 + * (also known as <i>trailing-surrogate code unit</i>).
23.842 + *
23.843 + * <p>Such values do not represent characters by themselves,
23.844 + * but are used in the representation of
23.845 + * <a href="#supplementary">supplementary characters</a>
23.846 + * in the UTF-16 encoding.
23.847 + *
23.848 + * @param ch the {@code char} value to be tested.
23.849 + * @return {@code true} if the {@code char} value is between
23.850 + * {@link #MIN_LOW_SURROGATE} and
23.851 + * {@link #MAX_LOW_SURROGATE} inclusive;
23.852 + * {@code false} otherwise.
23.853 + * @see Character#isHighSurrogate(char)
23.854 + * @since 1.5
23.855 + */
23.856 + public static boolean isLowSurrogate(char ch) {
23.857 + return ch >= MIN_LOW_SURROGATE && ch < (MAX_LOW_SURROGATE + 1);
23.858 + }
23.859 +
23.860 + /**
23.861 + * Determines if the given {@code char} value is a Unicode
23.862 + * <i>surrogate code unit</i>.
23.863 + *
23.864 + * <p>Such values do not represent characters by themselves,
23.865 + * but are used in the representation of
23.866 + * <a href="#supplementary">supplementary characters</a>
23.867 + * in the UTF-16 encoding.
23.868 + *
23.869 + * <p>A char value is a surrogate code unit if and only if it is either
23.870 + * a {@linkplain #isLowSurrogate(char) low-surrogate code unit} or
23.871 + * a {@linkplain #isHighSurrogate(char) high-surrogate code unit}.
23.872 + *
23.873 + * @param ch the {@code char} value to be tested.
23.874 + * @return {@code true} if the {@code char} value is between
23.875 + * {@link #MIN_SURROGATE} and
23.876 + * {@link #MAX_SURROGATE} inclusive;
23.877 + * {@code false} otherwise.
23.878 + * @since 1.7
23.879 + */
23.880 + public static boolean isSurrogate(char ch) {
23.881 + return ch >= MIN_SURROGATE && ch < (MAX_SURROGATE + 1);
23.882 + }
23.883 +
23.884 + /**
23.885 + * Determines whether the specified pair of {@code char}
23.886 + * values is a valid
23.887 + * <a href="http://www.unicode.org/glossary/#surrogate_pair">
23.888 + * Unicode surrogate pair</a>.
23.889 +
23.890 + * <p>This method is equivalent to the expression:
23.891 + * <blockquote><pre>
23.892 + * isHighSurrogate(high) && isLowSurrogate(low)
23.893 + * </pre></blockquote>
23.894 + *
23.895 + * @param high the high-surrogate code value to be tested
23.896 + * @param low the low-surrogate code value to be tested
23.897 + * @return {@code true} if the specified high and
23.898 + * low-surrogate code values represent a valid surrogate pair;
23.899 + * {@code false} otherwise.
23.900 + * @since 1.5
23.901 + */
23.902 + public static boolean isSurrogatePair(char high, char low) {
23.903 + return isHighSurrogate(high) && isLowSurrogate(low);
23.904 + }
23.905 +
23.906 + /**
23.907 + * Determines the number of {@code char} values needed to
23.908 + * represent the specified character (Unicode code point). If the
23.909 + * specified character is equal to or greater than 0x10000, then
23.910 + * the method returns 2. Otherwise, the method returns 1.
23.911 + *
23.912 + * <p>This method doesn't validate the specified character to be a
23.913 + * valid Unicode code point. The caller must validate the
23.914 + * character value using {@link #isValidCodePoint(int) isValidCodePoint}
23.915 + * if necessary.
23.916 + *
23.917 + * @param codePoint the character (Unicode code point) to be tested.
23.918 + * @return 2 if the character is a valid supplementary character; 1 otherwise.
23.919 + * @see Character#isSupplementaryCodePoint(int)
23.920 + * @since 1.5
23.921 + */
23.922 + public static int charCount(int codePoint) {
23.923 + return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT ? 2 : 1;
23.924 + }
23.925 +
23.926 + /**
23.927 + * Converts the specified surrogate pair to its supplementary code
23.928 + * point value. This method does not validate the specified
23.929 + * surrogate pair. The caller must validate it using {@link
23.930 + * #isSurrogatePair(char, char) isSurrogatePair} if necessary.
23.931 + *
23.932 + * @param high the high-surrogate code unit
23.933 + * @param low the low-surrogate code unit
23.934 + * @return the supplementary code point composed from the
23.935 + * specified surrogate pair.
23.936 + * @since 1.5
23.937 + */
23.938 + public static int toCodePoint(char high, char low) {
23.939 + // Optimized form of:
23.940 + // return ((high - MIN_HIGH_SURROGATE) << 10)
23.941 + // + (low - MIN_LOW_SURROGATE)
23.942 + // + MIN_SUPPLEMENTARY_CODE_POINT;
23.943 + return ((high << 10) + low) + (MIN_SUPPLEMENTARY_CODE_POINT
23.944 + - (MIN_HIGH_SURROGATE << 10)
23.945 + - MIN_LOW_SURROGATE);
23.946 + }
23.947 +
23.948 + /**
23.949 + * Returns the code point at the given index of the
23.950 + * {@code CharSequence}. If the {@code char} value at
23.951 + * the given index in the {@code CharSequence} is in the
23.952 + * high-surrogate range, the following index is less than the
23.953 + * length of the {@code CharSequence}, and the
23.954 + * {@code char} value at the following index is in the
23.955 + * low-surrogate range, then the supplementary code point
23.956 + * corresponding to this surrogate pair is returned. Otherwise,
23.957 + * the {@code char} value at the given index is returned.
23.958 + *
23.959 + * @param seq a sequence of {@code char} values (Unicode code
23.960 + * units)
23.961 + * @param index the index to the {@code char} values (Unicode
23.962 + * code units) in {@code seq} to be converted
23.963 + * @return the Unicode code point at the given index
23.964 + * @exception NullPointerException if {@code seq} is null.
23.965 + * @exception IndexOutOfBoundsException if the value
23.966 + * {@code index} is negative or not less than
23.967 + * {@link CharSequence#length() seq.length()}.
23.968 + * @since 1.5
23.969 + */
23.970 + public static int codePointAt(CharSequence seq, int index) {
23.971 + char c1 = seq.charAt(index++);
23.972 + if (isHighSurrogate(c1)) {
23.973 + if (index < seq.length()) {
23.974 + char c2 = seq.charAt(index);
23.975 + if (isLowSurrogate(c2)) {
23.976 + return toCodePoint(c1, c2);
23.977 + }
23.978 + }
23.979 + }
23.980 + return c1;
23.981 + }
23.982 +
23.983 + /**
23.984 + * Returns the code point at the given index of the
23.985 + * {@code char} array. If the {@code char} value at
23.986 + * the given index in the {@code char} array is in the
23.987 + * high-surrogate range, the following index is less than the
23.988 + * length of the {@code char} array, and the
23.989 + * {@code char} value at the following index is in the
23.990 + * low-surrogate range, then the supplementary code point
23.991 + * corresponding to this surrogate pair is returned. Otherwise,
23.992 + * the {@code char} value at the given index is returned.
23.993 + *
23.994 + * @param a the {@code char} array
23.995 + * @param index the index to the {@code char} values (Unicode
23.996 + * code units) in the {@code char} array to be converted
23.997 + * @return the Unicode code point at the given index
23.998 + * @exception NullPointerException if {@code a} is null.
23.999 + * @exception IndexOutOfBoundsException if the value
23.1000 + * {@code index} is negative or not less than
23.1001 + * the length of the {@code char} array.
23.1002 + * @since 1.5
23.1003 + */
23.1004 + public static int codePointAt(char[] a, int index) {
23.1005 + return codePointAtImpl(a, index, a.length);
23.1006 + }
23.1007 +
23.1008 + /**
23.1009 + * Returns the code point at the given index of the
23.1010 + * {@code char} array, where only array elements with
23.1011 + * {@code index} less than {@code limit} can be used. If
23.1012 + * the {@code char} value at the given index in the
23.1013 + * {@code char} array is in the high-surrogate range, the
23.1014 + * following index is less than the {@code limit}, and the
23.1015 + * {@code char} value at the following index is in the
23.1016 + * low-surrogate range, then the supplementary code point
23.1017 + * corresponding to this surrogate pair is returned. Otherwise,
23.1018 + * the {@code char} value at the given index is returned.
23.1019 + *
23.1020 + * @param a the {@code char} array
23.1021 + * @param index the index to the {@code char} values (Unicode
23.1022 + * code units) in the {@code char} array to be converted
23.1023 + * @param limit the index after the last array element that
23.1024 + * can be used in the {@code char} array
23.1025 + * @return the Unicode code point at the given index
23.1026 + * @exception NullPointerException if {@code a} is null.
23.1027 + * @exception IndexOutOfBoundsException if the {@code index}
23.1028 + * argument is negative or not less than the {@code limit}
23.1029 + * argument, or if the {@code limit} argument is negative or
23.1030 + * greater than the length of the {@code char} array.
23.1031 + * @since 1.5
23.1032 + */
23.1033 + public static int codePointAt(char[] a, int index, int limit) {
23.1034 + if (index >= limit || limit < 0 || limit > a.length) {
23.1035 + throw new IndexOutOfBoundsException();
23.1036 + }
23.1037 + return codePointAtImpl(a, index, limit);
23.1038 + }
23.1039 +
23.1040 + // throws ArrayIndexOutofBoundsException if index out of bounds
23.1041 + static int codePointAtImpl(char[] a, int index, int limit) {
23.1042 + char c1 = a[index++];
23.1043 + if (isHighSurrogate(c1)) {
23.1044 + if (index < limit) {
23.1045 + char c2 = a[index];
23.1046 + if (isLowSurrogate(c2)) {
23.1047 + return toCodePoint(c1, c2);
23.1048 + }
23.1049 + }
23.1050 + }
23.1051 + return c1;
23.1052 + }
23.1053 +
23.1054 + /**
23.1055 + * Returns the code point preceding the given index of the
23.1056 + * {@code CharSequence}. If the {@code char} value at
23.1057 + * {@code (index - 1)} in the {@code CharSequence} is in
23.1058 + * the low-surrogate range, {@code (index - 2)} is not
23.1059 + * negative, and the {@code char} value at {@code (index - 2)}
23.1060 + * in the {@code CharSequence} is in the
23.1061 + * high-surrogate range, then the supplementary code point
23.1062 + * corresponding to this surrogate pair is returned. Otherwise,
23.1063 + * the {@code char} value at {@code (index - 1)} is
23.1064 + * returned.
23.1065 + *
23.1066 + * @param seq the {@code CharSequence} instance
23.1067 + * @param index the index following the code point that should be returned
23.1068 + * @return the Unicode code point value before the given index.
23.1069 + * @exception NullPointerException if {@code seq} is null.
23.1070 + * @exception IndexOutOfBoundsException if the {@code index}
23.1071 + * argument is less than 1 or greater than {@link
23.1072 + * CharSequence#length() seq.length()}.
23.1073 + * @since 1.5
23.1074 + */
23.1075 + public static int codePointBefore(CharSequence seq, int index) {
23.1076 + char c2 = seq.charAt(--index);
23.1077 + if (isLowSurrogate(c2)) {
23.1078 + if (index > 0) {
23.1079 + char c1 = seq.charAt(--index);
23.1080 + if (isHighSurrogate(c1)) {
23.1081 + return toCodePoint(c1, c2);
23.1082 + }
23.1083 + }
23.1084 + }
23.1085 + return c2;
23.1086 + }
23.1087 +
23.1088 + /**
23.1089 + * Returns the code point preceding the given index of the
23.1090 + * {@code char} array. If the {@code char} value at
23.1091 + * {@code (index - 1)} in the {@code char} array is in
23.1092 + * the low-surrogate range, {@code (index - 2)} is not
23.1093 + * negative, and the {@code char} value at {@code (index - 2)}
23.1094 + * in the {@code char} array is in the
23.1095 + * high-surrogate range, then the supplementary code point
23.1096 + * corresponding to this surrogate pair is returned. Otherwise,
23.1097 + * the {@code char} value at {@code (index - 1)} is
23.1098 + * returned.
23.1099 + *
23.1100 + * @param a the {@code char} array
23.1101 + * @param index the index following the code point that should be returned
23.1102 + * @return the Unicode code point value before the given index.
23.1103 + * @exception NullPointerException if {@code a} is null.
23.1104 + * @exception IndexOutOfBoundsException if the {@code index}
23.1105 + * argument is less than 1 or greater than the length of the
23.1106 + * {@code char} array
23.1107 + * @since 1.5
23.1108 + */
23.1109 + public static int codePointBefore(char[] a, int index) {
23.1110 + return codePointBeforeImpl(a, index, 0);
23.1111 + }
23.1112 +
23.1113 + /**
23.1114 + * Returns the code point preceding the given index of the
23.1115 + * {@code char} array, where only array elements with
23.1116 + * {@code index} greater than or equal to {@code start}
23.1117 + * can be used. If the {@code char} value at {@code (index - 1)}
23.1118 + * in the {@code char} array is in the
23.1119 + * low-surrogate range, {@code (index - 2)} is not less than
23.1120 + * {@code start}, and the {@code char} value at
23.1121 + * {@code (index - 2)} in the {@code char} array is in
23.1122 + * the high-surrogate range, then the supplementary code point
23.1123 + * corresponding to this surrogate pair is returned. Otherwise,
23.1124 + * the {@code char} value at {@code (index - 1)} is
23.1125 + * returned.
23.1126 + *
23.1127 + * @param a the {@code char} array
23.1128 + * @param index the index following the code point that should be returned
23.1129 + * @param start the index of the first array element in the
23.1130 + * {@code char} array
23.1131 + * @return the Unicode code point value before the given index.
23.1132 + * @exception NullPointerException if {@code a} is null.
23.1133 + * @exception IndexOutOfBoundsException if the {@code index}
23.1134 + * argument is not greater than the {@code start} argument or
23.1135 + * is greater than the length of the {@code char} array, or
23.1136 + * if the {@code start} argument is negative or not less than
23.1137 + * the length of the {@code char} array.
23.1138 + * @since 1.5
23.1139 + */
23.1140 + public static int codePointBefore(char[] a, int index, int start) {
23.1141 + if (index <= start || start < 0 || start >= a.length) {
23.1142 + throw new IndexOutOfBoundsException();
23.1143 + }
23.1144 + return codePointBeforeImpl(a, index, start);
23.1145 + }
23.1146 +
23.1147 + // throws ArrayIndexOutofBoundsException if index-1 out of bounds
23.1148 + static int codePointBeforeImpl(char[] a, int index, int start) {
23.1149 + char c2 = a[--index];
23.1150 + if (isLowSurrogate(c2)) {
23.1151 + if (index > start) {
23.1152 + char c1 = a[--index];
23.1153 + if (isHighSurrogate(c1)) {
23.1154 + return toCodePoint(c1, c2);
23.1155 + }
23.1156 + }
23.1157 + }
23.1158 + return c2;
23.1159 + }
23.1160 +
23.1161 + /**
23.1162 + * Returns the leading surrogate (a
23.1163 + * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
23.1164 + * high surrogate code unit</a>) of the
23.1165 + * <a href="http://www.unicode.org/glossary/#surrogate_pair">
23.1166 + * surrogate pair</a>
23.1167 + * representing the specified supplementary character (Unicode
23.1168 + * code point) in the UTF-16 encoding. If the specified character
23.1169 + * is not a
23.1170 + * <a href="Character.html#supplementary">supplementary character</a>,
23.1171 + * an unspecified {@code char} is returned.
23.1172 + *
23.1173 + * <p>If
23.1174 + * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
23.1175 + * is {@code true}, then
23.1176 + * {@link #isHighSurrogate isHighSurrogate}{@code (highSurrogate(x))} and
23.1177 + * {@link #toCodePoint toCodePoint}{@code (highSurrogate(x), }{@link #lowSurrogate lowSurrogate}{@code (x)) == x}
23.1178 + * are also always {@code true}.
23.1179 + *
23.1180 + * @param codePoint a supplementary character (Unicode code point)
23.1181 + * @return the leading surrogate code unit used to represent the
23.1182 + * character in the UTF-16 encoding
23.1183 + * @since 1.7
23.1184 + */
23.1185 + public static char highSurrogate(int codePoint) {
23.1186 + return (char) ((codePoint >>> 10)
23.1187 + + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10)));
23.1188 + }
23.1189 +
23.1190 + /**
23.1191 + * Returns the trailing surrogate (a
23.1192 + * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
23.1193 + * low surrogate code unit</a>) of the
23.1194 + * <a href="http://www.unicode.org/glossary/#surrogate_pair">
23.1195 + * surrogate pair</a>
23.1196 + * representing the specified supplementary character (Unicode
23.1197 + * code point) in the UTF-16 encoding. If the specified character
23.1198 + * is not a
23.1199 + * <a href="Character.html#supplementary">supplementary character</a>,
23.1200 + * an unspecified {@code char} is returned.
23.1201 + *
23.1202 + * <p>If
23.1203 + * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
23.1204 + * is {@code true}, then
23.1205 + * {@link #isLowSurrogate isLowSurrogate}{@code (lowSurrogate(x))} and
23.1206 + * {@link #toCodePoint toCodePoint}{@code (}{@link #highSurrogate highSurrogate}{@code (x), lowSurrogate(x)) == x}
23.1207 + * are also always {@code true}.
23.1208 + *
23.1209 + * @param codePoint a supplementary character (Unicode code point)
23.1210 + * @return the trailing surrogate code unit used to represent the
23.1211 + * character in the UTF-16 encoding
23.1212 + * @since 1.7
23.1213 + */
23.1214 + public static char lowSurrogate(int codePoint) {
23.1215 + return (char) ((codePoint & 0x3ff) + MIN_LOW_SURROGATE);
23.1216 + }
23.1217 +
23.1218 + /**
23.1219 + * Converts the specified character (Unicode code point) to its
23.1220 + * UTF-16 representation. If the specified code point is a BMP
23.1221 + * (Basic Multilingual Plane or Plane 0) value, the same value is
23.1222 + * stored in {@code dst[dstIndex]}, and 1 is returned. If the
23.1223 + * specified code point is a supplementary character, its
23.1224 + * surrogate values are stored in {@code dst[dstIndex]}
23.1225 + * (high-surrogate) and {@code dst[dstIndex+1]}
23.1226 + * (low-surrogate), and 2 is returned.
23.1227 + *
23.1228 + * @param codePoint the character (Unicode code point) to be converted.
23.1229 + * @param dst an array of {@code char} in which the
23.1230 + * {@code codePoint}'s UTF-16 value is stored.
23.1231 + * @param dstIndex the start index into the {@code dst}
23.1232 + * array where the converted value is stored.
23.1233 + * @return 1 if the code point is a BMP code point, 2 if the
23.1234 + * code point is a supplementary code point.
23.1235 + * @exception IllegalArgumentException if the specified
23.1236 + * {@code codePoint} is not a valid Unicode code point.
23.1237 + * @exception NullPointerException if the specified {@code dst} is null.
23.1238 + * @exception IndexOutOfBoundsException if {@code dstIndex}
23.1239 + * is negative or not less than {@code dst.length}, or if
23.1240 + * {@code dst} at {@code dstIndex} doesn't have enough
23.1241 + * array element(s) to store the resulting {@code char}
23.1242 + * value(s). (If {@code dstIndex} is equal to
23.1243 + * {@code dst.length-1} and the specified
23.1244 + * {@code codePoint} is a supplementary character, the
23.1245 + * high-surrogate value is not stored in
23.1246 + * {@code dst[dstIndex]}.)
23.1247 + * @since 1.5
23.1248 + */
23.1249 + public static int toChars(int codePoint, char[] dst, int dstIndex) {
23.1250 + if (isBmpCodePoint(codePoint)) {
23.1251 + dst[dstIndex] = (char) codePoint;
23.1252 + return 1;
23.1253 + } else if (isValidCodePoint(codePoint)) {
23.1254 + toSurrogates(codePoint, dst, dstIndex);
23.1255 + return 2;
23.1256 + } else {
23.1257 + throw new IllegalArgumentException();
23.1258 + }
23.1259 + }
23.1260 +
23.1261 + /**
23.1262 + * Converts the specified character (Unicode code point) to its
23.1263 + * UTF-16 representation stored in a {@code char} array. If
23.1264 + * the specified code point is a BMP (Basic Multilingual Plane or
23.1265 + * Plane 0) value, the resulting {@code char} array has
23.1266 + * the same value as {@code codePoint}. If the specified code
23.1267 + * point is a supplementary code point, the resulting
23.1268 + * {@code char} array has the corresponding surrogate pair.
23.1269 + *
23.1270 + * @param codePoint a Unicode code point
23.1271 + * @return a {@code char} array having
23.1272 + * {@code codePoint}'s UTF-16 representation.
23.1273 + * @exception IllegalArgumentException if the specified
23.1274 + * {@code codePoint} is not a valid Unicode code point.
23.1275 + * @since 1.5
23.1276 + */
23.1277 + public static char[] toChars(int codePoint) {
23.1278 + if (isBmpCodePoint(codePoint)) {
23.1279 + return new char[] { (char) codePoint };
23.1280 + } else if (isValidCodePoint(codePoint)) {
23.1281 + char[] result = new char[2];
23.1282 + toSurrogates(codePoint, result, 0);
23.1283 + return result;
23.1284 + } else {
23.1285 + throw new IllegalArgumentException();
23.1286 + }
23.1287 + }
23.1288 +
23.1289 + static void toSurrogates(int codePoint, char[] dst, int index) {
23.1290 + // We write elements "backwards" to guarantee all-or-nothing
23.1291 + dst[index+1] = lowSurrogate(codePoint);
23.1292 + dst[index] = highSurrogate(codePoint);
23.1293 + }
23.1294 +
23.1295 + /**
23.1296 + * Returns the number of Unicode code points in the text range of
23.1297 + * the specified char sequence. The text range begins at the
23.1298 + * specified {@code beginIndex} and extends to the
23.1299 + * {@code char} at index {@code endIndex - 1}. Thus the
23.1300 + * length (in {@code char}s) of the text range is
23.1301 + * {@code endIndex-beginIndex}. Unpaired surrogates within
23.1302 + * the text range count as one code point each.
23.1303 + *
23.1304 + * @param seq the char sequence
23.1305 + * @param beginIndex the index to the first {@code char} of
23.1306 + * the text range.
23.1307 + * @param endIndex the index after the last {@code char} of
23.1308 + * the text range.
23.1309 + * @return the number of Unicode code points in the specified text
23.1310 + * range
23.1311 + * @exception NullPointerException if {@code seq} is null.
23.1312 + * @exception IndexOutOfBoundsException if the
23.1313 + * {@code beginIndex} is negative, or {@code endIndex}
23.1314 + * is larger than the length of the given sequence, or
23.1315 + * {@code beginIndex} is larger than {@code endIndex}.
23.1316 + * @since 1.5
23.1317 + */
23.1318 + public static int codePointCount(CharSequence seq, int beginIndex, int endIndex) {
23.1319 + int length = seq.length();
23.1320 + if (beginIndex < 0 || endIndex > length || beginIndex > endIndex) {
23.1321 + throw new IndexOutOfBoundsException();
23.1322 + }
23.1323 + int n = endIndex - beginIndex;
23.1324 + for (int i = beginIndex; i < endIndex; ) {
23.1325 + if (isHighSurrogate(seq.charAt(i++)) && i < endIndex &&
23.1326 + isLowSurrogate(seq.charAt(i))) {
23.1327 + n--;
23.1328 + i++;
23.1329 + }
23.1330 + }
23.1331 + return n;
23.1332 + }
23.1333 +
23.1334 + /**
23.1335 + * Returns the number of Unicode code points in a subarray of the
23.1336 + * {@code char} array argument. The {@code offset}
23.1337 + * argument is the index of the first {@code char} of the
23.1338 + * subarray and the {@code count} argument specifies the
23.1339 + * length of the subarray in {@code char}s. Unpaired
23.1340 + * surrogates within the subarray count as one code point each.
23.1341 + *
23.1342 + * @param a the {@code char} array
23.1343 + * @param offset the index of the first {@code char} in the
23.1344 + * given {@code char} array
23.1345 + * @param count the length of the subarray in {@code char}s
23.1346 + * @return the number of Unicode code points in the specified subarray
23.1347 + * @exception NullPointerException if {@code a} is null.
23.1348 + * @exception IndexOutOfBoundsException if {@code offset} or
23.1349 + * {@code count} is negative, or if {@code offset +
23.1350 + * count} is larger than the length of the given array.
23.1351 + * @since 1.5
23.1352 + */
23.1353 + public static int codePointCount(char[] a, int offset, int count) {
23.1354 + if (count > a.length - offset || offset < 0 || count < 0) {
23.1355 + throw new IndexOutOfBoundsException();
23.1356 + }
23.1357 + return codePointCountImpl(a, offset, count);
23.1358 + }
23.1359 +
23.1360 + static int codePointCountImpl(char[] a, int offset, int count) {
23.1361 + int endIndex = offset + count;
23.1362 + int n = count;
23.1363 + for (int i = offset; i < endIndex; ) {
23.1364 + if (isHighSurrogate(a[i++]) && i < endIndex &&
23.1365 + isLowSurrogate(a[i])) {
23.1366 + n--;
23.1367 + i++;
23.1368 + }
23.1369 + }
23.1370 + return n;
23.1371 + }
23.1372 +
23.1373 + /**
23.1374 + * Returns the index within the given char sequence that is offset
23.1375 + * from the given {@code index} by {@code codePointOffset}
23.1376 + * code points. Unpaired surrogates within the text range given by
23.1377 + * {@code index} and {@code codePointOffset} count as
23.1378 + * one code point each.
23.1379 + *
23.1380 + * @param seq the char sequence
23.1381 + * @param index the index to be offset
23.1382 + * @param codePointOffset the offset in code points
23.1383 + * @return the index within the char sequence
23.1384 + * @exception NullPointerException if {@code seq} is null.
23.1385 + * @exception IndexOutOfBoundsException if {@code index}
23.1386 + * is negative or larger then the length of the char sequence,
23.1387 + * or if {@code codePointOffset} is positive and the
23.1388 + * subsequence starting with {@code index} has fewer than
23.1389 + * {@code codePointOffset} code points, or if
23.1390 + * {@code codePointOffset} is negative and the subsequence
23.1391 + * before {@code index} has fewer than the absolute value
23.1392 + * of {@code codePointOffset} code points.
23.1393 + * @since 1.5
23.1394 + */
23.1395 + public static int offsetByCodePoints(CharSequence seq, int index,
23.1396 + int codePointOffset) {
23.1397 + int length = seq.length();
23.1398 + if (index < 0 || index > length) {
23.1399 + throw new IndexOutOfBoundsException();
23.1400 + }
23.1401 +
23.1402 + int x = index;
23.1403 + if (codePointOffset >= 0) {
23.1404 + int i;
23.1405 + for (i = 0; x < length && i < codePointOffset; i++) {
23.1406 + if (isHighSurrogate(seq.charAt(x++)) && x < length &&
23.1407 + isLowSurrogate(seq.charAt(x))) {
23.1408 + x++;
23.1409 + }
23.1410 + }
23.1411 + if (i < codePointOffset) {
23.1412 + throw new IndexOutOfBoundsException();
23.1413 + }
23.1414 + } else {
23.1415 + int i;
23.1416 + for (i = codePointOffset; x > 0 && i < 0; i++) {
23.1417 + if (isLowSurrogate(seq.charAt(--x)) && x > 0 &&
23.1418 + isHighSurrogate(seq.charAt(x-1))) {
23.1419 + x--;
23.1420 + }
23.1421 + }
23.1422 + if (i < 0) {
23.1423 + throw new IndexOutOfBoundsException();
23.1424 + }
23.1425 + }
23.1426 + return x;
23.1427 + }
23.1428 +
23.1429 + /**
23.1430 + * Returns the index within the given {@code char} subarray
23.1431 + * that is offset from the given {@code index} by
23.1432 + * {@code codePointOffset} code points. The
23.1433 + * {@code start} and {@code count} arguments specify a
23.1434 + * subarray of the {@code char} array. Unpaired surrogates
23.1435 + * within the text range given by {@code index} and
23.1436 + * {@code codePointOffset} count as one code point each.
23.1437 + *
23.1438 + * @param a the {@code char} array
23.1439 + * @param start the index of the first {@code char} of the
23.1440 + * subarray
23.1441 + * @param count the length of the subarray in {@code char}s
23.1442 + * @param index the index to be offset
23.1443 + * @param codePointOffset the offset in code points
23.1444 + * @return the index within the subarray
23.1445 + * @exception NullPointerException if {@code a} is null.
23.1446 + * @exception IndexOutOfBoundsException
23.1447 + * if {@code start} or {@code count} is negative,
23.1448 + * or if {@code start + count} is larger than the length of
23.1449 + * the given array,
23.1450 + * or if {@code index} is less than {@code start} or
23.1451 + * larger then {@code start + count},
23.1452 + * or if {@code codePointOffset} is positive and the text range
23.1453 + * starting with {@code index} and ending with {@code start + count - 1}
23.1454 + * has fewer than {@code codePointOffset} code
23.1455 + * points,
23.1456 + * or if {@code codePointOffset} is negative and the text range
23.1457 + * starting with {@code start} and ending with {@code index - 1}
23.1458 + * has fewer than the absolute value of
23.1459 + * {@code codePointOffset} code points.
23.1460 + * @since 1.5
23.1461 + */
23.1462 + public static int offsetByCodePoints(char[] a, int start, int count,
23.1463 + int index, int codePointOffset) {
23.1464 + if (count > a.length-start || start < 0 || count < 0
23.1465 + || index < start || index > start+count) {
23.1466 + throw new IndexOutOfBoundsException();
23.1467 + }
23.1468 + return offsetByCodePointsImpl(a, start, count, index, codePointOffset);
23.1469 + }
23.1470 +
23.1471 + static int offsetByCodePointsImpl(char[]a, int start, int count,
23.1472 + int index, int codePointOffset) {
23.1473 + int x = index;
23.1474 + if (codePointOffset >= 0) {
23.1475 + int limit = start + count;
23.1476 + int i;
23.1477 + for (i = 0; x < limit && i < codePointOffset; i++) {
23.1478 + if (isHighSurrogate(a[x++]) && x < limit &&
23.1479 + isLowSurrogate(a[x])) {
23.1480 + x++;
23.1481 + }
23.1482 + }
23.1483 + if (i < codePointOffset) {
23.1484 + throw new IndexOutOfBoundsException();
23.1485 + }
23.1486 + } else {
23.1487 + int i;
23.1488 + for (i = codePointOffset; x > start && i < 0; i++) {
23.1489 + if (isLowSurrogate(a[--x]) && x > start &&
23.1490 + isHighSurrogate(a[x-1])) {
23.1491 + x--;
23.1492 + }
23.1493 + }
23.1494 + if (i < 0) {
23.1495 + throw new IndexOutOfBoundsException();
23.1496 + }
23.1497 + }
23.1498 + return x;
23.1499 + }
23.1500 +
23.1501 + /**
23.1502 + * Determines if the specified character is a lowercase character.
23.1503 + * <p>
23.1504 + * A character is lowercase if its general category type, provided
23.1505 + * by {@code Character.getType(ch)}, is
23.1506 + * {@code LOWERCASE_LETTER}, or it has contributory property
23.1507 + * Other_Lowercase as defined by the Unicode Standard.
23.1508 + * <p>
23.1509 + * The following are examples of lowercase characters:
23.1510 + * <p><blockquote><pre>
23.1511 + * a b c d e f g h i j k l m n o p q r s t u v w x y z
23.1512 + * '\u00DF' '\u00E0' '\u00E1' '\u00E2' '\u00E3' '\u00E4' '\u00E5' '\u00E6'
23.1513 + * '\u00E7' '\u00E8' '\u00E9' '\u00EA' '\u00EB' '\u00EC' '\u00ED' '\u00EE'
23.1514 + * '\u00EF' '\u00F0' '\u00F1' '\u00F2' '\u00F3' '\u00F4' '\u00F5' '\u00F6'
23.1515 + * '\u00F8' '\u00F9' '\u00FA' '\u00FB' '\u00FC' '\u00FD' '\u00FE' '\u00FF'
23.1516 + * </pre></blockquote>
23.1517 + * <p> Many other Unicode characters are lowercase too.
23.1518 + *
23.1519 + * <p><b>Note:</b> This method cannot handle <a
23.1520 + * href="#supplementary"> supplementary characters</a>. To support
23.1521 + * all Unicode characters, including supplementary characters, use
23.1522 + * the {@link #isLowerCase(int)} method.
23.1523 + *
23.1524 + * @param ch the character to be tested.
23.1525 + * @return {@code true} if the character is lowercase;
23.1526 + * {@code false} otherwise.
23.1527 + * @see Character#isLowerCase(char)
23.1528 + * @see Character#isTitleCase(char)
23.1529 + * @see Character#toLowerCase(char)
23.1530 + * @see Character#getType(char)
23.1531 + */
23.1532 + public static boolean isLowerCase(char ch) {
23.1533 + return ch == toLowerCase(ch);
23.1534 + }
23.1535 +
23.1536 + /**
23.1537 + * Determines if the specified character is an uppercase character.
23.1538 + * <p>
23.1539 + * A character is uppercase if its general category type, provided by
23.1540 + * {@code Character.getType(ch)}, is {@code UPPERCASE_LETTER}.
23.1541 + * or it has contributory property Other_Uppercase as defined by the Unicode Standard.
23.1542 + * <p>
23.1543 + * The following are examples of uppercase characters:
23.1544 + * <p><blockquote><pre>
23.1545 + * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
23.1546 + * '\u00C0' '\u00C1' '\u00C2' '\u00C3' '\u00C4' '\u00C5' '\u00C6' '\u00C7'
23.1547 + * '\u00C8' '\u00C9' '\u00CA' '\u00CB' '\u00CC' '\u00CD' '\u00CE' '\u00CF'
23.1548 + * '\u00D0' '\u00D1' '\u00D2' '\u00D3' '\u00D4' '\u00D5' '\u00D6' '\u00D8'
23.1549 + * '\u00D9' '\u00DA' '\u00DB' '\u00DC' '\u00DD' '\u00DE'
23.1550 + * </pre></blockquote>
23.1551 + * <p> Many other Unicode characters are uppercase too.<p>
23.1552 + *
23.1553 + * <p><b>Note:</b> This method cannot handle <a
23.1554 + * href="#supplementary"> supplementary characters</a>. To support
23.1555 + * all Unicode characters, including supplementary characters, use
23.1556 + * the {@link #isUpperCase(int)} method.
23.1557 + *
23.1558 + * @param ch the character to be tested.
23.1559 + * @return {@code true} if the character is uppercase;
23.1560 + * {@code false} otherwise.
23.1561 + * @see Character#isLowerCase(char)
23.1562 + * @see Character#isTitleCase(char)
23.1563 + * @see Character#toUpperCase(char)
23.1564 + * @see Character#getType(char)
23.1565 + * @since 1.0
23.1566 + */
23.1567 + public static boolean isUpperCase(char ch) {
23.1568 + return ch == toUpperCase(ch);
23.1569 + }
23.1570 +
23.1571 + /**
23.1572 + * Determines if the specified character is a titlecase character.
23.1573 + * <p>
23.1574 + * A character is a titlecase character if its general
23.1575 + * category type, provided by {@code Character.getType(ch)},
23.1576 + * is {@code TITLECASE_LETTER}.
23.1577 + * <p>
23.1578 + * Some characters look like pairs of Latin letters. For example, there
23.1579 + * is an uppercase letter that looks like "LJ" and has a corresponding
23.1580 + * lowercase letter that looks like "lj". A third form, which looks like "Lj",
23.1581 + * is the appropriate form to use when rendering a word in lowercase
23.1582 + * with initial capitals, as for a book title.
23.1583 + * <p>
23.1584 + * These are some of the Unicode characters for which this method returns
23.1585 + * {@code true}:
23.1586 + * <ul>
23.1587 + * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
23.1588 + * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
23.1589 + * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
23.1590 + * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
23.1591 + * </ul>
23.1592 + * <p> Many other Unicode characters are titlecase too.<p>
23.1593 + *
23.1594 + * <p><b>Note:</b> This method cannot handle <a
23.1595 + * href="#supplementary"> supplementary characters</a>. To support
23.1596 + * all Unicode characters, including supplementary characters, use
23.1597 + * the {@link #isTitleCase(int)} method.
23.1598 + *
23.1599 + * @param ch the character to be tested.
23.1600 + * @return {@code true} if the character is titlecase;
23.1601 + * {@code false} otherwise.
23.1602 + * @see Character#isLowerCase(char)
23.1603 + * @see Character#isUpperCase(char)
23.1604 + * @see Character#toTitleCase(char)
23.1605 + * @see Character#getType(char)
23.1606 + * @since 1.0.2
23.1607 + */
23.1608 + public static boolean isTitleCase(char ch) {
23.1609 + return isTitleCase((int)ch);
23.1610 + }
23.1611 +
23.1612 + /**
23.1613 + * Determines if the specified character (Unicode code point) is a titlecase character.
23.1614 + * <p>
23.1615 + * A character is a titlecase character if its general
23.1616 + * category type, provided by {@link Character#getType(int) getType(codePoint)},
23.1617 + * is {@code TITLECASE_LETTER}.
23.1618 + * <p>
23.1619 + * Some characters look like pairs of Latin letters. For example, there
23.1620 + * is an uppercase letter that looks like "LJ" and has a corresponding
23.1621 + * lowercase letter that looks like "lj". A third form, which looks like "Lj",
23.1622 + * is the appropriate form to use when rendering a word in lowercase
23.1623 + * with initial capitals, as for a book title.
23.1624 + * <p>
23.1625 + * These are some of the Unicode characters for which this method returns
23.1626 + * {@code true}:
23.1627 + * <ul>
23.1628 + * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
23.1629 + * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
23.1630 + * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
23.1631 + * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
23.1632 + * </ul>
23.1633 + * <p> Many other Unicode characters are titlecase too.<p>
23.1634 + *
23.1635 + * @param codePoint the character (Unicode code point) to be tested.
23.1636 + * @return {@code true} if the character is titlecase;
23.1637 + * {@code false} otherwise.
23.1638 + * @see Character#isLowerCase(int)
23.1639 + * @see Character#isUpperCase(int)
23.1640 + * @see Character#toTitleCase(int)
23.1641 + * @see Character#getType(int)
23.1642 + * @since 1.5
23.1643 + */
23.1644 + public static boolean isTitleCase(int codePoint) {
23.1645 + return getType(codePoint) == Character.TITLECASE_LETTER;
23.1646 + }
23.1647 +
23.1648 + /**
23.1649 + * Determines if the specified character is a digit.
23.1650 + * <p>
23.1651 + * A character is a digit if its general category type, provided
23.1652 + * by {@code Character.getType(ch)}, is
23.1653 + * {@code DECIMAL_DIGIT_NUMBER}.
23.1654 + * <p>
23.1655 + * Some Unicode character ranges that contain digits:
23.1656 + * <ul>
23.1657 + * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
23.1658 + * ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
23.1659 + * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
23.1660 + * Arabic-Indic digits
23.1661 + * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
23.1662 + * Extended Arabic-Indic digits
23.1663 + * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
23.1664 + * Devanagari digits
23.1665 + * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
23.1666 + * Fullwidth digits
23.1667 + * </ul>
23.1668 + *
23.1669 + * Many other character ranges contain digits as well.
23.1670 + *
23.1671 + * <p><b>Note:</b> This method cannot handle <a
23.1672 + * href="#supplementary"> supplementary characters</a>. To support
23.1673 + * all Unicode characters, including supplementary characters, use
23.1674 + * the {@link #isDigit(int)} method.
23.1675 + *
23.1676 + * @param ch the character to be tested.
23.1677 + * @return {@code true} if the character is a digit;
23.1678 + * {@code false} otherwise.
23.1679 + * @see Character#digit(char, int)
23.1680 + * @see Character#forDigit(int, int)
23.1681 + * @see Character#getType(char)
23.1682 + */
23.1683 + public static boolean isDigit(char ch) {
23.1684 + return String.valueOf(ch).matches("\\d");
23.1685 + }
23.1686 +
23.1687 + /**
23.1688 + * Determines if the specified character (Unicode code point) is a digit.
23.1689 + * <p>
23.1690 + * A character is a digit if its general category type, provided
23.1691 + * by {@link Character#getType(int) getType(codePoint)}, is
23.1692 + * {@code DECIMAL_DIGIT_NUMBER}.
23.1693 + * <p>
23.1694 + * Some Unicode character ranges that contain digits:
23.1695 + * <ul>
23.1696 + * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
23.1697 + * ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
23.1698 + * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
23.1699 + * Arabic-Indic digits
23.1700 + * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
23.1701 + * Extended Arabic-Indic digits
23.1702 + * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
23.1703 + * Devanagari digits
23.1704 + * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
23.1705 + * Fullwidth digits
23.1706 + * </ul>
23.1707 + *
23.1708 + * Many other character ranges contain digits as well.
23.1709 + *
23.1710 + * @param codePoint the character (Unicode code point) to be tested.
23.1711 + * @return {@code true} if the character is a digit;
23.1712 + * {@code false} otherwise.
23.1713 + * @see Character#forDigit(int, int)
23.1714 + * @see Character#getType(int)
23.1715 + * @since 1.5
23.1716 + */
23.1717 + public static boolean isDigit(int codePoint) {
23.1718 + return fromCodeChars(codePoint).matches("\\d");
23.1719 + }
23.1720 +
23.1721 + @JavaScriptBody(args = "c", body = "return String.fromCharCode(c);")
23.1722 + private native static String fromCodeChars(int codePoint);
23.1723 +
23.1724 + /**
23.1725 + * Determines if a character is defined in Unicode.
23.1726 + * <p>
23.1727 + * A character is defined if at least one of the following is true:
23.1728 + * <ul>
23.1729 + * <li>It has an entry in the UnicodeData file.
23.1730 + * <li>It has a value in a range defined by the UnicodeData file.
23.1731 + * </ul>
23.1732 + *
23.1733 + * <p><b>Note:</b> This method cannot handle <a
23.1734 + * href="#supplementary"> supplementary characters</a>. To support
23.1735 + * all Unicode characters, including supplementary characters, use
23.1736 + * the {@link #isDefined(int)} method.
23.1737 + *
23.1738 + * @param ch the character to be tested
23.1739 + * @return {@code true} if the character has a defined meaning
23.1740 + * in Unicode; {@code false} otherwise.
23.1741 + * @see Character#isDigit(char)
23.1742 + * @see Character#isLetter(char)
23.1743 + * @see Character#isLetterOrDigit(char)
23.1744 + * @see Character#isLowerCase(char)
23.1745 + * @see Character#isTitleCase(char)
23.1746 + * @see Character#isUpperCase(char)
23.1747 + * @since 1.0.2
23.1748 + */
23.1749 + public static boolean isDefined(char ch) {
23.1750 + return isDefined((int)ch);
23.1751 + }
23.1752 +
23.1753 + /**
23.1754 + * Determines if a character (Unicode code point) is defined in Unicode.
23.1755 + * <p>
23.1756 + * A character is defined if at least one of the following is true:
23.1757 + * <ul>
23.1758 + * <li>It has an entry in the UnicodeData file.
23.1759 + * <li>It has a value in a range defined by the UnicodeData file.
23.1760 + * </ul>
23.1761 + *
23.1762 + * @param codePoint the character (Unicode code point) to be tested.
23.1763 + * @return {@code true} if the character has a defined meaning
23.1764 + * in Unicode; {@code false} otherwise.
23.1765 + * @see Character#isDigit(int)
23.1766 + * @see Character#isLetter(int)
23.1767 + * @see Character#isLetterOrDigit(int)
23.1768 + * @see Character#isLowerCase(int)
23.1769 + * @see Character#isTitleCase(int)
23.1770 + * @see Character#isUpperCase(int)
23.1771 + * @since 1.5
23.1772 + */
23.1773 + public static boolean isDefined(int codePoint) {
23.1774 + return getType(codePoint) != Character.UNASSIGNED;
23.1775 + }
23.1776 +
23.1777 + /**
23.1778 + * Determines if the specified character is a letter.
23.1779 + * <p>
23.1780 + * A character is considered to be a letter if its general
23.1781 + * category type, provided by {@code Character.getType(ch)},
23.1782 + * is any of the following:
23.1783 + * <ul>
23.1784 + * <li> {@code UPPERCASE_LETTER}
23.1785 + * <li> {@code LOWERCASE_LETTER}
23.1786 + * <li> {@code TITLECASE_LETTER}
23.1787 + * <li> {@code MODIFIER_LETTER}
23.1788 + * <li> {@code OTHER_LETTER}
23.1789 + * </ul>
23.1790 + *
23.1791 + * Not all letters have case. Many characters are
23.1792 + * letters but are neither uppercase nor lowercase nor titlecase.
23.1793 + *
23.1794 + * <p><b>Note:</b> This method cannot handle <a
23.1795 + * href="#supplementary"> supplementary characters</a>. To support
23.1796 + * all Unicode characters, including supplementary characters, use
23.1797 + * the {@link #isLetter(int)} method.
23.1798 + *
23.1799 + * @param ch the character to be tested.
23.1800 + * @return {@code true} if the character is a letter;
23.1801 + * {@code false} otherwise.
23.1802 + * @see Character#isDigit(char)
23.1803 + * @see Character#isJavaIdentifierStart(char)
23.1804 + * @see Character#isJavaLetter(char)
23.1805 + * @see Character#isJavaLetterOrDigit(char)
23.1806 + * @see Character#isLetterOrDigit(char)
23.1807 + * @see Character#isLowerCase(char)
23.1808 + * @see Character#isTitleCase(char)
23.1809 + * @see Character#isUnicodeIdentifierStart(char)
23.1810 + * @see Character#isUpperCase(char)
23.1811 + */
23.1812 + public static boolean isLetter(char ch) {
23.1813 + return String.valueOf(ch).matches("\\w") && !isDigit(ch);
23.1814 + }
23.1815 +
23.1816 + /**
23.1817 + * Determines if the specified character (Unicode code point) is a letter.
23.1818 + * <p>
23.1819 + * A character is considered to be a letter if its general
23.1820 + * category type, provided by {@link Character#getType(int) getType(codePoint)},
23.1821 + * is any of the following:
23.1822 + * <ul>
23.1823 + * <li> {@code UPPERCASE_LETTER}
23.1824 + * <li> {@code LOWERCASE_LETTER}
23.1825 + * <li> {@code TITLECASE_LETTER}
23.1826 + * <li> {@code MODIFIER_LETTER}
23.1827 + * <li> {@code OTHER_LETTER}
23.1828 + * </ul>
23.1829 + *
23.1830 + * Not all letters have case. Many characters are
23.1831 + * letters but are neither uppercase nor lowercase nor titlecase.
23.1832 + *
23.1833 + * @param codePoint the character (Unicode code point) to be tested.
23.1834 + * @return {@code true} if the character is a letter;
23.1835 + * {@code false} otherwise.
23.1836 + * @see Character#isDigit(int)
23.1837 + * @see Character#isJavaIdentifierStart(int)
23.1838 + * @see Character#isLetterOrDigit(int)
23.1839 + * @see Character#isLowerCase(int)
23.1840 + * @see Character#isTitleCase(int)
23.1841 + * @see Character#isUnicodeIdentifierStart(int)
23.1842 + * @see Character#isUpperCase(int)
23.1843 + * @since 1.5
23.1844 + */
23.1845 + public static boolean isLetter(int codePoint) {
23.1846 + return fromCodeChars(codePoint).matches("\\w") && !isDigit(codePoint);
23.1847 + }
23.1848 +
23.1849 + /**
23.1850 + * Determines if the specified character is a letter or digit.
23.1851 + * <p>
23.1852 + * A character is considered to be a letter or digit if either
23.1853 + * {@code Character.isLetter(char ch)} or
23.1854 + * {@code Character.isDigit(char ch)} returns
23.1855 + * {@code true} for the character.
23.1856 + *
23.1857 + * <p><b>Note:</b> This method cannot handle <a
23.1858 + * href="#supplementary"> supplementary characters</a>. To support
23.1859 + * all Unicode characters, including supplementary characters, use
23.1860 + * the {@link #isLetterOrDigit(int)} method.
23.1861 + *
23.1862 + * @param ch the character to be tested.
23.1863 + * @return {@code true} if the character is a letter or digit;
23.1864 + * {@code false} otherwise.
23.1865 + * @see Character#isDigit(char)
23.1866 + * @see Character#isJavaIdentifierPart(char)
23.1867 + * @see Character#isJavaLetter(char)
23.1868 + * @see Character#isJavaLetterOrDigit(char)
23.1869 + * @see Character#isLetter(char)
23.1870 + * @see Character#isUnicodeIdentifierPart(char)
23.1871 + * @since 1.0.2
23.1872 + */
23.1873 + public static boolean isLetterOrDigit(char ch) {
23.1874 + return String.valueOf(ch).matches("\\w");
23.1875 + }
23.1876 +
23.1877 + /**
23.1878 + * Determines if the specified character (Unicode code point) is a letter or digit.
23.1879 + * <p>
23.1880 + * A character is considered to be a letter or digit if either
23.1881 + * {@link #isLetter(int) isLetter(codePoint)} or
23.1882 + * {@link #isDigit(int) isDigit(codePoint)} returns
23.1883 + * {@code true} for the character.
23.1884 + *
23.1885 + * @param codePoint the character (Unicode code point) to be tested.
23.1886 + * @return {@code true} if the character is a letter or digit;
23.1887 + * {@code false} otherwise.
23.1888 + * @see Character#isDigit(int)
23.1889 + * @see Character#isJavaIdentifierPart(int)
23.1890 + * @see Character#isLetter(int)
23.1891 + * @see Character#isUnicodeIdentifierPart(int)
23.1892 + * @since 1.5
23.1893 + */
23.1894 + public static boolean isLetterOrDigit(int codePoint) {
23.1895 + return fromCodeChars(codePoint).matches("\\w");
23.1896 + }
23.1897 +
23.1898 + static int getType(int x) {
23.1899 + throw new UnsupportedOperationException();
23.1900 + }
23.1901 +
23.1902 + /**
23.1903 + * Converts the character argument to lowercase using case
23.1904 + * mapping information from the UnicodeData file.
23.1905 + * <p>
23.1906 + * Note that
23.1907 + * {@code Character.isLowerCase(Character.toLowerCase(ch))}
23.1908 + * does not always return {@code true} for some ranges of
23.1909 + * characters, particularly those that are symbols or ideographs.
23.1910 + *
23.1911 + * <p>In general, {@link String#toLowerCase()} should be used to map
23.1912 + * characters to lowercase. {@code String} case mapping methods
23.1913 + * have several benefits over {@code Character} case mapping methods.
23.1914 + * {@code String} case mapping methods can perform locale-sensitive
23.1915 + * mappings, context-sensitive mappings, and 1:M character mappings, whereas
23.1916 + * the {@code Character} case mapping methods cannot.
23.1917 + *
23.1918 + * <p><b>Note:</b> This method cannot handle <a
23.1919 + * href="#supplementary"> supplementary characters</a>. To support
23.1920 + * all Unicode characters, including supplementary characters, use
23.1921 + * the {@link #toLowerCase(int)} method.
23.1922 + *
23.1923 + * @param ch the character to be converted.
23.1924 + * @return the lowercase equivalent of the character, if any;
23.1925 + * otherwise, the character itself.
23.1926 + * @see Character#isLowerCase(char)
23.1927 + * @see String#toLowerCase()
23.1928 + */
23.1929 + public static char toLowerCase(char ch) {
23.1930 + return String.valueOf(ch).toLowerCase().charAt(0);
23.1931 + }
23.1932 +
23.1933 + /**
23.1934 + * Converts the character argument to uppercase using case mapping
23.1935 + * information from the UnicodeData file.
23.1936 + * <p>
23.1937 + * Note that
23.1938 + * {@code Character.isUpperCase(Character.toUpperCase(ch))}
23.1939 + * does not always return {@code true} for some ranges of
23.1940 + * characters, particularly those that are symbols or ideographs.
23.1941 + *
23.1942 + * <p>In general, {@link String#toUpperCase()} should be used to map
23.1943 + * characters to uppercase. {@code String} case mapping methods
23.1944 + * have several benefits over {@code Character} case mapping methods.
23.1945 + * {@code String} case mapping methods can perform locale-sensitive
23.1946 + * mappings, context-sensitive mappings, and 1:M character mappings, whereas
23.1947 + * the {@code Character} case mapping methods cannot.
23.1948 + *
23.1949 + * <p><b>Note:</b> This method cannot handle <a
23.1950 + * href="#supplementary"> supplementary characters</a>. To support
23.1951 + * all Unicode characters, including supplementary characters, use
23.1952 + * the {@link #toUpperCase(int)} method.
23.1953 + *
23.1954 + * @param ch the character to be converted.
23.1955 + * @return the uppercase equivalent of the character, if any;
23.1956 + * otherwise, the character itself.
23.1957 + * @see Character#isUpperCase(char)
23.1958 + * @see String#toUpperCase()
23.1959 + */
23.1960 + public static char toUpperCase(char ch) {
23.1961 + return String.valueOf(ch).toUpperCase().charAt(0);
23.1962 + }
23.1963 +
23.1964 + /**
23.1965 + * Returns the numeric value of the character {@code ch} in the
23.1966 + * specified radix.
23.1967 + * <p>
23.1968 + * If the radix is not in the range {@code MIN_RADIX} ≤
23.1969 + * {@code radix} ≤ {@code MAX_RADIX} or if the
23.1970 + * value of {@code ch} is not a valid digit in the specified
23.1971 + * radix, {@code -1} is returned. A character is a valid digit
23.1972 + * if at least one of the following is true:
23.1973 + * <ul>
23.1974 + * <li>The method {@code isDigit} is {@code true} of the character
23.1975 + * and the Unicode decimal digit value of the character (or its
23.1976 + * single-character decomposition) is less than the specified radix.
23.1977 + * In this case the decimal digit value is returned.
23.1978 + * <li>The character is one of the uppercase Latin letters
23.1979 + * {@code 'A'} through {@code 'Z'} and its code is less than
23.1980 + * {@code radix + 'A' - 10}.
23.1981 + * In this case, {@code ch - 'A' + 10}
23.1982 + * is returned.
23.1983 + * <li>The character is one of the lowercase Latin letters
23.1984 + * {@code 'a'} through {@code 'z'} and its code is less than
23.1985 + * {@code radix + 'a' - 10}.
23.1986 + * In this case, {@code ch - 'a' + 10}
23.1987 + * is returned.
23.1988 + * <li>The character is one of the fullwidth uppercase Latin letters A
23.1989 + * ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
23.1990 + * and its code is less than
23.1991 + * {@code radix + '\u005CuFF21' - 10}.
23.1992 + * In this case, {@code ch - '\u005CuFF21' + 10}
23.1993 + * is returned.
23.1994 + * <li>The character is one of the fullwidth lowercase Latin letters a
23.1995 + * ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
23.1996 + * and its code is less than
23.1997 + * {@code radix + '\u005CuFF41' - 10}.
23.1998 + * In this case, {@code ch - '\u005CuFF41' + 10}
23.1999 + * is returned.
23.2000 + * </ul>
23.2001 + *
23.2002 + * <p><b>Note:</b> This method cannot handle <a
23.2003 + * href="#supplementary"> supplementary characters</a>. To support
23.2004 + * all Unicode characters, including supplementary characters, use
23.2005 + * the {@link #digit(int, int)} method.
23.2006 + *
23.2007 + * @param ch the character to be converted.
23.2008 + * @param radix the radix.
23.2009 + * @return the numeric value represented by the character in the
23.2010 + * specified radix.
23.2011 + * @see Character#forDigit(int, int)
23.2012 + * @see Character#isDigit(char)
23.2013 + */
23.2014 + public static int digit(char ch, int radix) {
23.2015 + return digit((int)ch, radix);
23.2016 + }
23.2017 +
23.2018 + /**
23.2019 + * Returns the numeric value of the specified character (Unicode
23.2020 + * code point) in the specified radix.
23.2021 + *
23.2022 + * <p>If the radix is not in the range {@code MIN_RADIX} ≤
23.2023 + * {@code radix} ≤ {@code MAX_RADIX} or if the
23.2024 + * character is not a valid digit in the specified
23.2025 + * radix, {@code -1} is returned. A character is a valid digit
23.2026 + * if at least one of the following is true:
23.2027 + * <ul>
23.2028 + * <li>The method {@link #isDigit(int) isDigit(codePoint)} is {@code true} of the character
23.2029 + * and the Unicode decimal digit value of the character (or its
23.2030 + * single-character decomposition) is less than the specified radix.
23.2031 + * In this case the decimal digit value is returned.
23.2032 + * <li>The character is one of the uppercase Latin letters
23.2033 + * {@code 'A'} through {@code 'Z'} and its code is less than
23.2034 + * {@code radix + 'A' - 10}.
23.2035 + * In this case, {@code codePoint - 'A' + 10}
23.2036 + * is returned.
23.2037 + * <li>The character is one of the lowercase Latin letters
23.2038 + * {@code 'a'} through {@code 'z'} and its code is less than
23.2039 + * {@code radix + 'a' - 10}.
23.2040 + * In this case, {@code codePoint - 'a' + 10}
23.2041 + * is returned.
23.2042 + * <li>The character is one of the fullwidth uppercase Latin letters A
23.2043 + * ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
23.2044 + * and its code is less than
23.2045 + * {@code radix + '\u005CuFF21' - 10}.
23.2046 + * In this case,
23.2047 + * {@code codePoint - '\u005CuFF21' + 10}
23.2048 + * is returned.
23.2049 + * <li>The character is one of the fullwidth lowercase Latin letters a
23.2050 + * ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
23.2051 + * and its code is less than
23.2052 + * {@code radix + '\u005CuFF41'- 10}.
23.2053 + * In this case,
23.2054 + * {@code codePoint - '\u005CuFF41' + 10}
23.2055 + * is returned.
23.2056 + * </ul>
23.2057 + *
23.2058 + * @param codePoint the character (Unicode code point) to be converted.
23.2059 + * @param radix the radix.
23.2060 + * @return the numeric value represented by the character in the
23.2061 + * specified radix.
23.2062 + * @see Character#forDigit(int, int)
23.2063 + * @see Character#isDigit(int)
23.2064 + * @since 1.5
23.2065 + */
23.2066 + public static int digit(int codePoint, int radix) {
23.2067 + throw new UnsupportedOperationException();
23.2068 + }
23.2069 +
23.2070 + /**
23.2071 + * Returns the {@code int} value that the specified Unicode
23.2072 + * character represents. For example, the character
23.2073 + * {@code '\u005Cu216C'} (the roman numeral fifty) will return
23.2074 + * an int with a value of 50.
23.2075 + * <p>
23.2076 + * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
23.2077 + * {@code '\u005Cu005A'}), lowercase
23.2078 + * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
23.2079 + * full width variant ({@code '\u005CuFF21'} through
23.2080 + * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
23.2081 + * {@code '\u005CuFF5A'}) forms have numeric values from 10
23.2082 + * through 35. This is independent of the Unicode specification,
23.2083 + * which does not assign numeric values to these {@code char}
23.2084 + * values.
23.2085 + * <p>
23.2086 + * If the character does not have a numeric value, then -1 is returned.
23.2087 + * If the character has a numeric value that cannot be represented as a
23.2088 + * nonnegative integer (for example, a fractional value), then -2
23.2089 + * is returned.
23.2090 + *
23.2091 + * <p><b>Note:</b> This method cannot handle <a
23.2092 + * href="#supplementary"> supplementary characters</a>. To support
23.2093 + * all Unicode characters, including supplementary characters, use
23.2094 + * the {@link #getNumericValue(int)} method.
23.2095 + *
23.2096 + * @param ch the character to be converted.
23.2097 + * @return the numeric value of the character, as a nonnegative {@code int}
23.2098 + * value; -2 if the character has a numeric value that is not a
23.2099 + * nonnegative integer; -1 if the character has no numeric value.
23.2100 + * @see Character#forDigit(int, int)
23.2101 + * @see Character#isDigit(char)
23.2102 + * @since 1.1
23.2103 + */
23.2104 + public static int getNumericValue(char ch) {
23.2105 + return getNumericValue((int)ch);
23.2106 + }
23.2107 +
23.2108 + /**
23.2109 + * Returns the {@code int} value that the specified
23.2110 + * character (Unicode code point) represents. For example, the character
23.2111 + * {@code '\u005Cu216C'} (the Roman numeral fifty) will return
23.2112 + * an {@code int} with a value of 50.
23.2113 + * <p>
23.2114 + * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
23.2115 + * {@code '\u005Cu005A'}), lowercase
23.2116 + * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
23.2117 + * full width variant ({@code '\u005CuFF21'} through
23.2118 + * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
23.2119 + * {@code '\u005CuFF5A'}) forms have numeric values from 10
23.2120 + * through 35. This is independent of the Unicode specification,
23.2121 + * which does not assign numeric values to these {@code char}
23.2122 + * values.
23.2123 + * <p>
23.2124 + * If the character does not have a numeric value, then -1 is returned.
23.2125 + * If the character has a numeric value that cannot be represented as a
23.2126 + * nonnegative integer (for example, a fractional value), then -2
23.2127 + * is returned.
23.2128 + *
23.2129 + * @param codePoint the character (Unicode code point) to be converted.
23.2130 + * @return the numeric value of the character, as a nonnegative {@code int}
23.2131 + * value; -2 if the character has a numeric value that is not a
23.2132 + * nonnegative integer; -1 if the character has no numeric value.
23.2133 + * @see Character#forDigit(int, int)
23.2134 + * @see Character#isDigit(int)
23.2135 + * @since 1.5
23.2136 + */
23.2137 + public static int getNumericValue(int codePoint) {
23.2138 + throw new UnsupportedOperationException();
23.2139 + }
23.2140 +
23.2141 + /**
23.2142 + * Determines if the specified character is ISO-LATIN-1 white space.
23.2143 + * This method returns {@code true} for the following five
23.2144 + * characters only:
23.2145 + * <table>
23.2146 + * <tr><td>{@code '\t'}</td> <td>{@code U+0009}</td>
23.2147 + * <td>{@code HORIZONTAL TABULATION}</td></tr>
23.2148 + * <tr><td>{@code '\n'}</td> <td>{@code U+000A}</td>
23.2149 + * <td>{@code NEW LINE}</td></tr>
23.2150 + * <tr><td>{@code '\f'}</td> <td>{@code U+000C}</td>
23.2151 + * <td>{@code FORM FEED}</td></tr>
23.2152 + * <tr><td>{@code '\r'}</td> <td>{@code U+000D}</td>
23.2153 + * <td>{@code CARRIAGE RETURN}</td></tr>
23.2154 + * <tr><td>{@code ' '}</td> <td>{@code U+0020}</td>
23.2155 + * <td>{@code SPACE}</td></tr>
23.2156 + * </table>
23.2157 + *
23.2158 + * @param ch the character to be tested.
23.2159 + * @return {@code true} if the character is ISO-LATIN-1 white
23.2160 + * space; {@code false} otherwise.
23.2161 + * @see Character#isSpaceChar(char)
23.2162 + * @see Character#isWhitespace(char)
23.2163 + * @deprecated Replaced by isWhitespace(char).
23.2164 + */
23.2165 + @Deprecated
23.2166 + public static boolean isSpace(char ch) {
23.2167 + return (ch <= 0x0020) &&
23.2168 + (((((1L << 0x0009) |
23.2169 + (1L << 0x000A) |
23.2170 + (1L << 0x000C) |
23.2171 + (1L << 0x000D) |
23.2172 + (1L << 0x0020)) >> ch) & 1L) != 0);
23.2173 + }
23.2174 +
23.2175 +
23.2176 +
23.2177 + /**
23.2178 + * Determines if the specified character is white space according to Java.
23.2179 + * A character is a Java whitespace character if and only if it satisfies
23.2180 + * one of the following criteria:
23.2181 + * <ul>
23.2182 + * <li> It is a Unicode space character ({@code SPACE_SEPARATOR},
23.2183 + * {@code LINE_SEPARATOR}, or {@code PARAGRAPH_SEPARATOR})
23.2184 + * but is not also a non-breaking space ({@code '\u005Cu00A0'},
23.2185 + * {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
23.2186 + * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
23.2187 + * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
23.2188 + * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
23.2189 + * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
23.2190 + * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
23.2191 + * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
23.2192 + * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
23.2193 + * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
23.2194 + * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
23.2195 + * </ul>
23.2196 + *
23.2197 + * <p><b>Note:</b> This method cannot handle <a
23.2198 + * href="#supplementary"> supplementary characters</a>. To support
23.2199 + * all Unicode characters, including supplementary characters, use
23.2200 + * the {@link #isWhitespace(int)} method.
23.2201 + *
23.2202 + * @param ch the character to be tested.
23.2203 + * @return {@code true} if the character is a Java whitespace
23.2204 + * character; {@code false} otherwise.
23.2205 + * @see Character#isSpaceChar(char)
23.2206 + * @since 1.1
23.2207 + */
23.2208 + public static boolean isWhitespace(char ch) {
23.2209 + return isWhitespace((int)ch);
23.2210 + }
23.2211 +
23.2212 + /**
23.2213 + * Determines if the specified character (Unicode code point) is
23.2214 + * white space according to Java. A character is a Java
23.2215 + * whitespace character if and only if it satisfies one of the
23.2216 + * following criteria:
23.2217 + * <ul>
23.2218 + * <li> It is a Unicode space character ({@link #SPACE_SEPARATOR},
23.2219 + * {@link #LINE_SEPARATOR}, or {@link #PARAGRAPH_SEPARATOR})
23.2220 + * but is not also a non-breaking space ({@code '\u005Cu00A0'},
23.2221 + * {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
23.2222 + * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
23.2223 + * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
23.2224 + * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
23.2225 + * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
23.2226 + * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
23.2227 + * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
23.2228 + * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
23.2229 + * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
23.2230 + * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
23.2231 + * </ul>
23.2232 + * <p>
23.2233 + *
23.2234 + * @param codePoint the character (Unicode code point) to be tested.
23.2235 + * @return {@code true} if the character is a Java whitespace
23.2236 + * character; {@code false} otherwise.
23.2237 + * @see Character#isSpaceChar(int)
23.2238 + * @since 1.5
23.2239 + */
23.2240 + public static boolean isWhitespace(int codePoint) {
23.2241 + throw new UnsupportedOperationException();
23.2242 + }
23.2243 +
23.2244 + /**
23.2245 + * Determines if the specified character is an ISO control
23.2246 + * character. A character is considered to be an ISO control
23.2247 + * character if its code is in the range {@code '\u005Cu0000'}
23.2248 + * through {@code '\u005Cu001F'} or in the range
23.2249 + * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
23.2250 + *
23.2251 + * <p><b>Note:</b> This method cannot handle <a
23.2252 + * href="#supplementary"> supplementary characters</a>. To support
23.2253 + * all Unicode characters, including supplementary characters, use
23.2254 + * the {@link #isISOControl(int)} method.
23.2255 + *
23.2256 + * @param ch the character to be tested.
23.2257 + * @return {@code true} if the character is an ISO control character;
23.2258 + * {@code false} otherwise.
23.2259 + *
23.2260 + * @see Character#isSpaceChar(char)
23.2261 + * @see Character#isWhitespace(char)
23.2262 + * @since 1.1
23.2263 + */
23.2264 + public static boolean isISOControl(char ch) {
23.2265 + return isISOControl((int)ch);
23.2266 + }
23.2267 +
23.2268 + /**
23.2269 + * Determines if the referenced character (Unicode code point) is an ISO control
23.2270 + * character. A character is considered to be an ISO control
23.2271 + * character if its code is in the range {@code '\u005Cu0000'}
23.2272 + * through {@code '\u005Cu001F'} or in the range
23.2273 + * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
23.2274 + *
23.2275 + * @param codePoint the character (Unicode code point) to be tested.
23.2276 + * @return {@code true} if the character is an ISO control character;
23.2277 + * {@code false} otherwise.
23.2278 + * @see Character#isSpaceChar(int)
23.2279 + * @see Character#isWhitespace(int)
23.2280 + * @since 1.5
23.2281 + */
23.2282 + public static boolean isISOControl(int codePoint) {
23.2283 + // Optimized form of:
23.2284 + // (codePoint >= 0x00 && codePoint <= 0x1F) ||
23.2285 + // (codePoint >= 0x7F && codePoint <= 0x9F);
23.2286 + return codePoint <= 0x9F &&
23.2287 + (codePoint >= 0x7F || (codePoint >>> 5 == 0));
23.2288 + }
23.2289 +
23.2290 + /**
23.2291 + * Determines the character representation for a specific digit in
23.2292 + * the specified radix. If the value of {@code radix} is not a
23.2293 + * valid radix, or the value of {@code digit} is not a valid
23.2294 + * digit in the specified radix, the null character
23.2295 + * ({@code '\u005Cu0000'}) is returned.
23.2296 + * <p>
23.2297 + * The {@code radix} argument is valid if it is greater than or
23.2298 + * equal to {@code MIN_RADIX} and less than or equal to
23.2299 + * {@code MAX_RADIX}. The {@code digit} argument is valid if
23.2300 + * {@code 0 <= digit < radix}.
23.2301 + * <p>
23.2302 + * If the digit is less than 10, then
23.2303 + * {@code '0' + digit} is returned. Otherwise, the value
23.2304 + * {@code 'a' + digit - 10} is returned.
23.2305 + *
23.2306 + * @param digit the number to convert to a character.
23.2307 + * @param radix the radix.
23.2308 + * @return the {@code char} representation of the specified digit
23.2309 + * in the specified radix.
23.2310 + * @see Character#MIN_RADIX
23.2311 + * @see Character#MAX_RADIX
23.2312 + * @see Character#digit(char, int)
23.2313 + */
23.2314 + public static char forDigit(int digit, int radix) {
23.2315 + if ((digit >= radix) || (digit < 0)) {
23.2316 + return '\0';
23.2317 + }
23.2318 + if ((radix < Character.MIN_RADIX) || (radix > Character.MAX_RADIX)) {
23.2319 + return '\0';
23.2320 + }
23.2321 + if (digit < 10) {
23.2322 + return (char)('0' + digit);
23.2323 + }
23.2324 + return (char)('a' - 10 + digit);
23.2325 + }
23.2326 +
23.2327 + /**
23.2328 + * Compares two {@code Character} objects numerically.
23.2329 + *
23.2330 + * @param anotherCharacter the {@code Character} to be compared.
23.2331 +
23.2332 + * @return the value {@code 0} if the argument {@code Character}
23.2333 + * is equal to this {@code Character}; a value less than
23.2334 + * {@code 0} if this {@code Character} is numerically less
23.2335 + * than the {@code Character} argument; and a value greater than
23.2336 + * {@code 0} if this {@code Character} is numerically greater
23.2337 + * than the {@code Character} argument (unsigned comparison).
23.2338 + * Note that this is strictly a numerical comparison; it is not
23.2339 + * locale-dependent.
23.2340 + * @since 1.2
23.2341 + */
23.2342 + public int compareTo(Character anotherCharacter) {
23.2343 + return compare(this.value, anotherCharacter.value);
23.2344 + }
23.2345 +
23.2346 + /**
23.2347 + * Compares two {@code char} values numerically.
23.2348 + * The value returned is identical to what would be returned by:
23.2349 + * <pre>
23.2350 + * Character.valueOf(x).compareTo(Character.valueOf(y))
23.2351 + * </pre>
23.2352 + *
23.2353 + * @param x the first {@code char} to compare
23.2354 + * @param y the second {@code char} to compare
23.2355 + * @return the value {@code 0} if {@code x == y};
23.2356 + * a value less than {@code 0} if {@code x < y}; and
23.2357 + * a value greater than {@code 0} if {@code x > y}
23.2358 + * @since 1.7
23.2359 + */
23.2360 + public static int compare(char x, char y) {
23.2361 + return x - y;
23.2362 + }
23.2363 +
23.2364 +
23.2365 + /**
23.2366 + * The number of bits used to represent a <tt>char</tt> value in unsigned
23.2367 + * binary form, constant {@code 16}.
23.2368 + *
23.2369 + * @since 1.5
23.2370 + */
23.2371 + public static final int SIZE = 16;
23.2372 +
23.2373 + /**
23.2374 + * Returns the value obtained by reversing the order of the bytes in the
23.2375 + * specified <tt>char</tt> value.
23.2376 + *
23.2377 + * @return the value obtained by reversing (or, equivalently, swapping)
23.2378 + * the bytes in the specified <tt>char</tt> value.
23.2379 + * @since 1.5
23.2380 + */
23.2381 + public static char reverseBytes(char ch) {
23.2382 + return (char) (((ch & 0xFF00) >> 8) | (ch << 8));
23.2383 + }
23.2384 +
23.2385 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
24.2 +++ b/emul/mini/src/main/java/java/lang/Class.java Wed Jan 23 20:39:23 2013 +0100
24.3 @@ -0,0 +1,1205 @@
24.4 +/*
24.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24.7 + *
24.8 + * This code is free software; you can redistribute it and/or modify it
24.9 + * under the terms of the GNU General Public License version 2 only, as
24.10 + * published by the Free Software Foundation. Oracle designates this
24.11 + * particular file as subject to the "Classpath" exception as provided
24.12 + * by Oracle in the LICENSE file that accompanied this code.
24.13 + *
24.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
24.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24.17 + * version 2 for more details (a copy is included in the LICENSE file that
24.18 + * accompanied this code).
24.19 + *
24.20 + * You should have received a copy of the GNU General Public License version
24.21 + * 2 along with this work; if not, write to the Free Software Foundation,
24.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24.23 + *
24.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24.25 + * or visit www.oracle.com if you need additional information or have any
24.26 + * questions.
24.27 + */
24.28 +
24.29 +package java.lang;
24.30 +
24.31 +import java.io.ByteArrayInputStream;
24.32 +import org.apidesign.bck2brwsr.emul.AnnotationImpl;
24.33 +import java.io.InputStream;
24.34 +import java.lang.annotation.Annotation;
24.35 +import java.lang.reflect.Field;
24.36 +import java.lang.reflect.Method;
24.37 +import java.lang.reflect.TypeVariable;
24.38 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
24.39 +import org.apidesign.bck2brwsr.emul.MethodImpl;
24.40 +
24.41 +/**
24.42 + * Instances of the class {@code Class} represent classes and
24.43 + * interfaces in a running Java application. An enum is a kind of
24.44 + * class and an annotation is a kind of interface. Every array also
24.45 + * belongs to a class that is reflected as a {@code Class} object
24.46 + * that is shared by all arrays with the same element type and number
24.47 + * of dimensions. The primitive Java types ({@code boolean},
24.48 + * {@code byte}, {@code char}, {@code short},
24.49 + * {@code int}, {@code long}, {@code float}, and
24.50 + * {@code double}), and the keyword {@code void} are also
24.51 + * represented as {@code Class} objects.
24.52 + *
24.53 + * <p> {@code Class} has no public constructor. Instead {@code Class}
24.54 + * objects are constructed automatically by the Java Virtual Machine as classes
24.55 + * are loaded and by calls to the {@code defineClass} method in the class
24.56 + * loader.
24.57 + *
24.58 + * <p> The following example uses a {@code Class} object to print the
24.59 + * class name of an object:
24.60 + *
24.61 + * <p> <blockquote><pre>
24.62 + * void printClassName(Object obj) {
24.63 + * System.out.println("The class of " + obj +
24.64 + * " is " + obj.getClass().getName());
24.65 + * }
24.66 + * </pre></blockquote>
24.67 + *
24.68 + * <p> It is also possible to get the {@code Class} object for a named
24.69 + * type (or for void) using a class literal. See Section 15.8.2 of
24.70 + * <cite>The Java™ Language Specification</cite>.
24.71 + * For example:
24.72 + *
24.73 + * <p> <blockquote>
24.74 + * {@code System.out.println("The name of class Foo is: "+Foo.class.getName());}
24.75 + * </blockquote>
24.76 + *
24.77 + * @param <T> the type of the class modeled by this {@code Class}
24.78 + * object. For example, the type of {@code String.class} is {@code
24.79 + * Class<String>}. Use {@code Class<?>} if the class being modeled is
24.80 + * unknown.
24.81 + *
24.82 + * @author unascribed
24.83 + * @see java.lang.ClassLoader#defineClass(byte[], int, int)
24.84 + * @since JDK1.0
24.85 + */
24.86 +public final
24.87 + class Class<T> implements java.io.Serializable,
24.88 + java.lang.reflect.GenericDeclaration,
24.89 + java.lang.reflect.Type,
24.90 + java.lang.reflect.AnnotatedElement {
24.91 + private static final int ANNOTATION= 0x00002000;
24.92 + private static final int ENUM = 0x00004000;
24.93 + private static final int SYNTHETIC = 0x00001000;
24.94 +
24.95 + /*
24.96 + * Constructor. Only the Java Virtual Machine creates Class
24.97 + * objects.
24.98 + */
24.99 + private Class() {}
24.100 +
24.101 +
24.102 + /**
24.103 + * Converts the object to a string. The string representation is the
24.104 + * string "class" or "interface", followed by a space, and then by the
24.105 + * fully qualified name of the class in the format returned by
24.106 + * {@code getName}. If this {@code Class} object represents a
24.107 + * primitive type, this method returns the name of the primitive type. If
24.108 + * this {@code Class} object represents void this method returns
24.109 + * "void".
24.110 + *
24.111 + * @return a string representation of this class object.
24.112 + */
24.113 + public String toString() {
24.114 + return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
24.115 + + getName();
24.116 + }
24.117 +
24.118 +
24.119 + /**
24.120 + * Returns the {@code Class} object associated with the class or
24.121 + * interface with the given string name. Invoking this method is
24.122 + * equivalent to:
24.123 + *
24.124 + * <blockquote>
24.125 + * {@code Class.forName(className, true, currentLoader)}
24.126 + * </blockquote>
24.127 + *
24.128 + * where {@code currentLoader} denotes the defining class loader of
24.129 + * the current class.
24.130 + *
24.131 + * <p> For example, the following code fragment returns the
24.132 + * runtime {@code Class} descriptor for the class named
24.133 + * {@code java.lang.Thread}:
24.134 + *
24.135 + * <blockquote>
24.136 + * {@code Class t = Class.forName("java.lang.Thread")}
24.137 + * </blockquote>
24.138 + * <p>
24.139 + * A call to {@code forName("X")} causes the class named
24.140 + * {@code X} to be initialized.
24.141 + *
24.142 + * @param className the fully qualified name of the desired class.
24.143 + * @return the {@code Class} object for the class with the
24.144 + * specified name.
24.145 + * @exception LinkageError if the linkage fails
24.146 + * @exception ExceptionInInitializerError if the initialization provoked
24.147 + * by this method fails
24.148 + * @exception ClassNotFoundException if the class cannot be located
24.149 + */
24.150 + public static Class<?> forName(String className)
24.151 + throws ClassNotFoundException {
24.152 + if (className.startsWith("[")) {
24.153 + Class<?> arrType = defineArray(className);
24.154 + Class<?> c = arrType;
24.155 + while (c != null && c.isArray()) {
24.156 + c = c.getComponentType0(); // verify component type is sane
24.157 + }
24.158 + return arrType;
24.159 + }
24.160 + Class<?> c = loadCls(className, className.replace('.', '_'));
24.161 + if (c == null) {
24.162 + throw new ClassNotFoundException(className);
24.163 + }
24.164 + return c;
24.165 + }
24.166 +
24.167 + @JavaScriptBody(args = {"n", "c" }, body =
24.168 + "if (vm[c]) return vm[c].$class;\n"
24.169 + + "if (vm.loadClass) {\n"
24.170 + + " vm.loadClass(n);\n"
24.171 + + " if (vm[c]) return vm[c].$class;\n"
24.172 + + "}\n"
24.173 + + "return null;"
24.174 + )
24.175 + private static native Class<?> loadCls(String n, String c);
24.176 +
24.177 +
24.178 + /**
24.179 + * Creates a new instance of the class represented by this {@code Class}
24.180 + * object. The class is instantiated as if by a {@code new}
24.181 + * expression with an empty argument list. The class is initialized if it
24.182 + * has not already been initialized.
24.183 + *
24.184 + * <p>Note that this method propagates any exception thrown by the
24.185 + * nullary constructor, including a checked exception. Use of
24.186 + * this method effectively bypasses the compile-time exception
24.187 + * checking that would otherwise be performed by the compiler.
24.188 + * The {@link
24.189 + * java.lang.reflect.Constructor#newInstance(java.lang.Object...)
24.190 + * Constructor.newInstance} method avoids this problem by wrapping
24.191 + * any exception thrown by the constructor in a (checked) {@link
24.192 + * java.lang.reflect.InvocationTargetException}.
24.193 + *
24.194 + * @return a newly allocated instance of the class represented by this
24.195 + * object.
24.196 + * @exception IllegalAccessException if the class or its nullary
24.197 + * constructor is not accessible.
24.198 + * @exception InstantiationException
24.199 + * if this {@code Class} represents an abstract class,
24.200 + * an interface, an array class, a primitive type, or void;
24.201 + * or if the class has no nullary constructor;
24.202 + * or if the instantiation fails for some other reason.
24.203 + * @exception ExceptionInInitializerError if the initialization
24.204 + * provoked by this method fails.
24.205 + * @exception SecurityException
24.206 + * If a security manager, <i>s</i>, is present and any of the
24.207 + * following conditions is met:
24.208 + *
24.209 + * <ul>
24.210 + *
24.211 + * <li> invocation of
24.212 + * {@link SecurityManager#checkMemberAccess
24.213 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
24.214 + * creation of new instances of this class
24.215 + *
24.216 + * <li> the caller's class loader is not the same as or an
24.217 + * ancestor of the class loader for the current class and
24.218 + * invocation of {@link SecurityManager#checkPackageAccess
24.219 + * s.checkPackageAccess()} denies access to the package
24.220 + * of this class
24.221 + *
24.222 + * </ul>
24.223 + *
24.224 + */
24.225 + @JavaScriptBody(args = { "self", "illegal" }, body =
24.226 + "\nvar c = self.cnstr;"
24.227 + + "\nif (c['cons__V']) {"
24.228 + + "\n if ((c.cons__V.access & 0x1) != 0) {"
24.229 + + "\n var inst = c();"
24.230 + + "\n c.cons__V.call(inst);"
24.231 + + "\n return inst;"
24.232 + + "\n }"
24.233 + + "\n return illegal;"
24.234 + + "\n}"
24.235 + + "\nreturn null;"
24.236 + )
24.237 + private static native Object newInstance0(Class<?> self, Object illegal);
24.238 +
24.239 + public T newInstance()
24.240 + throws InstantiationException, IllegalAccessException
24.241 + {
24.242 + Object illegal = new Object();
24.243 + Object inst = newInstance0(this, illegal);
24.244 + if (inst == null) {
24.245 + throw new InstantiationException(getName());
24.246 + }
24.247 + if (inst == illegal) {
24.248 + throw new IllegalAccessException();
24.249 + }
24.250 + return (T)inst;
24.251 + }
24.252 +
24.253 + /**
24.254 + * Determines if the specified {@code Object} is assignment-compatible
24.255 + * with the object represented by this {@code Class}. This method is
24.256 + * the dynamic equivalent of the Java language {@code instanceof}
24.257 + * operator. The method returns {@code true} if the specified
24.258 + * {@code Object} argument is non-null and can be cast to the
24.259 + * reference type represented by this {@code Class} object without
24.260 + * raising a {@code ClassCastException.} It returns {@code false}
24.261 + * otherwise.
24.262 + *
24.263 + * <p> Specifically, if this {@code Class} object represents a
24.264 + * declared class, this method returns {@code true} if the specified
24.265 + * {@code Object} argument is an instance of the represented class (or
24.266 + * of any of its subclasses); it returns {@code false} otherwise. If
24.267 + * this {@code Class} object represents an array class, this method
24.268 + * returns {@code true} if the specified {@code Object} argument
24.269 + * can be converted to an object of the array class by an identity
24.270 + * conversion or by a widening reference conversion; it returns
24.271 + * {@code false} otherwise. If this {@code Class} object
24.272 + * represents an interface, this method returns {@code true} if the
24.273 + * class or any superclass of the specified {@code Object} argument
24.274 + * implements this interface; it returns {@code false} otherwise. If
24.275 + * this {@code Class} object represents a primitive type, this method
24.276 + * returns {@code false}.
24.277 + *
24.278 + * @param obj the object to check
24.279 + * @return true if {@code obj} is an instance of this class
24.280 + *
24.281 + * @since JDK1.1
24.282 + */
24.283 + public boolean isInstance(Object obj) {
24.284 + String prop = "$instOf_" + getName().replace('.', '_');
24.285 + return hasProperty(obj, prop);
24.286 + }
24.287 +
24.288 + @JavaScriptBody(args = { "who", "prop" }, body =
24.289 + "if (who[prop]) return true; else return false;"
24.290 + )
24.291 + private static native boolean hasProperty(Object who, String prop);
24.292 +
24.293 +
24.294 + /**
24.295 + * Determines if the class or interface represented by this
24.296 + * {@code Class} object is either the same as, or is a superclass or
24.297 + * superinterface of, the class or interface represented by the specified
24.298 + * {@code Class} parameter. It returns {@code true} if so;
24.299 + * otherwise it returns {@code false}. If this {@code Class}
24.300 + * object represents a primitive type, this method returns
24.301 + * {@code true} if the specified {@code Class} parameter is
24.302 + * exactly this {@code Class} object; otherwise it returns
24.303 + * {@code false}.
24.304 + *
24.305 + * <p> Specifically, this method tests whether the type represented by the
24.306 + * specified {@code Class} parameter can be converted to the type
24.307 + * represented by this {@code Class} object via an identity conversion
24.308 + * or via a widening reference conversion. See <em>The Java Language
24.309 + * Specification</em>, sections 5.1.1 and 5.1.4 , for details.
24.310 + *
24.311 + * @param cls the {@code Class} object to be checked
24.312 + * @return the {@code boolean} value indicating whether objects of the
24.313 + * type {@code cls} can be assigned to objects of this class
24.314 + * @exception NullPointerException if the specified Class parameter is
24.315 + * null.
24.316 + * @since JDK1.1
24.317 + */
24.318 + public native boolean isAssignableFrom(Class<?> cls);
24.319 +
24.320 +
24.321 + /**
24.322 + * Determines if the specified {@code Class} object represents an
24.323 + * interface type.
24.324 + *
24.325 + * @return {@code true} if this object represents an interface;
24.326 + * {@code false} otherwise.
24.327 + */
24.328 + public boolean isInterface() {
24.329 + return (getAccess() & 0x200) != 0;
24.330 + }
24.331 +
24.332 + @JavaScriptBody(args = {}, body = "return this.access;")
24.333 + private native int getAccess();
24.334 +
24.335 +
24.336 + /**
24.337 + * Determines if this {@code Class} object represents an array class.
24.338 + *
24.339 + * @return {@code true} if this object represents an array class;
24.340 + * {@code false} otherwise.
24.341 + * @since JDK1.1
24.342 + */
24.343 + public boolean isArray() {
24.344 + return hasProperty(this, "array"); // NOI18N
24.345 + }
24.346 +
24.347 +
24.348 + /**
24.349 + * Determines if the specified {@code Class} object represents a
24.350 + * primitive type.
24.351 + *
24.352 + * <p> There are nine predefined {@code Class} objects to represent
24.353 + * the eight primitive types and void. These are created by the Java
24.354 + * Virtual Machine, and have the same names as the primitive types that
24.355 + * they represent, namely {@code boolean}, {@code byte},
24.356 + * {@code char}, {@code short}, {@code int},
24.357 + * {@code long}, {@code float}, and {@code double}.
24.358 + *
24.359 + * <p> These objects may only be accessed via the following public static
24.360 + * final variables, and are the only {@code Class} objects for which
24.361 + * this method returns {@code true}.
24.362 + *
24.363 + * @return true if and only if this class represents a primitive type
24.364 + *
24.365 + * @see java.lang.Boolean#TYPE
24.366 + * @see java.lang.Character#TYPE
24.367 + * @see java.lang.Byte#TYPE
24.368 + * @see java.lang.Short#TYPE
24.369 + * @see java.lang.Integer#TYPE
24.370 + * @see java.lang.Long#TYPE
24.371 + * @see java.lang.Float#TYPE
24.372 + * @see java.lang.Double#TYPE
24.373 + * @see java.lang.Void#TYPE
24.374 + * @since JDK1.1
24.375 + */
24.376 + @JavaScriptBody(args = {}, body =
24.377 + "if (this.primitive) return true;"
24.378 + + "else return false;"
24.379 + )
24.380 + public native boolean isPrimitive();
24.381 +
24.382 + /**
24.383 + * Returns true if this {@code Class} object represents an annotation
24.384 + * type. Note that if this method returns true, {@link #isInterface()}
24.385 + * would also return true, as all annotation types are also interfaces.
24.386 + *
24.387 + * @return {@code true} if this class object represents an annotation
24.388 + * type; {@code false} otherwise
24.389 + * @since 1.5
24.390 + */
24.391 + public boolean isAnnotation() {
24.392 + return (getModifiers() & ANNOTATION) != 0;
24.393 + }
24.394 +
24.395 + /**
24.396 + * Returns {@code true} if this class is a synthetic class;
24.397 + * returns {@code false} otherwise.
24.398 + * @return {@code true} if and only if this class is a synthetic class as
24.399 + * defined by the Java Language Specification.
24.400 + * @since 1.5
24.401 + */
24.402 + public boolean isSynthetic() {
24.403 + return (getModifiers() & SYNTHETIC) != 0;
24.404 + }
24.405 +
24.406 + /**
24.407 + * Returns the name of the entity (class, interface, array class,
24.408 + * primitive type, or void) represented by this {@code Class} object,
24.409 + * as a {@code String}.
24.410 + *
24.411 + * <p> If this class object represents a reference type that is not an
24.412 + * array type then the binary name of the class is returned, as specified
24.413 + * by
24.414 + * <cite>The Java™ Language Specification</cite>.
24.415 + *
24.416 + * <p> If this class object represents a primitive type or void, then the
24.417 + * name returned is a {@code String} equal to the Java language
24.418 + * keyword corresponding to the primitive type or void.
24.419 + *
24.420 + * <p> If this class object represents a class of arrays, then the internal
24.421 + * form of the name consists of the name of the element type preceded by
24.422 + * one or more '{@code [}' characters representing the depth of the array
24.423 + * nesting. The encoding of element type names is as follows:
24.424 + *
24.425 + * <blockquote><table summary="Element types and encodings">
24.426 + * <tr><th> Element Type <th> <th> Encoding
24.427 + * <tr><td> boolean <td> <td align=center> Z
24.428 + * <tr><td> byte <td> <td align=center> B
24.429 + * <tr><td> char <td> <td align=center> C
24.430 + * <tr><td> class or interface
24.431 + * <td> <td align=center> L<i>classname</i>;
24.432 + * <tr><td> double <td> <td align=center> D
24.433 + * <tr><td> float <td> <td align=center> F
24.434 + * <tr><td> int <td> <td align=center> I
24.435 + * <tr><td> long <td> <td align=center> J
24.436 + * <tr><td> short <td> <td align=center> S
24.437 + * </table></blockquote>
24.438 + *
24.439 + * <p> The class or interface name <i>classname</i> is the binary name of
24.440 + * the class specified above.
24.441 + *
24.442 + * <p> Examples:
24.443 + * <blockquote><pre>
24.444 + * String.class.getName()
24.445 + * returns "java.lang.String"
24.446 + * byte.class.getName()
24.447 + * returns "byte"
24.448 + * (new Object[3]).getClass().getName()
24.449 + * returns "[Ljava.lang.Object;"
24.450 + * (new int[3][4][5][6][7][8][9]).getClass().getName()
24.451 + * returns "[[[[[[[I"
24.452 + * </pre></blockquote>
24.453 + *
24.454 + * @return the name of the class or interface
24.455 + * represented by this object.
24.456 + */
24.457 + public String getName() {
24.458 + return jvmName().replace('/', '.');
24.459 + }
24.460 +
24.461 + @JavaScriptBody(args = {}, body = "return this.jvmName;")
24.462 + private native String jvmName();
24.463 +
24.464 +
24.465 + /**
24.466 + * Returns an array of {@code TypeVariable} objects that represent the
24.467 + * type variables declared by the generic declaration represented by this
24.468 + * {@code GenericDeclaration} object, in declaration order. Returns an
24.469 + * array of length 0 if the underlying generic declaration declares no type
24.470 + * variables.
24.471 + *
24.472 + * @return an array of {@code TypeVariable} objects that represent
24.473 + * the type variables declared by this generic declaration
24.474 + * @throws java.lang.reflect.GenericSignatureFormatError if the generic
24.475 + * signature of this generic declaration does not conform to
24.476 + * the format specified in
24.477 + * <cite>The Java™ Virtual Machine Specification</cite>
24.478 + * @since 1.5
24.479 + */
24.480 + public TypeVariable<Class<T>>[] getTypeParameters() {
24.481 + throw new UnsupportedOperationException();
24.482 + }
24.483 +
24.484 + /**
24.485 + * Returns the {@code Class} representing the superclass of the entity
24.486 + * (class, interface, primitive type or void) represented by this
24.487 + * {@code Class}. If this {@code Class} represents either the
24.488 + * {@code Object} class, an interface, a primitive type, or void, then
24.489 + * null is returned. If this object represents an array class then the
24.490 + * {@code Class} object representing the {@code Object} class is
24.491 + * returned.
24.492 + *
24.493 + * @return the superclass of the class represented by this object.
24.494 + */
24.495 + @JavaScriptBody(args = {}, body = "return this.superclass;")
24.496 + public native Class<? super T> getSuperclass();
24.497 +
24.498 + /**
24.499 + * Returns the Java language modifiers for this class or interface, encoded
24.500 + * in an integer. The modifiers consist of the Java Virtual Machine's
24.501 + * constants for {@code public}, {@code protected},
24.502 + * {@code private}, {@code final}, {@code static},
24.503 + * {@code abstract} and {@code interface}; they should be decoded
24.504 + * using the methods of class {@code Modifier}.
24.505 + *
24.506 + * <p> If the underlying class is an array class, then its
24.507 + * {@code public}, {@code private} and {@code protected}
24.508 + * modifiers are the same as those of its component type. If this
24.509 + * {@code Class} represents a primitive type or void, its
24.510 + * {@code public} modifier is always {@code true}, and its
24.511 + * {@code protected} and {@code private} modifiers are always
24.512 + * {@code false}. If this object represents an array class, a
24.513 + * primitive type or void, then its {@code final} modifier is always
24.514 + * {@code true} and its interface modifier is always
24.515 + * {@code false}. The values of its other modifiers are not determined
24.516 + * by this specification.
24.517 + *
24.518 + * <p> The modifier encodings are defined in <em>The Java Virtual Machine
24.519 + * Specification</em>, table 4.1.
24.520 + *
24.521 + * @return the {@code int} representing the modifiers for this class
24.522 + * @see java.lang.reflect.Modifier
24.523 + * @since JDK1.1
24.524 + */
24.525 + public native int getModifiers();
24.526 +
24.527 +
24.528 + /**
24.529 + * Returns the simple name of the underlying class as given in the
24.530 + * source code. Returns an empty string if the underlying class is
24.531 + * anonymous.
24.532 + *
24.533 + * <p>The simple name of an array is the simple name of the
24.534 + * component type with "[]" appended. In particular the simple
24.535 + * name of an array whose component type is anonymous is "[]".
24.536 + *
24.537 + * @return the simple name of the underlying class
24.538 + * @since 1.5
24.539 + */
24.540 + public String getSimpleName() {
24.541 + if (isArray())
24.542 + return getComponentType().getSimpleName()+"[]";
24.543 +
24.544 + String simpleName = getSimpleBinaryName();
24.545 + if (simpleName == null) { // top level class
24.546 + simpleName = getName();
24.547 + return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
24.548 + }
24.549 + // According to JLS3 "Binary Compatibility" (13.1) the binary
24.550 + // name of non-package classes (not top level) is the binary
24.551 + // name of the immediately enclosing class followed by a '$' followed by:
24.552 + // (for nested and inner classes): the simple name.
24.553 + // (for local classes): 1 or more digits followed by the simple name.
24.554 + // (for anonymous classes): 1 or more digits.
24.555 +
24.556 + // Since getSimpleBinaryName() will strip the binary name of
24.557 + // the immediatly enclosing class, we are now looking at a
24.558 + // string that matches the regular expression "\$[0-9]*"
24.559 + // followed by a simple name (considering the simple of an
24.560 + // anonymous class to be the empty string).
24.561 +
24.562 + // Remove leading "\$[0-9]*" from the name
24.563 + int length = simpleName.length();
24.564 + if (length < 1 || simpleName.charAt(0) != '$')
24.565 + throw new IllegalStateException("Malformed class name");
24.566 + int index = 1;
24.567 + while (index < length && isAsciiDigit(simpleName.charAt(index)))
24.568 + index++;
24.569 + // Eventually, this is the empty string iff this is an anonymous class
24.570 + return simpleName.substring(index);
24.571 + }
24.572 +
24.573 + /**
24.574 + * Returns the "simple binary name" of the underlying class, i.e.,
24.575 + * the binary name without the leading enclosing class name.
24.576 + * Returns {@code null} if the underlying class is a top level
24.577 + * class.
24.578 + */
24.579 + private String getSimpleBinaryName() {
24.580 + Class<?> enclosingClass = null; // XXX getEnclosingClass();
24.581 + if (enclosingClass == null) // top level class
24.582 + return null;
24.583 + // Otherwise, strip the enclosing class' name
24.584 + try {
24.585 + return getName().substring(enclosingClass.getName().length());
24.586 + } catch (IndexOutOfBoundsException ex) {
24.587 + throw new IllegalStateException("Malformed class name");
24.588 + }
24.589 + }
24.590 +
24.591 + /**
24.592 + * Returns an array containing {@code Field} objects reflecting all
24.593 + * the accessible public fields of the class or interface represented by
24.594 + * this {@code Class} object. The elements in the array returned are
24.595 + * not sorted and are not in any particular order. This method returns an
24.596 + * array of length 0 if the class or interface has no accessible public
24.597 + * fields, or if it represents an array class, a primitive type, or void.
24.598 + *
24.599 + * <p> Specifically, if this {@code Class} object represents a class,
24.600 + * this method returns the public fields of this class and of all its
24.601 + * superclasses. If this {@code Class} object represents an
24.602 + * interface, this method returns the fields of this interface and of all
24.603 + * its superinterfaces.
24.604 + *
24.605 + * <p> The implicit length field for array class is not reflected by this
24.606 + * method. User code should use the methods of class {@code Array} to
24.607 + * manipulate arrays.
24.608 + *
24.609 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
24.610 + *
24.611 + * @return the array of {@code Field} objects representing the
24.612 + * public fields
24.613 + * @exception SecurityException
24.614 + * If a security manager, <i>s</i>, is present and any of the
24.615 + * following conditions is met:
24.616 + *
24.617 + * <ul>
24.618 + *
24.619 + * <li> invocation of
24.620 + * {@link SecurityManager#checkMemberAccess
24.621 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
24.622 + * access to the fields within this class
24.623 + *
24.624 + * <li> the caller's class loader is not the same as or an
24.625 + * ancestor of the class loader for the current class and
24.626 + * invocation of {@link SecurityManager#checkPackageAccess
24.627 + * s.checkPackageAccess()} denies access to the package
24.628 + * of this class
24.629 + *
24.630 + * </ul>
24.631 + *
24.632 + * @since JDK1.1
24.633 + */
24.634 + public Field[] getFields() throws SecurityException {
24.635 + throw new SecurityException();
24.636 + }
24.637 +
24.638 + /**
24.639 + * Returns an array containing {@code Method} objects reflecting all
24.640 + * the public <em>member</em> methods of the class or interface represented
24.641 + * by this {@code Class} object, including those declared by the class
24.642 + * or interface and those inherited from superclasses and
24.643 + * superinterfaces. Array classes return all the (public) member methods
24.644 + * inherited from the {@code Object} class. The elements in the array
24.645 + * returned are not sorted and are not in any particular order. This
24.646 + * method returns an array of length 0 if this {@code Class} object
24.647 + * represents a class or interface that has no public member methods, or if
24.648 + * this {@code Class} object represents a primitive type or void.
24.649 + *
24.650 + * <p> The class initialization method {@code <clinit>} is not
24.651 + * included in the returned array. If the class declares multiple public
24.652 + * member methods with the same parameter types, they are all included in
24.653 + * the returned array.
24.654 + *
24.655 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
24.656 + *
24.657 + * @return the array of {@code Method} objects representing the
24.658 + * public methods of this class
24.659 + * @exception SecurityException
24.660 + * If a security manager, <i>s</i>, is present and any of the
24.661 + * following conditions is met:
24.662 + *
24.663 + * <ul>
24.664 + *
24.665 + * <li> invocation of
24.666 + * {@link SecurityManager#checkMemberAccess
24.667 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
24.668 + * access to the methods within this class
24.669 + *
24.670 + * <li> the caller's class loader is not the same as or an
24.671 + * ancestor of the class loader for the current class and
24.672 + * invocation of {@link SecurityManager#checkPackageAccess
24.673 + * s.checkPackageAccess()} denies access to the package
24.674 + * of this class
24.675 + *
24.676 + * </ul>
24.677 + *
24.678 + * @since JDK1.1
24.679 + */
24.680 + public Method[] getMethods() throws SecurityException {
24.681 + return MethodImpl.findMethods(this, 0x01);
24.682 + }
24.683 +
24.684 + /**
24.685 + * Returns a {@code Field} object that reflects the specified public
24.686 + * member field of the class or interface represented by this
24.687 + * {@code Class} object. The {@code name} parameter is a
24.688 + * {@code String} specifying the simple name of the desired field.
24.689 + *
24.690 + * <p> The field to be reflected is determined by the algorithm that
24.691 + * follows. Let C be the class represented by this object:
24.692 + * <OL>
24.693 + * <LI> If C declares a public field with the name specified, that is the
24.694 + * field to be reflected.</LI>
24.695 + * <LI> If no field was found in step 1 above, this algorithm is applied
24.696 + * recursively to each direct superinterface of C. The direct
24.697 + * superinterfaces are searched in the order they were declared.</LI>
24.698 + * <LI> If no field was found in steps 1 and 2 above, and C has a
24.699 + * superclass S, then this algorithm is invoked recursively upon S.
24.700 + * If C has no superclass, then a {@code NoSuchFieldException}
24.701 + * is thrown.</LI>
24.702 + * </OL>
24.703 + *
24.704 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
24.705 + *
24.706 + * @param name the field name
24.707 + * @return the {@code Field} object of this class specified by
24.708 + * {@code name}
24.709 + * @exception NoSuchFieldException if a field with the specified name is
24.710 + * not found.
24.711 + * @exception NullPointerException if {@code name} is {@code null}
24.712 + * @exception SecurityException
24.713 + * If a security manager, <i>s</i>, is present and any of the
24.714 + * following conditions is met:
24.715 + *
24.716 + * <ul>
24.717 + *
24.718 + * <li> invocation of
24.719 + * {@link SecurityManager#checkMemberAccess
24.720 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
24.721 + * access to the field
24.722 + *
24.723 + * <li> the caller's class loader is not the same as or an
24.724 + * ancestor of the class loader for the current class and
24.725 + * invocation of {@link SecurityManager#checkPackageAccess
24.726 + * s.checkPackageAccess()} denies access to the package
24.727 + * of this class
24.728 + *
24.729 + * </ul>
24.730 + *
24.731 + * @since JDK1.1
24.732 + */
24.733 + public Field getField(String name)
24.734 + throws SecurityException {
24.735 + throw new SecurityException();
24.736 + }
24.737 +
24.738 +
24.739 + /**
24.740 + * Returns a {@code Method} object that reflects the specified public
24.741 + * member method of the class or interface represented by this
24.742 + * {@code Class} object. The {@code name} parameter is a
24.743 + * {@code String} specifying the simple name of the desired method. The
24.744 + * {@code parameterTypes} parameter is an array of {@code Class}
24.745 + * objects that identify the method's formal parameter types, in declared
24.746 + * order. If {@code parameterTypes} is {@code null}, it is
24.747 + * treated as if it were an empty array.
24.748 + *
24.749 + * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
24.750 + * {@code NoSuchMethodException} is raised. Otherwise, the method to
24.751 + * be reflected is determined by the algorithm that follows. Let C be the
24.752 + * class represented by this object:
24.753 + * <OL>
24.754 + * <LI> C is searched for any <I>matching methods</I>. If no matching
24.755 + * method is found, the algorithm of step 1 is invoked recursively on
24.756 + * the superclass of C.</LI>
24.757 + * <LI> If no method was found in step 1 above, the superinterfaces of C
24.758 + * are searched for a matching method. If any such method is found, it
24.759 + * is reflected.</LI>
24.760 + * </OL>
24.761 + *
24.762 + * To find a matching method in a class C: If C declares exactly one
24.763 + * public method with the specified name and exactly the same formal
24.764 + * parameter types, that is the method reflected. If more than one such
24.765 + * method is found in C, and one of these methods has a return type that is
24.766 + * more specific than any of the others, that method is reflected;
24.767 + * otherwise one of the methods is chosen arbitrarily.
24.768 + *
24.769 + * <p>Note that there may be more than one matching method in a
24.770 + * class because while the Java language forbids a class to
24.771 + * declare multiple methods with the same signature but different
24.772 + * return types, the Java virtual machine does not. This
24.773 + * increased flexibility in the virtual machine can be used to
24.774 + * implement various language features. For example, covariant
24.775 + * returns can be implemented with {@linkplain
24.776 + * java.lang.reflect.Method#isBridge bridge methods}; the bridge
24.777 + * method and the method being overridden would have the same
24.778 + * signature but different return types.
24.779 + *
24.780 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
24.781 + *
24.782 + * @param name the name of the method
24.783 + * @param parameterTypes the list of parameters
24.784 + * @return the {@code Method} object that matches the specified
24.785 + * {@code name} and {@code parameterTypes}
24.786 + * @exception NoSuchMethodException if a matching method is not found
24.787 + * or if the name is "<init>"or "<clinit>".
24.788 + * @exception NullPointerException if {@code name} is {@code null}
24.789 + * @exception SecurityException
24.790 + * If a security manager, <i>s</i>, is present and any of the
24.791 + * following conditions is met:
24.792 + *
24.793 + * <ul>
24.794 + *
24.795 + * <li> invocation of
24.796 + * {@link SecurityManager#checkMemberAccess
24.797 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
24.798 + * access to the method
24.799 + *
24.800 + * <li> the caller's class loader is not the same as or an
24.801 + * ancestor of the class loader for the current class and
24.802 + * invocation of {@link SecurityManager#checkPackageAccess
24.803 + * s.checkPackageAccess()} denies access to the package
24.804 + * of this class
24.805 + *
24.806 + * </ul>
24.807 + *
24.808 + * @since JDK1.1
24.809 + */
24.810 + public Method getMethod(String name, Class<?>... parameterTypes)
24.811 + throws SecurityException, NoSuchMethodException {
24.812 + Method m = MethodImpl.findMethod(this, name, parameterTypes);
24.813 + if (m == null) {
24.814 + StringBuilder sb = new StringBuilder();
24.815 + sb.append(getName()).append('.').append(name).append('(');
24.816 + String sep = "";
24.817 + for (int i = 0; i < parameterTypes.length; i++) {
24.818 + sb.append(sep).append(parameterTypes[i].getName());
24.819 + sep = ", ";
24.820 + }
24.821 + sb.append(')');
24.822 + throw new NoSuchMethodException(sb.toString());
24.823 + }
24.824 + return m;
24.825 + }
24.826 +
24.827 + /**
24.828 + * Character.isDigit answers {@code true} to some non-ascii
24.829 + * digits. This one does not.
24.830 + */
24.831 + private static boolean isAsciiDigit(char c) {
24.832 + return '0' <= c && c <= '9';
24.833 + }
24.834 +
24.835 + /**
24.836 + * Returns the canonical name of the underlying class as
24.837 + * defined by the Java Language Specification. Returns null if
24.838 + * the underlying class does not have a canonical name (i.e., if
24.839 + * it is a local or anonymous class or an array whose component
24.840 + * type does not have a canonical name).
24.841 + * @return the canonical name of the underlying class if it exists, and
24.842 + * {@code null} otherwise.
24.843 + * @since 1.5
24.844 + */
24.845 + public String getCanonicalName() {
24.846 + if (isArray()) {
24.847 + String canonicalName = getComponentType().getCanonicalName();
24.848 + if (canonicalName != null)
24.849 + return canonicalName + "[]";
24.850 + else
24.851 + return null;
24.852 + }
24.853 +// if (isLocalOrAnonymousClass())
24.854 +// return null;
24.855 +// Class<?> enclosingClass = getEnclosingClass();
24.856 + Class<?> enclosingClass = null;
24.857 + if (enclosingClass == null) { // top level class
24.858 + return getName();
24.859 + } else {
24.860 + String enclosingName = enclosingClass.getCanonicalName();
24.861 + if (enclosingName == null)
24.862 + return null;
24.863 + return enclosingName + "." + getSimpleName();
24.864 + }
24.865 + }
24.866 +
24.867 + /**
24.868 + * Finds a resource with a given name. The rules for searching resources
24.869 + * associated with a given class are implemented by the defining
24.870 + * {@linkplain ClassLoader class loader} of the class. This method
24.871 + * delegates to this object's class loader. If this object was loaded by
24.872 + * the bootstrap class loader, the method delegates to {@link
24.873 + * ClassLoader#getSystemResourceAsStream}.
24.874 + *
24.875 + * <p> Before delegation, an absolute resource name is constructed from the
24.876 + * given resource name using this algorithm:
24.877 + *
24.878 + * <ul>
24.879 + *
24.880 + * <li> If the {@code name} begins with a {@code '/'}
24.881 + * (<tt>'\u002f'</tt>), then the absolute name of the resource is the
24.882 + * portion of the {@code name} following the {@code '/'}.
24.883 + *
24.884 + * <li> Otherwise, the absolute name is of the following form:
24.885 + *
24.886 + * <blockquote>
24.887 + * {@code modified_package_name/name}
24.888 + * </blockquote>
24.889 + *
24.890 + * <p> Where the {@code modified_package_name} is the package name of this
24.891 + * object with {@code '/'} substituted for {@code '.'}
24.892 + * (<tt>'\u002e'</tt>).
24.893 + *
24.894 + * </ul>
24.895 + *
24.896 + * @param name name of the desired resource
24.897 + * @return A {@link java.io.InputStream} object or {@code null} if
24.898 + * no resource with this name is found
24.899 + * @throws NullPointerException If {@code name} is {@code null}
24.900 + * @since JDK1.1
24.901 + */
24.902 + public InputStream getResourceAsStream(String name) {
24.903 + name = resolveName(name);
24.904 + byte[] arr = getResourceAsStream0(name);
24.905 + return arr == null ? null : new ByteArrayInputStream(arr);
24.906 + }
24.907 +
24.908 + @JavaScriptBody(args = "name", body =
24.909 + "return (vm.loadBytes) ? vm.loadBytes(name) : null;"
24.910 + )
24.911 + private static native byte[] getResourceAsStream0(String name);
24.912 +
24.913 + /**
24.914 + * Finds a resource with a given name. The rules for searching resources
24.915 + * associated with a given class are implemented by the defining
24.916 + * {@linkplain ClassLoader class loader} of the class. This method
24.917 + * delegates to this object's class loader. If this object was loaded by
24.918 + * the bootstrap class loader, the method delegates to {@link
24.919 + * ClassLoader#getSystemResource}.
24.920 + *
24.921 + * <p> Before delegation, an absolute resource name is constructed from the
24.922 + * given resource name using this algorithm:
24.923 + *
24.924 + * <ul>
24.925 + *
24.926 + * <li> If the {@code name} begins with a {@code '/'}
24.927 + * (<tt>'\u002f'</tt>), then the absolute name of the resource is the
24.928 + * portion of the {@code name} following the {@code '/'}.
24.929 + *
24.930 + * <li> Otherwise, the absolute name is of the following form:
24.931 + *
24.932 + * <blockquote>
24.933 + * {@code modified_package_name/name}
24.934 + * </blockquote>
24.935 + *
24.936 + * <p> Where the {@code modified_package_name} is the package name of this
24.937 + * object with {@code '/'} substituted for {@code '.'}
24.938 + * (<tt>'\u002e'</tt>).
24.939 + *
24.940 + * </ul>
24.941 + *
24.942 + * @param name name of the desired resource
24.943 + * @return A {@link java.net.URL} object or {@code null} if no
24.944 + * resource with this name is found
24.945 + * @since JDK1.1
24.946 + */
24.947 + public java.net.URL getResource(String name) {
24.948 + name = resolveName(name);
24.949 + ClassLoader cl = null;
24.950 + if (cl==null) {
24.951 + // A system class.
24.952 + return ClassLoader.getSystemResource(name);
24.953 + }
24.954 + return cl.getResource(name);
24.955 + }
24.956 +
24.957 +
24.958 + /**
24.959 + * Add a package name prefix if the name is not absolute Remove leading "/"
24.960 + * if name is absolute
24.961 + */
24.962 + private String resolveName(String name) {
24.963 + if (name == null) {
24.964 + return name;
24.965 + }
24.966 + if (!name.startsWith("/")) {
24.967 + Class<?> c = this;
24.968 + while (c.isArray()) {
24.969 + c = c.getComponentType();
24.970 + }
24.971 + String baseName = c.getName();
24.972 + int index = baseName.lastIndexOf('.');
24.973 + if (index != -1) {
24.974 + name = baseName.substring(0, index).replace('.', '/')
24.975 + +"/"+name;
24.976 + }
24.977 + } else {
24.978 + name = name.substring(1);
24.979 + }
24.980 + return name;
24.981 + }
24.982 +
24.983 + /**
24.984 + * Returns the class loader for the class. Some implementations may use
24.985 + * null to represent the bootstrap class loader. This method will return
24.986 + * null in such implementations if this class was loaded by the bootstrap
24.987 + * class loader.
24.988 + *
24.989 + * <p> If a security manager is present, and the caller's class loader is
24.990 + * not null and the caller's class loader is not the same as or an ancestor of
24.991 + * the class loader for the class whose class loader is requested, then
24.992 + * this method calls the security manager's {@code checkPermission}
24.993 + * method with a {@code RuntimePermission("getClassLoader")}
24.994 + * permission to ensure it's ok to access the class loader for the class.
24.995 + *
24.996 + * <p>If this object
24.997 + * represents a primitive type or void, null is returned.
24.998 + *
24.999 + * @return the class loader that loaded the class or interface
24.1000 + * represented by this object.
24.1001 + * @throws SecurityException
24.1002 + * if a security manager exists and its
24.1003 + * {@code checkPermission} method denies
24.1004 + * access to the class loader for the class.
24.1005 + * @see java.lang.ClassLoader
24.1006 + * @see SecurityManager#checkPermission
24.1007 + * @see java.lang.RuntimePermission
24.1008 + */
24.1009 + public ClassLoader getClassLoader() {
24.1010 + throw new SecurityException();
24.1011 + }
24.1012 +
24.1013 + /**
24.1014 + * Returns the {@code Class} representing the component type of an
24.1015 + * array. If this class does not represent an array class this method
24.1016 + * returns null.
24.1017 + *
24.1018 + * @return the {@code Class} representing the component type of this
24.1019 + * class if this class is an array
24.1020 + * @see java.lang.reflect.Array
24.1021 + * @since JDK1.1
24.1022 + */
24.1023 + public Class<?> getComponentType() {
24.1024 + if (isArray()) {
24.1025 + try {
24.1026 + return getComponentType0();
24.1027 + } catch (ClassNotFoundException cnfe) {
24.1028 + throw new IllegalStateException(cnfe);
24.1029 + }
24.1030 + }
24.1031 + return null;
24.1032 + }
24.1033 +
24.1034 + private Class<?> getComponentType0() throws ClassNotFoundException {
24.1035 + String n = getName().substring(1);
24.1036 + switch (n.charAt(0)) {
24.1037 + case 'L':
24.1038 + n = n.substring(1, n.length() - 1);
24.1039 + return Class.forName(n);
24.1040 + case 'I':
24.1041 + return Integer.TYPE;
24.1042 + case 'J':
24.1043 + return Long.TYPE;
24.1044 + case 'D':
24.1045 + return Double.TYPE;
24.1046 + case 'F':
24.1047 + return Float.TYPE;
24.1048 + case 'B':
24.1049 + return Byte.TYPE;
24.1050 + case 'Z':
24.1051 + return Boolean.TYPE;
24.1052 + case 'S':
24.1053 + return Short.TYPE;
24.1054 + case 'V':
24.1055 + return Void.TYPE;
24.1056 + case 'C':
24.1057 + return Character.TYPE;
24.1058 + case '[':
24.1059 + return defineArray(n);
24.1060 + default:
24.1061 + throw new ClassNotFoundException("Unknown component type of " + getName());
24.1062 + }
24.1063 + }
24.1064 +
24.1065 + @JavaScriptBody(args = { "sig" }, body =
24.1066 + "var c = Array[sig];\n" +
24.1067 + "if (c) return c;\n" +
24.1068 + "c = vm.java_lang_Class(true);\n" +
24.1069 + "c.jvmName = sig;\n" +
24.1070 + "c.superclass = vm.java_lang_Object(false).$class;\n" +
24.1071 + "c.array = true;\n" +
24.1072 + "Array[sig] = c;\n" +
24.1073 + "return c;"
24.1074 + )
24.1075 + private static native Class<?> defineArray(String sig);
24.1076 +
24.1077 + /**
24.1078 + * Returns true if and only if this class was declared as an enum in the
24.1079 + * source code.
24.1080 + *
24.1081 + * @return true if and only if this class was declared as an enum in the
24.1082 + * source code
24.1083 + * @since 1.5
24.1084 + */
24.1085 + public boolean isEnum() {
24.1086 + // An enum must both directly extend java.lang.Enum and have
24.1087 + // the ENUM bit set; classes for specialized enum constants
24.1088 + // don't do the former.
24.1089 + return (this.getModifiers() & ENUM) != 0 &&
24.1090 + this.getSuperclass() == java.lang.Enum.class;
24.1091 + }
24.1092 +
24.1093 + /**
24.1094 + * Casts an object to the class or interface represented
24.1095 + * by this {@code Class} object.
24.1096 + *
24.1097 + * @param obj the object to be cast
24.1098 + * @return the object after casting, or null if obj is null
24.1099 + *
24.1100 + * @throws ClassCastException if the object is not
24.1101 + * null and is not assignable to the type T.
24.1102 + *
24.1103 + * @since 1.5
24.1104 + */
24.1105 + public T cast(Object obj) {
24.1106 + if (obj != null && !isInstance(obj))
24.1107 + throw new ClassCastException(cannotCastMsg(obj));
24.1108 + return (T) obj;
24.1109 + }
24.1110 +
24.1111 + private String cannotCastMsg(Object obj) {
24.1112 + return "Cannot cast " + obj.getClass().getName() + " to " + getName();
24.1113 + }
24.1114 +
24.1115 + /**
24.1116 + * Casts this {@code Class} object to represent a subclass of the class
24.1117 + * represented by the specified class object. Checks that that the cast
24.1118 + * is valid, and throws a {@code ClassCastException} if it is not. If
24.1119 + * this method succeeds, it always returns a reference to this class object.
24.1120 + *
24.1121 + * <p>This method is useful when a client needs to "narrow" the type of
24.1122 + * a {@code Class} object to pass it to an API that restricts the
24.1123 + * {@code Class} objects that it is willing to accept. A cast would
24.1124 + * generate a compile-time warning, as the correctness of the cast
24.1125 + * could not be checked at runtime (because generic types are implemented
24.1126 + * by erasure).
24.1127 + *
24.1128 + * @return this {@code Class} object, cast to represent a subclass of
24.1129 + * the specified class object.
24.1130 + * @throws ClassCastException if this {@code Class} object does not
24.1131 + * represent a subclass of the specified class (here "subclass" includes
24.1132 + * the class itself).
24.1133 + * @since 1.5
24.1134 + */
24.1135 + public <U> Class<? extends U> asSubclass(Class<U> clazz) {
24.1136 + if (clazz.isAssignableFrom(this))
24.1137 + return (Class<? extends U>) this;
24.1138 + else
24.1139 + throw new ClassCastException(this.toString());
24.1140 + }
24.1141 +
24.1142 + @JavaScriptBody(args = { "ac" },
24.1143 + body =
24.1144 + "if (this.anno) {"
24.1145 + + " return this.anno['L' + ac.jvmName + ';'];"
24.1146 + + "} else return null;"
24.1147 + )
24.1148 + private Object getAnnotationData(Class<?> annotationClass) {
24.1149 + throw new UnsupportedOperationException();
24.1150 + }
24.1151 + /**
24.1152 + * @throws NullPointerException {@inheritDoc}
24.1153 + * @since 1.5
24.1154 + */
24.1155 + public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
24.1156 + Object data = getAnnotationData(annotationClass);
24.1157 + return data == null ? null : AnnotationImpl.create(annotationClass, data);
24.1158 + }
24.1159 +
24.1160 + /**
24.1161 + * @throws NullPointerException {@inheritDoc}
24.1162 + * @since 1.5
24.1163 + */
24.1164 + @JavaScriptBody(args = { "ac" },
24.1165 + body = "if (this.anno && this.anno['L' + ac.jvmName + ';']) { return true; }"
24.1166 + + "else return false;"
24.1167 + )
24.1168 + public boolean isAnnotationPresent(
24.1169 + Class<? extends Annotation> annotationClass) {
24.1170 + if (annotationClass == null)
24.1171 + throw new NullPointerException();
24.1172 +
24.1173 + return getAnnotation(annotationClass) != null;
24.1174 + }
24.1175 +
24.1176 + @JavaScriptBody(args = {}, body = "return this.anno;")
24.1177 + private Object getAnnotationData() {
24.1178 + throw new UnsupportedOperationException();
24.1179 + }
24.1180 +
24.1181 + /**
24.1182 + * @since 1.5
24.1183 + */
24.1184 + public Annotation[] getAnnotations() {
24.1185 + Object data = getAnnotationData();
24.1186 + return data == null ? new Annotation[0] : AnnotationImpl.create(data);
24.1187 + }
24.1188 +
24.1189 + /**
24.1190 + * @since 1.5
24.1191 + */
24.1192 + public Annotation[] getDeclaredAnnotations() {
24.1193 + throw new UnsupportedOperationException();
24.1194 + }
24.1195 +
24.1196 + @JavaScriptBody(args = "type", body = ""
24.1197 + + "var c = vm.java_lang_Class(true);"
24.1198 + + "c.jvmName = type;"
24.1199 + + "c.primitive = true;"
24.1200 + + "return c;"
24.1201 + )
24.1202 + native static Class getPrimitiveClass(String type);
24.1203 +
24.1204 + @JavaScriptBody(args = {}, body =
24.1205 + "return vm.desiredAssertionStatus ? vm.desiredAssertionStatus : false;"
24.1206 + )
24.1207 + public native boolean desiredAssertionStatus();
24.1208 +}
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
25.2 +++ b/emul/mini/src/main/java/java/lang/ClassCastException.java Wed Jan 23 20:39:23 2013 +0100
25.3 @@ -0,0 +1,60 @@
25.4 +/*
25.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
25.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
25.7 + *
25.8 + * This code is free software; you can redistribute it and/or modify it
25.9 + * under the terms of the GNU General Public License version 2 only, as
25.10 + * published by the Free Software Foundation. Oracle designates this
25.11 + * particular file as subject to the "Classpath" exception as provided
25.12 + * by Oracle in the LICENSE file that accompanied this code.
25.13 + *
25.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
25.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25.17 + * version 2 for more details (a copy is included in the LICENSE file that
25.18 + * accompanied this code).
25.19 + *
25.20 + * You should have received a copy of the GNU General Public License version
25.21 + * 2 along with this work; if not, write to the Free Software Foundation,
25.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25.23 + *
25.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
25.25 + * or visit www.oracle.com if you need additional information or have any
25.26 + * questions.
25.27 + */
25.28 +
25.29 +package java.lang;
25.30 +
25.31 +/**
25.32 + * Thrown to indicate that the code has attempted to cast an object
25.33 + * to a subclass of which it is not an instance. For example, the
25.34 + * following code generates a <code>ClassCastException</code>:
25.35 + * <p><blockquote><pre>
25.36 + * Object x = new Integer(0);
25.37 + * System.out.println((String)x);
25.38 + * </pre></blockquote>
25.39 + *
25.40 + * @author unascribed
25.41 + * @since JDK1.0
25.42 + */
25.43 +public
25.44 +class ClassCastException extends RuntimeException {
25.45 + private static final long serialVersionUID = -9223365651070458532L;
25.46 +
25.47 + /**
25.48 + * Constructs a <code>ClassCastException</code> with no detail message.
25.49 + */
25.50 + public ClassCastException() {
25.51 + super();
25.52 + }
25.53 +
25.54 + /**
25.55 + * Constructs a <code>ClassCastException</code> with the specified
25.56 + * detail message.
25.57 + *
25.58 + * @param s the detail message.
25.59 + */
25.60 + public ClassCastException(String s) {
25.61 + super(s);
25.62 + }
25.63 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
26.2 +++ b/emul/mini/src/main/java/java/lang/ClassFormatError.java Wed Jan 23 20:39:23 2013 +0100
26.3 @@ -0,0 +1,56 @@
26.4 +/*
26.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
26.7 + *
26.8 + * This code is free software; you can redistribute it and/or modify it
26.9 + * under the terms of the GNU General Public License version 2 only, as
26.10 + * published by the Free Software Foundation. Oracle designates this
26.11 + * particular file as subject to the "Classpath" exception as provided
26.12 + * by Oracle in the LICENSE file that accompanied this code.
26.13 + *
26.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
26.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26.17 + * version 2 for more details (a copy is included in the LICENSE file that
26.18 + * accompanied this code).
26.19 + *
26.20 + * You should have received a copy of the GNU General Public License version
26.21 + * 2 along with this work; if not, write to the Free Software Foundation,
26.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26.23 + *
26.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
26.25 + * or visit www.oracle.com if you need additional information or have any
26.26 + * questions.
26.27 + */
26.28 +
26.29 +package java.lang;
26.30 +
26.31 +/**
26.32 + * Thrown when the Java Virtual Machine attempts to read a class
26.33 + * file and determines that the file is malformed or otherwise cannot
26.34 + * be interpreted as a class file.
26.35 + *
26.36 + * @author unascribed
26.37 + * @since JDK1.0
26.38 + */
26.39 +public
26.40 +class ClassFormatError extends LinkageError {
26.41 + private static final long serialVersionUID = -8420114879011949195L;
26.42 +
26.43 + /**
26.44 + * Constructs a <code>ClassFormatError</code> with no detail message.
26.45 + */
26.46 + public ClassFormatError() {
26.47 + super();
26.48 + }
26.49 +
26.50 + /**
26.51 + * Constructs a <code>ClassFormatError</code> with the specified
26.52 + * detail message.
26.53 + *
26.54 + * @param s the detail message.
26.55 + */
26.56 + public ClassFormatError(String s) {
26.57 + super(s);
26.58 + }
26.59 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
27.2 +++ b/emul/mini/src/main/java/java/lang/ClassLoader.java Wed Jan 23 20:39:23 2013 +0100
27.3 @@ -0,0 +1,914 @@
27.4 +/*
27.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.7 + *
27.8 + * This code is free software; you can redistribute it and/or modify it
27.9 + * under the terms of the GNU General Public License version 2 only, as
27.10 + * published by the Free Software Foundation. Oracle designates this
27.11 + * particular file as subject to the "Classpath" exception as provided
27.12 + * by Oracle in the LICENSE file that accompanied this code.
27.13 + *
27.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
27.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.17 + * version 2 for more details (a copy is included in the LICENSE file that
27.18 + * accompanied this code).
27.19 + *
27.20 + * You should have received a copy of the GNU General Public License version
27.21 + * 2 along with this work; if not, write to the Free Software Foundation,
27.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.23 + *
27.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
27.25 + * or visit www.oracle.com if you need additional information or have any
27.26 + * questions.
27.27 + */
27.28 +package java.lang;
27.29 +
27.30 +import java.io.InputStream;
27.31 +import java.io.IOException;
27.32 +import java.net.URL;
27.33 +import java.util.Enumeration;
27.34 +import java.util.NoSuchElementException;
27.35 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
27.36 +
27.37 +/**
27.38 + * A class loader is an object that is responsible for loading classes. The
27.39 + * class <tt>ClassLoader</tt> is an abstract class. Given the <a
27.40 + * href="#name">binary name</a> of a class, a class loader should attempt to
27.41 + * locate or generate data that constitutes a definition for the class. A
27.42 + * typical strategy is to transform the name into a file name and then read a
27.43 + * "class file" of that name from a file system.
27.44 + *
27.45 + * <p> Every {@link Class <tt>Class</tt>} object contains a {@link
27.46 + * Class#getClassLoader() reference} to the <tt>ClassLoader</tt> that defined
27.47 + * it.
27.48 + *
27.49 + * <p> <tt>Class</tt> objects for array classes are not created by class
27.50 + * loaders, but are created automatically as required by the Java runtime.
27.51 + * The class loader for an array class, as returned by {@link
27.52 + * Class#getClassLoader()} is the same as the class loader for its element
27.53 + * type; if the element type is a primitive type, then the array class has no
27.54 + * class loader.
27.55 + *
27.56 + * <p> Applications implement subclasses of <tt>ClassLoader</tt> in order to
27.57 + * extend the manner in which the Java virtual machine dynamically loads
27.58 + * classes.
27.59 + *
27.60 + * <p> Class loaders may typically be used by security managers to indicate
27.61 + * security domains.
27.62 + *
27.63 + * <p> The <tt>ClassLoader</tt> class uses a delegation model to search for
27.64 + * classes and resources. Each instance of <tt>ClassLoader</tt> has an
27.65 + * associated parent class loader. When requested to find a class or
27.66 + * resource, a <tt>ClassLoader</tt> instance will delegate the search for the
27.67 + * class or resource to its parent class loader before attempting to find the
27.68 + * class or resource itself. The virtual machine's built-in class loader,
27.69 + * called the "bootstrap class loader", does not itself have a parent but may
27.70 + * serve as the parent of a <tt>ClassLoader</tt> instance.
27.71 + *
27.72 + * <p> Class loaders that support concurrent loading of classes are known as
27.73 + * <em>parallel capable</em> class loaders and are required to register
27.74 + * themselves at their class initialization time by invoking the
27.75 + * {@link
27.76 + * #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>}
27.77 + * method. Note that the <tt>ClassLoader</tt> class is registered as parallel
27.78 + * capable by default. However, its subclasses still need to register themselves
27.79 + * if they are parallel capable. <br>
27.80 + * In environments in which the delegation model is not strictly
27.81 + * hierarchical, class loaders need to be parallel capable, otherwise class
27.82 + * loading can lead to deadlocks because the loader lock is held for the
27.83 + * duration of the class loading process (see {@link #loadClass
27.84 + * <tt>loadClass</tt>} methods).
27.85 + *
27.86 + * <p> Normally, the Java virtual machine loads classes from the local file
27.87 + * system in a platform-dependent manner. For example, on UNIX systems, the
27.88 + * virtual machine loads classes from the directory defined by the
27.89 + * <tt>CLASSPATH</tt> environment variable.
27.90 + *
27.91 + * <p> However, some classes may not originate from a file; they may originate
27.92 + * from other sources, such as the network, or they could be constructed by an
27.93 + * application. The method {@link #defineClass(String, byte[], int, int)
27.94 + * <tt>defineClass</tt>} converts an array of bytes into an instance of class
27.95 + * <tt>Class</tt>. Instances of this newly defined class can be created using
27.96 + * {@link Class#newInstance <tt>Class.newInstance</tt>}.
27.97 + *
27.98 + * <p> The methods and constructors of objects created by a class loader may
27.99 + * reference other classes. To determine the class(es) referred to, the Java
27.100 + * virtual machine invokes the {@link #loadClass <tt>loadClass</tt>} method of
27.101 + * the class loader that originally created the class.
27.102 + *
27.103 + * <p> For example, an application could create a network class loader to
27.104 + * download class files from a server. Sample code might look like:
27.105 + *
27.106 + * <blockquote><pre>
27.107 + * ClassLoader loader = new NetworkClassLoader(host, port);
27.108 + * Object main = loader.loadClass("Main", true).newInstance();
27.109 + * . . .
27.110 + * </pre></blockquote>
27.111 + *
27.112 + * <p> The network class loader subclass must define the methods {@link
27.113 + * #findClass <tt>findClass</tt>} and <tt>loadClassData</tt> to load a class
27.114 + * from the network. Once it has downloaded the bytes that make up the class,
27.115 + * it should use the method {@link #defineClass <tt>defineClass</tt>} to
27.116 + * create a class instance. A sample implementation is:
27.117 + *
27.118 + * <blockquote><pre>
27.119 + * class NetworkClassLoader extends ClassLoader {
27.120 + * String host;
27.121 + * int port;
27.122 + *
27.123 + * public Class findClass(String name) {
27.124 + * byte[] b = loadClassData(name);
27.125 + * return defineClass(name, b, 0, b.length);
27.126 + * }
27.127 + *
27.128 + * private byte[] loadClassData(String name) {
27.129 + * // load the class data from the connection
27.130 + * . . .
27.131 + * }
27.132 + * }
27.133 + * </pre></blockquote>
27.134 + *
27.135 + * <h4> <a name="name">Binary names</a> </h4>
27.136 + *
27.137 + * <p> Any class name provided as a {@link String} parameter to methods in
27.138 + * <tt>ClassLoader</tt> must be a binary name as defined by
27.139 + * <cite>The Java™ Language Specification</cite>.
27.140 + *
27.141 + * <p> Examples of valid class names include:
27.142 + * <blockquote><pre>
27.143 + * "java.lang.String"
27.144 + * "javax.swing.JSpinner$DefaultEditor"
27.145 + * "java.security.KeyStore$Builder$FileBuilder$1"
27.146 + * "java.net.URLClassLoader$3$1"
27.147 + * </pre></blockquote>
27.148 + *
27.149 + * @see #resolveClass(Class)
27.150 + * @since 1.0
27.151 + */
27.152 +public abstract class ClassLoader {
27.153 +
27.154 + @JavaScriptBody(args = {}, body = "")
27.155 + private static native void registerNatives();
27.156 + static {
27.157 + registerNatives();
27.158 + }
27.159 +
27.160 + // The parent class loader for delegation
27.161 + // Note: VM hardcoded the offset of this field, thus all new fields
27.162 + // must be added *after* it.
27.163 + private final ClassLoader parent;
27.164 +
27.165 +
27.166 + /**
27.167 + * Creates a new class loader using the specified parent class loader for
27.168 + * delegation.
27.169 + *
27.170 + * <p> If there is a security manager, its {@link
27.171 + * SecurityManager#checkCreateClassLoader()
27.172 + * <tt>checkCreateClassLoader</tt>} method is invoked. This may result in
27.173 + * a security exception. </p>
27.174 + *
27.175 + * @param parent
27.176 + * The parent class loader
27.177 + *
27.178 + * @throws SecurityException
27.179 + * If a security manager exists and its
27.180 + * <tt>checkCreateClassLoader</tt> method doesn't allow creation
27.181 + * of a new class loader.
27.182 + *
27.183 + * @since 1.2
27.184 + */
27.185 + protected ClassLoader(ClassLoader parent) {
27.186 + throw new SecurityException();
27.187 + }
27.188 +
27.189 + /**
27.190 + * Creates a new class loader using the <tt>ClassLoader</tt> returned by
27.191 + * the method {@link #getSystemClassLoader()
27.192 + * <tt>getSystemClassLoader()</tt>} as the parent class loader.
27.193 + *
27.194 + * <p> If there is a security manager, its {@link
27.195 + * SecurityManager#checkCreateClassLoader()
27.196 + * <tt>checkCreateClassLoader</tt>} method is invoked. This may result in
27.197 + * a security exception. </p>
27.198 + *
27.199 + * @throws SecurityException
27.200 + * If a security manager exists and its
27.201 + * <tt>checkCreateClassLoader</tt> method doesn't allow creation
27.202 + * of a new class loader.
27.203 + */
27.204 + protected ClassLoader() {
27.205 + throw new SecurityException();
27.206 + }
27.207 +
27.208 + // -- Class --
27.209 +
27.210 + /**
27.211 + * Loads the class with the specified <a href="#name">binary name</a>.
27.212 + * This method searches for classes in the same manner as the {@link
27.213 + * #loadClass(String, boolean)} method. It is invoked by the Java virtual
27.214 + * machine to resolve class references. Invoking this method is equivalent
27.215 + * to invoking {@link #loadClass(String, boolean) <tt>loadClass(name,
27.216 + * false)</tt>}. </p>
27.217 + *
27.218 + * @param name
27.219 + * The <a href="#name">binary name</a> of the class
27.220 + *
27.221 + * @return The resulting <tt>Class</tt> object
27.222 + *
27.223 + * @throws ClassNotFoundException
27.224 + * If the class was not found
27.225 + */
27.226 + public Class<?> loadClass(String name) throws ClassNotFoundException {
27.227 + return loadClass(name, false);
27.228 + }
27.229 +
27.230 + /**
27.231 + * Loads the class with the specified <a href="#name">binary name</a>. The
27.232 + * default implementation of this method searches for classes in the
27.233 + * following order:
27.234 + *
27.235 + * <p><ol>
27.236 + *
27.237 + * <li><p> Invoke {@link #findLoadedClass(String)} to check if the class
27.238 + * has already been loaded. </p></li>
27.239 + *
27.240 + * <li><p> Invoke the {@link #loadClass(String) <tt>loadClass</tt>} method
27.241 + * on the parent class loader. If the parent is <tt>null</tt> the class
27.242 + * loader built-in to the virtual machine is used, instead. </p></li>
27.243 + *
27.244 + * <li><p> Invoke the {@link #findClass(String)} method to find the
27.245 + * class. </p></li>
27.246 + *
27.247 + * </ol>
27.248 + *
27.249 + * <p> If the class was found using the above steps, and the
27.250 + * <tt>resolve</tt> flag is true, this method will then invoke the {@link
27.251 + * #resolveClass(Class)} method on the resulting <tt>Class</tt> object.
27.252 + *
27.253 + * <p> Subclasses of <tt>ClassLoader</tt> are encouraged to override {@link
27.254 + * #findClass(String)}, rather than this method. </p>
27.255 + *
27.256 + * <p> Unless overridden, this method synchronizes on the result of
27.257 + * {@link #getClassLoadingLock <tt>getClassLoadingLock</tt>} method
27.258 + * during the entire class loading process.
27.259 + *
27.260 + * @param name
27.261 + * The <a href="#name">binary name</a> of the class
27.262 + *
27.263 + * @param resolve
27.264 + * If <tt>true</tt> then resolve the class
27.265 + *
27.266 + * @return The resulting <tt>Class</tt> object
27.267 + *
27.268 + * @throws ClassNotFoundException
27.269 + * If the class could not be found
27.270 + */
27.271 + protected Class<?> loadClass(String name, boolean resolve)
27.272 + throws ClassNotFoundException
27.273 + {
27.274 + synchronized (getClassLoadingLock(name)) {
27.275 + // First, check if the class has already been loaded
27.276 + Class c = findLoadedClass(name);
27.277 + if (c == null) {
27.278 + try {
27.279 + if (parent != null) {
27.280 + c = parent.loadClass(name, false);
27.281 + } else {
27.282 + c = findBootstrapClassOrNull(name);
27.283 + }
27.284 + } catch (ClassNotFoundException e) {
27.285 + // ClassNotFoundException thrown if class not found
27.286 + // from the non-null parent class loader
27.287 + }
27.288 +
27.289 + if (c == null) {
27.290 + // If still not found, then invoke findClass in order
27.291 + // to find the class.
27.292 + c = findClass(name);
27.293 +
27.294 +// // this is the defining class loader; record the stats
27.295 +// sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
27.296 +// sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
27.297 +// sun.misc.PerfCounter.getFindClasses().increment();
27.298 + }
27.299 + }
27.300 + if (resolve) {
27.301 + resolveClass(c);
27.302 + }
27.303 + return c;
27.304 + }
27.305 + }
27.306 +
27.307 + /**
27.308 + * Returns the lock object for class loading operations.
27.309 + * For backward compatibility, the default implementation of this method
27.310 + * behaves as follows. If this ClassLoader object is registered as
27.311 + * parallel capable, the method returns a dedicated object associated
27.312 + * with the specified class name. Otherwise, the method returns this
27.313 + * ClassLoader object. </p>
27.314 + *
27.315 + * @param className
27.316 + * The name of the to-be-loaded class
27.317 + *
27.318 + * @return the lock for class loading operations
27.319 + *
27.320 + * @throws NullPointerException
27.321 + * If registered as parallel capable and <tt>className</tt> is null
27.322 + *
27.323 + * @see #loadClass(String, boolean)
27.324 + *
27.325 + * @since 1.7
27.326 + */
27.327 + protected Object getClassLoadingLock(String className) {
27.328 + Object lock = this;
27.329 + return lock;
27.330 + }
27.331 +
27.332 + /**
27.333 + * Finds the class with the specified <a href="#name">binary name</a>.
27.334 + * This method should be overridden by class loader implementations that
27.335 + * follow the delegation model for loading classes, and will be invoked by
27.336 + * the {@link #loadClass <tt>loadClass</tt>} method after checking the
27.337 + * parent class loader for the requested class. The default implementation
27.338 + * throws a <tt>ClassNotFoundException</tt>. </p>
27.339 + *
27.340 + * @param name
27.341 + * The <a href="#name">binary name</a> of the class
27.342 + *
27.343 + * @return The resulting <tt>Class</tt> object
27.344 + *
27.345 + * @throws ClassNotFoundException
27.346 + * If the class could not be found
27.347 + *
27.348 + * @since 1.2
27.349 + */
27.350 + protected Class<?> findClass(String name) throws ClassNotFoundException {
27.351 + throw new ClassNotFoundException(name);
27.352 + }
27.353 +
27.354 + /**
27.355 + * Converts an array of bytes into an instance of class <tt>Class</tt>.
27.356 + * Before the <tt>Class</tt> can be used it must be resolved. This method
27.357 + * is deprecated in favor of the version that takes a <a
27.358 + * href="#name">binary name</a> as its first argument, and is more secure.
27.359 + *
27.360 + * @param b
27.361 + * The bytes that make up the class data. The bytes in positions
27.362 + * <tt>off</tt> through <tt>off+len-1</tt> should have the format
27.363 + * of a valid class file as defined by
27.364 + * <cite>The Java™ Virtual Machine Specification</cite>.
27.365 + *
27.366 + * @param off
27.367 + * The start offset in <tt>b</tt> of the class data
27.368 + *
27.369 + * @param len
27.370 + * The length of the class data
27.371 + *
27.372 + * @return The <tt>Class</tt> object that was created from the specified
27.373 + * class data
27.374 + *
27.375 + * @throws ClassFormatError
27.376 + * If the data did not contain a valid class
27.377 + *
27.378 + * @throws IndexOutOfBoundsException
27.379 + * If either <tt>off</tt> or <tt>len</tt> is negative, or if
27.380 + * <tt>off+len</tt> is greater than <tt>b.length</tt>.
27.381 + *
27.382 + * @throws SecurityException
27.383 + * If an attempt is made to add this class to a package that
27.384 + * contains classes that were signed by a different set of
27.385 + * certificates than this class, or if an attempt is made
27.386 + * to define a class in a package with a fully-qualified name
27.387 + * that starts with "{@code java.}".
27.388 + *
27.389 + * @see #loadClass(String, boolean)
27.390 + * @see #resolveClass(Class)
27.391 + *
27.392 + * @deprecated Replaced by {@link #defineClass(String, byte[], int, int)
27.393 + * defineClass(String, byte[], int, int)}
27.394 + */
27.395 + @Deprecated
27.396 + protected final Class<?> defineClass(byte[] b, int off, int len)
27.397 + throws ClassFormatError
27.398 + {
27.399 + throw new SecurityException();
27.400 + }
27.401 +
27.402 + /**
27.403 + * Converts an array of bytes into an instance of class <tt>Class</tt>.
27.404 + * Before the <tt>Class</tt> can be used it must be resolved.
27.405 + *
27.406 + * <p> This method assigns a default {@link java.security.ProtectionDomain
27.407 + * <tt>ProtectionDomain</tt>} to the newly defined class. The
27.408 + * <tt>ProtectionDomain</tt> is effectively granted the same set of
27.409 + * permissions returned when {@link
27.410 + * java.security.Policy#getPermissions(java.security.CodeSource)
27.411 + * <tt>Policy.getPolicy().getPermissions(new CodeSource(null, null))</tt>}
27.412 + * is invoked. The default domain is created on the first invocation of
27.413 + * {@link #defineClass(String, byte[], int, int) <tt>defineClass</tt>},
27.414 + * and re-used on subsequent invocations.
27.415 + *
27.416 + * <p> To assign a specific <tt>ProtectionDomain</tt> to the class, use
27.417 + * the {@link #defineClass(String, byte[], int, int,
27.418 + * java.security.ProtectionDomain) <tt>defineClass</tt>} method that takes a
27.419 + * <tt>ProtectionDomain</tt> as one of its arguments. </p>
27.420 + *
27.421 + * @param name
27.422 + * The expected <a href="#name">binary name</a> of the class, or
27.423 + * <tt>null</tt> if not known
27.424 + *
27.425 + * @param b
27.426 + * The bytes that make up the class data. The bytes in positions
27.427 + * <tt>off</tt> through <tt>off+len-1</tt> should have the format
27.428 + * of a valid class file as defined by
27.429 + * <cite>The Java™ Virtual Machine Specification</cite>.
27.430 + *
27.431 + * @param off
27.432 + * The start offset in <tt>b</tt> of the class data
27.433 + *
27.434 + * @param len
27.435 + * The length of the class data
27.436 + *
27.437 + * @return The <tt>Class</tt> object that was created from the specified
27.438 + * class data.
27.439 + *
27.440 + * @throws ClassFormatError
27.441 + * If the data did not contain a valid class
27.442 + *
27.443 + * @throws IndexOutOfBoundsException
27.444 + * If either <tt>off</tt> or <tt>len</tt> is negative, or if
27.445 + * <tt>off+len</tt> is greater than <tt>b.length</tt>.
27.446 + *
27.447 + * @throws SecurityException
27.448 + * If an attempt is made to add this class to a package that
27.449 + * contains classes that were signed by a different set of
27.450 + * certificates than this class (which is unsigned), or if
27.451 + * <tt>name</tt> begins with "<tt>java.</tt>".
27.452 + *
27.453 + * @see #loadClass(String, boolean)
27.454 + * @see #resolveClass(Class)
27.455 + * @see java.security.CodeSource
27.456 + * @see java.security.SecureClassLoader
27.457 + *
27.458 + * @since 1.1
27.459 + */
27.460 + protected final Class<?> defineClass(String name, byte[] b, int off, int len)
27.461 + throws ClassFormatError
27.462 + {
27.463 + throw new SecurityException();
27.464 + }
27.465 +
27.466 + /**
27.467 + * Links the specified class. This (misleadingly named) method may be
27.468 + * used by a class loader to link a class. If the class <tt>c</tt> has
27.469 + * already been linked, then this method simply returns. Otherwise, the
27.470 + * class is linked as described in the "Execution" chapter of
27.471 + * <cite>The Java™ Language Specification</cite>.
27.472 + * </p>
27.473 + *
27.474 + * @param c
27.475 + * The class to link
27.476 + *
27.477 + * @throws NullPointerException
27.478 + * If <tt>c</tt> is <tt>null</tt>.
27.479 + *
27.480 + * @see #defineClass(String, byte[], int, int)
27.481 + */
27.482 + protected final void resolveClass(Class<?> c) {
27.483 + resolveClass0(c);
27.484 + }
27.485 +
27.486 + private native void resolveClass0(Class c);
27.487 +
27.488 +
27.489 + /**
27.490 + * Returns the class with the given <a href="#name">binary name</a> if this
27.491 + * loader has been recorded by the Java virtual machine as an initiating
27.492 + * loader of a class with that <a href="#name">binary name</a>. Otherwise
27.493 + * <tt>null</tt> is returned. </p>
27.494 + *
27.495 + * @param name
27.496 + * The <a href="#name">binary name</a> of the class
27.497 + *
27.498 + * @return The <tt>Class</tt> object, or <tt>null</tt> if the class has
27.499 + * not been loaded
27.500 + *
27.501 + * @since 1.1
27.502 + */
27.503 + protected final Class<?> findLoadedClass(String name) {
27.504 + if (!checkName(name))
27.505 + return null;
27.506 + return findLoadedClass0(name);
27.507 + }
27.508 +
27.509 + private native final Class findLoadedClass0(String name);
27.510 +
27.511 + /**
27.512 + * Sets the signers of a class. This should be invoked after defining a
27.513 + * class. </p>
27.514 + *
27.515 + * @param c
27.516 + * The <tt>Class</tt> object
27.517 + *
27.518 + * @param signers
27.519 + * The signers for the class
27.520 + *
27.521 + * @since 1.1
27.522 + */
27.523 + protected final void setSigners(Class<?> c, Object[] signers) {
27.524 + //c.setSigners(signers);
27.525 + throw new UnsupportedOperationException();
27.526 + }
27.527 +
27.528 +
27.529 + // -- Resource --
27.530 +
27.531 + /**
27.532 + * Finds the resource with the given name. A resource is some data
27.533 + * (images, audio, text, etc) that can be accessed by class code in a way
27.534 + * that is independent of the location of the code.
27.535 + *
27.536 + * <p> The name of a resource is a '<tt>/</tt>'-separated path name that
27.537 + * identifies the resource.
27.538 + *
27.539 + * <p> This method will first search the parent class loader for the
27.540 + * resource; if the parent is <tt>null</tt> the path of the class loader
27.541 + * built-in to the virtual machine is searched. That failing, this method
27.542 + * will invoke {@link #findResource(String)} to find the resource. </p>
27.543 + *
27.544 + * @param name
27.545 + * The resource name
27.546 + *
27.547 + * @return A <tt>URL</tt> object for reading the resource, or
27.548 + * <tt>null</tt> if the resource could not be found or the invoker
27.549 + * doesn't have adequate privileges to get the resource.
27.550 + *
27.551 + * @since 1.1
27.552 + */
27.553 + public URL getResource(String name) {
27.554 + URL url;
27.555 + if (parent != null) {
27.556 + url = parent.getResource(name);
27.557 + } else {
27.558 + url = getBootstrapResource(name);
27.559 + }
27.560 + if (url == null) {
27.561 + url = findResource(name);
27.562 + }
27.563 + return url;
27.564 + }
27.565 +
27.566 + /**
27.567 + * Finds all the resources with the given name. A resource is some data
27.568 + * (images, audio, text, etc) that can be accessed by class code in a way
27.569 + * that is independent of the location of the code.
27.570 + *
27.571 + * <p>The name of a resource is a <tt>/</tt>-separated path name that
27.572 + * identifies the resource.
27.573 + *
27.574 + * <p> The search order is described in the documentation for {@link
27.575 + * #getResource(String)}. </p>
27.576 + *
27.577 + * @param name
27.578 + * The resource name
27.579 + *
27.580 + * @return An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
27.581 + * the resource. If no resources could be found, the enumeration
27.582 + * will be empty. Resources that the class loader doesn't have
27.583 + * access to will not be in the enumeration.
27.584 + *
27.585 + * @throws IOException
27.586 + * If I/O errors occur
27.587 + *
27.588 + * @see #findResources(String)
27.589 + *
27.590 + * @since 1.2
27.591 + */
27.592 + public Enumeration<URL> getResources(String name) throws IOException {
27.593 + Enumeration[] tmp = new Enumeration[2];
27.594 + if (parent != null) {
27.595 + tmp[0] = parent.getResources(name);
27.596 + } else {
27.597 + tmp[0] = getBootstrapResources(name);
27.598 + }
27.599 + tmp[1] = findResources(name);
27.600 +
27.601 + return new CompoundEnumeration(tmp);
27.602 + }
27.603 +
27.604 + /**
27.605 + * Finds the resource with the given name. Class loader implementations
27.606 + * should override this method to specify where to find resources. </p>
27.607 + *
27.608 + * @param name
27.609 + * The resource name
27.610 + *
27.611 + * @return A <tt>URL</tt> object for reading the resource, or
27.612 + * <tt>null</tt> if the resource could not be found
27.613 + *
27.614 + * @since 1.2
27.615 + */
27.616 + protected URL findResource(String name) {
27.617 + return null;
27.618 + }
27.619 +
27.620 + /**
27.621 + * Returns an enumeration of {@link java.net.URL <tt>URL</tt>} objects
27.622 + * representing all the resources with the given name. Class loader
27.623 + * implementations should override this method to specify where to load
27.624 + * resources from. </p>
27.625 + *
27.626 + * @param name
27.627 + * The resource name
27.628 + *
27.629 + * @return An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
27.630 + * the resources
27.631 + *
27.632 + * @throws IOException
27.633 + * If I/O errors occur
27.634 + *
27.635 + * @since 1.2
27.636 + */
27.637 + protected Enumeration<URL> findResources(String name) throws IOException {
27.638 + return new CompoundEnumeration(new Enumeration[0]);
27.639 + }
27.640 +
27.641 + // index 0: java.lang.ClassLoader.class
27.642 + // index 1: the immediate caller of index 0.
27.643 + // index 2: the immediate caller of index 1.
27.644 + private static native Class<? extends ClassLoader> getCaller(int index);
27.645 +
27.646 + /**
27.647 + * Registers the caller as parallel capable.</p>
27.648 + * The registration succeeds if and only if all of the following
27.649 + * conditions are met: <br>
27.650 + * 1. no instance of the caller has been created</p>
27.651 + * 2. all of the super classes (except class Object) of the caller are
27.652 + * registered as parallel capable</p>
27.653 + * Note that once a class loader is registered as parallel capable, there
27.654 + * is no way to change it back. </p>
27.655 + *
27.656 + * @return true if the caller is successfully registered as
27.657 + * parallel capable and false if otherwise.
27.658 + *
27.659 + * @since 1.7
27.660 + */
27.661 +// protected static boolean registerAsParallelCapable() {
27.662 +// return false;
27.663 +// }
27.664 +
27.665 + /**
27.666 + * Find a resource of the specified name from the search path used to load
27.667 + * classes. This method locates the resource through the system class
27.668 + * loader (see {@link #getSystemClassLoader()}). </p>
27.669 + *
27.670 + * @param name
27.671 + * The resource name
27.672 + *
27.673 + * @return A {@link java.net.URL <tt>URL</tt>} object for reading the
27.674 + * resource, or <tt>null</tt> if the resource could not be found
27.675 + *
27.676 + * @since 1.1
27.677 + */
27.678 + public static URL getSystemResource(String name) {
27.679 + ClassLoader system = getSystemClassLoader();
27.680 + if (system == null) {
27.681 + return getBootstrapResource(name);
27.682 + }
27.683 + return system.getResource(name);
27.684 + }
27.685 +
27.686 + /**
27.687 + * Finds all resources of the specified name from the search path used to
27.688 + * load classes. The resources thus found are returned as an
27.689 + * {@link java.util.Enumeration <tt>Enumeration</tt>} of {@link
27.690 + * java.net.URL <tt>URL</tt>} objects.
27.691 + *
27.692 + * <p> The search order is described in the documentation for {@link
27.693 + * #getSystemResource(String)}. </p>
27.694 + *
27.695 + * @param name
27.696 + * The resource name
27.697 + *
27.698 + * @return An enumeration of resource {@link java.net.URL <tt>URL</tt>}
27.699 + * objects
27.700 + *
27.701 + * @throws IOException
27.702 + * If I/O errors occur
27.703 +
27.704 + * @since 1.2
27.705 + */
27.706 + public static Enumeration<URL> getSystemResources(String name)
27.707 + throws IOException
27.708 + {
27.709 + ClassLoader system = getSystemClassLoader();
27.710 + if (system == null) {
27.711 + return getBootstrapResources(name);
27.712 + }
27.713 + return system.getResources(name);
27.714 + }
27.715 +
27.716 +
27.717 +
27.718 + /**
27.719 + * Returns an input stream for reading the specified resource.
27.720 + *
27.721 + * <p> The search order is described in the documentation for {@link
27.722 + * #getResource(String)}. </p>
27.723 + *
27.724 + * @param name
27.725 + * The resource name
27.726 + *
27.727 + * @return An input stream for reading the resource, or <tt>null</tt>
27.728 + * if the resource could not be found
27.729 + *
27.730 + * @since 1.1
27.731 + */
27.732 + public InputStream getResourceAsStream(String name) {
27.733 + URL url = getResource(name);
27.734 + try {
27.735 + return url != null ? url.openStream() : null;
27.736 + } catch (IOException e) {
27.737 + return null;
27.738 + }
27.739 + }
27.740 +
27.741 + /**
27.742 + * Open for reading, a resource of the specified name from the search path
27.743 + * used to load classes. This method locates the resource through the
27.744 + * system class loader (see {@link #getSystemClassLoader()}). </p>
27.745 + *
27.746 + * @param name
27.747 + * The resource name
27.748 + *
27.749 + * @return An input stream for reading the resource, or <tt>null</tt>
27.750 + * if the resource could not be found
27.751 + *
27.752 + * @since 1.1
27.753 + */
27.754 + public static InputStream getSystemResourceAsStream(String name) {
27.755 + URL url = getSystemResource(name);
27.756 + try {
27.757 + return url != null ? url.openStream() : null;
27.758 + } catch (IOException e) {
27.759 + return null;
27.760 + }
27.761 + }
27.762 +
27.763 +
27.764 + // -- Hierarchy --
27.765 +
27.766 + /**
27.767 + * Returns the parent class loader for delegation. Some implementations may
27.768 + * use <tt>null</tt> to represent the bootstrap class loader. This method
27.769 + * will return <tt>null</tt> in such implementations if this class loader's
27.770 + * parent is the bootstrap class loader.
27.771 + *
27.772 + * <p> If a security manager is present, and the invoker's class loader is
27.773 + * not <tt>null</tt> and is not an ancestor of this class loader, then this
27.774 + * method invokes the security manager's {@link
27.775 + * SecurityManager#checkPermission(java.security.Permission)
27.776 + * <tt>checkPermission</tt>} method with a {@link
27.777 + * RuntimePermission#RuntimePermission(String)
27.778 + * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
27.779 + * access to the parent class loader is permitted. If not, a
27.780 + * <tt>SecurityException</tt> will be thrown. </p>
27.781 + *
27.782 + * @return The parent <tt>ClassLoader</tt>
27.783 + *
27.784 + * @throws SecurityException
27.785 + * If a security manager exists and its <tt>checkPermission</tt>
27.786 + * method doesn't allow access to this class loader's parent class
27.787 + * loader.
27.788 + *
27.789 + * @since 1.2
27.790 + */
27.791 + public final ClassLoader getParent() {
27.792 + throw new SecurityException();
27.793 + }
27.794 +
27.795 + /**
27.796 + * Returns the system class loader for delegation. This is the default
27.797 + * delegation parent for new <tt>ClassLoader</tt> instances, and is
27.798 + * typically the class loader used to start the application.
27.799 + *
27.800 + * <p> This method is first invoked early in the runtime's startup
27.801 + * sequence, at which point it creates the system class loader and sets it
27.802 + * as the context class loader of the invoking <tt>Thread</tt>.
27.803 + *
27.804 + * <p> The default system class loader is an implementation-dependent
27.805 + * instance of this class.
27.806 + *
27.807 + * <p> If the system property "<tt>java.system.class.loader</tt>" is defined
27.808 + * when this method is first invoked then the value of that property is
27.809 + * taken to be the name of a class that will be returned as the system
27.810 + * class loader. The class is loaded using the default system class loader
27.811 + * and must define a public constructor that takes a single parameter of
27.812 + * type <tt>ClassLoader</tt> which is used as the delegation parent. An
27.813 + * instance is then created using this constructor with the default system
27.814 + * class loader as the parameter. The resulting class loader is defined
27.815 + * to be the system class loader.
27.816 + *
27.817 + * <p> If a security manager is present, and the invoker's class loader is
27.818 + * not <tt>null</tt> and the invoker's class loader is not the same as or
27.819 + * an ancestor of the system class loader, then this method invokes the
27.820 + * security manager's {@link
27.821 + * SecurityManager#checkPermission(java.security.Permission)
27.822 + * <tt>checkPermission</tt>} method with a {@link
27.823 + * RuntimePermission#RuntimePermission(String)
27.824 + * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
27.825 + * access to the system class loader. If not, a
27.826 + * <tt>SecurityException</tt> will be thrown. </p>
27.827 + *
27.828 + * @return The system <tt>ClassLoader</tt> for delegation, or
27.829 + * <tt>null</tt> if none
27.830 + *
27.831 + * @throws SecurityException
27.832 + * If a security manager exists and its <tt>checkPermission</tt>
27.833 + * method doesn't allow access to the system class loader.
27.834 + *
27.835 + * @throws IllegalStateException
27.836 + * If invoked recursively during the construction of the class
27.837 + * loader specified by the "<tt>java.system.class.loader</tt>"
27.838 + * property.
27.839 + *
27.840 + * @throws Error
27.841 + * If the system property "<tt>java.system.class.loader</tt>"
27.842 + * is defined but the named class could not be loaded, the
27.843 + * provider class does not define the required constructor, or an
27.844 + * exception is thrown by that constructor when it is invoked. The
27.845 + * underlying cause of the error can be retrieved via the
27.846 + * {@link Throwable#getCause()} method.
27.847 + *
27.848 + * @revised 1.4
27.849 + */
27.850 + public static ClassLoader getSystemClassLoader() {
27.851 + throw new SecurityException();
27.852 + }
27.853 +
27.854 + // Returns true if the specified class loader can be found in this class
27.855 + // loader's delegation chain.
27.856 + boolean isAncestor(ClassLoader cl) {
27.857 + ClassLoader acl = this;
27.858 + do {
27.859 + acl = acl.parent;
27.860 + if (cl == acl) {
27.861 + return true;
27.862 + }
27.863 + } while (acl != null);
27.864 + return false;
27.865 + }
27.866 +
27.867 + private boolean checkName(String name) {
27.868 + throw new UnsupportedOperationException();
27.869 + }
27.870 +
27.871 + private Class findBootstrapClassOrNull(String name) {
27.872 + throw new UnsupportedOperationException();
27.873 + }
27.874 +
27.875 + private static URL getBootstrapResource(String name) {
27.876 + throw new UnsupportedOperationException();
27.877 + }
27.878 +
27.879 + private static Enumeration<URL> getBootstrapResources(String name) {
27.880 + throw new UnsupportedOperationException();
27.881 + }
27.882 +
27.883 + private static class CompoundEnumeration implements Enumeration<URL> {
27.884 + private URL next;
27.885 + private int index;
27.886 + private final Enumeration[] arr;
27.887 +
27.888 + public CompoundEnumeration(Enumeration[] arr) {
27.889 + this.arr = arr;
27.890 + this.index = 0;
27.891 + }
27.892 +
27.893 + public boolean hasMoreElements() {
27.894 + if (next == null) {
27.895 + if (arr[index].hasMoreElements()) {
27.896 + next = (URL) arr[index].nextElement();
27.897 + } else {
27.898 + if (index < arr.length) {
27.899 + index++;
27.900 + return hasMoreElements();
27.901 + }
27.902 + }
27.903 + }
27.904 + return next != null;
27.905 + }
27.906 +
27.907 + public URL nextElement() {
27.908 + if (!hasMoreElements()) {
27.909 + throw new NoSuchElementException();
27.910 + }
27.911 + URL r = next;
27.912 + next = null;
27.913 + return r;
27.914 + }
27.915 +
27.916 + }
27.917 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
28.2 +++ b/emul/mini/src/main/java/java/lang/ClassNotFoundException.java Wed Jan 23 20:39:23 2013 +0100
28.3 @@ -0,0 +1,125 @@
28.4 +/*
28.5 + * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
28.7 + *
28.8 + * This code is free software; you can redistribute it and/or modify it
28.9 + * under the terms of the GNU General Public License version 2 only, as
28.10 + * published by the Free Software Foundation. Oracle designates this
28.11 + * particular file as subject to the "Classpath" exception as provided
28.12 + * by Oracle in the LICENSE file that accompanied this code.
28.13 + *
28.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
28.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
28.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28.17 + * version 2 for more details (a copy is included in the LICENSE file that
28.18 + * accompanied this code).
28.19 + *
28.20 + * You should have received a copy of the GNU General Public License version
28.21 + * 2 along with this work; if not, write to the Free Software Foundation,
28.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28.23 + *
28.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28.25 + * or visit www.oracle.com if you need additional information or have any
28.26 + * questions.
28.27 + */
28.28 +
28.29 +package java.lang;
28.30 +
28.31 +/**
28.32 + * Thrown when an application tries to load in a class through its
28.33 + * string name using:
28.34 + * <ul>
28.35 + * <li>The <code>forName</code> method in class <code>Class</code>.
28.36 + * <li>The <code>findSystemClass</code> method in class
28.37 + * <code>ClassLoader</code> .
28.38 + * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.
28.39 + * </ul>
28.40 + * <p>
28.41 + * but no definition for the class with the specified name could be found.
28.42 + *
28.43 + * <p>As of release 1.4, this exception has been retrofitted to conform to
28.44 + * the general purpose exception-chaining mechanism. The "optional exception
28.45 + * that was raised while loading the class" that may be provided at
28.46 + * construction time and accessed via the {@link #getException()} method is
28.47 + * now known as the <i>cause</i>, and may be accessed via the {@link
28.48 + * Throwable#getCause()} method, as well as the aforementioned "legacy method."
28.49 + *
28.50 + * @author unascribed
28.51 + * @see java.lang.Class#forName(java.lang.String)
28.52 + * @see java.lang.ClassLoader#findSystemClass(java.lang.String)
28.53 + * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
28.54 + * @since JDK1.0
28.55 + */
28.56 +public class ClassNotFoundException extends ReflectiveOperationException {
28.57 + /**
28.58 + * use serialVersionUID from JDK 1.1.X for interoperability
28.59 + */
28.60 + private static final long serialVersionUID = 9176873029745254542L;
28.61 +
28.62 + /**
28.63 + * This field holds the exception ex if the
28.64 + * ClassNotFoundException(String s, Throwable ex) constructor was
28.65 + * used to instantiate the object
28.66 + * @serial
28.67 + * @since 1.2
28.68 + */
28.69 + private Throwable ex;
28.70 +
28.71 + /**
28.72 + * Constructs a <code>ClassNotFoundException</code> with no detail message.
28.73 + */
28.74 + public ClassNotFoundException() {
28.75 + super((Throwable)null); // Disallow initCause
28.76 + }
28.77 +
28.78 + /**
28.79 + * Constructs a <code>ClassNotFoundException</code> with the
28.80 + * specified detail message.
28.81 + *
28.82 + * @param s the detail message.
28.83 + */
28.84 + public ClassNotFoundException(String s) {
28.85 + super(s, null); // Disallow initCause
28.86 + }
28.87 +
28.88 + /**
28.89 + * Constructs a <code>ClassNotFoundException</code> with the
28.90 + * specified detail message and optional exception that was
28.91 + * raised while loading the class.
28.92 + *
28.93 + * @param s the detail message
28.94 + * @param ex the exception that was raised while loading the class
28.95 + * @since 1.2
28.96 + */
28.97 + public ClassNotFoundException(String s, Throwable ex) {
28.98 + super(s, null); // Disallow initCause
28.99 + this.ex = ex;
28.100 + }
28.101 +
28.102 + /**
28.103 + * Returns the exception that was raised if an error occurred while
28.104 + * attempting to load the class. Otherwise, returns <tt>null</tt>.
28.105 + *
28.106 + * <p>This method predates the general-purpose exception chaining facility.
28.107 + * The {@link Throwable#getCause()} method is now the preferred means of
28.108 + * obtaining this information.
28.109 + *
28.110 + * @return the <code>Exception</code> that was raised while loading a class
28.111 + * @since 1.2
28.112 + */
28.113 + public Throwable getException() {
28.114 + return ex;
28.115 + }
28.116 +
28.117 + /**
28.118 + * Returns the cause of this exception (the exception that was raised
28.119 + * if an error occurred while attempting to load the class; otherwise
28.120 + * <tt>null</tt>).
28.121 + *
28.122 + * @return the cause of this exception.
28.123 + * @since 1.4
28.124 + */
28.125 + public Throwable getCause() {
28.126 + return ex;
28.127 + }
28.128 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
29.2 +++ b/emul/mini/src/main/java/java/lang/CloneNotSupportedException.java Wed Jan 23 20:39:23 2013 +0100
29.3 @@ -0,0 +1,65 @@
29.4 +/*
29.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
29.7 + *
29.8 + * This code is free software; you can redistribute it and/or modify it
29.9 + * under the terms of the GNU General Public License version 2 only, as
29.10 + * published by the Free Software Foundation. Oracle designates this
29.11 + * particular file as subject to the "Classpath" exception as provided
29.12 + * by Oracle in the LICENSE file that accompanied this code.
29.13 + *
29.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
29.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29.17 + * version 2 for more details (a copy is included in the LICENSE file that
29.18 + * accompanied this code).
29.19 + *
29.20 + * You should have received a copy of the GNU General Public License version
29.21 + * 2 along with this work; if not, write to the Free Software Foundation,
29.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29.23 + *
29.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
29.25 + * or visit www.oracle.com if you need additional information or have any
29.26 + * questions.
29.27 + */
29.28 +
29.29 +package java.lang;
29.30 +
29.31 +/**
29.32 + * Thrown to indicate that the <code>clone</code> method in class
29.33 + * <code>Object</code> has been called to clone an object, but that
29.34 + * the object's class does not implement the <code>Cloneable</code>
29.35 + * interface.
29.36 + * <p>
29.37 + * Applications that override the <code>clone</code> method can also
29.38 + * throw this exception to indicate that an object could not or
29.39 + * should not be cloned.
29.40 + *
29.41 + * @author unascribed
29.42 + * @see java.lang.Cloneable
29.43 + * @see java.lang.Object#clone()
29.44 + * @since JDK1.0
29.45 + */
29.46 +
29.47 +public
29.48 +class CloneNotSupportedException extends Exception {
29.49 + private static final long serialVersionUID = 5195511250079656443L;
29.50 +
29.51 + /**
29.52 + * Constructs a <code>CloneNotSupportedException</code> with no
29.53 + * detail message.
29.54 + */
29.55 + public CloneNotSupportedException() {
29.56 + super();
29.57 + }
29.58 +
29.59 + /**
29.60 + * Constructs a <code>CloneNotSupportedException</code> with the
29.61 + * specified detail message.
29.62 + *
29.63 + * @param s the detail message.
29.64 + */
29.65 + public CloneNotSupportedException(String s) {
29.66 + super(s);
29.67 + }
29.68 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
30.2 +++ b/emul/mini/src/main/java/java/lang/Comparable.java Wed Jan 23 20:39:23 2013 +0100
30.3 @@ -0,0 +1,137 @@
30.4 +/*
30.5 + * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
30.7 + *
30.8 + * This code is free software; you can redistribute it and/or modify it
30.9 + * under the terms of the GNU General Public License version 2 only, as
30.10 + * published by the Free Software Foundation. Oracle designates this
30.11 + * particular file as subject to the "Classpath" exception as provided
30.12 + * by Oracle in the LICENSE file that accompanied this code.
30.13 + *
30.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
30.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
30.17 + * version 2 for more details (a copy is included in the LICENSE file that
30.18 + * accompanied this code).
30.19 + *
30.20 + * You should have received a copy of the GNU General Public License version
30.21 + * 2 along with this work; if not, write to the Free Software Foundation,
30.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
30.23 + *
30.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
30.25 + * or visit www.oracle.com if you need additional information or have any
30.26 + * questions.
30.27 + */
30.28 +
30.29 +package java.lang;
30.30 +
30.31 +/**
30.32 + * This interface imposes a total ordering on the objects of each class that
30.33 + * implements it. This ordering is referred to as the class's <i>natural
30.34 + * ordering</i>, and the class's <tt>compareTo</tt> method is referred to as
30.35 + * its <i>natural comparison method</i>.<p>
30.36 + *
30.37 + * Lists (and arrays) of objects that implement this interface can be sorted
30.38 + * automatically by {@link Collections#sort(List) Collections.sort} (and
30.39 + * {@link Arrays#sort(Object[]) Arrays.sort}). Objects that implement this
30.40 + * interface can be used as keys in a {@linkplain SortedMap sorted map} or as
30.41 + * elements in a {@linkplain SortedSet sorted set}, without the need to
30.42 + * specify a {@linkplain Comparator comparator}.<p>
30.43 + *
30.44 + * The natural ordering for a class <tt>C</tt> is said to be <i>consistent
30.45 + * with equals</i> if and only if <tt>e1.compareTo(e2) == 0</tt> has
30.46 + * the same boolean value as <tt>e1.equals(e2)</tt> for every
30.47 + * <tt>e1</tt> and <tt>e2</tt> of class <tt>C</tt>. Note that <tt>null</tt>
30.48 + * is not an instance of any class, and <tt>e.compareTo(null)</tt> should
30.49 + * throw a <tt>NullPointerException</tt> even though <tt>e.equals(null)</tt>
30.50 + * returns <tt>false</tt>.<p>
30.51 + *
30.52 + * It is strongly recommended (though not required) that natural orderings be
30.53 + * consistent with equals. This is so because sorted sets (and sorted maps)
30.54 + * without explicit comparators behave "strangely" when they are used with
30.55 + * elements (or keys) whose natural ordering is inconsistent with equals. In
30.56 + * particular, such a sorted set (or sorted map) violates the general contract
30.57 + * for set (or map), which is defined in terms of the <tt>equals</tt>
30.58 + * method.<p>
30.59 + *
30.60 + * For example, if one adds two keys <tt>a</tt> and <tt>b</tt> such that
30.61 + * <tt>(!a.equals(b) && a.compareTo(b) == 0)</tt> to a sorted
30.62 + * set that does not use an explicit comparator, the second <tt>add</tt>
30.63 + * operation returns false (and the size of the sorted set does not increase)
30.64 + * because <tt>a</tt> and <tt>b</tt> are equivalent from the sorted set's
30.65 + * perspective.<p>
30.66 + *
30.67 + * Virtually all Java core classes that implement <tt>Comparable</tt> have natural
30.68 + * orderings that are consistent with equals. One exception is
30.69 + * <tt>java.math.BigDecimal</tt>, whose natural ordering equates
30.70 + * <tt>BigDecimal</tt> objects with equal values and different precisions
30.71 + * (such as 4.0 and 4.00).<p>
30.72 + *
30.73 + * For the mathematically inclined, the <i>relation</i> that defines
30.74 + * the natural ordering on a given class C is:<pre>
30.75 + * {(x, y) such that x.compareTo(y) <= 0}.
30.76 + * </pre> The <i>quotient</i> for this total order is: <pre>
30.77 + * {(x, y) such that x.compareTo(y) == 0}.
30.78 + * </pre>
30.79 + *
30.80 + * It follows immediately from the contract for <tt>compareTo</tt> that the
30.81 + * quotient is an <i>equivalence relation</i> on <tt>C</tt>, and that the
30.82 + * natural ordering is a <i>total order</i> on <tt>C</tt>. When we say that a
30.83 + * class's natural ordering is <i>consistent with equals</i>, we mean that the
30.84 + * quotient for the natural ordering is the equivalence relation defined by
30.85 + * the class's {@link Object#equals(Object) equals(Object)} method:<pre>
30.86 + * {(x, y) such that x.equals(y)}. </pre><p>
30.87 + *
30.88 + * This interface is a member of the
30.89 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
30.90 + * Java Collections Framework</a>.
30.91 + *
30.92 + * @param <T> the type of objects that this object may be compared to
30.93 + *
30.94 + * @author Josh Bloch
30.95 + * @see java.util.Comparator
30.96 + * @since 1.2
30.97 + */
30.98 +
30.99 +public interface Comparable<T> {
30.100 + /**
30.101 + * Compares this object with the specified object for order. Returns a
30.102 + * negative integer, zero, or a positive integer as this object is less
30.103 + * than, equal to, or greater than the specified object.
30.104 + *
30.105 + * <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
30.106 + * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
30.107 + * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
30.108 + * <tt>y.compareTo(x)</tt> throws an exception.)
30.109 + *
30.110 + * <p>The implementor must also ensure that the relation is transitive:
30.111 + * <tt>(x.compareTo(y)>0 && y.compareTo(z)>0)</tt> implies
30.112 + * <tt>x.compareTo(z)>0</tt>.
30.113 + *
30.114 + * <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
30.115 + * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
30.116 + * all <tt>z</tt>.
30.117 + *
30.118 + * <p>It is strongly recommended, but <i>not</i> strictly required that
30.119 + * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>. Generally speaking, any
30.120 + * class that implements the <tt>Comparable</tt> interface and violates
30.121 + * this condition should clearly indicate this fact. The recommended
30.122 + * language is "Note: this class has a natural ordering that is
30.123 + * inconsistent with equals."
30.124 + *
30.125 + * <p>In the foregoing description, the notation
30.126 + * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
30.127 + * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
30.128 + * <tt>0</tt>, or <tt>1</tt> according to whether the value of
30.129 + * <i>expression</i> is negative, zero or positive.
30.130 + *
30.131 + * @param o the object to be compared.
30.132 + * @return a negative integer, zero, or a positive integer as this object
30.133 + * is less than, equal to, or greater than the specified object.
30.134 + *
30.135 + * @throws NullPointerException if the specified object is null
30.136 + * @throws ClassCastException if the specified object's type prevents it
30.137 + * from being compared to this object.
30.138 + */
30.139 + public int compareTo(T o);
30.140 +}
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
31.2 +++ b/emul/mini/src/main/java/java/lang/Deprecated.java Wed Jan 23 20:39:23 2013 +0100
31.3 @@ -0,0 +1,44 @@
31.4 +/*
31.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
31.7 + *
31.8 + * This code is free software; you can redistribute it and/or modify it
31.9 + * under the terms of the GNU General Public License version 2 only, as
31.10 + * published by the Free Software Foundation. Oracle designates this
31.11 + * particular file as subject to the "Classpath" exception as provided
31.12 + * by Oracle in the LICENSE file that accompanied this code.
31.13 + *
31.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
31.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
31.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31.17 + * version 2 for more details (a copy is included in the LICENSE file that
31.18 + * accompanied this code).
31.19 + *
31.20 + * You should have received a copy of the GNU General Public License version
31.21 + * 2 along with this work; if not, write to the Free Software Foundation,
31.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
31.23 + *
31.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
31.25 + * or visit www.oracle.com if you need additional information or have any
31.26 + * questions.
31.27 + */
31.28 +
31.29 +package java.lang;
31.30 +
31.31 +import java.lang.annotation.*;
31.32 +import static java.lang.annotation.ElementType.*;
31.33 +
31.34 +/**
31.35 + * A program element annotated @Deprecated is one that programmers
31.36 + * are discouraged from using, typically because it is dangerous,
31.37 + * or because a better alternative exists. Compilers warn when a
31.38 + * deprecated program element is used or overridden in non-deprecated code.
31.39 + *
31.40 + * @author Neal Gafter
31.41 + * @since 1.5
31.42 + */
31.43 +@Documented
31.44 +@Retention(RetentionPolicy.RUNTIME)
31.45 +@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
31.46 +public @interface Deprecated {
31.47 +}
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
32.2 +++ b/emul/mini/src/main/java/java/lang/Double.java Wed Jan 23 20:39:23 2013 +0100
32.3 @@ -0,0 +1,994 @@
32.4 +/*
32.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
32.7 + *
32.8 + * This code is free software; you can redistribute it and/or modify it
32.9 + * under the terms of the GNU General Public License version 2 only, as
32.10 + * published by the Free Software Foundation. Oracle designates this
32.11 + * particular file as subject to the "Classpath" exception as provided
32.12 + * by Oracle in the LICENSE file that accompanied this code.
32.13 + *
32.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
32.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
32.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
32.17 + * version 2 for more details (a copy is included in the LICENSE file that
32.18 + * accompanied this code).
32.19 + *
32.20 + * You should have received a copy of the GNU General Public License version
32.21 + * 2 along with this work; if not, write to the Free Software Foundation,
32.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
32.23 + *
32.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
32.25 + * or visit www.oracle.com if you need additional information or have any
32.26 + * questions.
32.27 + */
32.28 +
32.29 +package java.lang;
32.30 +
32.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
32.32 +
32.33 +/**
32.34 + * The {@code Double} class wraps a value of the primitive type
32.35 + * {@code double} in an object. An object of type
32.36 + * {@code Double} contains a single field whose type is
32.37 + * {@code double}.
32.38 + *
32.39 + * <p>In addition, this class provides several methods for converting a
32.40 + * {@code double} to a {@code String} and a
32.41 + * {@code String} to a {@code double}, as well as other
32.42 + * constants and methods useful when dealing with a
32.43 + * {@code double}.
32.44 + *
32.45 + * @author Lee Boynton
32.46 + * @author Arthur van Hoff
32.47 + * @author Joseph D. Darcy
32.48 + * @since JDK1.0
32.49 + */
32.50 +public final class Double extends Number implements Comparable<Double> {
32.51 + /**
32.52 + * A constant holding the positive infinity of type
32.53 + * {@code double}. It is equal to the value returned by
32.54 + * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
32.55 + */
32.56 + public static final double POSITIVE_INFINITY = 1.0 / 0.0;
32.57 +
32.58 + /**
32.59 + * A constant holding the negative infinity of type
32.60 + * {@code double}. It is equal to the value returned by
32.61 + * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
32.62 + */
32.63 + public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
32.64 +
32.65 + /**
32.66 + * A constant holding a Not-a-Number (NaN) value of type
32.67 + * {@code double}. It is equivalent to the value returned by
32.68 + * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
32.69 + */
32.70 + public static final double NaN = 0.0d / 0.0;
32.71 +
32.72 + /**
32.73 + * A constant holding the largest positive finite value of type
32.74 + * {@code double},
32.75 + * (2-2<sup>-52</sup>)·2<sup>1023</sup>. It is equal to
32.76 + * the hexadecimal floating-point literal
32.77 + * {@code 0x1.fffffffffffffP+1023} and also equal to
32.78 + * {@code Double.longBitsToDouble(0x7fefffffffffffffL)}.
32.79 + */
32.80 + public static final double MAX_VALUE = 0x1.fffffffffffffP+1023; // 1.7976931348623157e+308
32.81 +
32.82 + /**
32.83 + * A constant holding the smallest positive normal value of type
32.84 + * {@code double}, 2<sup>-1022</sup>. It is equal to the
32.85 + * hexadecimal floating-point literal {@code 0x1.0p-1022} and also
32.86 + * equal to {@code Double.longBitsToDouble(0x0010000000000000L)}.
32.87 + *
32.88 + * @since 1.6
32.89 + */
32.90 + public static final double MIN_NORMAL = 0x1.0p-1022; // 2.2250738585072014E-308
32.91 +
32.92 + /**
32.93 + * A constant holding the smallest positive nonzero value of type
32.94 + * {@code double}, 2<sup>-1074</sup>. It is equal to the
32.95 + * hexadecimal floating-point literal
32.96 + * {@code 0x0.0000000000001P-1022} and also equal to
32.97 + * {@code Double.longBitsToDouble(0x1L)}.
32.98 + */
32.99 + public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324
32.100 +
32.101 + /**
32.102 + * Maximum exponent a finite {@code double} variable may have.
32.103 + * It is equal to the value returned by
32.104 + * {@code Math.getExponent(Double.MAX_VALUE)}.
32.105 + *
32.106 + * @since 1.6
32.107 + */
32.108 + public static final int MAX_EXPONENT = 1023;
32.109 +
32.110 + /**
32.111 + * Minimum exponent a normalized {@code double} variable may
32.112 + * have. It is equal to the value returned by
32.113 + * {@code Math.getExponent(Double.MIN_NORMAL)}.
32.114 + *
32.115 + * @since 1.6
32.116 + */
32.117 + public static final int MIN_EXPONENT = -1022;
32.118 +
32.119 + /**
32.120 + * The number of bits used to represent a {@code double} value.
32.121 + *
32.122 + * @since 1.5
32.123 + */
32.124 + public static final int SIZE = 64;
32.125 +
32.126 + /**
32.127 + * The {@code Class} instance representing the primitive type
32.128 + * {@code double}.
32.129 + *
32.130 + * @since JDK1.1
32.131 + */
32.132 + public static final Class<Double> TYPE = (Class<Double>) Class.getPrimitiveClass("double");
32.133 +
32.134 + /**
32.135 + * Returns a string representation of the {@code double}
32.136 + * argument. All characters mentioned below are ASCII characters.
32.137 + * <ul>
32.138 + * <li>If the argument is NaN, the result is the string
32.139 + * "{@code NaN}".
32.140 + * <li>Otherwise, the result is a string that represents the sign and
32.141 + * magnitude (absolute value) of the argument. If the sign is negative,
32.142 + * the first character of the result is '{@code -}'
32.143 + * (<code>'\u002D'</code>); if the sign is positive, no sign character
32.144 + * appears in the result. As for the magnitude <i>m</i>:
32.145 + * <ul>
32.146 + * <li>If <i>m</i> is infinity, it is represented by the characters
32.147 + * {@code "Infinity"}; thus, positive infinity produces the result
32.148 + * {@code "Infinity"} and negative infinity produces the result
32.149 + * {@code "-Infinity"}.
32.150 + *
32.151 + * <li>If <i>m</i> is zero, it is represented by the characters
32.152 + * {@code "0.0"}; thus, negative zero produces the result
32.153 + * {@code "-0.0"} and positive zero produces the result
32.154 + * {@code "0.0"}.
32.155 + *
32.156 + * <li>If <i>m</i> is greater than or equal to 10<sup>-3</sup> but less
32.157 + * than 10<sup>7</sup>, then it is represented as the integer part of
32.158 + * <i>m</i>, in decimal form with no leading zeroes, followed by
32.159 + * '{@code .}' (<code>'\u002E'</code>), followed by one or
32.160 + * more decimal digits representing the fractional part of <i>m</i>.
32.161 + *
32.162 + * <li>If <i>m</i> is less than 10<sup>-3</sup> or greater than or
32.163 + * equal to 10<sup>7</sup>, then it is represented in so-called
32.164 + * "computerized scientific notation." Let <i>n</i> be the unique
32.165 + * integer such that 10<sup><i>n</i></sup> ≤ <i>m</i> {@literal <}
32.166 + * 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
32.167 + * mathematically exact quotient of <i>m</i> and
32.168 + * 10<sup><i>n</i></sup> so that 1 ≤ <i>a</i> {@literal <} 10. The
32.169 + * magnitude is then represented as the integer part of <i>a</i>,
32.170 + * as a single decimal digit, followed by '{@code .}'
32.171 + * (<code>'\u002E'</code>), followed by decimal digits
32.172 + * representing the fractional part of <i>a</i>, followed by the
32.173 + * letter '{@code E}' (<code>'\u0045'</code>), followed
32.174 + * by a representation of <i>n</i> as a decimal integer, as
32.175 + * produced by the method {@link Integer#toString(int)}.
32.176 + * </ul>
32.177 + * </ul>
32.178 + * How many digits must be printed for the fractional part of
32.179 + * <i>m</i> or <i>a</i>? There must be at least one digit to represent
32.180 + * the fractional part, and beyond that as many, but only as many, more
32.181 + * digits as are needed to uniquely distinguish the argument value from
32.182 + * adjacent values of type {@code double}. That is, suppose that
32.183 + * <i>x</i> is the exact mathematical value represented by the decimal
32.184 + * representation produced by this method for a finite nonzero argument
32.185 + * <i>d</i>. Then <i>d</i> must be the {@code double} value nearest
32.186 + * to <i>x</i>; or if two {@code double} values are equally close
32.187 + * to <i>x</i>, then <i>d</i> must be one of them and the least
32.188 + * significant bit of the significand of <i>d</i> must be {@code 0}.
32.189 + *
32.190 + * <p>To create localized string representations of a floating-point
32.191 + * value, use subclasses of {@link java.text.NumberFormat}.
32.192 + *
32.193 + * @param d the {@code double} to be converted.
32.194 + * @return a string representation of the argument.
32.195 + */
32.196 + @JavaScriptBody(args="d", body="var r = d.toString();"
32.197 + + "if (r.indexOf('.') === -1) r = r + '.0';"
32.198 + + "return r;")
32.199 + public static String toString(double d) {
32.200 + throw new UnsupportedOperationException();
32.201 + }
32.202 +
32.203 + /**
32.204 + * Returns a hexadecimal string representation of the
32.205 + * {@code double} argument. All characters mentioned below
32.206 + * are ASCII characters.
32.207 + *
32.208 + * <ul>
32.209 + * <li>If the argument is NaN, the result is the string
32.210 + * "{@code NaN}".
32.211 + * <li>Otherwise, the result is a string that represents the sign
32.212 + * and magnitude of the argument. If the sign is negative, the
32.213 + * first character of the result is '{@code -}'
32.214 + * (<code>'\u002D'</code>); if the sign is positive, no sign
32.215 + * character appears in the result. As for the magnitude <i>m</i>:
32.216 + *
32.217 + * <ul>
32.218 + * <li>If <i>m</i> is infinity, it is represented by the string
32.219 + * {@code "Infinity"}; thus, positive infinity produces the
32.220 + * result {@code "Infinity"} and negative infinity produces
32.221 + * the result {@code "-Infinity"}.
32.222 + *
32.223 + * <li>If <i>m</i> is zero, it is represented by the string
32.224 + * {@code "0x0.0p0"}; thus, negative zero produces the result
32.225 + * {@code "-0x0.0p0"} and positive zero produces the result
32.226 + * {@code "0x0.0p0"}.
32.227 + *
32.228 + * <li>If <i>m</i> is a {@code double} value with a
32.229 + * normalized representation, substrings are used to represent the
32.230 + * significand and exponent fields. The significand is
32.231 + * represented by the characters {@code "0x1."}
32.232 + * followed by a lowercase hexadecimal representation of the rest
32.233 + * of the significand as a fraction. Trailing zeros in the
32.234 + * hexadecimal representation are removed unless all the digits
32.235 + * are zero, in which case a single zero is used. Next, the
32.236 + * exponent is represented by {@code "p"} followed
32.237 + * by a decimal string of the unbiased exponent as if produced by
32.238 + * a call to {@link Integer#toString(int) Integer.toString} on the
32.239 + * exponent value.
32.240 + *
32.241 + * <li>If <i>m</i> is a {@code double} value with a subnormal
32.242 + * representation, the significand is represented by the
32.243 + * characters {@code "0x0."} followed by a
32.244 + * hexadecimal representation of the rest of the significand as a
32.245 + * fraction. Trailing zeros in the hexadecimal representation are
32.246 + * removed. Next, the exponent is represented by
32.247 + * {@code "p-1022"}. Note that there must be at
32.248 + * least one nonzero digit in a subnormal significand.
32.249 + *
32.250 + * </ul>
32.251 + *
32.252 + * </ul>
32.253 + *
32.254 + * <table border>
32.255 + * <caption><h3>Examples</h3></caption>
32.256 + * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
32.257 + * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
32.258 + * <tr><td>{@code -1.0}</td> <td>{@code -0x1.0p0}</td>
32.259 + * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
32.260 + * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
32.261 + * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
32.262 + * <tr><td>{@code 0.25}</td> <td>{@code 0x1.0p-2}</td>
32.263 + * <tr><td>{@code Double.MAX_VALUE}</td>
32.264 + * <td>{@code 0x1.fffffffffffffp1023}</td>
32.265 + * <tr><td>{@code Minimum Normal Value}</td>
32.266 + * <td>{@code 0x1.0p-1022}</td>
32.267 + * <tr><td>{@code Maximum Subnormal Value}</td>
32.268 + * <td>{@code 0x0.fffffffffffffp-1022}</td>
32.269 + * <tr><td>{@code Double.MIN_VALUE}</td>
32.270 + * <td>{@code 0x0.0000000000001p-1022}</td>
32.271 + * </table>
32.272 + * @param d the {@code double} to be converted.
32.273 + * @return a hex string representation of the argument.
32.274 + * @since 1.5
32.275 + * @author Joseph D. Darcy
32.276 + */
32.277 + public static String toHexString(double d) {
32.278 + throw new UnsupportedOperationException();
32.279 +// /*
32.280 +// * Modeled after the "a" conversion specifier in C99, section
32.281 +// * 7.19.6.1; however, the output of this method is more
32.282 +// * tightly specified.
32.283 +// */
32.284 +// if (!FpUtils.isFinite(d) )
32.285 +// // For infinity and NaN, use the decimal output.
32.286 +// return Double.toString(d);
32.287 +// else {
32.288 +// // Initialized to maximum size of output.
32.289 +// StringBuffer answer = new StringBuffer(24);
32.290 +//
32.291 +// if (FpUtils.rawCopySign(1.0, d) == -1.0) // value is negative,
32.292 +// answer.append("-"); // so append sign info
32.293 +//
32.294 +// answer.append("0x");
32.295 +//
32.296 +// d = Math.abs(d);
32.297 +//
32.298 +// if(d == 0.0) {
32.299 +// answer.append("0.0p0");
32.300 +// }
32.301 +// else {
32.302 +// boolean subnormal = (d < DoubleConsts.MIN_NORMAL);
32.303 +//
32.304 +// // Isolate significand bits and OR in a high-order bit
32.305 +// // so that the string representation has a known
32.306 +// // length.
32.307 +// long signifBits = (Double.doubleToLongBits(d)
32.308 +// & DoubleConsts.SIGNIF_BIT_MASK) |
32.309 +// 0x1000000000000000L;
32.310 +//
32.311 +// // Subnormal values have a 0 implicit bit; normal
32.312 +// // values have a 1 implicit bit.
32.313 +// answer.append(subnormal ? "0." : "1.");
32.314 +//
32.315 +// // Isolate the low-order 13 digits of the hex
32.316 +// // representation. If all the digits are zero,
32.317 +// // replace with a single 0; otherwise, remove all
32.318 +// // trailing zeros.
32.319 +// String signif = Long.toHexString(signifBits).substring(3,16);
32.320 +// answer.append(signif.equals("0000000000000") ? // 13 zeros
32.321 +// "0":
32.322 +// signif.replaceFirst("0{1,12}$", ""));
32.323 +//
32.324 +// // If the value is subnormal, use the E_min exponent
32.325 +// // value for double; otherwise, extract and report d's
32.326 +// // exponent (the representation of a subnormal uses
32.327 +// // E_min -1).
32.328 +// answer.append("p" + (subnormal ?
32.329 +// DoubleConsts.MIN_EXPONENT:
32.330 +// FpUtils.getExponent(d) ));
32.331 +// }
32.332 +// return answer.toString();
32.333 +// }
32.334 + }
32.335 +
32.336 + /**
32.337 + * Returns a {@code Double} object holding the
32.338 + * {@code double} value represented by the argument string
32.339 + * {@code s}.
32.340 + *
32.341 + * <p>If {@code s} is {@code null}, then a
32.342 + * {@code NullPointerException} is thrown.
32.343 + *
32.344 + * <p>Leading and trailing whitespace characters in {@code s}
32.345 + * are ignored. Whitespace is removed as if by the {@link
32.346 + * String#trim} method; that is, both ASCII space and control
32.347 + * characters are removed. The rest of {@code s} should
32.348 + * constitute a <i>FloatValue</i> as described by the lexical
32.349 + * syntax rules:
32.350 + *
32.351 + * <blockquote>
32.352 + * <dl>
32.353 + * <dt><i>FloatValue:</i>
32.354 + * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
32.355 + * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
32.356 + * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
32.357 + * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
32.358 + * <dd><i>SignedInteger</i>
32.359 + * </dl>
32.360 + *
32.361 + * <p>
32.362 + *
32.363 + * <dl>
32.364 + * <dt><i>HexFloatingPointLiteral</i>:
32.365 + * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
32.366 + * </dl>
32.367 + *
32.368 + * <p>
32.369 + *
32.370 + * <dl>
32.371 + * <dt><i>HexSignificand:</i>
32.372 + * <dd><i>HexNumeral</i>
32.373 + * <dd><i>HexNumeral</i> {@code .}
32.374 + * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
32.375 + * </i>{@code .}<i> HexDigits</i>
32.376 + * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
32.377 + * </i>{@code .} <i>HexDigits</i>
32.378 + * </dl>
32.379 + *
32.380 + * <p>
32.381 + *
32.382 + * <dl>
32.383 + * <dt><i>BinaryExponent:</i>
32.384 + * <dd><i>BinaryExponentIndicator SignedInteger</i>
32.385 + * </dl>
32.386 + *
32.387 + * <p>
32.388 + *
32.389 + * <dl>
32.390 + * <dt><i>BinaryExponentIndicator:</i>
32.391 + * <dd>{@code p}
32.392 + * <dd>{@code P}
32.393 + * </dl>
32.394 + *
32.395 + * </blockquote>
32.396 + *
32.397 + * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
32.398 + * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
32.399 + * <i>FloatTypeSuffix</i> are as defined in the lexical structure
32.400 + * sections of
32.401 + * <cite>The Java™ Language Specification</cite>,
32.402 + * except that underscores are not accepted between digits.
32.403 + * If {@code s} does not have the form of
32.404 + * a <i>FloatValue</i>, then a {@code NumberFormatException}
32.405 + * is thrown. Otherwise, {@code s} is regarded as
32.406 + * representing an exact decimal value in the usual
32.407 + * "computerized scientific notation" or as an exact
32.408 + * hexadecimal value; this exact numerical value is then
32.409 + * conceptually converted to an "infinitely precise"
32.410 + * binary value that is then rounded to type {@code double}
32.411 + * by the usual round-to-nearest rule of IEEE 754 floating-point
32.412 + * arithmetic, which includes preserving the sign of a zero
32.413 + * value.
32.414 + *
32.415 + * Note that the round-to-nearest rule also implies overflow and
32.416 + * underflow behaviour; if the exact value of {@code s} is large
32.417 + * enough in magnitude (greater than or equal to ({@link
32.418 + * #MAX_VALUE} + {@link Math#ulp(double) ulp(MAX_VALUE)}/2),
32.419 + * rounding to {@code double} will result in an infinity and if the
32.420 + * exact value of {@code s} is small enough in magnitude (less
32.421 + * than or equal to {@link #MIN_VALUE}/2), rounding to float will
32.422 + * result in a zero.
32.423 + *
32.424 + * Finally, after rounding a {@code Double} object representing
32.425 + * this {@code double} value is returned.
32.426 + *
32.427 + * <p> To interpret localized string representations of a
32.428 + * floating-point value, use subclasses of {@link
32.429 + * java.text.NumberFormat}.
32.430 + *
32.431 + * <p>Note that trailing format specifiers, specifiers that
32.432 + * determine the type of a floating-point literal
32.433 + * ({@code 1.0f} is a {@code float} value;
32.434 + * {@code 1.0d} is a {@code double} value), do
32.435 + * <em>not</em> influence the results of this method. In other
32.436 + * words, the numerical value of the input string is converted
32.437 + * directly to the target floating-point type. The two-step
32.438 + * sequence of conversions, string to {@code float} followed
32.439 + * by {@code float} to {@code double}, is <em>not</em>
32.440 + * equivalent to converting a string directly to
32.441 + * {@code double}. For example, the {@code float}
32.442 + * literal {@code 0.1f} is equal to the {@code double}
32.443 + * value {@code 0.10000000149011612}; the {@code float}
32.444 + * literal {@code 0.1f} represents a different numerical
32.445 + * value than the {@code double} literal
32.446 + * {@code 0.1}. (The numerical value 0.1 cannot be exactly
32.447 + * represented in a binary floating-point number.)
32.448 + *
32.449 + * <p>To avoid calling this method on an invalid string and having
32.450 + * a {@code NumberFormatException} be thrown, the regular
32.451 + * expression below can be used to screen the input string:
32.452 + *
32.453 + * <code>
32.454 + * <pre>
32.455 + * final String Digits = "(\\p{Digit}+)";
32.456 + * final String HexDigits = "(\\p{XDigit}+)";
32.457 + * // an exponent is 'e' or 'E' followed by an optionally
32.458 + * // signed decimal integer.
32.459 + * final String Exp = "[eE][+-]?"+Digits;
32.460 + * final String fpRegex =
32.461 + * ("[\\x00-\\x20]*"+ // Optional leading "whitespace"
32.462 + * "[+-]?(" + // Optional sign character
32.463 + * "NaN|" + // "NaN" string
32.464 + * "Infinity|" + // "Infinity" string
32.465 + *
32.466 + * // A decimal floating-point string representing a finite positive
32.467 + * // number without a leading sign has at most five basic pieces:
32.468 + * // Digits . Digits ExponentPart FloatTypeSuffix
32.469 + * //
32.470 + * // Since this method allows integer-only strings as input
32.471 + * // in addition to strings of floating-point literals, the
32.472 + * // two sub-patterns below are simplifications of the grammar
32.473 + * // productions from section 3.10.2 of
32.474 + * // <cite>The Java™ Language Specification</cite>.
32.475 + *
32.476 + * // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
32.477 + * "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
32.478 + *
32.479 + * // . Digits ExponentPart_opt FloatTypeSuffix_opt
32.480 + * "(\\.("+Digits+")("+Exp+")?)|"+
32.481 + *
32.482 + * // Hexadecimal strings
32.483 + * "((" +
32.484 + * // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
32.485 + * "(0[xX]" + HexDigits + "(\\.)?)|" +
32.486 + *
32.487 + * // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
32.488 + * "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
32.489 + *
32.490 + * ")[pP][+-]?" + Digits + "))" +
32.491 + * "[fFdD]?))" +
32.492 + * "[\\x00-\\x20]*");// Optional trailing "whitespace"
32.493 + *
32.494 + * if (Pattern.matches(fpRegex, myString))
32.495 + * Double.valueOf(myString); // Will not throw NumberFormatException
32.496 + * else {
32.497 + * // Perform suitable alternative action
32.498 + * }
32.499 + * </pre>
32.500 + * </code>
32.501 + *
32.502 + * @param s the string to be parsed.
32.503 + * @return a {@code Double} object holding the value
32.504 + * represented by the {@code String} argument.
32.505 + * @throws NumberFormatException if the string does not contain a
32.506 + * parsable number.
32.507 + */
32.508 + @JavaScriptBody(args="s", body="return parseFloat(s);")
32.509 + public static Double valueOf(String s) throws NumberFormatException {
32.510 + throw new UnsupportedOperationException();
32.511 +// return new Double(FloatingDecimal.readJavaFormatString(s).doubleValue());
32.512 + }
32.513 +
32.514 + /**
32.515 + * Returns a {@code Double} instance representing the specified
32.516 + * {@code double} value.
32.517 + * If a new {@code Double} instance is not required, this method
32.518 + * should generally be used in preference to the constructor
32.519 + * {@link #Double(double)}, as this method is likely to yield
32.520 + * significantly better space and time performance by caching
32.521 + * frequently requested values.
32.522 + *
32.523 + * @param d a double value.
32.524 + * @return a {@code Double} instance representing {@code d}.
32.525 + * @since 1.5
32.526 + */
32.527 + public static Double valueOf(double d) {
32.528 + return new Double(d);
32.529 + }
32.530 +
32.531 + /**
32.532 + * Returns a new {@code double} initialized to the value
32.533 + * represented by the specified {@code String}, as performed
32.534 + * by the {@code valueOf} method of class
32.535 + * {@code Double}.
32.536 + *
32.537 + * @param s the string to be parsed.
32.538 + * @return the {@code double} value represented by the string
32.539 + * argument.
32.540 + * @throws NullPointerException if the string is null
32.541 + * @throws NumberFormatException if the string does not contain
32.542 + * a parsable {@code double}.
32.543 + * @see java.lang.Double#valueOf(String)
32.544 + * @since 1.2
32.545 + */
32.546 + @JavaScriptBody(args="s", body="return parseFloat(s);")
32.547 + public static double parseDouble(String s) throws NumberFormatException {
32.548 + throw new UnsupportedOperationException();
32.549 +// return FloatingDecimal.readJavaFormatString(s).doubleValue();
32.550 + }
32.551 +
32.552 + /**
32.553 + * Returns {@code true} if the specified number is a
32.554 + * Not-a-Number (NaN) value, {@code false} otherwise.
32.555 + *
32.556 + * @param v the value to be tested.
32.557 + * @return {@code true} if the value of the argument is NaN;
32.558 + * {@code false} otherwise.
32.559 + */
32.560 + static public boolean isNaN(double v) {
32.561 + return (v != v);
32.562 + }
32.563 +
32.564 + /**
32.565 + * Returns {@code true} if the specified number is infinitely
32.566 + * large in magnitude, {@code false} otherwise.
32.567 + *
32.568 + * @param v the value to be tested.
32.569 + * @return {@code true} if the value of the argument is positive
32.570 + * infinity or negative infinity; {@code false} otherwise.
32.571 + */
32.572 + static public boolean isInfinite(double v) {
32.573 + return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
32.574 + }
32.575 +
32.576 + /**
32.577 + * The value of the Double.
32.578 + *
32.579 + * @serial
32.580 + */
32.581 + private final double value;
32.582 +
32.583 + /**
32.584 + * Constructs a newly allocated {@code Double} object that
32.585 + * represents the primitive {@code double} argument.
32.586 + *
32.587 + * @param value the value to be represented by the {@code Double}.
32.588 + */
32.589 + public Double(double value) {
32.590 + this.value = value;
32.591 + }
32.592 +
32.593 + /**
32.594 + * Constructs a newly allocated {@code Double} object that
32.595 + * represents the floating-point value of type {@code double}
32.596 + * represented by the string. The string is converted to a
32.597 + * {@code double} value as if by the {@code valueOf} method.
32.598 + *
32.599 + * @param s a string to be converted to a {@code Double}.
32.600 + * @throws NumberFormatException if the string does not contain a
32.601 + * parsable number.
32.602 + * @see java.lang.Double#valueOf(java.lang.String)
32.603 + */
32.604 + public Double(String s) throws NumberFormatException {
32.605 + // REMIND: this is inefficient
32.606 + this(valueOf(s).doubleValue());
32.607 + }
32.608 +
32.609 + /**
32.610 + * Returns {@code true} if this {@code Double} value is
32.611 + * a Not-a-Number (NaN), {@code false} otherwise.
32.612 + *
32.613 + * @return {@code true} if the value represented by this object is
32.614 + * NaN; {@code false} otherwise.
32.615 + */
32.616 + public boolean isNaN() {
32.617 + return isNaN(value);
32.618 + }
32.619 +
32.620 + /**
32.621 + * Returns {@code true} if this {@code Double} value is
32.622 + * infinitely large in magnitude, {@code false} otherwise.
32.623 + *
32.624 + * @return {@code true} if the value represented by this object is
32.625 + * positive infinity or negative infinity;
32.626 + * {@code false} otherwise.
32.627 + */
32.628 + public boolean isInfinite() {
32.629 + return isInfinite(value);
32.630 + }
32.631 +
32.632 + /**
32.633 + * Returns a string representation of this {@code Double} object.
32.634 + * The primitive {@code double} value represented by this
32.635 + * object is converted to a string exactly as if by the method
32.636 + * {@code toString} of one argument.
32.637 + *
32.638 + * @return a {@code String} representation of this object.
32.639 + * @see java.lang.Double#toString(double)
32.640 + */
32.641 + public String toString() {
32.642 + return toString(value);
32.643 + }
32.644 +
32.645 + /**
32.646 + * Returns the value of this {@code Double} as a {@code byte} (by
32.647 + * casting to a {@code byte}).
32.648 + *
32.649 + * @return the {@code double} value represented by this object
32.650 + * converted to type {@code byte}
32.651 + * @since JDK1.1
32.652 + */
32.653 + public byte byteValue() {
32.654 + return (byte)value;
32.655 + }
32.656 +
32.657 + /**
32.658 + * Returns the value of this {@code Double} as a
32.659 + * {@code short} (by casting to a {@code short}).
32.660 + *
32.661 + * @return the {@code double} value represented by this object
32.662 + * converted to type {@code short}
32.663 + * @since JDK1.1
32.664 + */
32.665 + public short shortValue() {
32.666 + return (short)value;
32.667 + }
32.668 +
32.669 + /**
32.670 + * Returns the value of this {@code Double} as an
32.671 + * {@code int} (by casting to type {@code int}).
32.672 + *
32.673 + * @return the {@code double} value represented by this object
32.674 + * converted to type {@code int}
32.675 + */
32.676 + public int intValue() {
32.677 + return (int)value;
32.678 + }
32.679 +
32.680 + /**
32.681 + * Returns the value of this {@code Double} as a
32.682 + * {@code long} (by casting to type {@code long}).
32.683 + *
32.684 + * @return the {@code double} value represented by this object
32.685 + * converted to type {@code long}
32.686 + */
32.687 + public long longValue() {
32.688 + return (long)value;
32.689 + }
32.690 +
32.691 + /**
32.692 + * Returns the {@code float} value of this
32.693 + * {@code Double} object.
32.694 + *
32.695 + * @return the {@code double} value represented by this object
32.696 + * converted to type {@code float}
32.697 + * @since JDK1.0
32.698 + */
32.699 + public float floatValue() {
32.700 + return (float)value;
32.701 + }
32.702 +
32.703 + /**
32.704 + * Returns the {@code double} value of this
32.705 + * {@code Double} object.
32.706 + *
32.707 + * @return the {@code double} value represented by this object
32.708 + */
32.709 + public double doubleValue() {
32.710 + return (double)value;
32.711 + }
32.712 +
32.713 + /**
32.714 + * Returns a hash code for this {@code Double} object. The
32.715 + * result is the exclusive OR of the two halves of the
32.716 + * {@code long} integer bit representation, exactly as
32.717 + * produced by the method {@link #doubleToLongBits(double)}, of
32.718 + * the primitive {@code double} value represented by this
32.719 + * {@code Double} object. That is, the hash code is the value
32.720 + * of the expression:
32.721 + *
32.722 + * <blockquote>
32.723 + * {@code (int)(v^(v>>>32))}
32.724 + * </blockquote>
32.725 + *
32.726 + * where {@code v} is defined by:
32.727 + *
32.728 + * <blockquote>
32.729 + * {@code long v = Double.doubleToLongBits(this.doubleValue());}
32.730 + * </blockquote>
32.731 + *
32.732 + * @return a {@code hash code} value for this object.
32.733 + */
32.734 + public int hashCode() {
32.735 + long bits = doubleToLongBits(value);
32.736 + return (int)(bits ^ (bits >>> 32));
32.737 + }
32.738 +
32.739 + /**
32.740 + * Compares this object against the specified object. The result
32.741 + * is {@code true} if and only if the argument is not
32.742 + * {@code null} and is a {@code Double} object that
32.743 + * represents a {@code double} that has the same value as the
32.744 + * {@code double} represented by this object. For this
32.745 + * purpose, two {@code double} values are considered to be
32.746 + * the same if and only if the method {@link
32.747 + * #doubleToLongBits(double)} returns the identical
32.748 + * {@code long} value when applied to each.
32.749 + *
32.750 + * <p>Note that in most cases, for two instances of class
32.751 + * {@code Double}, {@code d1} and {@code d2}, the
32.752 + * value of {@code d1.equals(d2)} is {@code true} if and
32.753 + * only if
32.754 + *
32.755 + * <blockquote>
32.756 + * {@code d1.doubleValue() == d2.doubleValue()}
32.757 + * </blockquote>
32.758 + *
32.759 + * <p>also has the value {@code true}. However, there are two
32.760 + * exceptions:
32.761 + * <ul>
32.762 + * <li>If {@code d1} and {@code d2} both represent
32.763 + * {@code Double.NaN}, then the {@code equals} method
32.764 + * returns {@code true}, even though
32.765 + * {@code Double.NaN==Double.NaN} has the value
32.766 + * {@code false}.
32.767 + * <li>If {@code d1} represents {@code +0.0} while
32.768 + * {@code d2} represents {@code -0.0}, or vice versa,
32.769 + * the {@code equal} test has the value {@code false},
32.770 + * even though {@code +0.0==-0.0} has the value {@code true}.
32.771 + * </ul>
32.772 + * This definition allows hash tables to operate properly.
32.773 + * @param obj the object to compare with.
32.774 + * @return {@code true} if the objects are the same;
32.775 + * {@code false} otherwise.
32.776 + * @see java.lang.Double#doubleToLongBits(double)
32.777 + */
32.778 + public boolean equals(Object obj) {
32.779 + return (obj instanceof Double)
32.780 + && (((Double)obj).value) == value;
32.781 + }
32.782 +
32.783 + /**
32.784 + * Returns a representation of the specified floating-point value
32.785 + * according to the IEEE 754 floating-point "double
32.786 + * format" bit layout.
32.787 + *
32.788 + * <p>Bit 63 (the bit that is selected by the mask
32.789 + * {@code 0x8000000000000000L}) represents the sign of the
32.790 + * floating-point number. Bits
32.791 + * 62-52 (the bits that are selected by the mask
32.792 + * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
32.793 + * (the bits that are selected by the mask
32.794 + * {@code 0x000fffffffffffffL}) represent the significand
32.795 + * (sometimes called the mantissa) of the floating-point number.
32.796 + *
32.797 + * <p>If the argument is positive infinity, the result is
32.798 + * {@code 0x7ff0000000000000L}.
32.799 + *
32.800 + * <p>If the argument is negative infinity, the result is
32.801 + * {@code 0xfff0000000000000L}.
32.802 + *
32.803 + * <p>If the argument is NaN, the result is
32.804 + * {@code 0x7ff8000000000000L}.
32.805 + *
32.806 + * <p>In all cases, the result is a {@code long} integer that, when
32.807 + * given to the {@link #longBitsToDouble(long)} method, will produce a
32.808 + * floating-point value the same as the argument to
32.809 + * {@code doubleToLongBits} (except all NaN values are
32.810 + * collapsed to a single "canonical" NaN value).
32.811 + *
32.812 + * @param value a {@code double} precision floating-point number.
32.813 + * @return the bits that represent the floating-point number.
32.814 + */
32.815 + public static long doubleToLongBits(double value) {
32.816 + throw new UnsupportedOperationException();
32.817 +// long result = doubleToRawLongBits(value);
32.818 +// // Check for NaN based on values of bit fields, maximum
32.819 +// // exponent and nonzero significand.
32.820 +// if ( ((result & DoubleConsts.EXP_BIT_MASK) ==
32.821 +// DoubleConsts.EXP_BIT_MASK) &&
32.822 +// (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
32.823 +// result = 0x7ff8000000000000L;
32.824 +// return result;
32.825 + }
32.826 +
32.827 + /**
32.828 + * Returns a representation of the specified floating-point value
32.829 + * according to the IEEE 754 floating-point "double
32.830 + * format" bit layout, preserving Not-a-Number (NaN) values.
32.831 + *
32.832 + * <p>Bit 63 (the bit that is selected by the mask
32.833 + * {@code 0x8000000000000000L}) represents the sign of the
32.834 + * floating-point number. Bits
32.835 + * 62-52 (the bits that are selected by the mask
32.836 + * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
32.837 + * (the bits that are selected by the mask
32.838 + * {@code 0x000fffffffffffffL}) represent the significand
32.839 + * (sometimes called the mantissa) of the floating-point number.
32.840 + *
32.841 + * <p>If the argument is positive infinity, the result is
32.842 + * {@code 0x7ff0000000000000L}.
32.843 + *
32.844 + * <p>If the argument is negative infinity, the result is
32.845 + * {@code 0xfff0000000000000L}.
32.846 + *
32.847 + * <p>If the argument is NaN, the result is the {@code long}
32.848 + * integer representing the actual NaN value. Unlike the
32.849 + * {@code doubleToLongBits} method,
32.850 + * {@code doubleToRawLongBits} does not collapse all the bit
32.851 + * patterns encoding a NaN to a single "canonical" NaN
32.852 + * value.
32.853 + *
32.854 + * <p>In all cases, the result is a {@code long} integer that,
32.855 + * when given to the {@link #longBitsToDouble(long)} method, will
32.856 + * produce a floating-point value the same as the argument to
32.857 + * {@code doubleToRawLongBits}.
32.858 + *
32.859 + * @param value a {@code double} precision floating-point number.
32.860 + * @return the bits that represent the floating-point number.
32.861 + * @since 1.3
32.862 + */
32.863 + public static native long doubleToRawLongBits(double value);
32.864 +
32.865 + /**
32.866 + * Returns the {@code double} value corresponding to a given
32.867 + * bit representation.
32.868 + * The argument is considered to be a representation of a
32.869 + * floating-point value according to the IEEE 754 floating-point
32.870 + * "double format" bit layout.
32.871 + *
32.872 + * <p>If the argument is {@code 0x7ff0000000000000L}, the result
32.873 + * is positive infinity.
32.874 + *
32.875 + * <p>If the argument is {@code 0xfff0000000000000L}, the result
32.876 + * is negative infinity.
32.877 + *
32.878 + * <p>If the argument is any value in the range
32.879 + * {@code 0x7ff0000000000001L} through
32.880 + * {@code 0x7fffffffffffffffL} or in the range
32.881 + * {@code 0xfff0000000000001L} through
32.882 + * {@code 0xffffffffffffffffL}, the result is a NaN. No IEEE
32.883 + * 754 floating-point operation provided by Java can distinguish
32.884 + * between two NaN values of the same type with different bit
32.885 + * patterns. Distinct values of NaN are only distinguishable by
32.886 + * use of the {@code Double.doubleToRawLongBits} method.
32.887 + *
32.888 + * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
32.889 + * values that can be computed from the argument:
32.890 + *
32.891 + * <blockquote><pre>
32.892 + * int s = ((bits >> 63) == 0) ? 1 : -1;
32.893 + * int e = (int)((bits >> 52) & 0x7ffL);
32.894 + * long m = (e == 0) ?
32.895 + * (bits & 0xfffffffffffffL) << 1 :
32.896 + * (bits & 0xfffffffffffffL) | 0x10000000000000L;
32.897 + * </pre></blockquote>
32.898 + *
32.899 + * Then the floating-point result equals the value of the mathematical
32.900 + * expression <i>s</i>·<i>m</i>·2<sup><i>e</i>-1075</sup>.
32.901 + *
32.902 + * <p>Note that this method may not be able to return a
32.903 + * {@code double} NaN with exactly same bit pattern as the
32.904 + * {@code long} argument. IEEE 754 distinguishes between two
32.905 + * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>. The
32.906 + * differences between the two kinds of NaN are generally not
32.907 + * visible in Java. Arithmetic operations on signaling NaNs turn
32.908 + * them into quiet NaNs with a different, but often similar, bit
32.909 + * pattern. However, on some processors merely copying a
32.910 + * signaling NaN also performs that conversion. In particular,
32.911 + * copying a signaling NaN to return it to the calling method
32.912 + * may perform this conversion. So {@code longBitsToDouble}
32.913 + * may not be able to return a {@code double} with a
32.914 + * signaling NaN bit pattern. Consequently, for some
32.915 + * {@code long} values,
32.916 + * {@code doubleToRawLongBits(longBitsToDouble(start))} may
32.917 + * <i>not</i> equal {@code start}. Moreover, which
32.918 + * particular bit patterns represent signaling NaNs is platform
32.919 + * dependent; although all NaN bit patterns, quiet or signaling,
32.920 + * must be in the NaN range identified above.
32.921 + *
32.922 + * @param bits any {@code long} integer.
32.923 + * @return the {@code double} floating-point value with the same
32.924 + * bit pattern.
32.925 + */
32.926 + public static native double longBitsToDouble(long bits);
32.927 +
32.928 + /**
32.929 + * Compares two {@code Double} objects numerically. There
32.930 + * are two ways in which comparisons performed by this method
32.931 + * differ from those performed by the Java language numerical
32.932 + * comparison operators ({@code <, <=, ==, >=, >})
32.933 + * when applied to primitive {@code double} values:
32.934 + * <ul><li>
32.935 + * {@code Double.NaN} is considered by this method
32.936 + * to be equal to itself and greater than all other
32.937 + * {@code double} values (including
32.938 + * {@code Double.POSITIVE_INFINITY}).
32.939 + * <li>
32.940 + * {@code 0.0d} is considered by this method to be greater
32.941 + * than {@code -0.0d}.
32.942 + * </ul>
32.943 + * This ensures that the <i>natural ordering</i> of
32.944 + * {@code Double} objects imposed by this method is <i>consistent
32.945 + * with equals</i>.
32.946 + *
32.947 + * @param anotherDouble the {@code Double} to be compared.
32.948 + * @return the value {@code 0} if {@code anotherDouble} is
32.949 + * numerically equal to this {@code Double}; a value
32.950 + * less than {@code 0} if this {@code Double}
32.951 + * is numerically less than {@code anotherDouble};
32.952 + * and a value greater than {@code 0} if this
32.953 + * {@code Double} is numerically greater than
32.954 + * {@code anotherDouble}.
32.955 + *
32.956 + * @since 1.2
32.957 + */
32.958 + public int compareTo(Double anotherDouble) {
32.959 + return Double.compare(value, anotherDouble.value);
32.960 + }
32.961 +
32.962 + /**
32.963 + * Compares the two specified {@code double} values. The sign
32.964 + * of the integer value returned is the same as that of the
32.965 + * integer that would be returned by the call:
32.966 + * <pre>
32.967 + * new Double(d1).compareTo(new Double(d2))
32.968 + * </pre>
32.969 + *
32.970 + * @param d1 the first {@code double} to compare
32.971 + * @param d2 the second {@code double} to compare
32.972 + * @return the value {@code 0} if {@code d1} is
32.973 + * numerically equal to {@code d2}; a value less than
32.974 + * {@code 0} if {@code d1} is numerically less than
32.975 + * {@code d2}; and a value greater than {@code 0}
32.976 + * if {@code d1} is numerically greater than
32.977 + * {@code d2}.
32.978 + * @since 1.4
32.979 + */
32.980 + public static int compare(double d1, double d2) {
32.981 + if (d1 < d2)
32.982 + return -1; // Neither val is NaN, thisVal is smaller
32.983 + if (d1 > d2)
32.984 + return 1; // Neither val is NaN, thisVal is larger
32.985 +
32.986 + // Cannot use doubleToRawLongBits because of possibility of NaNs.
32.987 + long thisBits = Double.doubleToLongBits(d1);
32.988 + long anotherBits = Double.doubleToLongBits(d2);
32.989 +
32.990 + return (thisBits == anotherBits ? 0 : // Values are equal
32.991 + (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
32.992 + 1)); // (0.0, -0.0) or (NaN, !NaN)
32.993 + }
32.994 +
32.995 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
32.996 + private static final long serialVersionUID = -9172774392245257468L;
32.997 +}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
33.2 +++ b/emul/mini/src/main/java/java/lang/Enum.java Wed Jan 23 20:39:23 2013 +0100
33.3 @@ -0,0 +1,254 @@
33.4 +/*
33.5 + * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33.7 + *
33.8 + * This code is free software; you can redistribute it and/or modify it
33.9 + * under the terms of the GNU General Public License version 2 only, as
33.10 + * published by the Free Software Foundation. Oracle designates this
33.11 + * particular file as subject to the "Classpath" exception as provided
33.12 + * by Oracle in the LICENSE file that accompanied this code.
33.13 + *
33.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
33.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
33.17 + * version 2 for more details (a copy is included in the LICENSE file that
33.18 + * accompanied this code).
33.19 + *
33.20 + * You should have received a copy of the GNU General Public License version
33.21 + * 2 along with this work; if not, write to the Free Software Foundation,
33.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33.23 + *
33.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
33.25 + * or visit www.oracle.com if you need additional information or have any
33.26 + * questions.
33.27 + */
33.28 +
33.29 +package java.lang;
33.30 +
33.31 +import java.io.Serializable;
33.32 +import java.io.IOException;
33.33 +
33.34 +/**
33.35 + * This is the common base class of all Java language enumeration types.
33.36 + *
33.37 + * More information about enums, including descriptions of the
33.38 + * implicitly declared methods synthesized by the compiler, can be
33.39 + * found in section 8.9 of
33.40 + * <cite>The Java™ Language Specification</cite>.
33.41 + *
33.42 + * <p> Note that when using an enumeration type as the type of a set
33.43 + * or as the type of the keys in a map, specialized and efficient
33.44 + * {@linkplain java.util.EnumSet set} and {@linkplain
33.45 + * java.util.EnumMap map} implementations are available.
33.46 + *
33.47 + * @param <E> The enum type subclass
33.48 + * @author Josh Bloch
33.49 + * @author Neal Gafter
33.50 + * @see Class#getEnumConstants()
33.51 + * @see java.util.EnumSet
33.52 + * @see java.util.EnumMap
33.53 + * @since 1.5
33.54 + */
33.55 +public abstract class Enum<E extends Enum<E>>
33.56 + implements Comparable<E>, Serializable {
33.57 + /**
33.58 + * The name of this enum constant, as declared in the enum declaration.
33.59 + * Most programmers should use the {@link #toString} method rather than
33.60 + * accessing this field.
33.61 + */
33.62 + private final String name;
33.63 +
33.64 + /**
33.65 + * Returns the name of this enum constant, exactly as declared in its
33.66 + * enum declaration.
33.67 + *
33.68 + * <b>Most programmers should use the {@link #toString} method in
33.69 + * preference to this one, as the toString method may return
33.70 + * a more user-friendly name.</b> This method is designed primarily for
33.71 + * use in specialized situations where correctness depends on getting the
33.72 + * exact name, which will not vary from release to release.
33.73 + *
33.74 + * @return the name of this enum constant
33.75 + */
33.76 + public final String name() {
33.77 + return name;
33.78 + }
33.79 +
33.80 + /**
33.81 + * The ordinal of this enumeration constant (its position
33.82 + * in the enum declaration, where the initial constant is assigned
33.83 + * an ordinal of zero).
33.84 + *
33.85 + * Most programmers will have no use for this field. It is designed
33.86 + * for use by sophisticated enum-based data structures, such as
33.87 + * {@link java.util.EnumSet} and {@link java.util.EnumMap}.
33.88 + */
33.89 + private final int ordinal;
33.90 +
33.91 + /**
33.92 + * Returns the ordinal of this enumeration constant (its position
33.93 + * in its enum declaration, where the initial constant is assigned
33.94 + * an ordinal of zero).
33.95 + *
33.96 + * Most programmers will have no use for this method. It is
33.97 + * designed for use by sophisticated enum-based data structures, such
33.98 + * as {@link java.util.EnumSet} and {@link java.util.EnumMap}.
33.99 + *
33.100 + * @return the ordinal of this enumeration constant
33.101 + */
33.102 + public final int ordinal() {
33.103 + return ordinal;
33.104 + }
33.105 +
33.106 + /**
33.107 + * Sole constructor. Programmers cannot invoke this constructor.
33.108 + * It is for use by code emitted by the compiler in response to
33.109 + * enum type declarations.
33.110 + *
33.111 + * @param name - The name of this enum constant, which is the identifier
33.112 + * used to declare it.
33.113 + * @param ordinal - The ordinal of this enumeration constant (its position
33.114 + * in the enum declaration, where the initial constant is assigned
33.115 + * an ordinal of zero).
33.116 + */
33.117 + protected Enum(String name, int ordinal) {
33.118 + this.name = name;
33.119 + this.ordinal = ordinal;
33.120 + }
33.121 +
33.122 + /**
33.123 + * Returns the name of this enum constant, as contained in the
33.124 + * declaration. This method may be overridden, though it typically
33.125 + * isn't necessary or desirable. An enum type should override this
33.126 + * method when a more "programmer-friendly" string form exists.
33.127 + *
33.128 + * @return the name of this enum constant
33.129 + */
33.130 + public String toString() {
33.131 + return name;
33.132 + }
33.133 +
33.134 + /**
33.135 + * Returns true if the specified object is equal to this
33.136 + * enum constant.
33.137 + *
33.138 + * @param other the object to be compared for equality with this object.
33.139 + * @return true if the specified object is equal to this
33.140 + * enum constant.
33.141 + */
33.142 + public final boolean equals(Object other) {
33.143 + return this==other;
33.144 + }
33.145 +
33.146 + /**
33.147 + * Returns a hash code for this enum constant.
33.148 + *
33.149 + * @return a hash code for this enum constant.
33.150 + */
33.151 + public final int hashCode() {
33.152 + return super.hashCode();
33.153 + }
33.154 +
33.155 + /**
33.156 + * Throws CloneNotSupportedException. This guarantees that enums
33.157 + * are never cloned, which is necessary to preserve their "singleton"
33.158 + * status.
33.159 + *
33.160 + * @return (never returns)
33.161 + */
33.162 + protected final Object clone() throws CloneNotSupportedException {
33.163 + throw new CloneNotSupportedException();
33.164 + }
33.165 +
33.166 + /**
33.167 + * Compares this enum with the specified object for order. Returns a
33.168 + * negative integer, zero, or a positive integer as this object is less
33.169 + * than, equal to, or greater than the specified object.
33.170 + *
33.171 + * Enum constants are only comparable to other enum constants of the
33.172 + * same enum type. The natural order implemented by this
33.173 + * method is the order in which the constants are declared.
33.174 + */
33.175 + public final int compareTo(E o) {
33.176 + Enum other = (Enum)o;
33.177 + Enum self = this;
33.178 + if (self.getClass() != other.getClass() && // optimization
33.179 + self.getDeclaringClass() != other.getDeclaringClass())
33.180 + throw new ClassCastException();
33.181 + return self.ordinal - other.ordinal;
33.182 + }
33.183 +
33.184 + /**
33.185 + * Returns the Class object corresponding to this enum constant's
33.186 + * enum type. Two enum constants e1 and e2 are of the
33.187 + * same enum type if and only if
33.188 + * e1.getDeclaringClass() == e2.getDeclaringClass().
33.189 + * (The value returned by this method may differ from the one returned
33.190 + * by the {@link Object#getClass} method for enum constants with
33.191 + * constant-specific class bodies.)
33.192 + *
33.193 + * @return the Class object corresponding to this enum constant's
33.194 + * enum type
33.195 + */
33.196 + public final Class<E> getDeclaringClass() {
33.197 + Class clazz = getClass();
33.198 + Class zuper = clazz.getSuperclass();
33.199 + return (zuper == Enum.class) ? clazz : zuper;
33.200 + }
33.201 +
33.202 + /**
33.203 + * Returns the enum constant of the specified enum type with the
33.204 + * specified name. The name must match exactly an identifier used
33.205 + * to declare an enum constant in this type. (Extraneous whitespace
33.206 + * characters are not permitted.)
33.207 + *
33.208 + * <p>Note that for a particular enum type {@code T}, the
33.209 + * implicitly declared {@code public static T valueOf(String)}
33.210 + * method on that enum may be used instead of this method to map
33.211 + * from a name to the corresponding enum constant. All the
33.212 + * constants of an enum type can be obtained by calling the
33.213 + * implicit {@code public static T[] values()} method of that
33.214 + * type.
33.215 + *
33.216 + * @param <T> The enum type whose constant is to be returned
33.217 + * @param enumType the {@code Class} object of the enum type from which
33.218 + * to return a constant
33.219 + * @param name the name of the constant to return
33.220 + * @return the enum constant of the specified enum type with the
33.221 + * specified name
33.222 + * @throws IllegalArgumentException if the specified enum type has
33.223 + * no constant with the specified name, or the specified
33.224 + * class object does not represent an enum type
33.225 + * @throws NullPointerException if {@code enumType} or {@code name}
33.226 + * is null
33.227 + * @since 1.5
33.228 + */
33.229 + public static <T extends Enum<T>> T valueOf(Class<T> enumType,
33.230 + String name) {
33.231 + throw new UnsupportedOperationException();
33.232 +// T result = enumType.enumConstantDirectory().get(name);
33.233 +// if (result != null)
33.234 +// return result;
33.235 +// if (name == null)
33.236 +// throw new NullPointerException("Name is null");
33.237 +// throw new IllegalArgumentException(
33.238 +// "No enum constant " + enumType.getCanonicalName() + "." + name);
33.239 + }
33.240 +
33.241 + /**
33.242 + * enum classes cannot have finalize methods.
33.243 + */
33.244 + protected final void finalize() { }
33.245 +
33.246 + /**
33.247 + * prevent default deserialization
33.248 + */
33.249 +// private void readObject(ObjectInputStream in) throws IOException,
33.250 +// ClassNotFoundException {
33.251 +// throw new InvalidObjectException("can't deserialize enum");
33.252 +// }
33.253 +//
33.254 +// private void readObjectNoData() throws ObjectStreamException {
33.255 +// throw new InvalidObjectException("can't deserialize enum");
33.256 +// }
33.257 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
34.2 +++ b/emul/mini/src/main/java/java/lang/Error.java Wed Jan 23 20:39:23 2013 +0100
34.3 @@ -0,0 +1,128 @@
34.4 +/*
34.5 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
34.7 + *
34.8 + * This code is free software; you can redistribute it and/or modify it
34.9 + * under the terms of the GNU General Public License version 2 only, as
34.10 + * published by the Free Software Foundation. Oracle designates this
34.11 + * particular file as subject to the "Classpath" exception as provided
34.12 + * by Oracle in the LICENSE file that accompanied this code.
34.13 + *
34.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
34.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
34.17 + * version 2 for more details (a copy is included in the LICENSE file that
34.18 + * accompanied this code).
34.19 + *
34.20 + * You should have received a copy of the GNU General Public License version
34.21 + * 2 along with this work; if not, write to the Free Software Foundation,
34.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
34.23 + *
34.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
34.25 + * or visit www.oracle.com if you need additional information or have any
34.26 + * questions.
34.27 + */
34.28 +
34.29 +package java.lang;
34.30 +
34.31 +/**
34.32 + * An {@code Error} is a subclass of {@code Throwable}
34.33 + * that indicates serious problems that a reasonable application
34.34 + * should not try to catch. Most such errors are abnormal conditions.
34.35 + * The {@code ThreadDeath} error, though a "normal" condition,
34.36 + * is also a subclass of {@code Error} because most applications
34.37 + * should not try to catch it.
34.38 + * <p>
34.39 + * A method is not required to declare in its {@code throws}
34.40 + * clause any subclasses of {@code Error} that might be thrown
34.41 + * during the execution of the method but not caught, since these
34.42 + * errors are abnormal conditions that should never occur.
34.43 + *
34.44 + * That is, {@code Error} and its subclasses are regarded as unchecked
34.45 + * exceptions for the purposes of compile-time checking of exceptions.
34.46 + *
34.47 + * @author Frank Yellin
34.48 + * @see java.lang.ThreadDeath
34.49 + * @jls 11.2 Compile-Time Checking of Exceptions
34.50 + * @since JDK1.0
34.51 + */
34.52 +public class Error extends Throwable {
34.53 + static final long serialVersionUID = 4980196508277280342L;
34.54 +
34.55 + /**
34.56 + * Constructs a new error with {@code null} as its detail message.
34.57 + * The cause is not initialized, and may subsequently be initialized by a
34.58 + * call to {@link #initCause}.
34.59 + */
34.60 + public Error() {
34.61 + super();
34.62 + }
34.63 +
34.64 + /**
34.65 + * Constructs a new error with the specified detail message. The
34.66 + * cause is not initialized, and may subsequently be initialized by
34.67 + * a call to {@link #initCause}.
34.68 + *
34.69 + * @param message the detail message. The detail message is saved for
34.70 + * later retrieval by the {@link #getMessage()} method.
34.71 + */
34.72 + public Error(String message) {
34.73 + super(message);
34.74 + }
34.75 +
34.76 + /**
34.77 + * Constructs a new error with the specified detail message and
34.78 + * cause. <p>Note that the detail message associated with
34.79 + * {@code cause} is <i>not</i> automatically incorporated in
34.80 + * this error's detail message.
34.81 + *
34.82 + * @param message the detail message (which is saved for later retrieval
34.83 + * by the {@link #getMessage()} method).
34.84 + * @param cause the cause (which is saved for later retrieval by the
34.85 + * {@link #getCause()} method). (A {@code null} value is
34.86 + * permitted, and indicates that the cause is nonexistent or
34.87 + * unknown.)
34.88 + * @since 1.4
34.89 + */
34.90 + public Error(String message, Throwable cause) {
34.91 + super(message, cause);
34.92 + }
34.93 +
34.94 + /**
34.95 + * Constructs a new error with the specified cause and a detail
34.96 + * message of {@code (cause==null ? null : cause.toString())} (which
34.97 + * typically contains the class and detail message of {@code cause}).
34.98 + * This constructor is useful for errors that are little more than
34.99 + * wrappers for other throwables.
34.100 + *
34.101 + * @param cause the cause (which is saved for later retrieval by the
34.102 + * {@link #getCause()} method). (A {@code null} value is
34.103 + * permitted, and indicates that the cause is nonexistent or
34.104 + * unknown.)
34.105 + * @since 1.4
34.106 + */
34.107 + public Error(Throwable cause) {
34.108 + super(cause);
34.109 + }
34.110 +
34.111 + /**
34.112 + * Constructs a new error with the specified detail message,
34.113 + * cause, suppression enabled or disabled, and writable stack
34.114 + * trace enabled or disabled.
34.115 + *
34.116 + * @param message the detail message.
34.117 + * @param cause the cause. (A {@code null} value is permitted,
34.118 + * and indicates that the cause is nonexistent or unknown.)
34.119 + * @param enableSuppression whether or not suppression is enabled
34.120 + * or disabled
34.121 + * @param writableStackTrace whether or not the stack trace should
34.122 + * be writable
34.123 + *
34.124 + * @since 1.7
34.125 + */
34.126 + protected Error(String message, Throwable cause,
34.127 + boolean enableSuppression,
34.128 + boolean writableStackTrace) {
34.129 + super(message, cause, enableSuppression, writableStackTrace);
34.130 + }
34.131 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
35.2 +++ b/emul/mini/src/main/java/java/lang/Exception.java Wed Jan 23 20:39:23 2013 +0100
35.3 @@ -0,0 +1,124 @@
35.4 +/*
35.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35.7 + *
35.8 + * This code is free software; you can redistribute it and/or modify it
35.9 + * under the terms of the GNU General Public License version 2 only, as
35.10 + * published by the Free Software Foundation. Oracle designates this
35.11 + * particular file as subject to the "Classpath" exception as provided
35.12 + * by Oracle in the LICENSE file that accompanied this code.
35.13 + *
35.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
35.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
35.17 + * version 2 for more details (a copy is included in the LICENSE file that
35.18 + * accompanied this code).
35.19 + *
35.20 + * You should have received a copy of the GNU General Public License version
35.21 + * 2 along with this work; if not, write to the Free Software Foundation,
35.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35.23 + *
35.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35.25 + * or visit www.oracle.com if you need additional information or have any
35.26 + * questions.
35.27 + */
35.28 +
35.29 +package java.lang;
35.30 +
35.31 +/**
35.32 + * The class {@code Exception} and its subclasses are a form of
35.33 + * {@code Throwable} that indicates conditions that a reasonable
35.34 + * application might want to catch.
35.35 + *
35.36 + * <p>The class {@code Exception} and any subclasses that are not also
35.37 + * subclasses of {@link RuntimeException} are <em>checked
35.38 + * exceptions</em>. Checked exceptions need to be declared in a
35.39 + * method or constructor's {@code throws} clause if they can be thrown
35.40 + * by the execution of the method or constructor and propagate outside
35.41 + * the method or constructor boundary.
35.42 + *
35.43 + * @author Frank Yellin
35.44 + * @see java.lang.Error
35.45 + * @jls 11.2 Compile-Time Checking of Exceptions
35.46 + * @since JDK1.0
35.47 + */
35.48 +public class Exception extends Throwable {
35.49 + static final long serialVersionUID = -3387516993124229948L;
35.50 +
35.51 + /**
35.52 + * Constructs a new exception with {@code null} as its detail message.
35.53 + * The cause is not initialized, and may subsequently be initialized by a
35.54 + * call to {@link #initCause}.
35.55 + */
35.56 + public Exception() {
35.57 + super();
35.58 + }
35.59 +
35.60 + /**
35.61 + * Constructs a new exception with the specified detail message. The
35.62 + * cause is not initialized, and may subsequently be initialized by
35.63 + * a call to {@link #initCause}.
35.64 + *
35.65 + * @param message the detail message. The detail message is saved for
35.66 + * later retrieval by the {@link #getMessage()} method.
35.67 + */
35.68 + public Exception(String message) {
35.69 + super(message);
35.70 + }
35.71 +
35.72 + /**
35.73 + * Constructs a new exception with the specified detail message and
35.74 + * cause. <p>Note that the detail message associated with
35.75 + * {@code cause} is <i>not</i> automatically incorporated in
35.76 + * this exception's detail message.
35.77 + *
35.78 + * @param message the detail message (which is saved for later retrieval
35.79 + * by the {@link #getMessage()} method).
35.80 + * @param cause the cause (which is saved for later retrieval by the
35.81 + * {@link #getCause()} method). (A <tt>null</tt> value is
35.82 + * permitted, and indicates that the cause is nonexistent or
35.83 + * unknown.)
35.84 + * @since 1.4
35.85 + */
35.86 + public Exception(String message, Throwable cause) {
35.87 + super(message, cause);
35.88 + }
35.89 +
35.90 + /**
35.91 + * Constructs a new exception with the specified cause and a detail
35.92 + * message of <tt>(cause==null ? null : cause.toString())</tt> (which
35.93 + * typically contains the class and detail message of <tt>cause</tt>).
35.94 + * This constructor is useful for exceptions that are little more than
35.95 + * wrappers for other throwables (for example, {@link
35.96 + * java.security.PrivilegedActionException}).
35.97 + *
35.98 + * @param cause the cause (which is saved for later retrieval by the
35.99 + * {@link #getCause()} method). (A <tt>null</tt> value is
35.100 + * permitted, and indicates that the cause is nonexistent or
35.101 + * unknown.)
35.102 + * @since 1.4
35.103 + */
35.104 + public Exception(Throwable cause) {
35.105 + super(cause);
35.106 + }
35.107 +
35.108 + /**
35.109 + * Constructs a new exception with the specified detail message,
35.110 + * cause, suppression enabled or disabled, and writable stack
35.111 + * trace enabled or disabled.
35.112 + *
35.113 + * @param message the detail message.
35.114 + * @param cause the cause. (A {@code null} value is permitted,
35.115 + * and indicates that the cause is nonexistent or unknown.)
35.116 + * @param enableSuppression whether or not suppression is enabled
35.117 + * or disabled
35.118 + * @param writableStackTrace whether or not the stack trace should
35.119 + * be writable
35.120 + * @since 1.7
35.121 + */
35.122 + protected Exception(String message, Throwable cause,
35.123 + boolean enableSuppression,
35.124 + boolean writableStackTrace) {
35.125 + super(message, cause, enableSuppression, writableStackTrace);
35.126 + }
35.127 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
36.2 +++ b/emul/mini/src/main/java/java/lang/Float.java Wed Jan 23 20:39:23 2013 +0100
36.3 @@ -0,0 +1,905 @@
36.4 +/*
36.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
36.7 + *
36.8 + * This code is free software; you can redistribute it and/or modify it
36.9 + * under the terms of the GNU General Public License version 2 only, as
36.10 + * published by the Free Software Foundation. Oracle designates this
36.11 + * particular file as subject to the "Classpath" exception as provided
36.12 + * by Oracle in the LICENSE file that accompanied this code.
36.13 + *
36.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
36.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
36.17 + * version 2 for more details (a copy is included in the LICENSE file that
36.18 + * accompanied this code).
36.19 + *
36.20 + * You should have received a copy of the GNU General Public License version
36.21 + * 2 along with this work; if not, write to the Free Software Foundation,
36.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
36.23 + *
36.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
36.25 + * or visit www.oracle.com if you need additional information or have any
36.26 + * questions.
36.27 + */
36.28 +
36.29 +package java.lang;
36.30 +
36.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
36.32 +
36.33 +/**
36.34 + * The {@code Float} class wraps a value of primitive type
36.35 + * {@code float} in an object. An object of type
36.36 + * {@code Float} contains a single field whose type is
36.37 + * {@code float}.
36.38 + *
36.39 + * <p>In addition, this class provides several methods for converting a
36.40 + * {@code float} to a {@code String} and a
36.41 + * {@code String} to a {@code float}, as well as other
36.42 + * constants and methods useful when dealing with a
36.43 + * {@code float}.
36.44 + *
36.45 + * @author Lee Boynton
36.46 + * @author Arthur van Hoff
36.47 + * @author Joseph D. Darcy
36.48 + * @since JDK1.0
36.49 + */
36.50 +public final class Float extends Number implements Comparable<Float> {
36.51 + /**
36.52 + * A constant holding the positive infinity of type
36.53 + * {@code float}. It is equal to the value returned by
36.54 + * {@code Float.intBitsToFloat(0x7f800000)}.
36.55 + */
36.56 + public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
36.57 +
36.58 + /**
36.59 + * A constant holding the negative infinity of type
36.60 + * {@code float}. It is equal to the value returned by
36.61 + * {@code Float.intBitsToFloat(0xff800000)}.
36.62 + */
36.63 + public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
36.64 +
36.65 + /**
36.66 + * A constant holding a Not-a-Number (NaN) value of type
36.67 + * {@code float}. It is equivalent to the value returned by
36.68 + * {@code Float.intBitsToFloat(0x7fc00000)}.
36.69 + */
36.70 + public static final float NaN = 0.0f / 0.0f;
36.71 +
36.72 + /**
36.73 + * A constant holding the largest positive finite value of type
36.74 + * {@code float}, (2-2<sup>-23</sup>)·2<sup>127</sup>.
36.75 + * It is equal to the hexadecimal floating-point literal
36.76 + * {@code 0x1.fffffeP+127f} and also equal to
36.77 + * {@code Float.intBitsToFloat(0x7f7fffff)}.
36.78 + */
36.79 + public static final float MAX_VALUE = 0x1.fffffeP+127f; // 3.4028235e+38f
36.80 +
36.81 + /**
36.82 + * A constant holding the smallest positive normal value of type
36.83 + * {@code float}, 2<sup>-126</sup>. It is equal to the
36.84 + * hexadecimal floating-point literal {@code 0x1.0p-126f} and also
36.85 + * equal to {@code Float.intBitsToFloat(0x00800000)}.
36.86 + *
36.87 + * @since 1.6
36.88 + */
36.89 + public static final float MIN_NORMAL = 0x1.0p-126f; // 1.17549435E-38f
36.90 +
36.91 + /**
36.92 + * A constant holding the smallest positive nonzero value of type
36.93 + * {@code float}, 2<sup>-149</sup>. It is equal to the
36.94 + * hexadecimal floating-point literal {@code 0x0.000002P-126f}
36.95 + * and also equal to {@code Float.intBitsToFloat(0x1)}.
36.96 + */
36.97 + public static final float MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f
36.98 +
36.99 + /**
36.100 + * Maximum exponent a finite {@code float} variable may have. It
36.101 + * is equal to the value returned by {@code
36.102 + * Math.getExponent(Float.MAX_VALUE)}.
36.103 + *
36.104 + * @since 1.6
36.105 + */
36.106 + public static final int MAX_EXPONENT = 127;
36.107 +
36.108 + /**
36.109 + * Minimum exponent a normalized {@code float} variable may have.
36.110 + * It is equal to the value returned by {@code
36.111 + * Math.getExponent(Float.MIN_NORMAL)}.
36.112 + *
36.113 + * @since 1.6
36.114 + */
36.115 + public static final int MIN_EXPONENT = -126;
36.116 +
36.117 + /**
36.118 + * The number of bits used to represent a {@code float} value.
36.119 + *
36.120 + * @since 1.5
36.121 + */
36.122 + public static final int SIZE = 32;
36.123 +
36.124 + /**
36.125 + * The {@code Class} instance representing the primitive type
36.126 + * {@code float}.
36.127 + *
36.128 + * @since JDK1.1
36.129 + */
36.130 + public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
36.131 +
36.132 + /**
36.133 + * Returns a string representation of the {@code float}
36.134 + * argument. All characters mentioned below are ASCII characters.
36.135 + * <ul>
36.136 + * <li>If the argument is NaN, the result is the string
36.137 + * "{@code NaN}".
36.138 + * <li>Otherwise, the result is a string that represents the sign and
36.139 + * magnitude (absolute value) of the argument. If the sign is
36.140 + * negative, the first character of the result is
36.141 + * '{@code -}' (<code>'\u002D'</code>); if the sign is
36.142 + * positive, no sign character appears in the result. As for
36.143 + * the magnitude <i>m</i>:
36.144 + * <ul>
36.145 + * <li>If <i>m</i> is infinity, it is represented by the characters
36.146 + * {@code "Infinity"}; thus, positive infinity produces
36.147 + * the result {@code "Infinity"} and negative infinity
36.148 + * produces the result {@code "-Infinity"}.
36.149 + * <li>If <i>m</i> is zero, it is represented by the characters
36.150 + * {@code "0.0"}; thus, negative zero produces the result
36.151 + * {@code "-0.0"} and positive zero produces the result
36.152 + * {@code "0.0"}.
36.153 + * <li> If <i>m</i> is greater than or equal to 10<sup>-3</sup> but
36.154 + * less than 10<sup>7</sup>, then it is represented as the
36.155 + * integer part of <i>m</i>, in decimal form with no leading
36.156 + * zeroes, followed by '{@code .}'
36.157 + * (<code>'\u002E'</code>), followed by one or more
36.158 + * decimal digits representing the fractional part of
36.159 + * <i>m</i>.
36.160 + * <li> If <i>m</i> is less than 10<sup>-3</sup> or greater than or
36.161 + * equal to 10<sup>7</sup>, then it is represented in
36.162 + * so-called "computerized scientific notation." Let <i>n</i>
36.163 + * be the unique integer such that 10<sup><i>n</i> </sup>≤
36.164 + * <i>m</i> {@literal <} 10<sup><i>n</i>+1</sup>; then let <i>a</i>
36.165 + * be the mathematically exact quotient of <i>m</i> and
36.166 + * 10<sup><i>n</i></sup> so that 1 ≤ <i>a</i> {@literal <} 10.
36.167 + * The magnitude is then represented as the integer part of
36.168 + * <i>a</i>, as a single decimal digit, followed by
36.169 + * '{@code .}' (<code>'\u002E'</code>), followed by
36.170 + * decimal digits representing the fractional part of
36.171 + * <i>a</i>, followed by the letter '{@code E}'
36.172 + * (<code>'\u0045'</code>), followed by a representation
36.173 + * of <i>n</i> as a decimal integer, as produced by the
36.174 + * method {@link java.lang.Integer#toString(int)}.
36.175 + *
36.176 + * </ul>
36.177 + * </ul>
36.178 + * How many digits must be printed for the fractional part of
36.179 + * <i>m</i> or <i>a</i>? There must be at least one digit
36.180 + * to represent the fractional part, and beyond that as many, but
36.181 + * only as many, more digits as are needed to uniquely distinguish
36.182 + * the argument value from adjacent values of type
36.183 + * {@code float}. That is, suppose that <i>x</i> is the
36.184 + * exact mathematical value represented by the decimal
36.185 + * representation produced by this method for a finite nonzero
36.186 + * argument <i>f</i>. Then <i>f</i> must be the {@code float}
36.187 + * value nearest to <i>x</i>; or, if two {@code float} values are
36.188 + * equally close to <i>x</i>, then <i>f</i> must be one of
36.189 + * them and the least significant bit of the significand of
36.190 + * <i>f</i> must be {@code 0}.
36.191 + *
36.192 + * <p>To create localized string representations of a floating-point
36.193 + * value, use subclasses of {@link java.text.NumberFormat}.
36.194 + *
36.195 + * @param f the float to be converted.
36.196 + * @return a string representation of the argument.
36.197 + */
36.198 + public static String toString(float f) {
36.199 + return Double.toString(f);
36.200 + }
36.201 +
36.202 + /**
36.203 + * Returns a hexadecimal string representation of the
36.204 + * {@code float} argument. All characters mentioned below are
36.205 + * ASCII characters.
36.206 + *
36.207 + * <ul>
36.208 + * <li>If the argument is NaN, the result is the string
36.209 + * "{@code NaN}".
36.210 + * <li>Otherwise, the result is a string that represents the sign and
36.211 + * magnitude (absolute value) of the argument. If the sign is negative,
36.212 + * the first character of the result is '{@code -}'
36.213 + * (<code>'\u002D'</code>); if the sign is positive, no sign character
36.214 + * appears in the result. As for the magnitude <i>m</i>:
36.215 + *
36.216 + * <ul>
36.217 + * <li>If <i>m</i> is infinity, it is represented by the string
36.218 + * {@code "Infinity"}; thus, positive infinity produces the
36.219 + * result {@code "Infinity"} and negative infinity produces
36.220 + * the result {@code "-Infinity"}.
36.221 + *
36.222 + * <li>If <i>m</i> is zero, it is represented by the string
36.223 + * {@code "0x0.0p0"}; thus, negative zero produces the result
36.224 + * {@code "-0x0.0p0"} and positive zero produces the result
36.225 + * {@code "0x0.0p0"}.
36.226 + *
36.227 + * <li>If <i>m</i> is a {@code float} value with a
36.228 + * normalized representation, substrings are used to represent the
36.229 + * significand and exponent fields. The significand is
36.230 + * represented by the characters {@code "0x1."}
36.231 + * followed by a lowercase hexadecimal representation of the rest
36.232 + * of the significand as a fraction. Trailing zeros in the
36.233 + * hexadecimal representation are removed unless all the digits
36.234 + * are zero, in which case a single zero is used. Next, the
36.235 + * exponent is represented by {@code "p"} followed
36.236 + * by a decimal string of the unbiased exponent as if produced by
36.237 + * a call to {@link Integer#toString(int) Integer.toString} on the
36.238 + * exponent value.
36.239 + *
36.240 + * <li>If <i>m</i> is a {@code float} value with a subnormal
36.241 + * representation, the significand is represented by the
36.242 + * characters {@code "0x0."} followed by a
36.243 + * hexadecimal representation of the rest of the significand as a
36.244 + * fraction. Trailing zeros in the hexadecimal representation are
36.245 + * removed. Next, the exponent is represented by
36.246 + * {@code "p-126"}. Note that there must be at
36.247 + * least one nonzero digit in a subnormal significand.
36.248 + *
36.249 + * </ul>
36.250 + *
36.251 + * </ul>
36.252 + *
36.253 + * <table border>
36.254 + * <caption><h3>Examples</h3></caption>
36.255 + * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
36.256 + * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
36.257 + * <tr><td>{@code -1.0}</td> <td>{@code -0x1.0p0}</td>
36.258 + * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
36.259 + * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
36.260 + * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
36.261 + * <tr><td>{@code 0.25}</td> <td>{@code 0x1.0p-2}</td>
36.262 + * <tr><td>{@code Float.MAX_VALUE}</td>
36.263 + * <td>{@code 0x1.fffffep127}</td>
36.264 + * <tr><td>{@code Minimum Normal Value}</td>
36.265 + * <td>{@code 0x1.0p-126}</td>
36.266 + * <tr><td>{@code Maximum Subnormal Value}</td>
36.267 + * <td>{@code 0x0.fffffep-126}</td>
36.268 + * <tr><td>{@code Float.MIN_VALUE}</td>
36.269 + * <td>{@code 0x0.000002p-126}</td>
36.270 + * </table>
36.271 + * @param f the {@code float} to be converted.
36.272 + * @return a hex string representation of the argument.
36.273 + * @since 1.5
36.274 + * @author Joseph D. Darcy
36.275 + */
36.276 + public static String toHexString(float f) {
36.277 + throw new UnsupportedOperationException();
36.278 +// if (Math.abs(f) < FloatConsts.MIN_NORMAL
36.279 +// && f != 0.0f ) {// float subnormal
36.280 +// // Adjust exponent to create subnormal double, then
36.281 +// // replace subnormal double exponent with subnormal float
36.282 +// // exponent
36.283 +// String s = Double.toHexString(FpUtils.scalb((double)f,
36.284 +// /* -1022+126 */
36.285 +// DoubleConsts.MIN_EXPONENT-
36.286 +// FloatConsts.MIN_EXPONENT));
36.287 +// return s.replaceFirst("p-1022$", "p-126");
36.288 +// }
36.289 +// else // double string will be the same as float string
36.290 +// return Double.toHexString(f);
36.291 + }
36.292 +
36.293 + /**
36.294 + * Returns a {@code Float} object holding the
36.295 + * {@code float} value represented by the argument string
36.296 + * {@code s}.
36.297 + *
36.298 + * <p>If {@code s} is {@code null}, then a
36.299 + * {@code NullPointerException} is thrown.
36.300 + *
36.301 + * <p>Leading and trailing whitespace characters in {@code s}
36.302 + * are ignored. Whitespace is removed as if by the {@link
36.303 + * String#trim} method; that is, both ASCII space and control
36.304 + * characters are removed. The rest of {@code s} should
36.305 + * constitute a <i>FloatValue</i> as described by the lexical
36.306 + * syntax rules:
36.307 + *
36.308 + * <blockquote>
36.309 + * <dl>
36.310 + * <dt><i>FloatValue:</i>
36.311 + * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
36.312 + * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
36.313 + * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
36.314 + * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
36.315 + * <dd><i>SignedInteger</i>
36.316 + * </dl>
36.317 + *
36.318 + * <p>
36.319 + *
36.320 + * <dl>
36.321 + * <dt><i>HexFloatingPointLiteral</i>:
36.322 + * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
36.323 + * </dl>
36.324 + *
36.325 + * <p>
36.326 + *
36.327 + * <dl>
36.328 + * <dt><i>HexSignificand:</i>
36.329 + * <dd><i>HexNumeral</i>
36.330 + * <dd><i>HexNumeral</i> {@code .}
36.331 + * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
36.332 + * </i>{@code .}<i> HexDigits</i>
36.333 + * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
36.334 + * </i>{@code .} <i>HexDigits</i>
36.335 + * </dl>
36.336 + *
36.337 + * <p>
36.338 + *
36.339 + * <dl>
36.340 + * <dt><i>BinaryExponent:</i>
36.341 + * <dd><i>BinaryExponentIndicator SignedInteger</i>
36.342 + * </dl>
36.343 + *
36.344 + * <p>
36.345 + *
36.346 + * <dl>
36.347 + * <dt><i>BinaryExponentIndicator:</i>
36.348 + * <dd>{@code p}
36.349 + * <dd>{@code P}
36.350 + * </dl>
36.351 + *
36.352 + * </blockquote>
36.353 + *
36.354 + * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
36.355 + * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
36.356 + * <i>FloatTypeSuffix</i> are as defined in the lexical structure
36.357 + * sections of
36.358 + * <cite>The Java™ Language Specification</cite>,
36.359 + * except that underscores are not accepted between digits.
36.360 + * If {@code s} does not have the form of
36.361 + * a <i>FloatValue</i>, then a {@code NumberFormatException}
36.362 + * is thrown. Otherwise, {@code s} is regarded as
36.363 + * representing an exact decimal value in the usual
36.364 + * "computerized scientific notation" or as an exact
36.365 + * hexadecimal value; this exact numerical value is then
36.366 + * conceptually converted to an "infinitely precise"
36.367 + * binary value that is then rounded to type {@code float}
36.368 + * by the usual round-to-nearest rule of IEEE 754 floating-point
36.369 + * arithmetic, which includes preserving the sign of a zero
36.370 + * value.
36.371 + *
36.372 + * Note that the round-to-nearest rule also implies overflow and
36.373 + * underflow behaviour; if the exact value of {@code s} is large
36.374 + * enough in magnitude (greater than or equal to ({@link
36.375 + * #MAX_VALUE} + {@link Math#ulp(float) ulp(MAX_VALUE)}/2),
36.376 + * rounding to {@code float} will result in an infinity and if the
36.377 + * exact value of {@code s} is small enough in magnitude (less
36.378 + * than or equal to {@link #MIN_VALUE}/2), rounding to float will
36.379 + * result in a zero.
36.380 + *
36.381 + * Finally, after rounding a {@code Float} object representing
36.382 + * this {@code float} value is returned.
36.383 + *
36.384 + * <p>To interpret localized string representations of a
36.385 + * floating-point value, use subclasses of {@link
36.386 + * java.text.NumberFormat}.
36.387 + *
36.388 + * <p>Note that trailing format specifiers, specifiers that
36.389 + * determine the type of a floating-point literal
36.390 + * ({@code 1.0f} is a {@code float} value;
36.391 + * {@code 1.0d} is a {@code double} value), do
36.392 + * <em>not</em> influence the results of this method. In other
36.393 + * words, the numerical value of the input string is converted
36.394 + * directly to the target floating-point type. In general, the
36.395 + * two-step sequence of conversions, string to {@code double}
36.396 + * followed by {@code double} to {@code float}, is
36.397 + * <em>not</em> equivalent to converting a string directly to
36.398 + * {@code float}. For example, if first converted to an
36.399 + * intermediate {@code double} and then to
36.400 + * {@code float}, the string<br>
36.401 + * {@code "1.00000017881393421514957253748434595763683319091796875001d"}<br>
36.402 + * results in the {@code float} value
36.403 + * {@code 1.0000002f}; if the string is converted directly to
36.404 + * {@code float}, <code>1.000000<b>1</b>f</code> results.
36.405 + *
36.406 + * <p>To avoid calling this method on an invalid string and having
36.407 + * a {@code NumberFormatException} be thrown, the documentation
36.408 + * for {@link Double#valueOf Double.valueOf} lists a regular
36.409 + * expression which can be used to screen the input.
36.410 + *
36.411 + * @param s the string to be parsed.
36.412 + * @return a {@code Float} object holding the value
36.413 + * represented by the {@code String} argument.
36.414 + * @throws NumberFormatException if the string does not contain a
36.415 + * parsable number.
36.416 + */
36.417 + public static Float valueOf(String s) throws NumberFormatException {
36.418 + throw new UnsupportedOperationException();
36.419 +// return new Float(FloatingDecimal.readJavaFormatString(s).floatValue());
36.420 + }
36.421 +
36.422 + /**
36.423 + * Returns a {@code Float} instance representing the specified
36.424 + * {@code float} value.
36.425 + * If a new {@code Float} instance is not required, this method
36.426 + * should generally be used in preference to the constructor
36.427 + * {@link #Float(float)}, as this method is likely to yield
36.428 + * significantly better space and time performance by caching
36.429 + * frequently requested values.
36.430 + *
36.431 + * @param f a float value.
36.432 + * @return a {@code Float} instance representing {@code f}.
36.433 + * @since 1.5
36.434 + */
36.435 + public static Float valueOf(float f) {
36.436 + return new Float(f);
36.437 + }
36.438 +
36.439 + /**
36.440 + * Returns a new {@code float} initialized to the value
36.441 + * represented by the specified {@code String}, as performed
36.442 + * by the {@code valueOf} method of class {@code Float}.
36.443 + *
36.444 + * @param s the string to be parsed.
36.445 + * @return the {@code float} value represented by the string
36.446 + * argument.
36.447 + * @throws NullPointerException if the string is null
36.448 + * @throws NumberFormatException if the string does not contain a
36.449 + * parsable {@code float}.
36.450 + * @see java.lang.Float#valueOf(String)
36.451 + * @since 1.2
36.452 + */
36.453 + public static float parseFloat(String s) throws NumberFormatException {
36.454 + throw new UnsupportedOperationException();
36.455 +// return FloatingDecimal.readJavaFormatString(s).floatValue();
36.456 + }
36.457 +
36.458 + /**
36.459 + * Returns {@code true} if the specified number is a
36.460 + * Not-a-Number (NaN) value, {@code false} otherwise.
36.461 + *
36.462 + * @param v the value to be tested.
36.463 + * @return {@code true} if the argument is NaN;
36.464 + * {@code false} otherwise.
36.465 + */
36.466 + static public boolean isNaN(float v) {
36.467 + return (v != v);
36.468 + }
36.469 +
36.470 + /**
36.471 + * Returns {@code true} if the specified number is infinitely
36.472 + * large in magnitude, {@code false} otherwise.
36.473 + *
36.474 + * @param v the value to be tested.
36.475 + * @return {@code true} if the argument is positive infinity or
36.476 + * negative infinity; {@code false} otherwise.
36.477 + */
36.478 + static public boolean isInfinite(float v) {
36.479 + return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
36.480 + }
36.481 +
36.482 + /**
36.483 + * The value of the Float.
36.484 + *
36.485 + * @serial
36.486 + */
36.487 + private final float value;
36.488 +
36.489 + /**
36.490 + * Constructs a newly allocated {@code Float} object that
36.491 + * represents the primitive {@code float} argument.
36.492 + *
36.493 + * @param value the value to be represented by the {@code Float}.
36.494 + */
36.495 + public Float(float value) {
36.496 + this.value = value;
36.497 + }
36.498 +
36.499 + /**
36.500 + * Constructs a newly allocated {@code Float} object that
36.501 + * represents the argument converted to type {@code float}.
36.502 + *
36.503 + * @param value the value to be represented by the {@code Float}.
36.504 + */
36.505 + public Float(double value) {
36.506 + this.value = (float)value;
36.507 + }
36.508 +
36.509 + /**
36.510 + * Constructs a newly allocated {@code Float} object that
36.511 + * represents the floating-point value of type {@code float}
36.512 + * represented by the string. The string is converted to a
36.513 + * {@code float} value as if by the {@code valueOf} method.
36.514 + *
36.515 + * @param s a string to be converted to a {@code Float}.
36.516 + * @throws NumberFormatException if the string does not contain a
36.517 + * parsable number.
36.518 + * @see java.lang.Float#valueOf(java.lang.String)
36.519 + */
36.520 + public Float(String s) throws NumberFormatException {
36.521 + // REMIND: this is inefficient
36.522 + this(valueOf(s).floatValue());
36.523 + }
36.524 +
36.525 + /**
36.526 + * Returns {@code true} if this {@code Float} value is a
36.527 + * Not-a-Number (NaN), {@code false} otherwise.
36.528 + *
36.529 + * @return {@code true} if the value represented by this object is
36.530 + * NaN; {@code false} otherwise.
36.531 + */
36.532 + public boolean isNaN() {
36.533 + return isNaN(value);
36.534 + }
36.535 +
36.536 + /**
36.537 + * Returns {@code true} if this {@code Float} value is
36.538 + * infinitely large in magnitude, {@code false} otherwise.
36.539 + *
36.540 + * @return {@code true} if the value represented by this object is
36.541 + * positive infinity or negative infinity;
36.542 + * {@code false} otherwise.
36.543 + */
36.544 + public boolean isInfinite() {
36.545 + return isInfinite(value);
36.546 + }
36.547 +
36.548 + /**
36.549 + * Returns a string representation of this {@code Float} object.
36.550 + * The primitive {@code float} value represented by this object
36.551 + * is converted to a {@code String} exactly as if by the method
36.552 + * {@code toString} of one argument.
36.553 + *
36.554 + * @return a {@code String} representation of this object.
36.555 + * @see java.lang.Float#toString(float)
36.556 + */
36.557 + public String toString() {
36.558 + return Float.toString(value);
36.559 + }
36.560 +
36.561 + /**
36.562 + * Returns the value of this {@code Float} as a {@code byte} (by
36.563 + * casting to a {@code byte}).
36.564 + *
36.565 + * @return the {@code float} value represented by this object
36.566 + * converted to type {@code byte}
36.567 + */
36.568 + public byte byteValue() {
36.569 + return (byte)value;
36.570 + }
36.571 +
36.572 + /**
36.573 + * Returns the value of this {@code Float} as a {@code short} (by
36.574 + * casting to a {@code short}).
36.575 + *
36.576 + * @return the {@code float} value represented by this object
36.577 + * converted to type {@code short}
36.578 + * @since JDK1.1
36.579 + */
36.580 + public short shortValue() {
36.581 + return (short)value;
36.582 + }
36.583 +
36.584 + /**
36.585 + * Returns the value of this {@code Float} as an {@code int} (by
36.586 + * casting to type {@code int}).
36.587 + *
36.588 + * @return the {@code float} value represented by this object
36.589 + * converted to type {@code int}
36.590 + */
36.591 + public int intValue() {
36.592 + return (int)value;
36.593 + }
36.594 +
36.595 + /**
36.596 + * Returns value of this {@code Float} as a {@code long} (by
36.597 + * casting to type {@code long}).
36.598 + *
36.599 + * @return the {@code float} value represented by this object
36.600 + * converted to type {@code long}
36.601 + */
36.602 + public long longValue() {
36.603 + return (long)value;
36.604 + }
36.605 +
36.606 + /**
36.607 + * Returns the {@code float} value of this {@code Float} object.
36.608 + *
36.609 + * @return the {@code float} value represented by this object
36.610 + */
36.611 + public float floatValue() {
36.612 + return value;
36.613 + }
36.614 +
36.615 + /**
36.616 + * Returns the {@code double} value of this {@code Float} object.
36.617 + *
36.618 + * @return the {@code float} value represented by this
36.619 + * object is converted to type {@code double} and the
36.620 + * result of the conversion is returned.
36.621 + */
36.622 + public double doubleValue() {
36.623 + return (double)value;
36.624 + }
36.625 +
36.626 + /**
36.627 + * Returns a hash code for this {@code Float} object. The
36.628 + * result is the integer bit representation, exactly as produced
36.629 + * by the method {@link #floatToIntBits(float)}, of the primitive
36.630 + * {@code float} value represented by this {@code Float}
36.631 + * object.
36.632 + *
36.633 + * @return a hash code value for this object.
36.634 + */
36.635 + public int hashCode() {
36.636 + return floatToIntBits(value);
36.637 + }
36.638 +
36.639 + /**
36.640 +
36.641 + * Compares this object against the specified object. The result
36.642 + * is {@code true} if and only if the argument is not
36.643 + * {@code null} and is a {@code Float} object that
36.644 + * represents a {@code float} with the same value as the
36.645 + * {@code float} represented by this object. For this
36.646 + * purpose, two {@code float} values are considered to be the
36.647 + * same if and only if the method {@link #floatToIntBits(float)}
36.648 + * returns the identical {@code int} value when applied to
36.649 + * each.
36.650 + *
36.651 + * <p>Note that in most cases, for two instances of class
36.652 + * {@code Float}, {@code f1} and {@code f2}, the value
36.653 + * of {@code f1.equals(f2)} is {@code true} if and only if
36.654 + *
36.655 + * <blockquote><pre>
36.656 + * f1.floatValue() == f2.floatValue()
36.657 + * </pre></blockquote>
36.658 + *
36.659 + * <p>also has the value {@code true}. However, there are two exceptions:
36.660 + * <ul>
36.661 + * <li>If {@code f1} and {@code f2} both represent
36.662 + * {@code Float.NaN}, then the {@code equals} method returns
36.663 + * {@code true}, even though {@code Float.NaN==Float.NaN}
36.664 + * has the value {@code false}.
36.665 + * <li>If {@code f1} represents {@code +0.0f} while
36.666 + * {@code f2} represents {@code -0.0f}, or vice
36.667 + * versa, the {@code equal} test has the value
36.668 + * {@code false}, even though {@code 0.0f==-0.0f}
36.669 + * has the value {@code true}.
36.670 + * </ul>
36.671 + *
36.672 + * This definition allows hash tables to operate properly.
36.673 + *
36.674 + * @param obj the object to be compared
36.675 + * @return {@code true} if the objects are the same;
36.676 + * {@code false} otherwise.
36.677 + * @see java.lang.Float#floatToIntBits(float)
36.678 + */
36.679 + public boolean equals(Object obj) {
36.680 + return (obj instanceof Float)
36.681 + && (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
36.682 + }
36.683 +
36.684 + /**
36.685 + * Returns a representation of the specified floating-point value
36.686 + * according to the IEEE 754 floating-point "single format" bit
36.687 + * layout.
36.688 + *
36.689 + * <p>Bit 31 (the bit that is selected by the mask
36.690 + * {@code 0x80000000}) represents the sign of the floating-point
36.691 + * number.
36.692 + * Bits 30-23 (the bits that are selected by the mask
36.693 + * {@code 0x7f800000}) represent the exponent.
36.694 + * Bits 22-0 (the bits that are selected by the mask
36.695 + * {@code 0x007fffff}) represent the significand (sometimes called
36.696 + * the mantissa) of the floating-point number.
36.697 + *
36.698 + * <p>If the argument is positive infinity, the result is
36.699 + * {@code 0x7f800000}.
36.700 + *
36.701 + * <p>If the argument is negative infinity, the result is
36.702 + * {@code 0xff800000}.
36.703 + *
36.704 + * <p>If the argument is NaN, the result is {@code 0x7fc00000}.
36.705 + *
36.706 + * <p>In all cases, the result is an integer that, when given to the
36.707 + * {@link #intBitsToFloat(int)} method, will produce a floating-point
36.708 + * value the same as the argument to {@code floatToIntBits}
36.709 + * (except all NaN values are collapsed to a single
36.710 + * "canonical" NaN value).
36.711 + *
36.712 + * @param value a floating-point number.
36.713 + * @return the bits that represent the floating-point number.
36.714 + */
36.715 + public static int floatToIntBits(float value) {
36.716 + throw new UnsupportedOperationException();
36.717 +// int result = floatToRawIntBits(value);
36.718 +// // Check for NaN based on values of bit fields, maximum
36.719 +// // exponent and nonzero significand.
36.720 +// if ( ((result & FloatConsts.EXP_BIT_MASK) ==
36.721 +// FloatConsts.EXP_BIT_MASK) &&
36.722 +// (result & FloatConsts.SIGNIF_BIT_MASK) != 0)
36.723 +// result = 0x7fc00000;
36.724 +// return result;
36.725 + }
36.726 +
36.727 + /**
36.728 + * Returns a representation of the specified floating-point value
36.729 + * according to the IEEE 754 floating-point "single format" bit
36.730 + * layout, preserving Not-a-Number (NaN) values.
36.731 + *
36.732 + * <p>Bit 31 (the bit that is selected by the mask
36.733 + * {@code 0x80000000}) represents the sign of the floating-point
36.734 + * number.
36.735 + * Bits 30-23 (the bits that are selected by the mask
36.736 + * {@code 0x7f800000}) represent the exponent.
36.737 + * Bits 22-0 (the bits that are selected by the mask
36.738 + * {@code 0x007fffff}) represent the significand (sometimes called
36.739 + * the mantissa) of the floating-point number.
36.740 + *
36.741 + * <p>If the argument is positive infinity, the result is
36.742 + * {@code 0x7f800000}.
36.743 + *
36.744 + * <p>If the argument is negative infinity, the result is
36.745 + * {@code 0xff800000}.
36.746 + *
36.747 + * <p>If the argument is NaN, the result is the integer representing
36.748 + * the actual NaN value. Unlike the {@code floatToIntBits}
36.749 + * method, {@code floatToRawIntBits} does not collapse all the
36.750 + * bit patterns encoding a NaN to a single "canonical"
36.751 + * NaN value.
36.752 + *
36.753 + * <p>In all cases, the result is an integer that, when given to the
36.754 + * {@link #intBitsToFloat(int)} method, will produce a
36.755 + * floating-point value the same as the argument to
36.756 + * {@code floatToRawIntBits}.
36.757 + *
36.758 + * @param value a floating-point number.
36.759 + * @return the bits that represent the floating-point number.
36.760 + * @since 1.3
36.761 + */
36.762 + public static native int floatToRawIntBits(float value);
36.763 +
36.764 + /**
36.765 + * Returns the {@code float} value corresponding to a given
36.766 + * bit representation.
36.767 + * The argument is considered to be a representation of a
36.768 + * floating-point value according to the IEEE 754 floating-point
36.769 + * "single format" bit layout.
36.770 + *
36.771 + * <p>If the argument is {@code 0x7f800000}, the result is positive
36.772 + * infinity.
36.773 + *
36.774 + * <p>If the argument is {@code 0xff800000}, the result is negative
36.775 + * infinity.
36.776 + *
36.777 + * <p>If the argument is any value in the range
36.778 + * {@code 0x7f800001} through {@code 0x7fffffff} or in
36.779 + * the range {@code 0xff800001} through
36.780 + * {@code 0xffffffff}, the result is a NaN. No IEEE 754
36.781 + * floating-point operation provided by Java can distinguish
36.782 + * between two NaN values of the same type with different bit
36.783 + * patterns. Distinct values of NaN are only distinguishable by
36.784 + * use of the {@code Float.floatToRawIntBits} method.
36.785 + *
36.786 + * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
36.787 + * values that can be computed from the argument:
36.788 + *
36.789 + * <blockquote><pre>
36.790 + * int s = ((bits >> 31) == 0) ? 1 : -1;
36.791 + * int e = ((bits >> 23) & 0xff);
36.792 + * int m = (e == 0) ?
36.793 + * (bits & 0x7fffff) << 1 :
36.794 + * (bits & 0x7fffff) | 0x800000;
36.795 + * </pre></blockquote>
36.796 + *
36.797 + * Then the floating-point result equals the value of the mathematical
36.798 + * expression <i>s</i>·<i>m</i>·2<sup><i>e</i>-150</sup>.
36.799 + *
36.800 + * <p>Note that this method may not be able to return a
36.801 + * {@code float} NaN with exactly same bit pattern as the
36.802 + * {@code int} argument. IEEE 754 distinguishes between two
36.803 + * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>. The
36.804 + * differences between the two kinds of NaN are generally not
36.805 + * visible in Java. Arithmetic operations on signaling NaNs turn
36.806 + * them into quiet NaNs with a different, but often similar, bit
36.807 + * pattern. However, on some processors merely copying a
36.808 + * signaling NaN also performs that conversion. In particular,
36.809 + * copying a signaling NaN to return it to the calling method may
36.810 + * perform this conversion. So {@code intBitsToFloat} may
36.811 + * not be able to return a {@code float} with a signaling NaN
36.812 + * bit pattern. Consequently, for some {@code int} values,
36.813 + * {@code floatToRawIntBits(intBitsToFloat(start))} may
36.814 + * <i>not</i> equal {@code start}. Moreover, which
36.815 + * particular bit patterns represent signaling NaNs is platform
36.816 + * dependent; although all NaN bit patterns, quiet or signaling,
36.817 + * must be in the NaN range identified above.
36.818 + *
36.819 + * @param bits an integer.
36.820 + * @return the {@code float} floating-point value with the same bit
36.821 + * pattern.
36.822 + */
36.823 + @JavaScriptBody(args = "bits",
36.824 + body =
36.825 + "if (bits === 0x7f800000) return Number.POSITIVE_INFINITY;\n"
36.826 + + "if (bits === 0xff800000) return Number.NEGATIVE_INFINITY;\n"
36.827 + + "if (bits >= 0x7f800001 && bits <= 0xffffffff) return Number.NaN;\n"
36.828 + + "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
36.829 + + "var e = ((bits >> 23) & 0xff);\n"
36.830 + + "var m = (e == 0) ?\n"
36.831 + + " (bits & 0x7fffff) << 1 :\n"
36.832 + + " (bits & 0x7fffff) | 0x800000;\n"
36.833 + + "return s * m * Math.pow(2.0, e - 150);\n"
36.834 + )
36.835 + public static native float intBitsToFloat(int bits);
36.836 +
36.837 + /**
36.838 + * Compares two {@code Float} objects numerically. There are
36.839 + * two ways in which comparisons performed by this method differ
36.840 + * from those performed by the Java language numerical comparison
36.841 + * operators ({@code <, <=, ==, >=, >}) when
36.842 + * applied to primitive {@code float} values:
36.843 + *
36.844 + * <ul><li>
36.845 + * {@code Float.NaN} is considered by this method to
36.846 + * be equal to itself and greater than all other
36.847 + * {@code float} values
36.848 + * (including {@code Float.POSITIVE_INFINITY}).
36.849 + * <li>
36.850 + * {@code 0.0f} is considered by this method to be greater
36.851 + * than {@code -0.0f}.
36.852 + * </ul>
36.853 + *
36.854 + * This ensures that the <i>natural ordering</i> of {@code Float}
36.855 + * objects imposed by this method is <i>consistent with equals</i>.
36.856 + *
36.857 + * @param anotherFloat the {@code Float} to be compared.
36.858 + * @return the value {@code 0} if {@code anotherFloat} is
36.859 + * numerically equal to this {@code Float}; a value
36.860 + * less than {@code 0} if this {@code Float}
36.861 + * is numerically less than {@code anotherFloat};
36.862 + * and a value greater than {@code 0} if this
36.863 + * {@code Float} is numerically greater than
36.864 + * {@code anotherFloat}.
36.865 + *
36.866 + * @since 1.2
36.867 + * @see Comparable#compareTo(Object)
36.868 + */
36.869 + public int compareTo(Float anotherFloat) {
36.870 + return Float.compare(value, anotherFloat.value);
36.871 + }
36.872 +
36.873 + /**
36.874 + * Compares the two specified {@code float} values. The sign
36.875 + * of the integer value returned is the same as that of the
36.876 + * integer that would be returned by the call:
36.877 + * <pre>
36.878 + * new Float(f1).compareTo(new Float(f2))
36.879 + * </pre>
36.880 + *
36.881 + * @param f1 the first {@code float} to compare.
36.882 + * @param f2 the second {@code float} to compare.
36.883 + * @return the value {@code 0} if {@code f1} is
36.884 + * numerically equal to {@code f2}; a value less than
36.885 + * {@code 0} if {@code f1} is numerically less than
36.886 + * {@code f2}; and a value greater than {@code 0}
36.887 + * if {@code f1} is numerically greater than
36.888 + * {@code f2}.
36.889 + * @since 1.4
36.890 + */
36.891 + public static int compare(float f1, float f2) {
36.892 + if (f1 < f2)
36.893 + return -1; // Neither val is NaN, thisVal is smaller
36.894 + if (f1 > f2)
36.895 + return 1; // Neither val is NaN, thisVal is larger
36.896 +
36.897 + // Cannot use floatToRawIntBits because of possibility of NaNs.
36.898 + int thisBits = Float.floatToIntBits(f1);
36.899 + int anotherBits = Float.floatToIntBits(f2);
36.900 +
36.901 + return (thisBits == anotherBits ? 0 : // Values are equal
36.902 + (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
36.903 + 1)); // (0.0, -0.0) or (NaN, !NaN)
36.904 + }
36.905 +
36.906 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
36.907 + private static final long serialVersionUID = -2671257302660747028L;
36.908 +}
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
37.2 +++ b/emul/mini/src/main/java/java/lang/IllegalAccessException.java Wed Jan 23 20:39:23 2013 +0100
37.3 @@ -0,0 +1,78 @@
37.4 +/*
37.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37.7 + *
37.8 + * This code is free software; you can redistribute it and/or modify it
37.9 + * under the terms of the GNU General Public License version 2 only, as
37.10 + * published by the Free Software Foundation. Oracle designates this
37.11 + * particular file as subject to the "Classpath" exception as provided
37.12 + * by Oracle in the LICENSE file that accompanied this code.
37.13 + *
37.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
37.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37.17 + * version 2 for more details (a copy is included in the LICENSE file that
37.18 + * accompanied this code).
37.19 + *
37.20 + * You should have received a copy of the GNU General Public License version
37.21 + * 2 along with this work; if not, write to the Free Software Foundation,
37.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37.23 + *
37.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
37.25 + * or visit www.oracle.com if you need additional information or have any
37.26 + * questions.
37.27 + */
37.28 +
37.29 +package java.lang;
37.30 +
37.31 +/**
37.32 + * An IllegalAccessException is thrown when an application tries
37.33 + * to reflectively create an instance (other than an array),
37.34 + * set or get a field, or invoke a method, but the currently
37.35 + * executing method does not have access to the definition of
37.36 + * the specified class, field, method or constructor.
37.37 + *
37.38 + * @author unascribed
37.39 + * @see Class#newInstance()
37.40 + * @see java.lang.reflect.Field#set(Object, Object)
37.41 + * @see java.lang.reflect.Field#setBoolean(Object, boolean)
37.42 + * @see java.lang.reflect.Field#setByte(Object, byte)
37.43 + * @see java.lang.reflect.Field#setShort(Object, short)
37.44 + * @see java.lang.reflect.Field#setChar(Object, char)
37.45 + * @see java.lang.reflect.Field#setInt(Object, int)
37.46 + * @see java.lang.reflect.Field#setLong(Object, long)
37.47 + * @see java.lang.reflect.Field#setFloat(Object, float)
37.48 + * @see java.lang.reflect.Field#setDouble(Object, double)
37.49 + * @see java.lang.reflect.Field#get(Object)
37.50 + * @see java.lang.reflect.Field#getBoolean(Object)
37.51 + * @see java.lang.reflect.Field#getByte(Object)
37.52 + * @see java.lang.reflect.Field#getShort(Object)
37.53 + * @see java.lang.reflect.Field#getChar(Object)
37.54 + * @see java.lang.reflect.Field#getInt(Object)
37.55 + * @see java.lang.reflect.Field#getLong(Object)
37.56 + * @see java.lang.reflect.Field#getFloat(Object)
37.57 + * @see java.lang.reflect.Field#getDouble(Object)
37.58 + * @see java.lang.reflect.Method#invoke(Object, Object[])
37.59 + * @see java.lang.reflect.Constructor#newInstance(Object[])
37.60 + * @since JDK1.0
37.61 + */
37.62 +public class IllegalAccessException extends ReflectiveOperationException {
37.63 + private static final long serialVersionUID = 6616958222490762034L;
37.64 +
37.65 + /**
37.66 + * Constructs an <code>IllegalAccessException</code> without a
37.67 + * detail message.
37.68 + */
37.69 + public IllegalAccessException() {
37.70 + super();
37.71 + }
37.72 +
37.73 + /**
37.74 + * Constructs an <code>IllegalAccessException</code> with a detail message.
37.75 + *
37.76 + * @param s the detail message.
37.77 + */
37.78 + public IllegalAccessException(String s) {
37.79 + super(s);
37.80 + }
37.81 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
38.2 +++ b/emul/mini/src/main/java/java/lang/IllegalArgumentException.java Wed Jan 23 20:39:23 2013 +0100
38.3 @@ -0,0 +1,95 @@
38.4 +/*
38.5 + * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
38.7 + *
38.8 + * This code is free software; you can redistribute it and/or modify it
38.9 + * under the terms of the GNU General Public License version 2 only, as
38.10 + * published by the Free Software Foundation. Oracle designates this
38.11 + * particular file as subject to the "Classpath" exception as provided
38.12 + * by Oracle in the LICENSE file that accompanied this code.
38.13 + *
38.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
38.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
38.17 + * version 2 for more details (a copy is included in the LICENSE file that
38.18 + * accompanied this code).
38.19 + *
38.20 + * You should have received a copy of the GNU General Public License version
38.21 + * 2 along with this work; if not, write to the Free Software Foundation,
38.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
38.23 + *
38.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
38.25 + * or visit www.oracle.com if you need additional information or have any
38.26 + * questions.
38.27 + */
38.28 +
38.29 +package java.lang;
38.30 +
38.31 +/**
38.32 + * Thrown to indicate that a method has been passed an illegal or
38.33 + * inappropriate argument.
38.34 + *
38.35 + * @author unascribed
38.36 + * @see java.lang.Thread#setPriority(int)
38.37 + * @since JDK1.0
38.38 + */
38.39 +public
38.40 +class IllegalArgumentException extends RuntimeException {
38.41 + /**
38.42 + * Constructs an <code>IllegalArgumentException</code> with no
38.43 + * detail message.
38.44 + */
38.45 + public IllegalArgumentException() {
38.46 + super();
38.47 + }
38.48 +
38.49 + /**
38.50 + * Constructs an <code>IllegalArgumentException</code> with the
38.51 + * specified detail message.
38.52 + *
38.53 + * @param s the detail message.
38.54 + */
38.55 + public IllegalArgumentException(String s) {
38.56 + super(s);
38.57 + }
38.58 +
38.59 + /**
38.60 + * Constructs a new exception with the specified detail message and
38.61 + * cause.
38.62 + *
38.63 + * <p>Note that the detail message associated with <code>cause</code> is
38.64 + * <i>not</i> automatically incorporated in this exception's detail
38.65 + * message.
38.66 + *
38.67 + * @param message the detail message (which is saved for later retrieval
38.68 + * by the {@link Throwable#getMessage()} method).
38.69 + * @param cause the cause (which is saved for later retrieval by the
38.70 + * {@link Throwable#getCause()} method). (A <tt>null</tt> value
38.71 + * is permitted, and indicates that the cause is nonexistent or
38.72 + * unknown.)
38.73 + * @since 1.5
38.74 + */
38.75 + public IllegalArgumentException(String message, Throwable cause) {
38.76 + super(message, cause);
38.77 + }
38.78 +
38.79 + /**
38.80 + * Constructs a new exception with the specified cause and a detail
38.81 + * message of <tt>(cause==null ? null : cause.toString())</tt> (which
38.82 + * typically contains the class and detail message of <tt>cause</tt>).
38.83 + * This constructor is useful for exceptions that are little more than
38.84 + * wrappers for other throwables (for example, {@link
38.85 + * java.security.PrivilegedActionException}).
38.86 + *
38.87 + * @param cause the cause (which is saved for later retrieval by the
38.88 + * {@link Throwable#getCause()} method). (A <tt>null</tt> value is
38.89 + * permitted, and indicates that the cause is nonexistent or
38.90 + * unknown.)
38.91 + * @since 1.5
38.92 + */
38.93 + public IllegalArgumentException(Throwable cause) {
38.94 + super(cause);
38.95 + }
38.96 +
38.97 + private static final long serialVersionUID = -5365630128856068164L;
38.98 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
39.2 +++ b/emul/mini/src/main/java/java/lang/IllegalStateException.java Wed Jan 23 20:39:23 2013 +0100
39.3 @@ -0,0 +1,97 @@
39.4 +/*
39.5 + * Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved.
39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39.7 + *
39.8 + * This code is free software; you can redistribute it and/or modify it
39.9 + * under the terms of the GNU General Public License version 2 only, as
39.10 + * published by the Free Software Foundation. Oracle designates this
39.11 + * particular file as subject to the "Classpath" exception as provided
39.12 + * by Oracle in the LICENSE file that accompanied this code.
39.13 + *
39.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
39.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
39.17 + * version 2 for more details (a copy is included in the LICENSE file that
39.18 + * accompanied this code).
39.19 + *
39.20 + * You should have received a copy of the GNU General Public License version
39.21 + * 2 along with this work; if not, write to the Free Software Foundation,
39.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39.23 + *
39.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
39.25 + * or visit www.oracle.com if you need additional information or have any
39.26 + * questions.
39.27 + */
39.28 +
39.29 +package java.lang;
39.30 +
39.31 +/**
39.32 + * Signals that a method has been invoked at an illegal or
39.33 + * inappropriate time. In other words, the Java environment or
39.34 + * Java application is not in an appropriate state for the requested
39.35 + * operation.
39.36 + *
39.37 + * @author Jonni Kanerva
39.38 + * @since JDK1.1
39.39 + */
39.40 +public
39.41 +class IllegalStateException extends RuntimeException {
39.42 + /**
39.43 + * Constructs an IllegalStateException with no detail message.
39.44 + * A detail message is a String that describes this particular exception.
39.45 + */
39.46 + public IllegalStateException() {
39.47 + super();
39.48 + }
39.49 +
39.50 + /**
39.51 + * Constructs an IllegalStateException with the specified detail
39.52 + * message. A detail message is a String that describes this particular
39.53 + * exception.
39.54 + *
39.55 + * @param s the String that contains a detailed message
39.56 + */
39.57 + public IllegalStateException(String s) {
39.58 + super(s);
39.59 + }
39.60 +
39.61 + /**
39.62 + * Constructs a new exception with the specified detail message and
39.63 + * cause.
39.64 + *
39.65 + * <p>Note that the detail message associated with <code>cause</code> is
39.66 + * <i>not</i> automatically incorporated in this exception's detail
39.67 + * message.
39.68 + *
39.69 + * @param message the detail message (which is saved for later retrieval
39.70 + * by the {@link Throwable#getMessage()} method).
39.71 + * @param cause the cause (which is saved for later retrieval by the
39.72 + * {@link Throwable#getCause()} method). (A <tt>null</tt> value
39.73 + * is permitted, and indicates that the cause is nonexistent or
39.74 + * unknown.)
39.75 + * @since 1.5
39.76 + */
39.77 + public IllegalStateException(String message, Throwable cause) {
39.78 + super(message, cause);
39.79 + }
39.80 +
39.81 + /**
39.82 + * Constructs a new exception with the specified cause and a detail
39.83 + * message of <tt>(cause==null ? null : cause.toString())</tt> (which
39.84 + * typically contains the class and detail message of <tt>cause</tt>).
39.85 + * This constructor is useful for exceptions that are little more than
39.86 + * wrappers for other throwables (for example, {@link
39.87 + * java.security.PrivilegedActionException}).
39.88 + *
39.89 + * @param cause the cause (which is saved for later retrieval by the
39.90 + * {@link Throwable#getCause()} method). (A <tt>null</tt> value is
39.91 + * permitted, and indicates that the cause is nonexistent or
39.92 + * unknown.)
39.93 + * @since 1.5
39.94 + */
39.95 + public IllegalStateException(Throwable cause) {
39.96 + super(cause);
39.97 + }
39.98 +
39.99 + static final long serialVersionUID = -1848914673093119416L;
39.100 +}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
40.2 +++ b/emul/mini/src/main/java/java/lang/IndexOutOfBoundsException.java Wed Jan 23 20:39:23 2013 +0100
40.3 @@ -0,0 +1,58 @@
40.4 +/*
40.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
40.7 + *
40.8 + * This code is free software; you can redistribute it and/or modify it
40.9 + * under the terms of the GNU General Public License version 2 only, as
40.10 + * published by the Free Software Foundation. Oracle designates this
40.11 + * particular file as subject to the "Classpath" exception as provided
40.12 + * by Oracle in the LICENSE file that accompanied this code.
40.13 + *
40.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
40.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
40.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
40.17 + * version 2 for more details (a copy is included in the LICENSE file that
40.18 + * accompanied this code).
40.19 + *
40.20 + * You should have received a copy of the GNU General Public License version
40.21 + * 2 along with this work; if not, write to the Free Software Foundation,
40.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
40.23 + *
40.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
40.25 + * or visit www.oracle.com if you need additional information or have any
40.26 + * questions.
40.27 + */
40.28 +
40.29 +package java.lang;
40.30 +
40.31 +/**
40.32 + * Thrown to indicate that an index of some sort (such as to an array, to a
40.33 + * string, or to a vector) is out of range.
40.34 + * <p>
40.35 + * Applications can subclass this class to indicate similar exceptions.
40.36 + *
40.37 + * @author Frank Yellin
40.38 + * @since JDK1.0
40.39 + */
40.40 +public
40.41 +class IndexOutOfBoundsException extends RuntimeException {
40.42 + private static final long serialVersionUID = 234122996006267687L;
40.43 +
40.44 + /**
40.45 + * Constructs an <code>IndexOutOfBoundsException</code> with no
40.46 + * detail message.
40.47 + */
40.48 + public IndexOutOfBoundsException() {
40.49 + super();
40.50 + }
40.51 +
40.52 + /**
40.53 + * Constructs an <code>IndexOutOfBoundsException</code> with the
40.54 + * specified detail message.
40.55 + *
40.56 + * @param s the detail message.
40.57 + */
40.58 + public IndexOutOfBoundsException(String s) {
40.59 + super(s);
40.60 + }
40.61 +}
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
41.2 +++ b/emul/mini/src/main/java/java/lang/InstantiationException.java Wed Jan 23 20:39:23 2013 +0100
41.3 @@ -0,0 +1,65 @@
41.4 +/*
41.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
41.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41.7 + *
41.8 + * This code is free software; you can redistribute it and/or modify it
41.9 + * under the terms of the GNU General Public License version 2 only, as
41.10 + * published by the Free Software Foundation. Oracle designates this
41.11 + * particular file as subject to the "Classpath" exception as provided
41.12 + * by Oracle in the LICENSE file that accompanied this code.
41.13 + *
41.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
41.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
41.17 + * version 2 for more details (a copy is included in the LICENSE file that
41.18 + * accompanied this code).
41.19 + *
41.20 + * You should have received a copy of the GNU General Public License version
41.21 + * 2 along with this work; if not, write to the Free Software Foundation,
41.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
41.23 + *
41.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
41.25 + * or visit www.oracle.com if you need additional information or have any
41.26 + * questions.
41.27 + */
41.28 +
41.29 +package java.lang;
41.30 +
41.31 +/**
41.32 + * Thrown when an application tries to create an instance of a class
41.33 + * using the {@code newInstance} method in class
41.34 + * {@code Class}, but the specified class object cannot be
41.35 + * instantiated. The instantiation can fail for a variety of
41.36 + * reasons including but not limited to:
41.37 + *
41.38 + * <ul>
41.39 + * <li> the class object represents an abstract class, an interface,
41.40 + * an array class, a primitive type, or {@code void}
41.41 + * <li> the class has no nullary constructor
41.42 + *</ul>
41.43 + *
41.44 + * @author unascribed
41.45 + * @see java.lang.Class#newInstance()
41.46 + * @since JDK1.0
41.47 + */
41.48 +public
41.49 +class InstantiationException extends ReflectiveOperationException {
41.50 + private static final long serialVersionUID = -8441929162975509110L;
41.51 +
41.52 + /**
41.53 + * Constructs an {@code InstantiationException} with no detail message.
41.54 + */
41.55 + public InstantiationException() {
41.56 + super();
41.57 + }
41.58 +
41.59 + /**
41.60 + * Constructs an {@code InstantiationException} with the
41.61 + * specified detail message.
41.62 + *
41.63 + * @param s the detail message.
41.64 + */
41.65 + public InstantiationException(String s) {
41.66 + super(s);
41.67 + }
41.68 +}
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
42.2 +++ b/emul/mini/src/main/java/java/lang/Integer.java Wed Jan 23 20:39:23 2013 +0100
42.3 @@ -0,0 +1,1246 @@
42.4 +/*
42.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
42.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42.7 + *
42.8 + * This code is free software; you can redistribute it and/or modify it
42.9 + * under the terms of the GNU General Public License version 2 only, as
42.10 + * published by the Free Software Foundation. Oracle designates this
42.11 + * particular file as subject to the "Classpath" exception as provided
42.12 + * by Oracle in the LICENSE file that accompanied this code.
42.13 + *
42.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
42.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
42.17 + * version 2 for more details (a copy is included in the LICENSE file that
42.18 + * accompanied this code).
42.19 + *
42.20 + * You should have received a copy of the GNU General Public License version
42.21 + * 2 along with this work; if not, write to the Free Software Foundation,
42.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
42.23 + *
42.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
42.25 + * or visit www.oracle.com if you need additional information or have any
42.26 + * questions.
42.27 + */
42.28 +
42.29 +package java.lang;
42.30 +
42.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
42.32 +
42.33 +/**
42.34 + * The {@code Integer} class wraps a value of the primitive type
42.35 + * {@code int} in an object. An object of type {@code Integer}
42.36 + * contains a single field whose type is {@code int}.
42.37 + *
42.38 + * <p>In addition, this class provides several methods for converting
42.39 + * an {@code int} to a {@code String} and a {@code String} to an
42.40 + * {@code int}, as well as other constants and methods useful when
42.41 + * dealing with an {@code int}.
42.42 + *
42.43 + * <p>Implementation note: The implementations of the "bit twiddling"
42.44 + * methods (such as {@link #highestOneBit(int) highestOneBit} and
42.45 + * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
42.46 + * based on material from Henry S. Warren, Jr.'s <i>Hacker's
42.47 + * Delight</i>, (Addison Wesley, 2002).
42.48 + *
42.49 + * @author Lee Boynton
42.50 + * @author Arthur van Hoff
42.51 + * @author Josh Bloch
42.52 + * @author Joseph D. Darcy
42.53 + * @since JDK1.0
42.54 + */
42.55 +public final class Integer extends Number implements Comparable<Integer> {
42.56 + /**
42.57 + * A constant holding the minimum value an {@code int} can
42.58 + * have, -2<sup>31</sup>.
42.59 + */
42.60 + public static final int MIN_VALUE = 0x80000000;
42.61 +
42.62 + /**
42.63 + * A constant holding the maximum value an {@code int} can
42.64 + * have, 2<sup>31</sup>-1.
42.65 + */
42.66 + public static final int MAX_VALUE = 0x7fffffff;
42.67 +
42.68 + /**
42.69 + * The {@code Class} instance representing the primitive type
42.70 + * {@code int}.
42.71 + *
42.72 + * @since JDK1.1
42.73 + */
42.74 + public static final Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
42.75 +
42.76 + /**
42.77 + * All possible chars for representing a number as a String
42.78 + */
42.79 + final static char[] digits = {
42.80 + '0' , '1' , '2' , '3' , '4' , '5' ,
42.81 + '6' , '7' , '8' , '9' , 'a' , 'b' ,
42.82 + 'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
42.83 + 'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
42.84 + 'o' , 'p' , 'q' , 'r' , 's' , 't' ,
42.85 + 'u' , 'v' , 'w' , 'x' , 'y' , 'z'
42.86 + };
42.87 +
42.88 + /**
42.89 + * Returns a string representation of the first argument in the
42.90 + * radix specified by the second argument.
42.91 + *
42.92 + * <p>If the radix is smaller than {@code Character.MIN_RADIX}
42.93 + * or larger than {@code Character.MAX_RADIX}, then the radix
42.94 + * {@code 10} is used instead.
42.95 + *
42.96 + * <p>If the first argument is negative, the first element of the
42.97 + * result is the ASCII minus character {@code '-'}
42.98 + * (<code>'\u002D'</code>). If the first argument is not
42.99 + * negative, no sign character appears in the result.
42.100 + *
42.101 + * <p>The remaining characters of the result represent the magnitude
42.102 + * of the first argument. If the magnitude is zero, it is
42.103 + * represented by a single zero character {@code '0'}
42.104 + * (<code>'\u0030'</code>); otherwise, the first character of
42.105 + * the representation of the magnitude will not be the zero
42.106 + * character. The following ASCII characters are used as digits:
42.107 + *
42.108 + * <blockquote>
42.109 + * {@code 0123456789abcdefghijklmnopqrstuvwxyz}
42.110 + * </blockquote>
42.111 + *
42.112 + * These are <code>'\u0030'</code> through
42.113 + * <code>'\u0039'</code> and <code>'\u0061'</code> through
42.114 + * <code>'\u007A'</code>. If {@code radix} is
42.115 + * <var>N</var>, then the first <var>N</var> of these characters
42.116 + * are used as radix-<var>N</var> digits in the order shown. Thus,
42.117 + * the digits for hexadecimal (radix 16) are
42.118 + * {@code 0123456789abcdef}. If uppercase letters are
42.119 + * desired, the {@link java.lang.String#toUpperCase()} method may
42.120 + * be called on the result:
42.121 + *
42.122 + * <blockquote>
42.123 + * {@code Integer.toString(n, 16).toUpperCase()}
42.124 + * </blockquote>
42.125 + *
42.126 + * @param i an integer to be converted to a string.
42.127 + * @param radix the radix to use in the string representation.
42.128 + * @return a string representation of the argument in the specified radix.
42.129 + * @see java.lang.Character#MAX_RADIX
42.130 + * @see java.lang.Character#MIN_RADIX
42.131 + */
42.132 + public static String toString(int i, int radix) {
42.133 +
42.134 + if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
42.135 + radix = 10;
42.136 +
42.137 + /* Use the faster version */
42.138 + if (radix == 10) {
42.139 + return toString(i);
42.140 + }
42.141 +
42.142 + char buf[] = new char[33];
42.143 + boolean negative = (i < 0);
42.144 + int charPos = 32;
42.145 +
42.146 + if (!negative) {
42.147 + i = -i;
42.148 + }
42.149 +
42.150 + while (i <= -radix) {
42.151 + buf[charPos--] = digits[-(i % radix)];
42.152 + i = i / radix;
42.153 + }
42.154 + buf[charPos] = digits[-i];
42.155 +
42.156 + if (negative) {
42.157 + buf[--charPos] = '-';
42.158 + }
42.159 +
42.160 + return new String(buf, charPos, (33 - charPos));
42.161 + }
42.162 +
42.163 + /**
42.164 + * Returns a string representation of the integer argument as an
42.165 + * unsigned integer in base 16.
42.166 + *
42.167 + * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
42.168 + * if the argument is negative; otherwise, it is equal to the
42.169 + * argument. This value is converted to a string of ASCII digits
42.170 + * in hexadecimal (base 16) with no extra leading
42.171 + * {@code 0}s. If the unsigned magnitude is zero, it is
42.172 + * represented by a single zero character {@code '0'}
42.173 + * (<code>'\u0030'</code>); otherwise, the first character of
42.174 + * the representation of the unsigned magnitude will not be the
42.175 + * zero character. The following characters are used as
42.176 + * hexadecimal digits:
42.177 + *
42.178 + * <blockquote>
42.179 + * {@code 0123456789abcdef}
42.180 + * </blockquote>
42.181 + *
42.182 + * These are the characters <code>'\u0030'</code> through
42.183 + * <code>'\u0039'</code> and <code>'\u0061'</code> through
42.184 + * <code>'\u0066'</code>. If uppercase letters are
42.185 + * desired, the {@link java.lang.String#toUpperCase()} method may
42.186 + * be called on the result:
42.187 + *
42.188 + * <blockquote>
42.189 + * {@code Integer.toHexString(n).toUpperCase()}
42.190 + * </blockquote>
42.191 + *
42.192 + * @param i an integer to be converted to a string.
42.193 + * @return the string representation of the unsigned integer value
42.194 + * represented by the argument in hexadecimal (base 16).
42.195 + * @since JDK1.0.2
42.196 + */
42.197 + public static String toHexString(int i) {
42.198 + return toUnsignedString(i, 4);
42.199 + }
42.200 +
42.201 + /**
42.202 + * Returns a string representation of the integer argument as an
42.203 + * unsigned integer in base 8.
42.204 + *
42.205 + * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
42.206 + * if the argument is negative; otherwise, it is equal to the
42.207 + * argument. This value is converted to a string of ASCII digits
42.208 + * in octal (base 8) with no extra leading {@code 0}s.
42.209 + *
42.210 + * <p>If the unsigned magnitude is zero, it is represented by a
42.211 + * single zero character {@code '0'}
42.212 + * (<code>'\u0030'</code>); otherwise, the first character of
42.213 + * the representation of the unsigned magnitude will not be the
42.214 + * zero character. The following characters are used as octal
42.215 + * digits:
42.216 + *
42.217 + * <blockquote>
42.218 + * {@code 01234567}
42.219 + * </blockquote>
42.220 + *
42.221 + * These are the characters <code>'\u0030'</code> through
42.222 + * <code>'\u0037'</code>.
42.223 + *
42.224 + * @param i an integer to be converted to a string.
42.225 + * @return the string representation of the unsigned integer value
42.226 + * represented by the argument in octal (base 8).
42.227 + * @since JDK1.0.2
42.228 + */
42.229 + public static String toOctalString(int i) {
42.230 + return toUnsignedString(i, 3);
42.231 + }
42.232 +
42.233 + /**
42.234 + * Returns a string representation of the integer argument as an
42.235 + * unsigned integer in base 2.
42.236 + *
42.237 + * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
42.238 + * if the argument is negative; otherwise it is equal to the
42.239 + * argument. This value is converted to a string of ASCII digits
42.240 + * in binary (base 2) with no extra leading {@code 0}s.
42.241 + * If the unsigned magnitude is zero, it is represented by a
42.242 + * single zero character {@code '0'}
42.243 + * (<code>'\u0030'</code>); otherwise, the first character of
42.244 + * the representation of the unsigned magnitude will not be the
42.245 + * zero character. The characters {@code '0'}
42.246 + * (<code>'\u0030'</code>) and {@code '1'}
42.247 + * (<code>'\u0031'</code>) are used as binary digits.
42.248 + *
42.249 + * @param i an integer to be converted to a string.
42.250 + * @return the string representation of the unsigned integer value
42.251 + * represented by the argument in binary (base 2).
42.252 + * @since JDK1.0.2
42.253 + */
42.254 + public static String toBinaryString(int i) {
42.255 + return toUnsignedString(i, 1);
42.256 + }
42.257 +
42.258 + /**
42.259 + * Convert the integer to an unsigned number.
42.260 + */
42.261 + private static String toUnsignedString(int i, int shift) {
42.262 + char[] buf = new char[32];
42.263 + int charPos = 32;
42.264 + int radix = 1 << shift;
42.265 + int mask = radix - 1;
42.266 + do {
42.267 + buf[--charPos] = digits[i & mask];
42.268 + i >>>= shift;
42.269 + } while (i != 0);
42.270 +
42.271 + return new String(buf, charPos, (32 - charPos));
42.272 + }
42.273 +
42.274 +
42.275 + final static char [] DigitTens = {
42.276 + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
42.277 + '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
42.278 + '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
42.279 + '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
42.280 + '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
42.281 + '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
42.282 + '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
42.283 + '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
42.284 + '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
42.285 + '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
42.286 + } ;
42.287 +
42.288 + final static char [] DigitOnes = {
42.289 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42.290 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42.291 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42.292 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42.293 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42.294 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42.295 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42.296 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42.297 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42.298 + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42.299 + } ;
42.300 +
42.301 + // I use the "invariant division by multiplication" trick to
42.302 + // accelerate Integer.toString. In particular we want to
42.303 + // avoid division by 10.
42.304 + //
42.305 + // The "trick" has roughly the same performance characteristics
42.306 + // as the "classic" Integer.toString code on a non-JIT VM.
42.307 + // The trick avoids .rem and .div calls but has a longer code
42.308 + // path and is thus dominated by dispatch overhead. In the
42.309 + // JIT case the dispatch overhead doesn't exist and the
42.310 + // "trick" is considerably faster than the classic code.
42.311 + //
42.312 + // TODO-FIXME: convert (x * 52429) into the equiv shift-add
42.313 + // sequence.
42.314 + //
42.315 + // RE: Division by Invariant Integers using Multiplication
42.316 + // T Gralund, P Montgomery
42.317 + // ACM PLDI 1994
42.318 + //
42.319 +
42.320 + /**
42.321 + * Returns a {@code String} object representing the
42.322 + * specified integer. The argument is converted to signed decimal
42.323 + * representation and returned as a string, exactly as if the
42.324 + * argument and radix 10 were given as arguments to the {@link
42.325 + * #toString(int, int)} method.
42.326 + *
42.327 + * @param i an integer to be converted.
42.328 + * @return a string representation of the argument in base 10.
42.329 + */
42.330 + @JavaScriptBody(args = "i", body = "return i.toString();")
42.331 + public static String toString(int i) {
42.332 + if (i == Integer.MIN_VALUE)
42.333 + return "-2147483648";
42.334 + int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
42.335 + char[] buf = new char[size];
42.336 + getChars(i, size, buf);
42.337 + return new String(buf, 0, size);
42.338 + }
42.339 +
42.340 + /**
42.341 + * Places characters representing the integer i into the
42.342 + * character array buf. The characters are placed into
42.343 + * the buffer backwards starting with the least significant
42.344 + * digit at the specified index (exclusive), and working
42.345 + * backwards from there.
42.346 + *
42.347 + * Will fail if i == Integer.MIN_VALUE
42.348 + */
42.349 + static void getChars(int i, int index, char[] buf) {
42.350 + int q, r;
42.351 + int charPos = index;
42.352 + char sign = 0;
42.353 +
42.354 + if (i < 0) {
42.355 + sign = '-';
42.356 + i = -i;
42.357 + }
42.358 +
42.359 + // Generate two digits per iteration
42.360 + while (i >= 65536) {
42.361 + q = i / 100;
42.362 + // really: r = i - (q * 100);
42.363 + r = i - ((q << 6) + (q << 5) + (q << 2));
42.364 + i = q;
42.365 + buf [--charPos] = DigitOnes[r];
42.366 + buf [--charPos] = DigitTens[r];
42.367 + }
42.368 +
42.369 + // Fall thru to fast mode for smaller numbers
42.370 + // assert(i <= 65536, i);
42.371 + for (;;) {
42.372 + q = (i * 52429) >>> (16+3);
42.373 + r = i - ((q << 3) + (q << 1)); // r = i-(q*10) ...
42.374 + buf [--charPos] = digits [r];
42.375 + i = q;
42.376 + if (i == 0) break;
42.377 + }
42.378 + if (sign != 0) {
42.379 + buf [--charPos] = sign;
42.380 + }
42.381 + }
42.382 +
42.383 + final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
42.384 + 99999999, 999999999, Integer.MAX_VALUE };
42.385 +
42.386 + // Requires positive x
42.387 + static int stringSize(int x) {
42.388 + for (int i=0; ; i++)
42.389 + if (x <= sizeTable[i])
42.390 + return i+1;
42.391 + }
42.392 +
42.393 + /**
42.394 + * Parses the string argument as a signed integer in the radix
42.395 + * specified by the second argument. The characters in the string
42.396 + * must all be digits of the specified radix (as determined by
42.397 + * whether {@link java.lang.Character#digit(char, int)} returns a
42.398 + * nonnegative value), except that the first character may be an
42.399 + * ASCII minus sign {@code '-'} (<code>'\u002D'</code>) to
42.400 + * indicate a negative value or an ASCII plus sign {@code '+'}
42.401 + * (<code>'\u002B'</code>) to indicate a positive value. The
42.402 + * resulting integer value is returned.
42.403 + *
42.404 + * <p>An exception of type {@code NumberFormatException} is
42.405 + * thrown if any of the following situations occurs:
42.406 + * <ul>
42.407 + * <li>The first argument is {@code null} or is a string of
42.408 + * length zero.
42.409 + *
42.410 + * <li>The radix is either smaller than
42.411 + * {@link java.lang.Character#MIN_RADIX} or
42.412 + * larger than {@link java.lang.Character#MAX_RADIX}.
42.413 + *
42.414 + * <li>Any character of the string is not a digit of the specified
42.415 + * radix, except that the first character may be a minus sign
42.416 + * {@code '-'} (<code>'\u002D'</code>) or plus sign
42.417 + * {@code '+'} (<code>'\u002B'</code>) provided that the
42.418 + * string is longer than length 1.
42.419 + *
42.420 + * <li>The value represented by the string is not a value of type
42.421 + * {@code int}.
42.422 + * </ul>
42.423 + *
42.424 + * <p>Examples:
42.425 + * <blockquote><pre>
42.426 + * parseInt("0", 10) returns 0
42.427 + * parseInt("473", 10) returns 473
42.428 + * parseInt("+42", 10) returns 42
42.429 + * parseInt("-0", 10) returns 0
42.430 + * parseInt("-FF", 16) returns -255
42.431 + * parseInt("1100110", 2) returns 102
42.432 + * parseInt("2147483647", 10) returns 2147483647
42.433 + * parseInt("-2147483648", 10) returns -2147483648
42.434 + * parseInt("2147483648", 10) throws a NumberFormatException
42.435 + * parseInt("99", 8) throws a NumberFormatException
42.436 + * parseInt("Kona", 10) throws a NumberFormatException
42.437 + * parseInt("Kona", 27) returns 411787
42.438 + * </pre></blockquote>
42.439 + *
42.440 + * @param s the {@code String} containing the integer
42.441 + * representation to be parsed
42.442 + * @param radix the radix to be used while parsing {@code s}.
42.443 + * @return the integer represented by the string argument in the
42.444 + * specified radix.
42.445 + * @exception NumberFormatException if the {@code String}
42.446 + * does not contain a parsable {@code int}.
42.447 + */
42.448 + @JavaScriptBody(args={"s", "radix"}, body="return parseInt(s,radix);")
42.449 + public static int parseInt(String s, int radix)
42.450 + throws NumberFormatException
42.451 + {
42.452 + /*
42.453 + * WARNING: This method may be invoked early during VM initialization
42.454 + * before IntegerCache is initialized. Care must be taken to not use
42.455 + * the valueOf method.
42.456 + */
42.457 +
42.458 + if (s == null) {
42.459 + throw new NumberFormatException("null");
42.460 + }
42.461 +
42.462 + if (radix < Character.MIN_RADIX) {
42.463 + throw new NumberFormatException("radix " + radix +
42.464 + " less than Character.MIN_RADIX");
42.465 + }
42.466 +
42.467 + if (radix > Character.MAX_RADIX) {
42.468 + throw new NumberFormatException("radix " + radix +
42.469 + " greater than Character.MAX_RADIX");
42.470 + }
42.471 +
42.472 + int result = 0;
42.473 + boolean negative = false;
42.474 + int i = 0, len = s.length();
42.475 + int limit = -Integer.MAX_VALUE;
42.476 + int multmin;
42.477 + int digit;
42.478 +
42.479 + if (len > 0) {
42.480 + char firstChar = s.charAt(0);
42.481 + if (firstChar < '0') { // Possible leading "+" or "-"
42.482 + if (firstChar == '-') {
42.483 + negative = true;
42.484 + limit = Integer.MIN_VALUE;
42.485 + } else if (firstChar != '+')
42.486 + throw NumberFormatException.forInputString(s);
42.487 +
42.488 + if (len == 1) // Cannot have lone "+" or "-"
42.489 + throw NumberFormatException.forInputString(s);
42.490 + i++;
42.491 + }
42.492 + multmin = limit / radix;
42.493 + while (i < len) {
42.494 + // Accumulating negatively avoids surprises near MAX_VALUE
42.495 + digit = Character.digit(s.charAt(i++),radix);
42.496 + if (digit < 0) {
42.497 + throw NumberFormatException.forInputString(s);
42.498 + }
42.499 + if (result < multmin) {
42.500 + throw NumberFormatException.forInputString(s);
42.501 + }
42.502 + result *= radix;
42.503 + if (result < limit + digit) {
42.504 + throw NumberFormatException.forInputString(s);
42.505 + }
42.506 + result -= digit;
42.507 + }
42.508 + } else {
42.509 + throw NumberFormatException.forInputString(s);
42.510 + }
42.511 + return negative ? result : -result;
42.512 + }
42.513 +
42.514 + /**
42.515 + * Parses the string argument as a signed decimal integer. The
42.516 + * characters in the string must all be decimal digits, except
42.517 + * that the first character may be an ASCII minus sign {@code '-'}
42.518 + * (<code>'\u002D'</code>) to indicate a negative value or an
42.519 + * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
42.520 + * indicate a positive value. The resulting integer value is
42.521 + * returned, exactly as if the argument and the radix 10 were
42.522 + * given as arguments to the {@link #parseInt(java.lang.String,
42.523 + * int)} method.
42.524 + *
42.525 + * @param s a {@code String} containing the {@code int}
42.526 + * representation to be parsed
42.527 + * @return the integer value represented by the argument in decimal.
42.528 + * @exception NumberFormatException if the string does not contain a
42.529 + * parsable integer.
42.530 + */
42.531 + public static int parseInt(String s) throws NumberFormatException {
42.532 + return parseInt(s,10);
42.533 + }
42.534 +
42.535 + /**
42.536 + * Returns an {@code Integer} object holding the value
42.537 + * extracted from the specified {@code String} when parsed
42.538 + * with the radix given by the second argument. The first argument
42.539 + * is interpreted as representing a signed integer in the radix
42.540 + * specified by the second argument, exactly as if the arguments
42.541 + * were given to the {@link #parseInt(java.lang.String, int)}
42.542 + * method. The result is an {@code Integer} object that
42.543 + * represents the integer value specified by the string.
42.544 + *
42.545 + * <p>In other words, this method returns an {@code Integer}
42.546 + * object equal to the value of:
42.547 + *
42.548 + * <blockquote>
42.549 + * {@code new Integer(Integer.parseInt(s, radix))}
42.550 + * </blockquote>
42.551 + *
42.552 + * @param s the string to be parsed.
42.553 + * @param radix the radix to be used in interpreting {@code s}
42.554 + * @return an {@code Integer} object holding the value
42.555 + * represented by the string argument in the specified
42.556 + * radix.
42.557 + * @exception NumberFormatException if the {@code String}
42.558 + * does not contain a parsable {@code int}.
42.559 + */
42.560 + public static Integer valueOf(String s, int radix) throws NumberFormatException {
42.561 + return Integer.valueOf(parseInt(s,radix));
42.562 + }
42.563 +
42.564 + /**
42.565 + * Returns an {@code Integer} object holding the
42.566 + * value of the specified {@code String}. The argument is
42.567 + * interpreted as representing a signed decimal integer, exactly
42.568 + * as if the argument were given to the {@link
42.569 + * #parseInt(java.lang.String)} method. The result is an
42.570 + * {@code Integer} object that represents the integer value
42.571 + * specified by the string.
42.572 + *
42.573 + * <p>In other words, this method returns an {@code Integer}
42.574 + * object equal to the value of:
42.575 + *
42.576 + * <blockquote>
42.577 + * {@code new Integer(Integer.parseInt(s))}
42.578 + * </blockquote>
42.579 + *
42.580 + * @param s the string to be parsed.
42.581 + * @return an {@code Integer} object holding the value
42.582 + * represented by the string argument.
42.583 + * @exception NumberFormatException if the string cannot be parsed
42.584 + * as an integer.
42.585 + */
42.586 + public static Integer valueOf(String s) throws NumberFormatException {
42.587 + return Integer.valueOf(parseInt(s, 10));
42.588 + }
42.589 +
42.590 + /**
42.591 + * Cache to support the object identity semantics of autoboxing for values between
42.592 + * -128 and 127 (inclusive) as required by JLS.
42.593 + *
42.594 + * The cache is initialized on first usage. The size of the cache
42.595 + * may be controlled by the -XX:AutoBoxCacheMax=<size> option.
42.596 + * During VM initialization, java.lang.Integer.IntegerCache.high property
42.597 + * may be set and saved in the private system properties in the
42.598 + * sun.misc.VM class.
42.599 + */
42.600 +
42.601 + private static class IntegerCache {
42.602 + static final int low = -128;
42.603 + static final int high;
42.604 + static final Integer cache[];
42.605 +
42.606 + static {
42.607 + // high value may be configured by property
42.608 + int h = 127;
42.609 + String integerCacheHighPropValue =
42.610 + AbstractStringBuilder.getProperty("java.lang.Integer.IntegerCache.high");
42.611 + if (integerCacheHighPropValue != null) {
42.612 + int i = parseInt(integerCacheHighPropValue);
42.613 + i = Math.max(i, 127);
42.614 + // Maximum array size is Integer.MAX_VALUE
42.615 + h = Math.min(i, Integer.MAX_VALUE - (-low));
42.616 + }
42.617 + high = h;
42.618 +
42.619 + cache = new Integer[(high - low) + 1];
42.620 + int j = low;
42.621 + for(int k = 0; k < cache.length; k++)
42.622 + cache[k] = new Integer(j++);
42.623 + }
42.624 +
42.625 + private IntegerCache() {}
42.626 + }
42.627 +
42.628 + /**
42.629 + * Returns an {@code Integer} instance representing the specified
42.630 + * {@code int} value. If a new {@code Integer} instance is not
42.631 + * required, this method should generally be used in preference to
42.632 + * the constructor {@link #Integer(int)}, as this method is likely
42.633 + * to yield significantly better space and time performance by
42.634 + * caching frequently requested values.
42.635 + *
42.636 + * This method will always cache values in the range -128 to 127,
42.637 + * inclusive, and may cache other values outside of this range.
42.638 + *
42.639 + * @param i an {@code int} value.
42.640 + * @return an {@code Integer} instance representing {@code i}.
42.641 + * @since 1.5
42.642 + */
42.643 + public static Integer valueOf(int i) {
42.644 + //assert IntegerCache.high >= 127;
42.645 + if (i >= IntegerCache.low && i <= IntegerCache.high)
42.646 + return IntegerCache.cache[i + (-IntegerCache.low)];
42.647 + return new Integer(i);
42.648 + }
42.649 +
42.650 + /**
42.651 + * The value of the {@code Integer}.
42.652 + *
42.653 + * @serial
42.654 + */
42.655 + private final int value;
42.656 +
42.657 + /**
42.658 + * Constructs a newly allocated {@code Integer} object that
42.659 + * represents the specified {@code int} value.
42.660 + *
42.661 + * @param value the value to be represented by the
42.662 + * {@code Integer} object.
42.663 + */
42.664 + public Integer(int value) {
42.665 + this.value = value;
42.666 + }
42.667 +
42.668 + /**
42.669 + * Constructs a newly allocated {@code Integer} object that
42.670 + * represents the {@code int} value indicated by the
42.671 + * {@code String} parameter. The string is converted to an
42.672 + * {@code int} value in exactly the manner used by the
42.673 + * {@code parseInt} method for radix 10.
42.674 + *
42.675 + * @param s the {@code String} to be converted to an
42.676 + * {@code Integer}.
42.677 + * @exception NumberFormatException if the {@code String} does not
42.678 + * contain a parsable integer.
42.679 + * @see java.lang.Integer#parseInt(java.lang.String, int)
42.680 + */
42.681 + public Integer(String s) throws NumberFormatException {
42.682 + this.value = parseInt(s, 10);
42.683 + }
42.684 +
42.685 + /**
42.686 + * Returns the value of this {@code Integer} as a
42.687 + * {@code byte}.
42.688 + */
42.689 + public byte byteValue() {
42.690 + return (byte)value;
42.691 + }
42.692 +
42.693 + /**
42.694 + * Returns the value of this {@code Integer} as a
42.695 + * {@code short}.
42.696 + */
42.697 + public short shortValue() {
42.698 + return (short)value;
42.699 + }
42.700 +
42.701 + /**
42.702 + * Returns the value of this {@code Integer} as an
42.703 + * {@code int}.
42.704 + */
42.705 + public int intValue() {
42.706 + return value;
42.707 + }
42.708 +
42.709 + /**
42.710 + * Returns the value of this {@code Integer} as a
42.711 + * {@code long}.
42.712 + */
42.713 + public long longValue() {
42.714 + return (long)value;
42.715 + }
42.716 +
42.717 + /**
42.718 + * Returns the value of this {@code Integer} as a
42.719 + * {@code float}.
42.720 + */
42.721 + public float floatValue() {
42.722 + return (float)value;
42.723 + }
42.724 +
42.725 + /**
42.726 + * Returns the value of this {@code Integer} as a
42.727 + * {@code double}.
42.728 + */
42.729 + public double doubleValue() {
42.730 + return (double)value;
42.731 + }
42.732 +
42.733 + /**
42.734 + * Returns a {@code String} object representing this
42.735 + * {@code Integer}'s value. The value is converted to signed
42.736 + * decimal representation and returned as a string, exactly as if
42.737 + * the integer value were given as an argument to the {@link
42.738 + * java.lang.Integer#toString(int)} method.
42.739 + *
42.740 + * @return a string representation of the value of this object in
42.741 + * base 10.
42.742 + */
42.743 + public String toString() {
42.744 + return toString(value);
42.745 + }
42.746 +
42.747 + /**
42.748 + * Returns a hash code for this {@code Integer}.
42.749 + *
42.750 + * @return a hash code value for this object, equal to the
42.751 + * primitive {@code int} value represented by this
42.752 + * {@code Integer} object.
42.753 + */
42.754 + public int hashCode() {
42.755 + return value;
42.756 + }
42.757 +
42.758 + /**
42.759 + * Compares this object to the specified object. The result is
42.760 + * {@code true} if and only if the argument is not
42.761 + * {@code null} and is an {@code Integer} object that
42.762 + * contains the same {@code int} value as this object.
42.763 + *
42.764 + * @param obj the object to compare with.
42.765 + * @return {@code true} if the objects are the same;
42.766 + * {@code false} otherwise.
42.767 + */
42.768 + public boolean equals(Object obj) {
42.769 + if (obj instanceof Integer) {
42.770 + return value == ((Integer)obj).intValue();
42.771 + }
42.772 + return false;
42.773 + }
42.774 +
42.775 + /**
42.776 + * Determines the integer value of the system property with the
42.777 + * specified name.
42.778 + *
42.779 + * <p>The first argument is treated as the name of a system property.
42.780 + * System properties are accessible through the
42.781 + * {@link java.lang.System#getProperty(java.lang.String)} method. The
42.782 + * string value of this property is then interpreted as an integer
42.783 + * value and an {@code Integer} object representing this value is
42.784 + * returned. Details of possible numeric formats can be found with
42.785 + * the definition of {@code getProperty}.
42.786 + *
42.787 + * <p>If there is no property with the specified name, if the specified name
42.788 + * is empty or {@code null}, or if the property does not have
42.789 + * the correct numeric format, then {@code null} is returned.
42.790 + *
42.791 + * <p>In other words, this method returns an {@code Integer}
42.792 + * object equal to the value of:
42.793 + *
42.794 + * <blockquote>
42.795 + * {@code getInteger(nm, null)}
42.796 + * </blockquote>
42.797 + *
42.798 + * @param nm property name.
42.799 + * @return the {@code Integer} value of the property.
42.800 + * @see java.lang.System#getProperty(java.lang.String)
42.801 + * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
42.802 + */
42.803 + public static Integer getInteger(String nm) {
42.804 + return getInteger(nm, null);
42.805 + }
42.806 +
42.807 + /**
42.808 + * Determines the integer value of the system property with the
42.809 + * specified name.
42.810 + *
42.811 + * <p>The first argument is treated as the name of a system property.
42.812 + * System properties are accessible through the {@link
42.813 + * java.lang.System#getProperty(java.lang.String)} method. The
42.814 + * string value of this property is then interpreted as an integer
42.815 + * value and an {@code Integer} object representing this value is
42.816 + * returned. Details of possible numeric formats can be found with
42.817 + * the definition of {@code getProperty}.
42.818 + *
42.819 + * <p>The second argument is the default value. An {@code Integer} object
42.820 + * that represents the value of the second argument is returned if there
42.821 + * is no property of the specified name, if the property does not have
42.822 + * the correct numeric format, or if the specified name is empty or
42.823 + * {@code null}.
42.824 + *
42.825 + * <p>In other words, this method returns an {@code Integer} object
42.826 + * equal to the value of:
42.827 + *
42.828 + * <blockquote>
42.829 + * {@code getInteger(nm, new Integer(val))}
42.830 + * </blockquote>
42.831 + *
42.832 + * but in practice it may be implemented in a manner such as:
42.833 + *
42.834 + * <blockquote><pre>
42.835 + * Integer result = getInteger(nm, null);
42.836 + * return (result == null) ? new Integer(val) : result;
42.837 + * </pre></blockquote>
42.838 + *
42.839 + * to avoid the unnecessary allocation of an {@code Integer}
42.840 + * object when the default value is not needed.
42.841 + *
42.842 + * @param nm property name.
42.843 + * @param val default value.
42.844 + * @return the {@code Integer} value of the property.
42.845 + * @see java.lang.System#getProperty(java.lang.String)
42.846 + * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
42.847 + */
42.848 + public static Integer getInteger(String nm, int val) {
42.849 + Integer result = getInteger(nm, null);
42.850 + return (result == null) ? Integer.valueOf(val) : result;
42.851 + }
42.852 +
42.853 + /**
42.854 + * Returns the integer value of the system property with the
42.855 + * specified name. The first argument is treated as the name of a
42.856 + * system property. System properties are accessible through the
42.857 + * {@link java.lang.System#getProperty(java.lang.String)} method.
42.858 + * The string value of this property is then interpreted as an
42.859 + * integer value, as per the {@code Integer.decode} method,
42.860 + * and an {@code Integer} object representing this value is
42.861 + * returned.
42.862 + *
42.863 + * <ul><li>If the property value begins with the two ASCII characters
42.864 + * {@code 0x} or the ASCII character {@code #}, not
42.865 + * followed by a minus sign, then the rest of it is parsed as a
42.866 + * hexadecimal integer exactly as by the method
42.867 + * {@link #valueOf(java.lang.String, int)} with radix 16.
42.868 + * <li>If the property value begins with the ASCII character
42.869 + * {@code 0} followed by another character, it is parsed as an
42.870 + * octal integer exactly as by the method
42.871 + * {@link #valueOf(java.lang.String, int)} with radix 8.
42.872 + * <li>Otherwise, the property value is parsed as a decimal integer
42.873 + * exactly as by the method {@link #valueOf(java.lang.String, int)}
42.874 + * with radix 10.
42.875 + * </ul>
42.876 + *
42.877 + * <p>The second argument is the default value. The default value is
42.878 + * returned if there is no property of the specified name, if the
42.879 + * property does not have the correct numeric format, or if the
42.880 + * specified name is empty or {@code null}.
42.881 + *
42.882 + * @param nm property name.
42.883 + * @param val default value.
42.884 + * @return the {@code Integer} value of the property.
42.885 + * @see java.lang.System#getProperty(java.lang.String)
42.886 + * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
42.887 + * @see java.lang.Integer#decode
42.888 + */
42.889 + public static Integer getInteger(String nm, Integer val) {
42.890 + String v = null;
42.891 + try {
42.892 + v = AbstractStringBuilder.getProperty(nm);
42.893 + } catch (IllegalArgumentException e) {
42.894 + } catch (NullPointerException e) {
42.895 + }
42.896 + if (v != null) {
42.897 + try {
42.898 + return Integer.decode(v);
42.899 + } catch (NumberFormatException e) {
42.900 + }
42.901 + }
42.902 + return val;
42.903 + }
42.904 +
42.905 + /**
42.906 + * Decodes a {@code String} into an {@code Integer}.
42.907 + * Accepts decimal, hexadecimal, and octal numbers given
42.908 + * by the following grammar:
42.909 + *
42.910 + * <blockquote>
42.911 + * <dl>
42.912 + * <dt><i>DecodableString:</i>
42.913 + * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
42.914 + * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
42.915 + * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
42.916 + * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
42.917 + * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
42.918 + * <p>
42.919 + * <dt><i>Sign:</i>
42.920 + * <dd>{@code -}
42.921 + * <dd>{@code +}
42.922 + * </dl>
42.923 + * </blockquote>
42.924 + *
42.925 + * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
42.926 + * are as defined in section 3.10.1 of
42.927 + * <cite>The Java™ Language Specification</cite>,
42.928 + * except that underscores are not accepted between digits.
42.929 + *
42.930 + * <p>The sequence of characters following an optional
42.931 + * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
42.932 + * "{@code #}", or leading zero) is parsed as by the {@code
42.933 + * Integer.parseInt} method with the indicated radix (10, 16, or
42.934 + * 8). This sequence of characters must represent a positive
42.935 + * value or a {@link NumberFormatException} will be thrown. The
42.936 + * result is negated if first character of the specified {@code
42.937 + * String} is the minus sign. No whitespace characters are
42.938 + * permitted in the {@code String}.
42.939 + *
42.940 + * @param nm the {@code String} to decode.
42.941 + * @return an {@code Integer} object holding the {@code int}
42.942 + * value represented by {@code nm}
42.943 + * @exception NumberFormatException if the {@code String} does not
42.944 + * contain a parsable integer.
42.945 + * @see java.lang.Integer#parseInt(java.lang.String, int)
42.946 + */
42.947 + public static Integer decode(String nm) throws NumberFormatException {
42.948 + int radix = 10;
42.949 + int index = 0;
42.950 + boolean negative = false;
42.951 + Integer result;
42.952 +
42.953 + if (nm.length() == 0)
42.954 + throw new NumberFormatException("Zero length string");
42.955 + char firstChar = nm.charAt(0);
42.956 + // Handle sign, if present
42.957 + if (firstChar == '-') {
42.958 + negative = true;
42.959 + index++;
42.960 + } else if (firstChar == '+')
42.961 + index++;
42.962 +
42.963 + // Handle radix specifier, if present
42.964 + if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
42.965 + index += 2;
42.966 + radix = 16;
42.967 + }
42.968 + else if (nm.startsWith("#", index)) {
42.969 + index ++;
42.970 + radix = 16;
42.971 + }
42.972 + else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
42.973 + index ++;
42.974 + radix = 8;
42.975 + }
42.976 +
42.977 + if (nm.startsWith("-", index) || nm.startsWith("+", index))
42.978 + throw new NumberFormatException("Sign character in wrong position");
42.979 +
42.980 + try {
42.981 + result = Integer.valueOf(nm.substring(index), radix);
42.982 + result = negative ? Integer.valueOf(-result.intValue()) : result;
42.983 + } catch (NumberFormatException e) {
42.984 + // If number is Integer.MIN_VALUE, we'll end up here. The next line
42.985 + // handles this case, and causes any genuine format error to be
42.986 + // rethrown.
42.987 + String constant = negative ? ("-" + nm.substring(index))
42.988 + : nm.substring(index);
42.989 + result = Integer.valueOf(constant, radix);
42.990 + }
42.991 + return result;
42.992 + }
42.993 +
42.994 + /**
42.995 + * Compares two {@code Integer} objects numerically.
42.996 + *
42.997 + * @param anotherInteger the {@code Integer} to be compared.
42.998 + * @return the value {@code 0} if this {@code Integer} is
42.999 + * equal to the argument {@code Integer}; a value less than
42.1000 + * {@code 0} if this {@code Integer} is numerically less
42.1001 + * than the argument {@code Integer}; and a value greater
42.1002 + * than {@code 0} if this {@code Integer} is numerically
42.1003 + * greater than the argument {@code Integer} (signed
42.1004 + * comparison).
42.1005 + * @since 1.2
42.1006 + */
42.1007 + public int compareTo(Integer anotherInteger) {
42.1008 + return compare(this.value, anotherInteger.value);
42.1009 + }
42.1010 +
42.1011 + /**
42.1012 + * Compares two {@code int} values numerically.
42.1013 + * The value returned is identical to what would be returned by:
42.1014 + * <pre>
42.1015 + * Integer.valueOf(x).compareTo(Integer.valueOf(y))
42.1016 + * </pre>
42.1017 + *
42.1018 + * @param x the first {@code int} to compare
42.1019 + * @param y the second {@code int} to compare
42.1020 + * @return the value {@code 0} if {@code x == y};
42.1021 + * a value less than {@code 0} if {@code x < y}; and
42.1022 + * a value greater than {@code 0} if {@code x > y}
42.1023 + * @since 1.7
42.1024 + */
42.1025 + public static int compare(int x, int y) {
42.1026 + return (x < y) ? -1 : ((x == y) ? 0 : 1);
42.1027 + }
42.1028 +
42.1029 +
42.1030 + // Bit twiddling
42.1031 +
42.1032 + /**
42.1033 + * The number of bits used to represent an {@code int} value in two's
42.1034 + * complement binary form.
42.1035 + *
42.1036 + * @since 1.5
42.1037 + */
42.1038 + public static final int SIZE = 32;
42.1039 +
42.1040 + /**
42.1041 + * Returns an {@code int} value with at most a single one-bit, in the
42.1042 + * position of the highest-order ("leftmost") one-bit in the specified
42.1043 + * {@code int} value. Returns zero if the specified value has no
42.1044 + * one-bits in its two's complement binary representation, that is, if it
42.1045 + * is equal to zero.
42.1046 + *
42.1047 + * @return an {@code int} value with a single one-bit, in the position
42.1048 + * of the highest-order one-bit in the specified value, or zero if
42.1049 + * the specified value is itself equal to zero.
42.1050 + * @since 1.5
42.1051 + */
42.1052 + public static int highestOneBit(int i) {
42.1053 + // HD, Figure 3-1
42.1054 + i |= (i >> 1);
42.1055 + i |= (i >> 2);
42.1056 + i |= (i >> 4);
42.1057 + i |= (i >> 8);
42.1058 + i |= (i >> 16);
42.1059 + return i - (i >>> 1);
42.1060 + }
42.1061 +
42.1062 + /**
42.1063 + * Returns an {@code int} value with at most a single one-bit, in the
42.1064 + * position of the lowest-order ("rightmost") one-bit in the specified
42.1065 + * {@code int} value. Returns zero if the specified value has no
42.1066 + * one-bits in its two's complement binary representation, that is, if it
42.1067 + * is equal to zero.
42.1068 + *
42.1069 + * @return an {@code int} value with a single one-bit, in the position
42.1070 + * of the lowest-order one-bit in the specified value, or zero if
42.1071 + * the specified value is itself equal to zero.
42.1072 + * @since 1.5
42.1073 + */
42.1074 + public static int lowestOneBit(int i) {
42.1075 + // HD, Section 2-1
42.1076 + return i & -i;
42.1077 + }
42.1078 +
42.1079 + /**
42.1080 + * Returns the number of zero bits preceding the highest-order
42.1081 + * ("leftmost") one-bit in the two's complement binary representation
42.1082 + * of the specified {@code int} value. Returns 32 if the
42.1083 + * specified value has no one-bits in its two's complement representation,
42.1084 + * in other words if it is equal to zero.
42.1085 + *
42.1086 + * <p>Note that this method is closely related to the logarithm base 2.
42.1087 + * For all positive {@code int} values x:
42.1088 + * <ul>
42.1089 + * <li>floor(log<sub>2</sub>(x)) = {@code 31 - numberOfLeadingZeros(x)}
42.1090 + * <li>ceil(log<sub>2</sub>(x)) = {@code 32 - numberOfLeadingZeros(x - 1)}
42.1091 + * </ul>
42.1092 + *
42.1093 + * @return the number of zero bits preceding the highest-order
42.1094 + * ("leftmost") one-bit in the two's complement binary representation
42.1095 + * of the specified {@code int} value, or 32 if the value
42.1096 + * is equal to zero.
42.1097 + * @since 1.5
42.1098 + */
42.1099 + public static int numberOfLeadingZeros(int i) {
42.1100 + // HD, Figure 5-6
42.1101 + if (i == 0)
42.1102 + return 32;
42.1103 + int n = 1;
42.1104 + if (i >>> 16 == 0) { n += 16; i <<= 16; }
42.1105 + if (i >>> 24 == 0) { n += 8; i <<= 8; }
42.1106 + if (i >>> 28 == 0) { n += 4; i <<= 4; }
42.1107 + if (i >>> 30 == 0) { n += 2; i <<= 2; }
42.1108 + n -= i >>> 31;
42.1109 + return n;
42.1110 + }
42.1111 +
42.1112 + /**
42.1113 + * Returns the number of zero bits following the lowest-order ("rightmost")
42.1114 + * one-bit in the two's complement binary representation of the specified
42.1115 + * {@code int} value. Returns 32 if the specified value has no
42.1116 + * one-bits in its two's complement representation, in other words if it is
42.1117 + * equal to zero.
42.1118 + *
42.1119 + * @return the number of zero bits following the lowest-order ("rightmost")
42.1120 + * one-bit in the two's complement binary representation of the
42.1121 + * specified {@code int} value, or 32 if the value is equal
42.1122 + * to zero.
42.1123 + * @since 1.5
42.1124 + */
42.1125 + public static int numberOfTrailingZeros(int i) {
42.1126 + // HD, Figure 5-14
42.1127 + int y;
42.1128 + if (i == 0) return 32;
42.1129 + int n = 31;
42.1130 + y = i <<16; if (y != 0) { n = n -16; i = y; }
42.1131 + y = i << 8; if (y != 0) { n = n - 8; i = y; }
42.1132 + y = i << 4; if (y != 0) { n = n - 4; i = y; }
42.1133 + y = i << 2; if (y != 0) { n = n - 2; i = y; }
42.1134 + return n - ((i << 1) >>> 31);
42.1135 + }
42.1136 +
42.1137 + /**
42.1138 + * Returns the number of one-bits in the two's complement binary
42.1139 + * representation of the specified {@code int} value. This function is
42.1140 + * sometimes referred to as the <i>population count</i>.
42.1141 + *
42.1142 + * @return the number of one-bits in the two's complement binary
42.1143 + * representation of the specified {@code int} value.
42.1144 + * @since 1.5
42.1145 + */
42.1146 + public static int bitCount(int i) {
42.1147 + // HD, Figure 5-2
42.1148 + i = i - ((i >>> 1) & 0x55555555);
42.1149 + i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
42.1150 + i = (i + (i >>> 4)) & 0x0f0f0f0f;
42.1151 + i = i + (i >>> 8);
42.1152 + i = i + (i >>> 16);
42.1153 + return i & 0x3f;
42.1154 + }
42.1155 +
42.1156 + /**
42.1157 + * Returns the value obtained by rotating the two's complement binary
42.1158 + * representation of the specified {@code int} value left by the
42.1159 + * specified number of bits. (Bits shifted out of the left hand, or
42.1160 + * high-order, side reenter on the right, or low-order.)
42.1161 + *
42.1162 + * <p>Note that left rotation with a negative distance is equivalent to
42.1163 + * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
42.1164 + * distance)}. Note also that rotation by any multiple of 32 is a
42.1165 + * no-op, so all but the last five bits of the rotation distance can be
42.1166 + * ignored, even if the distance is negative: {@code rotateLeft(val,
42.1167 + * distance) == rotateLeft(val, distance & 0x1F)}.
42.1168 + *
42.1169 + * @return the value obtained by rotating the two's complement binary
42.1170 + * representation of the specified {@code int} value left by the
42.1171 + * specified number of bits.
42.1172 + * @since 1.5
42.1173 + */
42.1174 + public static int rotateLeft(int i, int distance) {
42.1175 + return (i << distance) | (i >>> -distance);
42.1176 + }
42.1177 +
42.1178 + /**
42.1179 + * Returns the value obtained by rotating the two's complement binary
42.1180 + * representation of the specified {@code int} value right by the
42.1181 + * specified number of bits. (Bits shifted out of the right hand, or
42.1182 + * low-order, side reenter on the left, or high-order.)
42.1183 + *
42.1184 + * <p>Note that right rotation with a negative distance is equivalent to
42.1185 + * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
42.1186 + * distance)}. Note also that rotation by any multiple of 32 is a
42.1187 + * no-op, so all but the last five bits of the rotation distance can be
42.1188 + * ignored, even if the distance is negative: {@code rotateRight(val,
42.1189 + * distance) == rotateRight(val, distance & 0x1F)}.
42.1190 + *
42.1191 + * @return the value obtained by rotating the two's complement binary
42.1192 + * representation of the specified {@code int} value right by the
42.1193 + * specified number of bits.
42.1194 + * @since 1.5
42.1195 + */
42.1196 + public static int rotateRight(int i, int distance) {
42.1197 + return (i >>> distance) | (i << -distance);
42.1198 + }
42.1199 +
42.1200 + /**
42.1201 + * Returns the value obtained by reversing the order of the bits in the
42.1202 + * two's complement binary representation of the specified {@code int}
42.1203 + * value.
42.1204 + *
42.1205 + * @return the value obtained by reversing order of the bits in the
42.1206 + * specified {@code int} value.
42.1207 + * @since 1.5
42.1208 + */
42.1209 + public static int reverse(int i) {
42.1210 + // HD, Figure 7-1
42.1211 + i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
42.1212 + i = (i & 0x33333333) << 2 | (i >>> 2) & 0x33333333;
42.1213 + i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;
42.1214 + i = (i << 24) | ((i & 0xff00) << 8) |
42.1215 + ((i >>> 8) & 0xff00) | (i >>> 24);
42.1216 + return i;
42.1217 + }
42.1218 +
42.1219 + /**
42.1220 + * Returns the signum function of the specified {@code int} value. (The
42.1221 + * return value is -1 if the specified value is negative; 0 if the
42.1222 + * specified value is zero; and 1 if the specified value is positive.)
42.1223 + *
42.1224 + * @return the signum function of the specified {@code int} value.
42.1225 + * @since 1.5
42.1226 + */
42.1227 + public static int signum(int i) {
42.1228 + // HD, Section 2-7
42.1229 + return (i >> 31) | (-i >>> 31);
42.1230 + }
42.1231 +
42.1232 + /**
42.1233 + * Returns the value obtained by reversing the order of the bytes in the
42.1234 + * two's complement representation of the specified {@code int} value.
42.1235 + *
42.1236 + * @return the value obtained by reversing the bytes in the specified
42.1237 + * {@code int} value.
42.1238 + * @since 1.5
42.1239 + */
42.1240 + public static int reverseBytes(int i) {
42.1241 + return ((i >>> 24) ) |
42.1242 + ((i >> 8) & 0xFF00) |
42.1243 + ((i << 8) & 0xFF0000) |
42.1244 + ((i << 24));
42.1245 + }
42.1246 +
42.1247 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
42.1248 + private static final long serialVersionUID = 1360826667806852920L;
42.1249 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
43.2 +++ b/emul/mini/src/main/java/java/lang/InterruptedException.java Wed Jan 23 20:39:23 2013 +0100
43.3 @@ -0,0 +1,69 @@
43.4 +/*
43.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
43.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43.7 + *
43.8 + * This code is free software; you can redistribute it and/or modify it
43.9 + * under the terms of the GNU General Public License version 2 only, as
43.10 + * published by the Free Software Foundation. Oracle designates this
43.11 + * particular file as subject to the "Classpath" exception as provided
43.12 + * by Oracle in the LICENSE file that accompanied this code.
43.13 + *
43.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
43.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
43.17 + * version 2 for more details (a copy is included in the LICENSE file that
43.18 + * accompanied this code).
43.19 + *
43.20 + * You should have received a copy of the GNU General Public License version
43.21 + * 2 along with this work; if not, write to the Free Software Foundation,
43.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43.23 + *
43.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
43.25 + * or visit www.oracle.com if you need additional information or have any
43.26 + * questions.
43.27 + */
43.28 +
43.29 +package java.lang;
43.30 +
43.31 +/**
43.32 + * Thrown when a thread is waiting, sleeping, or otherwise occupied,
43.33 + * and the thread is interrupted, either before or during the activity.
43.34 + * Occasionally a method may wish to test whether the current
43.35 + * thread has been interrupted, and if so, to immediately throw
43.36 + * this exception. The following code can be used to achieve
43.37 + * this effect:
43.38 + * <pre>
43.39 + * if (Thread.interrupted()) // Clears interrupted status!
43.40 + * throw new InterruptedException();
43.41 + * </pre>
43.42 + *
43.43 + * @author Frank Yellin
43.44 + * @see java.lang.Object#wait()
43.45 + * @see java.lang.Object#wait(long)
43.46 + * @see java.lang.Object#wait(long, int)
43.47 + * @see java.lang.Thread#sleep(long)
43.48 + * @see java.lang.Thread#interrupt()
43.49 + * @see java.lang.Thread#interrupted()
43.50 + * @since JDK1.0
43.51 + */
43.52 +public
43.53 +class InterruptedException extends Exception {
43.54 + private static final long serialVersionUID = 6700697376100628473L;
43.55 +
43.56 + /**
43.57 + * Constructs an <code>InterruptedException</code> with no detail message.
43.58 + */
43.59 + public InterruptedException() {
43.60 + super();
43.61 + }
43.62 +
43.63 + /**
43.64 + * Constructs an <code>InterruptedException</code> with the
43.65 + * specified detail message.
43.66 + *
43.67 + * @param s the detail message.
43.68 + */
43.69 + public InterruptedException(String s) {
43.70 + super(s);
43.71 + }
43.72 +}
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
44.2 +++ b/emul/mini/src/main/java/java/lang/LinkageError.java Wed Jan 23 20:39:23 2013 +0100
44.3 @@ -0,0 +1,69 @@
44.4 +/*
44.5 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44.7 + *
44.8 + * This code is free software; you can redistribute it and/or modify it
44.9 + * under the terms of the GNU General Public License version 2 only, as
44.10 + * published by the Free Software Foundation. Oracle designates this
44.11 + * particular file as subject to the "Classpath" exception as provided
44.12 + * by Oracle in the LICENSE file that accompanied this code.
44.13 + *
44.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
44.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
44.17 + * version 2 for more details (a copy is included in the LICENSE file that
44.18 + * accompanied this code).
44.19 + *
44.20 + * You should have received a copy of the GNU General Public License version
44.21 + * 2 along with this work; if not, write to the Free Software Foundation,
44.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
44.23 + *
44.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
44.25 + * or visit www.oracle.com if you need additional information or have any
44.26 + * questions.
44.27 + */
44.28 +
44.29 +package java.lang;
44.30 +
44.31 +/**
44.32 + * Subclasses of {@code LinkageError} indicate that a class has
44.33 + * some dependency on another class; however, the latter class has
44.34 + * incompatibly changed after the compilation of the former class.
44.35 + *
44.36 + *
44.37 + * @author Frank Yellin
44.38 + * @since JDK1.0
44.39 + */
44.40 +public
44.41 +class LinkageError extends Error {
44.42 + private static final long serialVersionUID = 3579600108157160122L;
44.43 +
44.44 + /**
44.45 + * Constructs a {@code LinkageError} with no detail message.
44.46 + */
44.47 + public LinkageError() {
44.48 + super();
44.49 + }
44.50 +
44.51 + /**
44.52 + * Constructs a {@code LinkageError} with the specified detail
44.53 + * message.
44.54 + *
44.55 + * @param s the detail message.
44.56 + */
44.57 + public LinkageError(String s) {
44.58 + super(s);
44.59 + }
44.60 +
44.61 + /**
44.62 + * Constructs a {@code LinkageError} with the specified detail
44.63 + * message and cause.
44.64 + *
44.65 + * @param s the detail message.
44.66 + * @param cause the cause, may be {@code null}
44.67 + * @since 1.7
44.68 + */
44.69 + public LinkageError(String s, Throwable cause) {
44.70 + super(s, cause);
44.71 + }
44.72 +}
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
45.2 +++ b/emul/mini/src/main/java/java/lang/Long.java Wed Jan 23 20:39:23 2013 +0100
45.3 @@ -0,0 +1,1202 @@
45.4 +/*
45.5 + * Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
45.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45.7 + *
45.8 + * This code is free software; you can redistribute it and/or modify it
45.9 + * under the terms of the GNU General Public License version 2 only, as
45.10 + * published by the Free Software Foundation. Oracle designates this
45.11 + * particular file as subject to the "Classpath" exception as provided
45.12 + * by Oracle in the LICENSE file that accompanied this code.
45.13 + *
45.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
45.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
45.17 + * version 2 for more details (a copy is included in the LICENSE file that
45.18 + * accompanied this code).
45.19 + *
45.20 + * You should have received a copy of the GNU General Public License version
45.21 + * 2 along with this work; if not, write to the Free Software Foundation,
45.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45.23 + *
45.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
45.25 + * or visit www.oracle.com if you need additional information or have any
45.26 + * questions.
45.27 + */
45.28 +
45.29 +package java.lang;
45.30 +
45.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
45.32 +
45.33 +/**
45.34 + * The {@code Long} class wraps a value of the primitive type {@code
45.35 + * long} in an object. An object of type {@code Long} contains a
45.36 + * single field whose type is {@code long}.
45.37 + *
45.38 + * <p> In addition, this class provides several methods for converting
45.39 + * a {@code long} to a {@code String} and a {@code String} to a {@code
45.40 + * long}, as well as other constants and methods useful when dealing
45.41 + * with a {@code long}.
45.42 + *
45.43 + * <p>Implementation note: The implementations of the "bit twiddling"
45.44 + * methods (such as {@link #highestOneBit(long) highestOneBit} and
45.45 + * {@link #numberOfTrailingZeros(long) numberOfTrailingZeros}) are
45.46 + * based on material from Henry S. Warren, Jr.'s <i>Hacker's
45.47 + * Delight</i>, (Addison Wesley, 2002).
45.48 + *
45.49 + * @author Lee Boynton
45.50 + * @author Arthur van Hoff
45.51 + * @author Josh Bloch
45.52 + * @author Joseph D. Darcy
45.53 + * @since JDK1.0
45.54 + */
45.55 +public final class Long extends Number implements Comparable<Long> {
45.56 + /**
45.57 + * A constant holding the minimum value a {@code long} can
45.58 + * have, -2<sup>63</sup>.
45.59 + */
45.60 + public static final long MIN_VALUE = 0x8000000000000000L;
45.61 +
45.62 + /**
45.63 + * A constant holding the maximum value a {@code long} can
45.64 + * have, 2<sup>63</sup>-1.
45.65 + */
45.66 + public static final long MAX_VALUE = 0x7fffffffffffffffL;
45.67 +
45.68 + /**
45.69 + * The {@code Class} instance representing the primitive type
45.70 + * {@code long}.
45.71 + *
45.72 + * @since JDK1.1
45.73 + */
45.74 + public static final Class<Long> TYPE = (Class<Long>) Class.getPrimitiveClass("long");
45.75 +
45.76 + /**
45.77 + * Returns a string representation of the first argument in the
45.78 + * radix specified by the second argument.
45.79 + *
45.80 + * <p>If the radix is smaller than {@code Character.MIN_RADIX}
45.81 + * or larger than {@code Character.MAX_RADIX}, then the radix
45.82 + * {@code 10} is used instead.
45.83 + *
45.84 + * <p>If the first argument is negative, the first element of the
45.85 + * result is the ASCII minus sign {@code '-'}
45.86 + * (<code>'\u002d'</code>). If the first argument is not
45.87 + * negative, no sign character appears in the result.
45.88 + *
45.89 + * <p>The remaining characters of the result represent the magnitude
45.90 + * of the first argument. If the magnitude is zero, it is
45.91 + * represented by a single zero character {@code '0'}
45.92 + * (<code>'\u0030'</code>); otherwise, the first character of
45.93 + * the representation of the magnitude will not be the zero
45.94 + * character. The following ASCII characters are used as digits:
45.95 + *
45.96 + * <blockquote>
45.97 + * {@code 0123456789abcdefghijklmnopqrstuvwxyz}
45.98 + * </blockquote>
45.99 + *
45.100 + * These are <code>'\u0030'</code> through
45.101 + * <code>'\u0039'</code> and <code>'\u0061'</code> through
45.102 + * <code>'\u007a'</code>. If {@code radix} is
45.103 + * <var>N</var>, then the first <var>N</var> of these characters
45.104 + * are used as radix-<var>N</var> digits in the order shown. Thus,
45.105 + * the digits for hexadecimal (radix 16) are
45.106 + * {@code 0123456789abcdef}. If uppercase letters are
45.107 + * desired, the {@link java.lang.String#toUpperCase()} method may
45.108 + * be called on the result:
45.109 + *
45.110 + * <blockquote>
45.111 + * {@code Long.toString(n, 16).toUpperCase()}
45.112 + * </blockquote>
45.113 + *
45.114 + * @param i a {@code long} to be converted to a string.
45.115 + * @param radix the radix to use in the string representation.
45.116 + * @return a string representation of the argument in the specified radix.
45.117 + * @see java.lang.Character#MAX_RADIX
45.118 + * @see java.lang.Character#MIN_RADIX
45.119 + */
45.120 + public static String toString(long i, int radix) {
45.121 + if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
45.122 + radix = 10;
45.123 + if (radix == 10)
45.124 + return toString(i);
45.125 + char[] buf = new char[65];
45.126 + int charPos = 64;
45.127 + boolean negative = (i < 0);
45.128 +
45.129 + if (!negative) {
45.130 + i = -i;
45.131 + }
45.132 +
45.133 + while (i <= -radix) {
45.134 + buf[charPos--] = Integer.digits[(int)(-(i % radix))];
45.135 + i = i / radix;
45.136 + }
45.137 + buf[charPos] = Integer.digits[(int)(-i)];
45.138 +
45.139 + if (negative) {
45.140 + buf[--charPos] = '-';
45.141 + }
45.142 +
45.143 + return new String(buf, charPos, (65 - charPos));
45.144 + }
45.145 +
45.146 + /**
45.147 + * Returns a string representation of the {@code long}
45.148 + * argument as an unsigned integer in base 16.
45.149 + *
45.150 + * <p>The unsigned {@code long} value is the argument plus
45.151 + * 2<sup>64</sup> if the argument is negative; otherwise, it is
45.152 + * equal to the argument. This value is converted to a string of
45.153 + * ASCII digits in hexadecimal (base 16) with no extra
45.154 + * leading {@code 0}s. If the unsigned magnitude is zero, it
45.155 + * is represented by a single zero character {@code '0'}
45.156 + * (<code>'\u0030'</code>); otherwise, the first character of
45.157 + * the representation of the unsigned magnitude will not be the
45.158 + * zero character. The following characters are used as
45.159 + * hexadecimal digits:
45.160 + *
45.161 + * <blockquote>
45.162 + * {@code 0123456789abcdef}
45.163 + * </blockquote>
45.164 + *
45.165 + * These are the characters <code>'\u0030'</code> through
45.166 + * <code>'\u0039'</code> and <code>'\u0061'</code> through
45.167 + * <code>'\u0066'</code>. If uppercase letters are desired,
45.168 + * the {@link java.lang.String#toUpperCase()} method may be called
45.169 + * on the result:
45.170 + *
45.171 + * <blockquote>
45.172 + * {@code Long.toHexString(n).toUpperCase()}
45.173 + * </blockquote>
45.174 + *
45.175 + * @param i a {@code long} to be converted to a string.
45.176 + * @return the string representation of the unsigned {@code long}
45.177 + * value represented by the argument in hexadecimal
45.178 + * (base 16).
45.179 + * @since JDK 1.0.2
45.180 + */
45.181 + public static String toHexString(long i) {
45.182 + return toUnsignedString(i, 4);
45.183 + }
45.184 +
45.185 + /**
45.186 + * Returns a string representation of the {@code long}
45.187 + * argument as an unsigned integer in base 8.
45.188 + *
45.189 + * <p>The unsigned {@code long} value is the argument plus
45.190 + * 2<sup>64</sup> if the argument is negative; otherwise, it is
45.191 + * equal to the argument. This value is converted to a string of
45.192 + * ASCII digits in octal (base 8) with no extra leading
45.193 + * {@code 0}s.
45.194 + *
45.195 + * <p>If the unsigned magnitude is zero, it is represented by a
45.196 + * single zero character {@code '0'}
45.197 + * (<code>'\u0030'</code>); otherwise, the first character of
45.198 + * the representation of the unsigned magnitude will not be the
45.199 + * zero character. The following characters are used as octal
45.200 + * digits:
45.201 + *
45.202 + * <blockquote>
45.203 + * {@code 01234567}
45.204 + * </blockquote>
45.205 + *
45.206 + * These are the characters <code>'\u0030'</code> through
45.207 + * <code>'\u0037'</code>.
45.208 + *
45.209 + * @param i a {@code long} to be converted to a string.
45.210 + * @return the string representation of the unsigned {@code long}
45.211 + * value represented by the argument in octal (base 8).
45.212 + * @since JDK 1.0.2
45.213 + */
45.214 + public static String toOctalString(long i) {
45.215 + return toUnsignedString(i, 3);
45.216 + }
45.217 +
45.218 + /**
45.219 + * Returns a string representation of the {@code long}
45.220 + * argument as an unsigned integer in base 2.
45.221 + *
45.222 + * <p>The unsigned {@code long} value is the argument plus
45.223 + * 2<sup>64</sup> if the argument is negative; otherwise, it is
45.224 + * equal to the argument. This value is converted to a string of
45.225 + * ASCII digits in binary (base 2) with no extra leading
45.226 + * {@code 0}s. If the unsigned magnitude is zero, it is
45.227 + * represented by a single zero character {@code '0'}
45.228 + * (<code>'\u0030'</code>); otherwise, the first character of
45.229 + * the representation of the unsigned magnitude will not be the
45.230 + * zero character. The characters {@code '0'}
45.231 + * (<code>'\u0030'</code>) and {@code '1'}
45.232 + * (<code>'\u0031'</code>) are used as binary digits.
45.233 + *
45.234 + * @param i a {@code long} to be converted to a string.
45.235 + * @return the string representation of the unsigned {@code long}
45.236 + * value represented by the argument in binary (base 2).
45.237 + * @since JDK 1.0.2
45.238 + */
45.239 + public static String toBinaryString(long i) {
45.240 + return toUnsignedString(i, 1);
45.241 + }
45.242 +
45.243 + /**
45.244 + * Convert the integer to an unsigned number.
45.245 + */
45.246 + private static String toUnsignedString(long i, int shift) {
45.247 + char[] buf = new char[64];
45.248 + int charPos = 64;
45.249 + int radix = 1 << shift;
45.250 + long mask = radix - 1;
45.251 + do {
45.252 + buf[--charPos] = Integer.digits[(int)(i & mask)];
45.253 + i >>>= shift;
45.254 + } while (i != 0);
45.255 + return new String(buf, charPos, (64 - charPos));
45.256 + }
45.257 +
45.258 + /**
45.259 + * Returns a {@code String} object representing the specified
45.260 + * {@code long}. The argument is converted to signed decimal
45.261 + * representation and returned as a string, exactly as if the
45.262 + * argument and the radix 10 were given as arguments to the {@link
45.263 + * #toString(long, int)} method.
45.264 + *
45.265 + * @param i a {@code long} to be converted.
45.266 + * @return a string representation of the argument in base 10.
45.267 + */
45.268 + @JavaScriptBody(args = "i", body = "return i.toString();")
45.269 + public static String toString(long i) {
45.270 + if (i == Long.MIN_VALUE)
45.271 + return "-9223372036854775808";
45.272 + int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
45.273 + char[] buf = new char[size];
45.274 + getChars(i, size, buf);
45.275 + return new String(buf, 0, size);
45.276 + }
45.277 +
45.278 + /**
45.279 + * Places characters representing the integer i into the
45.280 + * character array buf. The characters are placed into
45.281 + * the buffer backwards starting with the least significant
45.282 + * digit at the specified index (exclusive), and working
45.283 + * backwards from there.
45.284 + *
45.285 + * Will fail if i == Long.MIN_VALUE
45.286 + */
45.287 + static void getChars(long i, int index, char[] buf) {
45.288 + long q;
45.289 + int r;
45.290 + int charPos = index;
45.291 + char sign = 0;
45.292 +
45.293 + if (i < 0) {
45.294 + sign = '-';
45.295 + i = -i;
45.296 + }
45.297 +
45.298 + // Get 2 digits/iteration using longs until quotient fits into an int
45.299 + while (i > Integer.MAX_VALUE) {
45.300 + q = i / 100;
45.301 + // really: r = i - (q * 100);
45.302 + r = (int)(i - ((q << 6) + (q << 5) + (q << 2)));
45.303 + i = q;
45.304 + buf[--charPos] = Integer.DigitOnes[r];
45.305 + buf[--charPos] = Integer.DigitTens[r];
45.306 + }
45.307 +
45.308 + // Get 2 digits/iteration using ints
45.309 + int q2;
45.310 + int i2 = (int)i;
45.311 + while (i2 >= 65536) {
45.312 + q2 = i2 / 100;
45.313 + // really: r = i2 - (q * 100);
45.314 + r = i2 - ((q2 << 6) + (q2 << 5) + (q2 << 2));
45.315 + i2 = q2;
45.316 + buf[--charPos] = Integer.DigitOnes[r];
45.317 + buf[--charPos] = Integer.DigitTens[r];
45.318 + }
45.319 +
45.320 + // Fall thru to fast mode for smaller numbers
45.321 + // assert(i2 <= 65536, i2);
45.322 + for (;;) {
45.323 + q2 = (i2 * 52429) >>> (16+3);
45.324 + r = i2 - ((q2 << 3) + (q2 << 1)); // r = i2-(q2*10) ...
45.325 + buf[--charPos] = Integer.digits[r];
45.326 + i2 = q2;
45.327 + if (i2 == 0) break;
45.328 + }
45.329 + if (sign != 0) {
45.330 + buf[--charPos] = sign;
45.331 + }
45.332 + }
45.333 +
45.334 + // Requires positive x
45.335 + static int stringSize(long x) {
45.336 + long p = 10;
45.337 + for (int i=1; i<19; i++) {
45.338 + if (x < p)
45.339 + return i;
45.340 + p = 10*p;
45.341 + }
45.342 + return 19;
45.343 + }
45.344 +
45.345 + /**
45.346 + * Parses the string argument as a signed {@code long} in the
45.347 + * radix specified by the second argument. The characters in the
45.348 + * string must all be digits of the specified radix (as determined
45.349 + * by whether {@link java.lang.Character#digit(char, int)} returns
45.350 + * a nonnegative value), except that the first character may be an
45.351 + * ASCII minus sign {@code '-'} (<code>'\u002D'</code>) to
45.352 + * indicate a negative value or an ASCII plus sign {@code '+'}
45.353 + * (<code>'\u002B'</code>) to indicate a positive value. The
45.354 + * resulting {@code long} value is returned.
45.355 + *
45.356 + * <p>Note that neither the character {@code L}
45.357 + * (<code>'\u004C'</code>) nor {@code l}
45.358 + * (<code>'\u006C'</code>) is permitted to appear at the end
45.359 + * of the string as a type indicator, as would be permitted in
45.360 + * Java programming language source code - except that either
45.361 + * {@code L} or {@code l} may appear as a digit for a
45.362 + * radix greater than 22.
45.363 + *
45.364 + * <p>An exception of type {@code NumberFormatException} is
45.365 + * thrown if any of the following situations occurs:
45.366 + * <ul>
45.367 + *
45.368 + * <li>The first argument is {@code null} or is a string of
45.369 + * length zero.
45.370 + *
45.371 + * <li>The {@code radix} is either smaller than {@link
45.372 + * java.lang.Character#MIN_RADIX} or larger than {@link
45.373 + * java.lang.Character#MAX_RADIX}.
45.374 + *
45.375 + * <li>Any character of the string is not a digit of the specified
45.376 + * radix, except that the first character may be a minus sign
45.377 + * {@code '-'} (<code>'\u002d'</code>) or plus sign {@code
45.378 + * '+'} (<code>'\u002B'</code>) provided that the string is
45.379 + * longer than length 1.
45.380 + *
45.381 + * <li>The value represented by the string is not a value of type
45.382 + * {@code long}.
45.383 + * </ul>
45.384 + *
45.385 + * <p>Examples:
45.386 + * <blockquote><pre>
45.387 + * parseLong("0", 10) returns 0L
45.388 + * parseLong("473", 10) returns 473L
45.389 + * parseLong("+42", 10) returns 42L
45.390 + * parseLong("-0", 10) returns 0L
45.391 + * parseLong("-FF", 16) returns -255L
45.392 + * parseLong("1100110", 2) returns 102L
45.393 + * parseLong("99", 8) throws a NumberFormatException
45.394 + * parseLong("Hazelnut", 10) throws a NumberFormatException
45.395 + * parseLong("Hazelnut", 36) returns 1356099454469L
45.396 + * </pre></blockquote>
45.397 + *
45.398 + * @param s the {@code String} containing the
45.399 + * {@code long} representation to be parsed.
45.400 + * @param radix the radix to be used while parsing {@code s}.
45.401 + * @return the {@code long} represented by the string argument in
45.402 + * the specified radix.
45.403 + * @throws NumberFormatException if the string does not contain a
45.404 + * parsable {@code long}.
45.405 + */
45.406 + public static long parseLong(String s, int radix)
45.407 + throws NumberFormatException
45.408 + {
45.409 + if (s == null) {
45.410 + throw new NumberFormatException("null");
45.411 + }
45.412 +
45.413 + if (radix < Character.MIN_RADIX) {
45.414 + throw new NumberFormatException("radix " + radix +
45.415 + " less than Character.MIN_RADIX");
45.416 + }
45.417 + if (radix > Character.MAX_RADIX) {
45.418 + throw new NumberFormatException("radix " + radix +
45.419 + " greater than Character.MAX_RADIX");
45.420 + }
45.421 +
45.422 + long result = 0;
45.423 + boolean negative = false;
45.424 + int i = 0, len = s.length();
45.425 + long limit = -Long.MAX_VALUE;
45.426 + long multmin;
45.427 + int digit;
45.428 +
45.429 + if (len > 0) {
45.430 + char firstChar = s.charAt(0);
45.431 + if (firstChar < '0') { // Possible leading "+" or "-"
45.432 + if (firstChar == '-') {
45.433 + negative = true;
45.434 + limit = Long.MIN_VALUE;
45.435 + } else if (firstChar != '+')
45.436 + throw NumberFormatException.forInputString(s);
45.437 +
45.438 + if (len == 1) // Cannot have lone "+" or "-"
45.439 + throw NumberFormatException.forInputString(s);
45.440 + i++;
45.441 + }
45.442 + multmin = limit / radix;
45.443 + while (i < len) {
45.444 + // Accumulating negatively avoids surprises near MAX_VALUE
45.445 + digit = Character.digit(s.charAt(i++),radix);
45.446 + if (digit < 0) {
45.447 + throw NumberFormatException.forInputString(s);
45.448 + }
45.449 + if (result < multmin) {
45.450 + throw NumberFormatException.forInputString(s);
45.451 + }
45.452 + result *= radix;
45.453 + if (result < limit + digit) {
45.454 + throw NumberFormatException.forInputString(s);
45.455 + }
45.456 + result -= digit;
45.457 + }
45.458 + } else {
45.459 + throw NumberFormatException.forInputString(s);
45.460 + }
45.461 + return negative ? result : -result;
45.462 + }
45.463 +
45.464 + /**
45.465 + * Parses the string argument as a signed decimal {@code long}.
45.466 + * The characters in the string must all be decimal digits, except
45.467 + * that the first character may be an ASCII minus sign {@code '-'}
45.468 + * (<code>\u002D'</code>) to indicate a negative value or an
45.469 + * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
45.470 + * indicate a positive value. The resulting {@code long} value is
45.471 + * returned, exactly as if the argument and the radix {@code 10}
45.472 + * were given as arguments to the {@link
45.473 + * #parseLong(java.lang.String, int)} method.
45.474 + *
45.475 + * <p>Note that neither the character {@code L}
45.476 + * (<code>'\u004C'</code>) nor {@code l}
45.477 + * (<code>'\u006C'</code>) is permitted to appear at the end
45.478 + * of the string as a type indicator, as would be permitted in
45.479 + * Java programming language source code.
45.480 + *
45.481 + * @param s a {@code String} containing the {@code long}
45.482 + * representation to be parsed
45.483 + * @return the {@code long} represented by the argument in
45.484 + * decimal.
45.485 + * @throws NumberFormatException if the string does not contain a
45.486 + * parsable {@code long}.
45.487 + */
45.488 + public static long parseLong(String s) throws NumberFormatException {
45.489 + return parseLong(s, 10);
45.490 + }
45.491 +
45.492 + /**
45.493 + * Returns a {@code Long} object holding the value
45.494 + * extracted from the specified {@code String} when parsed
45.495 + * with the radix given by the second argument. The first
45.496 + * argument is interpreted as representing a signed
45.497 + * {@code long} in the radix specified by the second
45.498 + * argument, exactly as if the arguments were given to the {@link
45.499 + * #parseLong(java.lang.String, int)} method. The result is a
45.500 + * {@code Long} object that represents the {@code long}
45.501 + * value specified by the string.
45.502 + *
45.503 + * <p>In other words, this method returns a {@code Long} object equal
45.504 + * to the value of:
45.505 + *
45.506 + * <blockquote>
45.507 + * {@code new Long(Long.parseLong(s, radix))}
45.508 + * </blockquote>
45.509 + *
45.510 + * @param s the string to be parsed
45.511 + * @param radix the radix to be used in interpreting {@code s}
45.512 + * @return a {@code Long} object holding the value
45.513 + * represented by the string argument in the specified
45.514 + * radix.
45.515 + * @throws NumberFormatException If the {@code String} does not
45.516 + * contain a parsable {@code long}.
45.517 + */
45.518 + public static Long valueOf(String s, int radix) throws NumberFormatException {
45.519 + return Long.valueOf(parseLong(s, radix));
45.520 + }
45.521 +
45.522 + /**
45.523 + * Returns a {@code Long} object holding the value
45.524 + * of the specified {@code String}. The argument is
45.525 + * interpreted as representing a signed decimal {@code long},
45.526 + * exactly as if the argument were given to the {@link
45.527 + * #parseLong(java.lang.String)} method. The result is a
45.528 + * {@code Long} object that represents the integer value
45.529 + * specified by the string.
45.530 + *
45.531 + * <p>In other words, this method returns a {@code Long} object
45.532 + * equal to the value of:
45.533 + *
45.534 + * <blockquote>
45.535 + * {@code new Long(Long.parseLong(s))}
45.536 + * </blockquote>
45.537 + *
45.538 + * @param s the string to be parsed.
45.539 + * @return a {@code Long} object holding the value
45.540 + * represented by the string argument.
45.541 + * @throws NumberFormatException If the string cannot be parsed
45.542 + * as a {@code long}.
45.543 + */
45.544 + public static Long valueOf(String s) throws NumberFormatException
45.545 + {
45.546 + return Long.valueOf(parseLong(s, 10));
45.547 + }
45.548 +
45.549 + private static class LongCache {
45.550 + private LongCache(){}
45.551 +
45.552 + static final Long cache[] = new Long[-(-128) + 127 + 1];
45.553 +
45.554 + static {
45.555 + for(int i = 0; i < cache.length; i++)
45.556 + cache[i] = new Long(i - 128);
45.557 + }
45.558 + }
45.559 +
45.560 + /**
45.561 + * Returns a {@code Long} instance representing the specified
45.562 + * {@code long} value.
45.563 + * If a new {@code Long} instance is not required, this method
45.564 + * should generally be used in preference to the constructor
45.565 + * {@link #Long(long)}, as this method is likely to yield
45.566 + * significantly better space and time performance by caching
45.567 + * frequently requested values.
45.568 + *
45.569 + * Note that unlike the {@linkplain Integer#valueOf(int)
45.570 + * corresponding method} in the {@code Integer} class, this method
45.571 + * is <em>not</em> required to cache values within a particular
45.572 + * range.
45.573 + *
45.574 + * @param l a long value.
45.575 + * @return a {@code Long} instance representing {@code l}.
45.576 + * @since 1.5
45.577 + */
45.578 + public static Long valueOf(long l) {
45.579 + final int offset = 128;
45.580 + if (l >= -128 && l <= 127) { // will cache
45.581 + return LongCache.cache[(int)l + offset];
45.582 + }
45.583 + return new Long(l);
45.584 + }
45.585 +
45.586 + /**
45.587 + * Decodes a {@code String} into a {@code Long}.
45.588 + * Accepts decimal, hexadecimal, and octal numbers given by the
45.589 + * following grammar:
45.590 + *
45.591 + * <blockquote>
45.592 + * <dl>
45.593 + * <dt><i>DecodableString:</i>
45.594 + * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
45.595 + * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
45.596 + * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
45.597 + * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
45.598 + * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
45.599 + * <p>
45.600 + * <dt><i>Sign:</i>
45.601 + * <dd>{@code -}
45.602 + * <dd>{@code +}
45.603 + * </dl>
45.604 + * </blockquote>
45.605 + *
45.606 + * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
45.607 + * are as defined in section 3.10.1 of
45.608 + * <cite>The Java™ Language Specification</cite>,
45.609 + * except that underscores are not accepted between digits.
45.610 + *
45.611 + * <p>The sequence of characters following an optional
45.612 + * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
45.613 + * "{@code #}", or leading zero) is parsed as by the {@code
45.614 + * Long.parseLong} method with the indicated radix (10, 16, or 8).
45.615 + * This sequence of characters must represent a positive value or
45.616 + * a {@link NumberFormatException} will be thrown. The result is
45.617 + * negated if first character of the specified {@code String} is
45.618 + * the minus sign. No whitespace characters are permitted in the
45.619 + * {@code String}.
45.620 + *
45.621 + * @param nm the {@code String} to decode.
45.622 + * @return a {@code Long} object holding the {@code long}
45.623 + * value represented by {@code nm}
45.624 + * @throws NumberFormatException if the {@code String} does not
45.625 + * contain a parsable {@code long}.
45.626 + * @see java.lang.Long#parseLong(String, int)
45.627 + * @since 1.2
45.628 + */
45.629 + public static Long decode(String nm) throws NumberFormatException {
45.630 + int radix = 10;
45.631 + int index = 0;
45.632 + boolean negative = false;
45.633 + Long result;
45.634 +
45.635 + if (nm.length() == 0)
45.636 + throw new NumberFormatException("Zero length string");
45.637 + char firstChar = nm.charAt(0);
45.638 + // Handle sign, if present
45.639 + if (firstChar == '-') {
45.640 + negative = true;
45.641 + index++;
45.642 + } else if (firstChar == '+')
45.643 + index++;
45.644 +
45.645 + // Handle radix specifier, if present
45.646 + if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
45.647 + index += 2;
45.648 + radix = 16;
45.649 + }
45.650 + else if (nm.startsWith("#", index)) {
45.651 + index ++;
45.652 + radix = 16;
45.653 + }
45.654 + else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
45.655 + index ++;
45.656 + radix = 8;
45.657 + }
45.658 +
45.659 + if (nm.startsWith("-", index) || nm.startsWith("+", index))
45.660 + throw new NumberFormatException("Sign character in wrong position");
45.661 +
45.662 + try {
45.663 + result = Long.valueOf(nm.substring(index), radix);
45.664 + result = negative ? Long.valueOf(-result.longValue()) : result;
45.665 + } catch (NumberFormatException e) {
45.666 + // If number is Long.MIN_VALUE, we'll end up here. The next line
45.667 + // handles this case, and causes any genuine format error to be
45.668 + // rethrown.
45.669 + String constant = negative ? ("-" + nm.substring(index))
45.670 + : nm.substring(index);
45.671 + result = Long.valueOf(constant, radix);
45.672 + }
45.673 + return result;
45.674 + }
45.675 +
45.676 + /**
45.677 + * The value of the {@code Long}.
45.678 + *
45.679 + * @serial
45.680 + */
45.681 + private final long value;
45.682 +
45.683 + /**
45.684 + * Constructs a newly allocated {@code Long} object that
45.685 + * represents the specified {@code long} argument.
45.686 + *
45.687 + * @param value the value to be represented by the
45.688 + * {@code Long} object.
45.689 + */
45.690 + public Long(long value) {
45.691 + this.value = value;
45.692 + }
45.693 +
45.694 + /**
45.695 + * Constructs a newly allocated {@code Long} object that
45.696 + * represents the {@code long} value indicated by the
45.697 + * {@code String} parameter. The string is converted to a
45.698 + * {@code long} value in exactly the manner used by the
45.699 + * {@code parseLong} method for radix 10.
45.700 + *
45.701 + * @param s the {@code String} to be converted to a
45.702 + * {@code Long}.
45.703 + * @throws NumberFormatException if the {@code String} does not
45.704 + * contain a parsable {@code long}.
45.705 + * @see java.lang.Long#parseLong(java.lang.String, int)
45.706 + */
45.707 + public Long(String s) throws NumberFormatException {
45.708 + this.value = parseLong(s, 10);
45.709 + }
45.710 +
45.711 + /**
45.712 + * Returns the value of this {@code Long} as a
45.713 + * {@code byte}.
45.714 + */
45.715 + public byte byteValue() {
45.716 + return (byte)value;
45.717 + }
45.718 +
45.719 + /**
45.720 + * Returns the value of this {@code Long} as a
45.721 + * {@code short}.
45.722 + */
45.723 + public short shortValue() {
45.724 + return (short)value;
45.725 + }
45.726 +
45.727 + /**
45.728 + * Returns the value of this {@code Long} as an
45.729 + * {@code int}.
45.730 + */
45.731 + public int intValue() {
45.732 + return (int)value;
45.733 + }
45.734 +
45.735 + /**
45.736 + * Returns the value of this {@code Long} as a
45.737 + * {@code long} value.
45.738 + */
45.739 + public long longValue() {
45.740 + return (long)value;
45.741 + }
45.742 +
45.743 + /**
45.744 + * Returns the value of this {@code Long} as a
45.745 + * {@code float}.
45.746 + */
45.747 + public float floatValue() {
45.748 + return (float)value;
45.749 + }
45.750 +
45.751 + /**
45.752 + * Returns the value of this {@code Long} as a
45.753 + * {@code double}.
45.754 + */
45.755 + public double doubleValue() {
45.756 + return (double)value;
45.757 + }
45.758 +
45.759 + /**
45.760 + * Returns a {@code String} object representing this
45.761 + * {@code Long}'s value. The value is converted to signed
45.762 + * decimal representation and returned as a string, exactly as if
45.763 + * the {@code long} value were given as an argument to the
45.764 + * {@link java.lang.Long#toString(long)} method.
45.765 + *
45.766 + * @return a string representation of the value of this object in
45.767 + * base 10.
45.768 + */
45.769 + public String toString() {
45.770 + return toString(value);
45.771 + }
45.772 +
45.773 + /**
45.774 + * Returns a hash code for this {@code Long}. The result is
45.775 + * the exclusive OR of the two halves of the primitive
45.776 + * {@code long} value held by this {@code Long}
45.777 + * object. That is, the hashcode is the value of the expression:
45.778 + *
45.779 + * <blockquote>
45.780 + * {@code (int)(this.longValue()^(this.longValue()>>>32))}
45.781 + * </blockquote>
45.782 + *
45.783 + * @return a hash code value for this object.
45.784 + */
45.785 + public int hashCode() {
45.786 + return (int)(value ^ (value >>> 32));
45.787 + }
45.788 +
45.789 + /**
45.790 + * Compares this object to the specified object. The result is
45.791 + * {@code true} if and only if the argument is not
45.792 + * {@code null} and is a {@code Long} object that
45.793 + * contains the same {@code long} value as this object.
45.794 + *
45.795 + * @param obj the object to compare with.
45.796 + * @return {@code true} if the objects are the same;
45.797 + * {@code false} otherwise.
45.798 + */
45.799 + public boolean equals(Object obj) {
45.800 + if (obj instanceof Long) {
45.801 + return value == ((Long)obj).longValue();
45.802 + }
45.803 + return false;
45.804 + }
45.805 +
45.806 + /**
45.807 + * Determines the {@code long} value of the system property
45.808 + * with the specified name.
45.809 + *
45.810 + * <p>The first argument is treated as the name of a system property.
45.811 + * System properties are accessible through the {@link
45.812 + * java.lang.System#getProperty(java.lang.String)} method. The
45.813 + * string value of this property is then interpreted as a
45.814 + * {@code long} value and a {@code Long} object
45.815 + * representing this value is returned. Details of possible
45.816 + * numeric formats can be found with the definition of
45.817 + * {@code getProperty}.
45.818 + *
45.819 + * <p>If there is no property with the specified name, if the
45.820 + * specified name is empty or {@code null}, or if the
45.821 + * property does not have the correct numeric format, then
45.822 + * {@code null} is returned.
45.823 + *
45.824 + * <p>In other words, this method returns a {@code Long} object equal to
45.825 + * the value of:
45.826 + *
45.827 + * <blockquote>
45.828 + * {@code getLong(nm, null)}
45.829 + * </blockquote>
45.830 + *
45.831 + * @param nm property name.
45.832 + * @return the {@code Long} value of the property.
45.833 + * @see java.lang.System#getProperty(java.lang.String)
45.834 + * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
45.835 + */
45.836 + public static Long getLong(String nm) {
45.837 + return getLong(nm, null);
45.838 + }
45.839 +
45.840 + /**
45.841 + * Determines the {@code long} value of the system property
45.842 + * with the specified name.
45.843 + *
45.844 + * <p>The first argument is treated as the name of a system property.
45.845 + * System properties are accessible through the {@link
45.846 + * java.lang.System#getProperty(java.lang.String)} method. The
45.847 + * string value of this property is then interpreted as a
45.848 + * {@code long} value and a {@code Long} object
45.849 + * representing this value is returned. Details of possible
45.850 + * numeric formats can be found with the definition of
45.851 + * {@code getProperty}.
45.852 + *
45.853 + * <p>The second argument is the default value. A {@code Long} object
45.854 + * that represents the value of the second argument is returned if there
45.855 + * is no property of the specified name, if the property does not have
45.856 + * the correct numeric format, or if the specified name is empty or null.
45.857 + *
45.858 + * <p>In other words, this method returns a {@code Long} object equal
45.859 + * to the value of:
45.860 + *
45.861 + * <blockquote>
45.862 + * {@code getLong(nm, new Long(val))}
45.863 + * </blockquote>
45.864 + *
45.865 + * but in practice it may be implemented in a manner such as:
45.866 + *
45.867 + * <blockquote><pre>
45.868 + * Long result = getLong(nm, null);
45.869 + * return (result == null) ? new Long(val) : result;
45.870 + * </pre></blockquote>
45.871 + *
45.872 + * to avoid the unnecessary allocation of a {@code Long} object when
45.873 + * the default value is not needed.
45.874 + *
45.875 + * @param nm property name.
45.876 + * @param val default value.
45.877 + * @return the {@code Long} value of the property.
45.878 + * @see java.lang.System#getProperty(java.lang.String)
45.879 + * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
45.880 + */
45.881 + public static Long getLong(String nm, long val) {
45.882 + Long result = Long.getLong(nm, null);
45.883 + return (result == null) ? Long.valueOf(val) : result;
45.884 + }
45.885 +
45.886 + /**
45.887 + * Returns the {@code long} value of the system property with
45.888 + * the specified name. The first argument is treated as the name
45.889 + * of a system property. System properties are accessible through
45.890 + * the {@link java.lang.System#getProperty(java.lang.String)}
45.891 + * method. The string value of this property is then interpreted
45.892 + * as a {@code long} value, as per the
45.893 + * {@code Long.decode} method, and a {@code Long} object
45.894 + * representing this value is returned.
45.895 + *
45.896 + * <ul>
45.897 + * <li>If the property value begins with the two ASCII characters
45.898 + * {@code 0x} or the ASCII character {@code #}, not followed by
45.899 + * a minus sign, then the rest of it is parsed as a hexadecimal integer
45.900 + * exactly as for the method {@link #valueOf(java.lang.String, int)}
45.901 + * with radix 16.
45.902 + * <li>If the property value begins with the ASCII character
45.903 + * {@code 0} followed by another character, it is parsed as
45.904 + * an octal integer exactly as by the method {@link
45.905 + * #valueOf(java.lang.String, int)} with radix 8.
45.906 + * <li>Otherwise the property value is parsed as a decimal
45.907 + * integer exactly as by the method
45.908 + * {@link #valueOf(java.lang.String, int)} with radix 10.
45.909 + * </ul>
45.910 + *
45.911 + * <p>Note that, in every case, neither {@code L}
45.912 + * (<code>'\u004C'</code>) nor {@code l}
45.913 + * (<code>'\u006C'</code>) is permitted to appear at the end
45.914 + * of the property value as a type indicator, as would be
45.915 + * permitted in Java programming language source code.
45.916 + *
45.917 + * <p>The second argument is the default value. The default value is
45.918 + * returned if there is no property of the specified name, if the
45.919 + * property does not have the correct numeric format, or if the
45.920 + * specified name is empty or {@code null}.
45.921 + *
45.922 + * @param nm property name.
45.923 + * @param val default value.
45.924 + * @return the {@code Long} value of the property.
45.925 + * @see java.lang.System#getProperty(java.lang.String)
45.926 + * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
45.927 + * @see java.lang.Long#decode
45.928 + */
45.929 + public static Long getLong(String nm, Long val) {
45.930 + String v = null;
45.931 + try {
45.932 + v = AbstractStringBuilder.getProperty(nm);
45.933 + } catch (IllegalArgumentException e) {
45.934 + } catch (NullPointerException e) {
45.935 + }
45.936 + if (v != null) {
45.937 + try {
45.938 + return Long.decode(v);
45.939 + } catch (NumberFormatException e) {
45.940 + }
45.941 + }
45.942 + return val;
45.943 + }
45.944 +
45.945 + /**
45.946 + * Compares two {@code Long} objects numerically.
45.947 + *
45.948 + * @param anotherLong the {@code Long} to be compared.
45.949 + * @return the value {@code 0} if this {@code Long} is
45.950 + * equal to the argument {@code Long}; a value less than
45.951 + * {@code 0} if this {@code Long} is numerically less
45.952 + * than the argument {@code Long}; and a value greater
45.953 + * than {@code 0} if this {@code Long} is numerically
45.954 + * greater than the argument {@code Long} (signed
45.955 + * comparison).
45.956 + * @since 1.2
45.957 + */
45.958 + public int compareTo(Long anotherLong) {
45.959 + return compare(this.value, anotherLong.value);
45.960 + }
45.961 +
45.962 + /**
45.963 + * Compares two {@code long} values numerically.
45.964 + * The value returned is identical to what would be returned by:
45.965 + * <pre>
45.966 + * Long.valueOf(x).compareTo(Long.valueOf(y))
45.967 + * </pre>
45.968 + *
45.969 + * @param x the first {@code long} to compare
45.970 + * @param y the second {@code long} to compare
45.971 + * @return the value {@code 0} if {@code x == y};
45.972 + * a value less than {@code 0} if {@code x < y}; and
45.973 + * a value greater than {@code 0} if {@code x > y}
45.974 + * @since 1.7
45.975 + */
45.976 + public static int compare(long x, long y) {
45.977 + return (x < y) ? -1 : ((x == y) ? 0 : 1);
45.978 + }
45.979 +
45.980 +
45.981 + // Bit Twiddling
45.982 +
45.983 + /**
45.984 + * The number of bits used to represent a {@code long} value in two's
45.985 + * complement binary form.
45.986 + *
45.987 + * @since 1.5
45.988 + */
45.989 + public static final int SIZE = 64;
45.990 +
45.991 + /**
45.992 + * Returns a {@code long} value with at most a single one-bit, in the
45.993 + * position of the highest-order ("leftmost") one-bit in the specified
45.994 + * {@code long} value. Returns zero if the specified value has no
45.995 + * one-bits in its two's complement binary representation, that is, if it
45.996 + * is equal to zero.
45.997 + *
45.998 + * @return a {@code long} value with a single one-bit, in the position
45.999 + * of the highest-order one-bit in the specified value, or zero if
45.1000 + * the specified value is itself equal to zero.
45.1001 + * @since 1.5
45.1002 + */
45.1003 + public static long highestOneBit(long i) {
45.1004 + // HD, Figure 3-1
45.1005 + i |= (i >> 1);
45.1006 + i |= (i >> 2);
45.1007 + i |= (i >> 4);
45.1008 + i |= (i >> 8);
45.1009 + i |= (i >> 16);
45.1010 + i |= (i >> 32);
45.1011 + return i - (i >>> 1);
45.1012 + }
45.1013 +
45.1014 + /**
45.1015 + * Returns a {@code long} value with at most a single one-bit, in the
45.1016 + * position of the lowest-order ("rightmost") one-bit in the specified
45.1017 + * {@code long} value. Returns zero if the specified value has no
45.1018 + * one-bits in its two's complement binary representation, that is, if it
45.1019 + * is equal to zero.
45.1020 + *
45.1021 + * @return a {@code long} value with a single one-bit, in the position
45.1022 + * of the lowest-order one-bit in the specified value, or zero if
45.1023 + * the specified value is itself equal to zero.
45.1024 + * @since 1.5
45.1025 + */
45.1026 + public static long lowestOneBit(long i) {
45.1027 + // HD, Section 2-1
45.1028 + return i & -i;
45.1029 + }
45.1030 +
45.1031 + /**
45.1032 + * Returns the number of zero bits preceding the highest-order
45.1033 + * ("leftmost") one-bit in the two's complement binary representation
45.1034 + * of the specified {@code long} value. Returns 64 if the
45.1035 + * specified value has no one-bits in its two's complement representation,
45.1036 + * in other words if it is equal to zero.
45.1037 + *
45.1038 + * <p>Note that this method is closely related to the logarithm base 2.
45.1039 + * For all positive {@code long} values x:
45.1040 + * <ul>
45.1041 + * <li>floor(log<sub>2</sub>(x)) = {@code 63 - numberOfLeadingZeros(x)}
45.1042 + * <li>ceil(log<sub>2</sub>(x)) = {@code 64 - numberOfLeadingZeros(x - 1)}
45.1043 + * </ul>
45.1044 + *
45.1045 + * @return the number of zero bits preceding the highest-order
45.1046 + * ("leftmost") one-bit in the two's complement binary representation
45.1047 + * of the specified {@code long} value, or 64 if the value
45.1048 + * is equal to zero.
45.1049 + * @since 1.5
45.1050 + */
45.1051 + public static int numberOfLeadingZeros(long i) {
45.1052 + // HD, Figure 5-6
45.1053 + if (i == 0)
45.1054 + return 64;
45.1055 + int n = 1;
45.1056 + int x = (int)(i >>> 32);
45.1057 + if (x == 0) { n += 32; x = (int)i; }
45.1058 + if (x >>> 16 == 0) { n += 16; x <<= 16; }
45.1059 + if (x >>> 24 == 0) { n += 8; x <<= 8; }
45.1060 + if (x >>> 28 == 0) { n += 4; x <<= 4; }
45.1061 + if (x >>> 30 == 0) { n += 2; x <<= 2; }
45.1062 + n -= x >>> 31;
45.1063 + return n;
45.1064 + }
45.1065 +
45.1066 + /**
45.1067 + * Returns the number of zero bits following the lowest-order ("rightmost")
45.1068 + * one-bit in the two's complement binary representation of the specified
45.1069 + * {@code long} value. Returns 64 if the specified value has no
45.1070 + * one-bits in its two's complement representation, in other words if it is
45.1071 + * equal to zero.
45.1072 + *
45.1073 + * @return the number of zero bits following the lowest-order ("rightmost")
45.1074 + * one-bit in the two's complement binary representation of the
45.1075 + * specified {@code long} value, or 64 if the value is equal
45.1076 + * to zero.
45.1077 + * @since 1.5
45.1078 + */
45.1079 + public static int numberOfTrailingZeros(long i) {
45.1080 + // HD, Figure 5-14
45.1081 + int x, y;
45.1082 + if (i == 0) return 64;
45.1083 + int n = 63;
45.1084 + y = (int)i; if (y != 0) { n = n -32; x = y; } else x = (int)(i>>>32);
45.1085 + y = x <<16; if (y != 0) { n = n -16; x = y; }
45.1086 + y = x << 8; if (y != 0) { n = n - 8; x = y; }
45.1087 + y = x << 4; if (y != 0) { n = n - 4; x = y; }
45.1088 + y = x << 2; if (y != 0) { n = n - 2; x = y; }
45.1089 + return n - ((x << 1) >>> 31);
45.1090 + }
45.1091 +
45.1092 + /**
45.1093 + * Returns the number of one-bits in the two's complement binary
45.1094 + * representation of the specified {@code long} value. This function is
45.1095 + * sometimes referred to as the <i>population count</i>.
45.1096 + *
45.1097 + * @return the number of one-bits in the two's complement binary
45.1098 + * representation of the specified {@code long} value.
45.1099 + * @since 1.5
45.1100 + */
45.1101 + public static int bitCount(long i) {
45.1102 + // HD, Figure 5-14
45.1103 + i = i - ((i >>> 1) & 0x5555555555555555L);
45.1104 + i = (i & 0x3333333333333333L) + ((i >>> 2) & 0x3333333333333333L);
45.1105 + i = (i + (i >>> 4)) & 0x0f0f0f0f0f0f0f0fL;
45.1106 + i = i + (i >>> 8);
45.1107 + i = i + (i >>> 16);
45.1108 + i = i + (i >>> 32);
45.1109 + return (int)i & 0x7f;
45.1110 + }
45.1111 +
45.1112 + /**
45.1113 + * Returns the value obtained by rotating the two's complement binary
45.1114 + * representation of the specified {@code long} value left by the
45.1115 + * specified number of bits. (Bits shifted out of the left hand, or
45.1116 + * high-order, side reenter on the right, or low-order.)
45.1117 + *
45.1118 + * <p>Note that left rotation with a negative distance is equivalent to
45.1119 + * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
45.1120 + * distance)}. Note also that rotation by any multiple of 64 is a
45.1121 + * no-op, so all but the last six bits of the rotation distance can be
45.1122 + * ignored, even if the distance is negative: {@code rotateLeft(val,
45.1123 + * distance) == rotateLeft(val, distance & 0x3F)}.
45.1124 + *
45.1125 + * @return the value obtained by rotating the two's complement binary
45.1126 + * representation of the specified {@code long} value left by the
45.1127 + * specified number of bits.
45.1128 + * @since 1.5
45.1129 + */
45.1130 + public static long rotateLeft(long i, int distance) {
45.1131 + return (i << distance) | (i >>> -distance);
45.1132 + }
45.1133 +
45.1134 + /**
45.1135 + * Returns the value obtained by rotating the two's complement binary
45.1136 + * representation of the specified {@code long} value right by the
45.1137 + * specified number of bits. (Bits shifted out of the right hand, or
45.1138 + * low-order, side reenter on the left, or high-order.)
45.1139 + *
45.1140 + * <p>Note that right rotation with a negative distance is equivalent to
45.1141 + * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
45.1142 + * distance)}. Note also that rotation by any multiple of 64 is a
45.1143 + * no-op, so all but the last six bits of the rotation distance can be
45.1144 + * ignored, even if the distance is negative: {@code rotateRight(val,
45.1145 + * distance) == rotateRight(val, distance & 0x3F)}.
45.1146 + *
45.1147 + * @return the value obtained by rotating the two's complement binary
45.1148 + * representation of the specified {@code long} value right by the
45.1149 + * specified number of bits.
45.1150 + * @since 1.5
45.1151 + */
45.1152 + public static long rotateRight(long i, int distance) {
45.1153 + return (i >>> distance) | (i << -distance);
45.1154 + }
45.1155 +
45.1156 + /**
45.1157 + * Returns the value obtained by reversing the order of the bits in the
45.1158 + * two's complement binary representation of the specified {@code long}
45.1159 + * value.
45.1160 + *
45.1161 + * @return the value obtained by reversing order of the bits in the
45.1162 + * specified {@code long} value.
45.1163 + * @since 1.5
45.1164 + */
45.1165 + public static long reverse(long i) {
45.1166 + // HD, Figure 7-1
45.1167 + i = (i & 0x5555555555555555L) << 1 | (i >>> 1) & 0x5555555555555555L;
45.1168 + i = (i & 0x3333333333333333L) << 2 | (i >>> 2) & 0x3333333333333333L;
45.1169 + i = (i & 0x0f0f0f0f0f0f0f0fL) << 4 | (i >>> 4) & 0x0f0f0f0f0f0f0f0fL;
45.1170 + i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
45.1171 + i = (i << 48) | ((i & 0xffff0000L) << 16) |
45.1172 + ((i >>> 16) & 0xffff0000L) | (i >>> 48);
45.1173 + return i;
45.1174 + }
45.1175 +
45.1176 + /**
45.1177 + * Returns the signum function of the specified {@code long} value. (The
45.1178 + * return value is -1 if the specified value is negative; 0 if the
45.1179 + * specified value is zero; and 1 if the specified value is positive.)
45.1180 + *
45.1181 + * @return the signum function of the specified {@code long} value.
45.1182 + * @since 1.5
45.1183 + */
45.1184 + public static int signum(long i) {
45.1185 + // HD, Section 2-7
45.1186 + return (int) ((i >> 63) | (-i >>> 63));
45.1187 + }
45.1188 +
45.1189 + /**
45.1190 + * Returns the value obtained by reversing the order of the bytes in the
45.1191 + * two's complement representation of the specified {@code long} value.
45.1192 + *
45.1193 + * @return the value obtained by reversing the bytes in the specified
45.1194 + * {@code long} value.
45.1195 + * @since 1.5
45.1196 + */
45.1197 + public static long reverseBytes(long i) {
45.1198 + i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
45.1199 + return (i << 48) | ((i & 0xffff0000L) << 16) |
45.1200 + ((i >>> 16) & 0xffff0000L) | (i >>> 48);
45.1201 + }
45.1202 +
45.1203 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
45.1204 + private static final long serialVersionUID = 4290774380558885855L;
45.1205 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
46.2 +++ b/emul/mini/src/main/java/java/lang/Math.java Wed Jan 23 20:39:23 2013 +0100
46.3 @@ -0,0 +1,1244 @@
46.4 +/*
46.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
46.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
46.7 + *
46.8 + * This code is free software; you can redistribute it and/or modify it
46.9 + * under the terms of the GNU General Public License version 2 only, as
46.10 + * published by the Free Software Foundation. Oracle designates this
46.11 + * particular file as subject to the "Classpath" exception as provided
46.12 + * by Oracle in the LICENSE file that accompanied this code.
46.13 + *
46.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
46.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
46.17 + * version 2 for more details (a copy is included in the LICENSE file that
46.18 + * accompanied this code).
46.19 + *
46.20 + * You should have received a copy of the GNU General Public License version
46.21 + * 2 along with this work; if not, write to the Free Software Foundation,
46.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
46.23 + *
46.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
46.25 + * or visit www.oracle.com if you need additional information or have any
46.26 + * questions.
46.27 + */
46.28 +
46.29 +package java.lang;
46.30 +
46.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
46.32 +
46.33 +
46.34 +/**
46.35 + * The class {@code Math} contains methods for performing basic
46.36 + * numeric operations such as the elementary exponential, logarithm,
46.37 + * square root, and trigonometric functions.
46.38 + *
46.39 + * <p>Unlike some of the numeric methods of class
46.40 + * {@code StrictMath}, all implementations of the equivalent
46.41 + * functions of class {@code Math} are not defined to return the
46.42 + * bit-for-bit same results. This relaxation permits
46.43 + * better-performing implementations where strict reproducibility is
46.44 + * not required.
46.45 + *
46.46 + * <p>By default many of the {@code Math} methods simply call
46.47 + * the equivalent method in {@code StrictMath} for their
46.48 + * implementation. Code generators are encouraged to use
46.49 + * platform-specific native libraries or microprocessor instructions,
46.50 + * where available, to provide higher-performance implementations of
46.51 + * {@code Math} methods. Such higher-performance
46.52 + * implementations still must conform to the specification for
46.53 + * {@code Math}.
46.54 + *
46.55 + * <p>The quality of implementation specifications concern two
46.56 + * properties, accuracy of the returned result and monotonicity of the
46.57 + * method. Accuracy of the floating-point {@code Math} methods
46.58 + * is measured in terms of <i>ulps</i>, units in the last place. For
46.59 + * a given floating-point format, an ulp of a specific real number
46.60 + * value is the distance between the two floating-point values
46.61 + * bracketing that numerical value. When discussing the accuracy of a
46.62 + * method as a whole rather than at a specific argument, the number of
46.63 + * ulps cited is for the worst-case error at any argument. If a
46.64 + * method always has an error less than 0.5 ulps, the method always
46.65 + * returns the floating-point number nearest the exact result; such a
46.66 + * method is <i>correctly rounded</i>. A correctly rounded method is
46.67 + * generally the best a floating-point approximation can be; however,
46.68 + * it is impractical for many floating-point methods to be correctly
46.69 + * rounded. Instead, for the {@code Math} class, a larger error
46.70 + * bound of 1 or 2 ulps is allowed for certain methods. Informally,
46.71 + * with a 1 ulp error bound, when the exact result is a representable
46.72 + * number, the exact result should be returned as the computed result;
46.73 + * otherwise, either of the two floating-point values which bracket
46.74 + * the exact result may be returned. For exact results large in
46.75 + * magnitude, one of the endpoints of the bracket may be infinite.
46.76 + * Besides accuracy at individual arguments, maintaining proper
46.77 + * relations between the method at different arguments is also
46.78 + * important. Therefore, most methods with more than 0.5 ulp errors
46.79 + * are required to be <i>semi-monotonic</i>: whenever the mathematical
46.80 + * function is non-decreasing, so is the floating-point approximation,
46.81 + * likewise, whenever the mathematical function is non-increasing, so
46.82 + * is the floating-point approximation. Not all approximations that
46.83 + * have 1 ulp accuracy will automatically meet the monotonicity
46.84 + * requirements.
46.85 + *
46.86 + * @author unascribed
46.87 + * @author Joseph D. Darcy
46.88 + * @since JDK1.0
46.89 + */
46.90 +
46.91 +public final class Math {
46.92 +
46.93 + /**
46.94 + * Don't let anyone instantiate this class.
46.95 + */
46.96 + private Math() {}
46.97 +
46.98 + /**
46.99 + * The {@code double} value that is closer than any other to
46.100 + * <i>e</i>, the base of the natural logarithms.
46.101 + */
46.102 + public static final double E = 2.7182818284590452354;
46.103 +
46.104 + /**
46.105 + * The {@code double} value that is closer than any other to
46.106 + * <i>pi</i>, the ratio of the circumference of a circle to its
46.107 + * diameter.
46.108 + */
46.109 + public static final double PI = 3.14159265358979323846;
46.110 +
46.111 + /**
46.112 + * Returns the trigonometric sine of an angle. Special cases:
46.113 + * <ul><li>If the argument is NaN or an infinity, then the
46.114 + * result is NaN.
46.115 + * <li>If the argument is zero, then the result is a zero with the
46.116 + * same sign as the argument.</ul>
46.117 + *
46.118 + * <p>The computed result must be within 1 ulp of the exact result.
46.119 + * Results must be semi-monotonic.
46.120 + *
46.121 + * @param a an angle, in radians.
46.122 + * @return the sine of the argument.
46.123 + */
46.124 + @JavaScriptBody(args="a", body="return Math.sin(a);")
46.125 + public static double sin(double a) {
46.126 + throw new UnsupportedOperationException();
46.127 + }
46.128 +
46.129 + /**
46.130 + * Returns the trigonometric cosine of an angle. Special cases:
46.131 + * <ul><li>If the argument is NaN or an infinity, then the
46.132 + * result is NaN.</ul>
46.133 + *
46.134 + * <p>The computed result must be within 1 ulp of the exact result.
46.135 + * Results must be semi-monotonic.
46.136 + *
46.137 + * @param a an angle, in radians.
46.138 + * @return the cosine of the argument.
46.139 + */
46.140 + @JavaScriptBody(args="a", body="return Math.cos(a);")
46.141 + public static double cos(double a) {
46.142 + throw new UnsupportedOperationException();
46.143 + }
46.144 +
46.145 + /**
46.146 + * Returns the trigonometric tangent of an angle. Special cases:
46.147 + * <ul><li>If the argument is NaN or an infinity, then the result
46.148 + * is NaN.
46.149 + * <li>If the argument is zero, then the result is a zero with the
46.150 + * same sign as the argument.</ul>
46.151 + *
46.152 + * <p>The computed result must be within 1 ulp of the exact result.
46.153 + * Results must be semi-monotonic.
46.154 + *
46.155 + * @param a an angle, in radians.
46.156 + * @return the tangent of the argument.
46.157 + */
46.158 + @JavaScriptBody(args="a", body="return Math.tan(a);")
46.159 + public static double tan(double a) {
46.160 + throw new UnsupportedOperationException();
46.161 + }
46.162 +
46.163 + /**
46.164 + * Returns the arc sine of a value; the returned angle is in the
46.165 + * range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
46.166 + * <ul><li>If the argument is NaN or its absolute value is greater
46.167 + * than 1, then the result is NaN.
46.168 + * <li>If the argument is zero, then the result is a zero with the
46.169 + * same sign as the argument.</ul>
46.170 + *
46.171 + * <p>The computed result must be within 1 ulp of the exact result.
46.172 + * Results must be semi-monotonic.
46.173 + *
46.174 + * @param a the value whose arc sine is to be returned.
46.175 + * @return the arc sine of the argument.
46.176 + */
46.177 + @JavaScriptBody(args="a", body="return Math.asin(a);")
46.178 + public static double asin(double a) {
46.179 + throw new UnsupportedOperationException();
46.180 + }
46.181 +
46.182 + /**
46.183 + * Returns the arc cosine of a value; the returned angle is in the
46.184 + * range 0.0 through <i>pi</i>. Special case:
46.185 + * <ul><li>If the argument is NaN or its absolute value is greater
46.186 + * than 1, then the result is NaN.</ul>
46.187 + *
46.188 + * <p>The computed result must be within 1 ulp of the exact result.
46.189 + * Results must be semi-monotonic.
46.190 + *
46.191 + * @param a the value whose arc cosine is to be returned.
46.192 + * @return the arc cosine of the argument.
46.193 + */
46.194 + @JavaScriptBody(args="a", body="return Math.acos(a);")
46.195 + public static double acos(double a) {
46.196 + throw new UnsupportedOperationException();
46.197 + }
46.198 +
46.199 + /**
46.200 + * Returns the arc tangent of a value; the returned angle is in the
46.201 + * range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
46.202 + * <ul><li>If the argument is NaN, then the result is NaN.
46.203 + * <li>If the argument is zero, then the result is a zero with the
46.204 + * same sign as the argument.</ul>
46.205 + *
46.206 + * <p>The computed result must be within 1 ulp of the exact result.
46.207 + * Results must be semi-monotonic.
46.208 + *
46.209 + * @param a the value whose arc tangent is to be returned.
46.210 + * @return the arc tangent of the argument.
46.211 + */
46.212 + @JavaScriptBody(args="a", body="return Math.atan(a);")
46.213 + public static double atan(double a) {
46.214 + throw new UnsupportedOperationException();
46.215 + }
46.216 +
46.217 + /**
46.218 + * Converts an angle measured in degrees to an approximately
46.219 + * equivalent angle measured in radians. The conversion from
46.220 + * degrees to radians is generally inexact.
46.221 + *
46.222 + * @param angdeg an angle, in degrees
46.223 + * @return the measurement of the angle {@code angdeg}
46.224 + * in radians.
46.225 + * @since 1.2
46.226 + */
46.227 + public static double toRadians(double angdeg) {
46.228 + return angdeg / 180.0 * PI;
46.229 + }
46.230 +
46.231 + /**
46.232 + * Converts an angle measured in radians to an approximately
46.233 + * equivalent angle measured in degrees. The conversion from
46.234 + * radians to degrees is generally inexact; users should
46.235 + * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
46.236 + * equal {@code 0.0}.
46.237 + *
46.238 + * @param angrad an angle, in radians
46.239 + * @return the measurement of the angle {@code angrad}
46.240 + * in degrees.
46.241 + * @since 1.2
46.242 + */
46.243 + public static double toDegrees(double angrad) {
46.244 + return angrad * 180.0 / PI;
46.245 + }
46.246 +
46.247 + /**
46.248 + * Returns Euler's number <i>e</i> raised to the power of a
46.249 + * {@code double} value. Special cases:
46.250 + * <ul><li>If the argument is NaN, the result is NaN.
46.251 + * <li>If the argument is positive infinity, then the result is
46.252 + * positive infinity.
46.253 + * <li>If the argument is negative infinity, then the result is
46.254 + * positive zero.</ul>
46.255 + *
46.256 + * <p>The computed result must be within 1 ulp of the exact result.
46.257 + * Results must be semi-monotonic.
46.258 + *
46.259 + * @param a the exponent to raise <i>e</i> to.
46.260 + * @return the value <i>e</i><sup>{@code a}</sup>,
46.261 + * where <i>e</i> is the base of the natural logarithms.
46.262 + */
46.263 + @JavaScriptBody(args="a", body="return Math.exp(a);")
46.264 + public static double exp(double a) {
46.265 + throw new UnsupportedOperationException();
46.266 + }
46.267 +
46.268 + /**
46.269 + * Returns the natural logarithm (base <i>e</i>) of a {@code double}
46.270 + * value. Special cases:
46.271 + * <ul><li>If the argument is NaN or less than zero, then the result
46.272 + * is NaN.
46.273 + * <li>If the argument is positive infinity, then the result is
46.274 + * positive infinity.
46.275 + * <li>If the argument is positive zero or negative zero, then the
46.276 + * result is negative infinity.</ul>
46.277 + *
46.278 + * <p>The computed result must be within 1 ulp of the exact result.
46.279 + * Results must be semi-monotonic.
46.280 + *
46.281 + * @param a a value
46.282 + * @return the value ln {@code a}, the natural logarithm of
46.283 + * {@code a}.
46.284 + */
46.285 + @JavaScriptBody(args="a", body="return Math.log(a);")
46.286 + public static double log(double a) {
46.287 + throw new UnsupportedOperationException();
46.288 + }
46.289 +
46.290 + /**
46.291 + * Returns the base 10 logarithm of a {@code double} value.
46.292 + * Special cases:
46.293 + *
46.294 + * <ul><li>If the argument is NaN or less than zero, then the result
46.295 + * is NaN.
46.296 + * <li>If the argument is positive infinity, then the result is
46.297 + * positive infinity.
46.298 + * <li>If the argument is positive zero or negative zero, then the
46.299 + * result is negative infinity.
46.300 + * <li> If the argument is equal to 10<sup><i>n</i></sup> for
46.301 + * integer <i>n</i>, then the result is <i>n</i>.
46.302 + * </ul>
46.303 + *
46.304 + * <p>The computed result must be within 1 ulp of the exact result.
46.305 + * Results must be semi-monotonic.
46.306 + *
46.307 + * @param a a value
46.308 + * @return the base 10 logarithm of {@code a}.
46.309 + * @since 1.5
46.310 + */
46.311 + @JavaScriptBody(args="a", body="return Math.log(a) / Math.LN10;")
46.312 + public static double log10(double a) {
46.313 + throw new UnsupportedOperationException();
46.314 + }
46.315 +
46.316 + /**
46.317 + * Returns the correctly rounded positive square root of a
46.318 + * {@code double} value.
46.319 + * Special cases:
46.320 + * <ul><li>If the argument is NaN or less than zero, then the result
46.321 + * is NaN.
46.322 + * <li>If the argument is positive infinity, then the result is positive
46.323 + * infinity.
46.324 + * <li>If the argument is positive zero or negative zero, then the
46.325 + * result is the same as the argument.</ul>
46.326 + * Otherwise, the result is the {@code double} value closest to
46.327 + * the true mathematical square root of the argument value.
46.328 + *
46.329 + * @param a a value.
46.330 + * @return the positive square root of {@code a}.
46.331 + * If the argument is NaN or less than zero, the result is NaN.
46.332 + */
46.333 + @JavaScriptBody(args="a", body="return Math.sqrt(a);")
46.334 + public static double sqrt(double a) {
46.335 + throw new UnsupportedOperationException();
46.336 + }
46.337 +
46.338 + /**
46.339 + * Returns the smallest (closest to negative infinity)
46.340 + * {@code double} value that is greater than or equal to the
46.341 + * argument and is equal to a mathematical integer. Special cases:
46.342 + * <ul><li>If the argument value is already equal to a
46.343 + * mathematical integer, then the result is the same as the
46.344 + * argument. <li>If the argument is NaN or an infinity or
46.345 + * positive zero or negative zero, then the result is the same as
46.346 + * the argument. <li>If the argument value is less than zero but
46.347 + * greater than -1.0, then the result is negative zero.</ul> Note
46.348 + * that the value of {@code Math.ceil(x)} is exactly the
46.349 + * value of {@code -Math.floor(-x)}.
46.350 + *
46.351 + *
46.352 + * @param a a value.
46.353 + * @return the smallest (closest to negative infinity)
46.354 + * floating-point value that is greater than or equal to
46.355 + * the argument and is equal to a mathematical integer.
46.356 + */
46.357 + @JavaScriptBody(args="a", body="return Math.ceil(a);")
46.358 + public static double ceil(double a) {
46.359 + throw new UnsupportedOperationException();
46.360 + }
46.361 +
46.362 + /**
46.363 + * Returns the largest (closest to positive infinity)
46.364 + * {@code double} value that is less than or equal to the
46.365 + * argument and is equal to a mathematical integer. Special cases:
46.366 + * <ul><li>If the argument value is already equal to a
46.367 + * mathematical integer, then the result is the same as the
46.368 + * argument. <li>If the argument is NaN or an infinity or
46.369 + * positive zero or negative zero, then the result is the same as
46.370 + * the argument.</ul>
46.371 + *
46.372 + * @param a a value.
46.373 + * @return the largest (closest to positive infinity)
46.374 + * floating-point value that less than or equal to the argument
46.375 + * and is equal to a mathematical integer.
46.376 + */
46.377 + @JavaScriptBody(args="a", body="return Math.floor(a);")
46.378 + public static double floor(double a) {
46.379 + throw new UnsupportedOperationException();
46.380 + }
46.381 +
46.382 + /**
46.383 + * Returns the angle <i>theta</i> from the conversion of rectangular
46.384 + * coordinates ({@code x}, {@code y}) to polar
46.385 + * coordinates (r, <i>theta</i>).
46.386 + * This method computes the phase <i>theta</i> by computing an arc tangent
46.387 + * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
46.388 + * cases:
46.389 + * <ul><li>If either argument is NaN, then the result is NaN.
46.390 + * <li>If the first argument is positive zero and the second argument
46.391 + * is positive, or the first argument is positive and finite and the
46.392 + * second argument is positive infinity, then the result is positive
46.393 + * zero.
46.394 + * <li>If the first argument is negative zero and the second argument
46.395 + * is positive, or the first argument is negative and finite and the
46.396 + * second argument is positive infinity, then the result is negative zero.
46.397 + * <li>If the first argument is positive zero and the second argument
46.398 + * is negative, or the first argument is positive and finite and the
46.399 + * second argument is negative infinity, then the result is the
46.400 + * {@code double} value closest to <i>pi</i>.
46.401 + * <li>If the first argument is negative zero and the second argument
46.402 + * is negative, or the first argument is negative and finite and the
46.403 + * second argument is negative infinity, then the result is the
46.404 + * {@code double} value closest to -<i>pi</i>.
46.405 + * <li>If the first argument is positive and the second argument is
46.406 + * positive zero or negative zero, or the first argument is positive
46.407 + * infinity and the second argument is finite, then the result is the
46.408 + * {@code double} value closest to <i>pi</i>/2.
46.409 + * <li>If the first argument is negative and the second argument is
46.410 + * positive zero or negative zero, or the first argument is negative
46.411 + * infinity and the second argument is finite, then the result is the
46.412 + * {@code double} value closest to -<i>pi</i>/2.
46.413 + * <li>If both arguments are positive infinity, then the result is the
46.414 + * {@code double} value closest to <i>pi</i>/4.
46.415 + * <li>If the first argument is positive infinity and the second argument
46.416 + * is negative infinity, then the result is the {@code double}
46.417 + * value closest to 3*<i>pi</i>/4.
46.418 + * <li>If the first argument is negative infinity and the second argument
46.419 + * is positive infinity, then the result is the {@code double} value
46.420 + * closest to -<i>pi</i>/4.
46.421 + * <li>If both arguments are negative infinity, then the result is the
46.422 + * {@code double} value closest to -3*<i>pi</i>/4.</ul>
46.423 + *
46.424 + * <p>The computed result must be within 2 ulps of the exact result.
46.425 + * Results must be semi-monotonic.
46.426 + *
46.427 + * @param y the ordinate coordinate
46.428 + * @param x the abscissa coordinate
46.429 + * @return the <i>theta</i> component of the point
46.430 + * (<i>r</i>, <i>theta</i>)
46.431 + * in polar coordinates that corresponds to the point
46.432 + * (<i>x</i>, <i>y</i>) in Cartesian coordinates.
46.433 + */
46.434 + @JavaScriptBody(args={"y", "x"}, body="return Math.atan2(y, x);")
46.435 + public static double atan2(double y, double x) {
46.436 + throw new UnsupportedOperationException();
46.437 + }
46.438 +
46.439 + /**
46.440 + * Returns the value of the first argument raised to the power of the
46.441 + * second argument. Special cases:
46.442 + *
46.443 + * <ul><li>If the second argument is positive or negative zero, then the
46.444 + * result is 1.0.
46.445 + * <li>If the second argument is 1.0, then the result is the same as the
46.446 + * first argument.
46.447 + * <li>If the second argument is NaN, then the result is NaN.
46.448 + * <li>If the first argument is NaN and the second argument is nonzero,
46.449 + * then the result is NaN.
46.450 + *
46.451 + * <li>If
46.452 + * <ul>
46.453 + * <li>the absolute value of the first argument is greater than 1
46.454 + * and the second argument is positive infinity, or
46.455 + * <li>the absolute value of the first argument is less than 1 and
46.456 + * the second argument is negative infinity,
46.457 + * </ul>
46.458 + * then the result is positive infinity.
46.459 + *
46.460 + * <li>If
46.461 + * <ul>
46.462 + * <li>the absolute value of the first argument is greater than 1 and
46.463 + * the second argument is negative infinity, or
46.464 + * <li>the absolute value of the
46.465 + * first argument is less than 1 and the second argument is positive
46.466 + * infinity,
46.467 + * </ul>
46.468 + * then the result is positive zero.
46.469 + *
46.470 + * <li>If the absolute value of the first argument equals 1 and the
46.471 + * second argument is infinite, then the result is NaN.
46.472 + *
46.473 + * <li>If
46.474 + * <ul>
46.475 + * <li>the first argument is positive zero and the second argument
46.476 + * is greater than zero, or
46.477 + * <li>the first argument is positive infinity and the second
46.478 + * argument is less than zero,
46.479 + * </ul>
46.480 + * then the result is positive zero.
46.481 + *
46.482 + * <li>If
46.483 + * <ul>
46.484 + * <li>the first argument is positive zero and the second argument
46.485 + * is less than zero, or
46.486 + * <li>the first argument is positive infinity and the second
46.487 + * argument is greater than zero,
46.488 + * </ul>
46.489 + * then the result is positive infinity.
46.490 + *
46.491 + * <li>If
46.492 + * <ul>
46.493 + * <li>the first argument is negative zero and the second argument
46.494 + * is greater than zero but not a finite odd integer, or
46.495 + * <li>the first argument is negative infinity and the second
46.496 + * argument is less than zero but not a finite odd integer,
46.497 + * </ul>
46.498 + * then the result is positive zero.
46.499 + *
46.500 + * <li>If
46.501 + * <ul>
46.502 + * <li>the first argument is negative zero and the second argument
46.503 + * is a positive finite odd integer, or
46.504 + * <li>the first argument is negative infinity and the second
46.505 + * argument is a negative finite odd integer,
46.506 + * </ul>
46.507 + * then the result is negative zero.
46.508 + *
46.509 + * <li>If
46.510 + * <ul>
46.511 + * <li>the first argument is negative zero and the second argument
46.512 + * is less than zero but not a finite odd integer, or
46.513 + * <li>the first argument is negative infinity and the second
46.514 + * argument is greater than zero but not a finite odd integer,
46.515 + * </ul>
46.516 + * then the result is positive infinity.
46.517 + *
46.518 + * <li>If
46.519 + * <ul>
46.520 + * <li>the first argument is negative zero and the second argument
46.521 + * is a negative finite odd integer, or
46.522 + * <li>the first argument is negative infinity and the second
46.523 + * argument is a positive finite odd integer,
46.524 + * </ul>
46.525 + * then the result is negative infinity.
46.526 + *
46.527 + * <li>If the first argument is finite and less than zero
46.528 + * <ul>
46.529 + * <li> if the second argument is a finite even integer, the
46.530 + * result is equal to the result of raising the absolute value of
46.531 + * the first argument to the power of the second argument
46.532 + *
46.533 + * <li>if the second argument is a finite odd integer, the result
46.534 + * is equal to the negative of the result of raising the absolute
46.535 + * value of the first argument to the power of the second
46.536 + * argument
46.537 + *
46.538 + * <li>if the second argument is finite and not an integer, then
46.539 + * the result is NaN.
46.540 + * </ul>
46.541 + *
46.542 + * <li>If both arguments are integers, then the result is exactly equal
46.543 + * to the mathematical result of raising the first argument to the power
46.544 + * of the second argument if that result can in fact be represented
46.545 + * exactly as a {@code double} value.</ul>
46.546 + *
46.547 + * <p>(In the foregoing descriptions, a floating-point value is
46.548 + * considered to be an integer if and only if it is finite and a
46.549 + * fixed point of the method {@link #ceil ceil} or,
46.550 + * equivalently, a fixed point of the method {@link #floor
46.551 + * floor}. A value is a fixed point of a one-argument
46.552 + * method if and only if the result of applying the method to the
46.553 + * value is equal to the value.)
46.554 + *
46.555 + * <p>The computed result must be within 1 ulp of the exact result.
46.556 + * Results must be semi-monotonic.
46.557 + *
46.558 + * @param a the base.
46.559 + * @param b the exponent.
46.560 + * @return the value {@code a}<sup>{@code b}</sup>.
46.561 + */
46.562 + @JavaScriptBody(args={"a", "b"}, body="return Math.pow(a, b);")
46.563 + public static double pow(double a, double b) {
46.564 + throw new UnsupportedOperationException();
46.565 + }
46.566 +
46.567 + /**
46.568 + * Returns the closest {@code int} to the argument, with ties
46.569 + * rounding up.
46.570 + *
46.571 + * <p>
46.572 + * Special cases:
46.573 + * <ul><li>If the argument is NaN, the result is 0.
46.574 + * <li>If the argument is negative infinity or any value less than or
46.575 + * equal to the value of {@code Integer.MIN_VALUE}, the result is
46.576 + * equal to the value of {@code Integer.MIN_VALUE}.
46.577 + * <li>If the argument is positive infinity or any value greater than or
46.578 + * equal to the value of {@code Integer.MAX_VALUE}, the result is
46.579 + * equal to the value of {@code Integer.MAX_VALUE}.</ul>
46.580 + *
46.581 + * @param a a floating-point value to be rounded to an integer.
46.582 + * @return the value of the argument rounded to the nearest
46.583 + * {@code int} value.
46.584 + * @see java.lang.Integer#MAX_VALUE
46.585 + * @see java.lang.Integer#MIN_VALUE
46.586 + */
46.587 + @JavaScriptBody(args="a", body="return Math.round(a);")
46.588 + public static int round(float a) {
46.589 + throw new UnsupportedOperationException();
46.590 + }
46.591 +
46.592 + /**
46.593 + * Returns the closest {@code long} to the argument, with ties
46.594 + * rounding up.
46.595 + *
46.596 + * <p>Special cases:
46.597 + * <ul><li>If the argument is NaN, the result is 0.
46.598 + * <li>If the argument is negative infinity or any value less than or
46.599 + * equal to the value of {@code Long.MIN_VALUE}, the result is
46.600 + * equal to the value of {@code Long.MIN_VALUE}.
46.601 + * <li>If the argument is positive infinity or any value greater than or
46.602 + * equal to the value of {@code Long.MAX_VALUE}, the result is
46.603 + * equal to the value of {@code Long.MAX_VALUE}.</ul>
46.604 + *
46.605 + * @param a a floating-point value to be rounded to a
46.606 + * {@code long}.
46.607 + * @return the value of the argument rounded to the nearest
46.608 + * {@code long} value.
46.609 + * @see java.lang.Long#MAX_VALUE
46.610 + * @see java.lang.Long#MIN_VALUE
46.611 + */
46.612 + @JavaScriptBody(args="a", body="return Math.round(a);")
46.613 + public static long round(double a) {
46.614 + throw new UnsupportedOperationException();
46.615 + }
46.616 +
46.617 +// private static Random randomNumberGenerator;
46.618 +//
46.619 +// private static synchronized Random initRNG() {
46.620 +// Random rnd = randomNumberGenerator;
46.621 +// return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
46.622 +// }
46.623 +
46.624 + /**
46.625 + * Returns a {@code double} value with a positive sign, greater
46.626 + * than or equal to {@code 0.0} and less than {@code 1.0}.
46.627 + * Returned values are chosen pseudorandomly with (approximately)
46.628 + * uniform distribution from that range.
46.629 + *
46.630 + * <p>When this method is first called, it creates a single new
46.631 + * pseudorandom-number generator, exactly as if by the expression
46.632 + *
46.633 + * <blockquote>{@code new java.util.Random()}</blockquote>
46.634 + *
46.635 + * This new pseudorandom-number generator is used thereafter for
46.636 + * all calls to this method and is used nowhere else.
46.637 + *
46.638 + * <p>This method is properly synchronized to allow correct use by
46.639 + * more than one thread. However, if many threads need to generate
46.640 + * pseudorandom numbers at a great rate, it may reduce contention
46.641 + * for each thread to have its own pseudorandom-number generator.
46.642 + *
46.643 + * @return a pseudorandom {@code double} greater than or equal
46.644 + * to {@code 0.0} and less than {@code 1.0}.
46.645 + * @see Random#nextDouble()
46.646 + */
46.647 + @JavaScriptBody(args={}, body="return Math.random();")
46.648 + public static double random() {
46.649 + throw new UnsupportedOperationException();
46.650 + }
46.651 +
46.652 + /**
46.653 + * Returns the absolute value of an {@code int} value.
46.654 + * If the argument is not negative, the argument is returned.
46.655 + * If the argument is negative, the negation of the argument is returned.
46.656 + *
46.657 + * <p>Note that if the argument is equal to the value of
46.658 + * {@link Integer#MIN_VALUE}, the most negative representable
46.659 + * {@code int} value, the result is that same value, which is
46.660 + * negative.
46.661 + *
46.662 + * @param a the argument whose absolute value is to be determined
46.663 + * @return the absolute value of the argument.
46.664 + */
46.665 + public static int abs(int a) {
46.666 + return (a < 0) ? -a : a;
46.667 + }
46.668 +
46.669 + /**
46.670 + * Returns the absolute value of a {@code long} value.
46.671 + * If the argument is not negative, the argument is returned.
46.672 + * If the argument is negative, the negation of the argument is returned.
46.673 + *
46.674 + * <p>Note that if the argument is equal to the value of
46.675 + * {@link Long#MIN_VALUE}, the most negative representable
46.676 + * {@code long} value, the result is that same value, which
46.677 + * is negative.
46.678 + *
46.679 + * @param a the argument whose absolute value is to be determined
46.680 + * @return the absolute value of the argument.
46.681 + */
46.682 + public static long abs(long a) {
46.683 + return (a < 0) ? -a : a;
46.684 + }
46.685 +
46.686 + /**
46.687 + * Returns the absolute value of a {@code float} value.
46.688 + * If the argument is not negative, the argument is returned.
46.689 + * If the argument is negative, the negation of the argument is returned.
46.690 + * Special cases:
46.691 + * <ul><li>If the argument is positive zero or negative zero, the
46.692 + * result is positive zero.
46.693 + * <li>If the argument is infinite, the result is positive infinity.
46.694 + * <li>If the argument is NaN, the result is NaN.</ul>
46.695 + * In other words, the result is the same as the value of the expression:
46.696 + * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
46.697 + *
46.698 + * @param a the argument whose absolute value is to be determined
46.699 + * @return the absolute value of the argument.
46.700 + */
46.701 + public static float abs(float a) {
46.702 + return (a <= 0.0F) ? 0.0F - a : a;
46.703 + }
46.704 +
46.705 + /**
46.706 + * Returns the absolute value of a {@code double} value.
46.707 + * If the argument is not negative, the argument is returned.
46.708 + * If the argument is negative, the negation of the argument is returned.
46.709 + * Special cases:
46.710 + * <ul><li>If the argument is positive zero or negative zero, the result
46.711 + * is positive zero.
46.712 + * <li>If the argument is infinite, the result is positive infinity.
46.713 + * <li>If the argument is NaN, the result is NaN.</ul>
46.714 + * In other words, the result is the same as the value of the expression:
46.715 + * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
46.716 + *
46.717 + * @param a the argument whose absolute value is to be determined
46.718 + * @return the absolute value of the argument.
46.719 + */
46.720 + public static double abs(double a) {
46.721 + return (a <= 0.0D) ? 0.0D - a : a;
46.722 + }
46.723 +
46.724 + /**
46.725 + * Returns the greater of two {@code int} values. That is, the
46.726 + * result is the argument closer to the value of
46.727 + * {@link Integer#MAX_VALUE}. If the arguments have the same value,
46.728 + * the result is that same value.
46.729 + *
46.730 + * @param a an argument.
46.731 + * @param b another argument.
46.732 + * @return the larger of {@code a} and {@code b}.
46.733 + */
46.734 + public static int max(int a, int b) {
46.735 + return (a >= b) ? a : b;
46.736 + }
46.737 +
46.738 + /**
46.739 + * Returns the greater of two {@code long} values. That is, the
46.740 + * result is the argument closer to the value of
46.741 + * {@link Long#MAX_VALUE}. If the arguments have the same value,
46.742 + * the result is that same value.
46.743 + *
46.744 + * @param a an argument.
46.745 + * @param b another argument.
46.746 + * @return the larger of {@code a} and {@code b}.
46.747 + */
46.748 + public static long max(long a, long b) {
46.749 + return (a >= b) ? a : b;
46.750 + }
46.751 +
46.752 + /**
46.753 + * Returns the greater of two {@code float} values. That is,
46.754 + * the result is the argument closer to positive infinity. If the
46.755 + * arguments have the same value, the result is that same
46.756 + * value. If either value is NaN, then the result is NaN. Unlike
46.757 + * the numerical comparison operators, this method considers
46.758 + * negative zero to be strictly smaller than positive zero. If one
46.759 + * argument is positive zero and the other negative zero, the
46.760 + * result is positive zero.
46.761 + *
46.762 + * @param a an argument.
46.763 + * @param b another argument.
46.764 + * @return the larger of {@code a} and {@code b}.
46.765 + */
46.766 + @JavaScriptBody(args={"a", "b"},
46.767 + body="return Math.max(a,b);"
46.768 + )
46.769 + public static float max(float a, float b) {
46.770 + throw new UnsupportedOperationException();
46.771 + }
46.772 +
46.773 + /**
46.774 + * Returns the greater of two {@code double} values. That
46.775 + * is, the result is the argument closer to positive infinity. If
46.776 + * the arguments have the same value, the result is that same
46.777 + * value. If either value is NaN, then the result is NaN. Unlike
46.778 + * the numerical comparison operators, this method considers
46.779 + * negative zero to be strictly smaller than positive zero. If one
46.780 + * argument is positive zero and the other negative zero, the
46.781 + * result is positive zero.
46.782 + *
46.783 + * @param a an argument.
46.784 + * @param b another argument.
46.785 + * @return the larger of {@code a} and {@code b}.
46.786 + */
46.787 + @JavaScriptBody(args={"a", "b"},
46.788 + body="return Math.max(a,b);"
46.789 + )
46.790 + public static double max(double a, double b) {
46.791 + throw new UnsupportedOperationException();
46.792 + }
46.793 +
46.794 + /**
46.795 + * Returns the smaller of two {@code int} values. That is,
46.796 + * the result the argument closer to the value of
46.797 + * {@link Integer#MIN_VALUE}. If the arguments have the same
46.798 + * value, the result is that same value.
46.799 + *
46.800 + * @param a an argument.
46.801 + * @param b another argument.
46.802 + * @return the smaller of {@code a} and {@code b}.
46.803 + */
46.804 + public static int min(int a, int b) {
46.805 + return (a <= b) ? a : b;
46.806 + }
46.807 +
46.808 + /**
46.809 + * Returns the smaller of two {@code long} values. That is,
46.810 + * the result is the argument closer to the value of
46.811 + * {@link Long#MIN_VALUE}. If the arguments have the same
46.812 + * value, the result is that same value.
46.813 + *
46.814 + * @param a an argument.
46.815 + * @param b another argument.
46.816 + * @return the smaller of {@code a} and {@code b}.
46.817 + */
46.818 + public static long min(long a, long b) {
46.819 + return (a <= b) ? a : b;
46.820 + }
46.821 +
46.822 + /**
46.823 + * Returns the smaller of two {@code float} values. That is,
46.824 + * the result is the value closer to negative infinity. If the
46.825 + * arguments have the same value, the result is that same
46.826 + * value. If either value is NaN, then the result is NaN. Unlike
46.827 + * the numerical comparison operators, this method considers
46.828 + * negative zero to be strictly smaller than positive zero. If
46.829 + * one argument is positive zero and the other is negative zero,
46.830 + * the result is negative zero.
46.831 + *
46.832 + * @param a an argument.
46.833 + * @param b another argument.
46.834 + * @return the smaller of {@code a} and {@code b}.
46.835 + */
46.836 + @JavaScriptBody(args={"a", "b"},
46.837 + body="return Math.min(a,b);"
46.838 + )
46.839 + public static float min(float a, float b) {
46.840 + throw new UnsupportedOperationException();
46.841 + }
46.842 +
46.843 + /**
46.844 + * Returns the smaller of two {@code double} values. That
46.845 + * is, the result is the value closer to negative infinity. If the
46.846 + * arguments have the same value, the result is that same
46.847 + * value. If either value is NaN, then the result is NaN. Unlike
46.848 + * the numerical comparison operators, this method considers
46.849 + * negative zero to be strictly smaller than positive zero. If one
46.850 + * argument is positive zero and the other is negative zero, the
46.851 + * result is negative zero.
46.852 + *
46.853 + * @param a an argument.
46.854 + * @param b another argument.
46.855 + * @return the smaller of {@code a} and {@code b}.
46.856 + */
46.857 + @JavaScriptBody(args={"a", "b"},
46.858 + body="return Math.min(a,b);"
46.859 + )
46.860 + public static double min(double a, double b) {
46.861 + throw new UnsupportedOperationException();
46.862 + }
46.863 +
46.864 + /**
46.865 + * Returns the size of an ulp of the argument. An ulp of a
46.866 + * {@code double} value is the positive distance between this
46.867 + * floating-point value and the {@code double} value next
46.868 + * larger in magnitude. Note that for non-NaN <i>x</i>,
46.869 + * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
46.870 + *
46.871 + * <p>Special Cases:
46.872 + * <ul>
46.873 + * <li> If the argument is NaN, then the result is NaN.
46.874 + * <li> If the argument is positive or negative infinity, then the
46.875 + * result is positive infinity.
46.876 + * <li> If the argument is positive or negative zero, then the result is
46.877 + * {@code Double.MIN_VALUE}.
46.878 + * <li> If the argument is ±{@code Double.MAX_VALUE}, then
46.879 + * the result is equal to 2<sup>971</sup>.
46.880 + * </ul>
46.881 + *
46.882 + * @param d the floating-point value whose ulp is to be returned
46.883 + * @return the size of an ulp of the argument
46.884 + * @author Joseph D. Darcy
46.885 + * @since 1.5
46.886 + */
46.887 +// public static double ulp(double d) {
46.888 +// return sun.misc.FpUtils.ulp(d);
46.889 +// }
46.890 +
46.891 + /**
46.892 + * Returns the size of an ulp of the argument. An ulp of a
46.893 + * {@code float} value is the positive distance between this
46.894 + * floating-point value and the {@code float} value next
46.895 + * larger in magnitude. Note that for non-NaN <i>x</i>,
46.896 + * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
46.897 + *
46.898 + * <p>Special Cases:
46.899 + * <ul>
46.900 + * <li> If the argument is NaN, then the result is NaN.
46.901 + * <li> If the argument is positive or negative infinity, then the
46.902 + * result is positive infinity.
46.903 + * <li> If the argument is positive or negative zero, then the result is
46.904 + * {@code Float.MIN_VALUE}.
46.905 + * <li> If the argument is ±{@code Float.MAX_VALUE}, then
46.906 + * the result is equal to 2<sup>104</sup>.
46.907 + * </ul>
46.908 + *
46.909 + * @param f the floating-point value whose ulp is to be returned
46.910 + * @return the size of an ulp of the argument
46.911 + * @author Joseph D. Darcy
46.912 + * @since 1.5
46.913 + */
46.914 +// public static float ulp(float f) {
46.915 +// return sun.misc.FpUtils.ulp(f);
46.916 +// }
46.917 +
46.918 + /**
46.919 + * Returns the signum function of the argument; zero if the argument
46.920 + * is zero, 1.0 if the argument is greater than zero, -1.0 if the
46.921 + * argument is less than zero.
46.922 + *
46.923 + * <p>Special Cases:
46.924 + * <ul>
46.925 + * <li> If the argument is NaN, then the result is NaN.
46.926 + * <li> If the argument is positive zero or negative zero, then the
46.927 + * result is the same as the argument.
46.928 + * </ul>
46.929 + *
46.930 + * @param d the floating-point value whose signum is to be returned
46.931 + * @return the signum function of the argument
46.932 + * @author Joseph D. Darcy
46.933 + * @since 1.5
46.934 + */
46.935 +// public static double signum(double d) {
46.936 +// return sun.misc.FpUtils.signum(d);
46.937 +// }
46.938 +
46.939 + /**
46.940 + * Returns the signum function of the argument; zero if the argument
46.941 + * is zero, 1.0f if the argument is greater than zero, -1.0f if the
46.942 + * argument is less than zero.
46.943 + *
46.944 + * <p>Special Cases:
46.945 + * <ul>
46.946 + * <li> If the argument is NaN, then the result is NaN.
46.947 + * <li> If the argument is positive zero or negative zero, then the
46.948 + * result is the same as the argument.
46.949 + * </ul>
46.950 + *
46.951 + * @param f the floating-point value whose signum is to be returned
46.952 + * @return the signum function of the argument
46.953 + * @author Joseph D. Darcy
46.954 + * @since 1.5
46.955 + */
46.956 +// public static float signum(float f) {
46.957 +// return sun.misc.FpUtils.signum(f);
46.958 +// }
46.959 +
46.960 + /**
46.961 + * Returns the first floating-point argument with the sign of the
46.962 + * second floating-point argument. Note that unlike the {@link
46.963 + * StrictMath#copySign(double, double) StrictMath.copySign}
46.964 + * method, this method does not require NaN {@code sign}
46.965 + * arguments to be treated as positive values; implementations are
46.966 + * permitted to treat some NaN arguments as positive and other NaN
46.967 + * arguments as negative to allow greater performance.
46.968 + *
46.969 + * @param magnitude the parameter providing the magnitude of the result
46.970 + * @param sign the parameter providing the sign of the result
46.971 + * @return a value with the magnitude of {@code magnitude}
46.972 + * and the sign of {@code sign}.
46.973 + * @since 1.6
46.974 + */
46.975 +// public static double copySign(double magnitude, double sign) {
46.976 +// return sun.misc.FpUtils.rawCopySign(magnitude, sign);
46.977 +// }
46.978 +
46.979 + /**
46.980 + * Returns the first floating-point argument with the sign of the
46.981 + * second floating-point argument. Note that unlike the {@link
46.982 + * StrictMath#copySign(float, float) StrictMath.copySign}
46.983 + * method, this method does not require NaN {@code sign}
46.984 + * arguments to be treated as positive values; implementations are
46.985 + * permitted to treat some NaN arguments as positive and other NaN
46.986 + * arguments as negative to allow greater performance.
46.987 + *
46.988 + * @param magnitude the parameter providing the magnitude of the result
46.989 + * @param sign the parameter providing the sign of the result
46.990 + * @return a value with the magnitude of {@code magnitude}
46.991 + * and the sign of {@code sign}.
46.992 + * @since 1.6
46.993 + */
46.994 +// public static float copySign(float magnitude, float sign) {
46.995 +// return sun.misc.FpUtils.rawCopySign(magnitude, sign);
46.996 +// }
46.997 +
46.998 + /**
46.999 + * Returns the unbiased exponent used in the representation of a
46.1000 + * {@code float}. Special cases:
46.1001 + *
46.1002 + * <ul>
46.1003 + * <li>If the argument is NaN or infinite, then the result is
46.1004 + * {@link Float#MAX_EXPONENT} + 1.
46.1005 + * <li>If the argument is zero or subnormal, then the result is
46.1006 + * {@link Float#MIN_EXPONENT} -1.
46.1007 + * </ul>
46.1008 + * @param f a {@code float} value
46.1009 + * @return the unbiased exponent of the argument
46.1010 + * @since 1.6
46.1011 + */
46.1012 +// public static int getExponent(float f) {
46.1013 +// return sun.misc.FpUtils.getExponent(f);
46.1014 +// }
46.1015 +
46.1016 + /**
46.1017 + * Returns the unbiased exponent used in the representation of a
46.1018 + * {@code double}. Special cases:
46.1019 + *
46.1020 + * <ul>
46.1021 + * <li>If the argument is NaN or infinite, then the result is
46.1022 + * {@link Double#MAX_EXPONENT} + 1.
46.1023 + * <li>If the argument is zero or subnormal, then the result is
46.1024 + * {@link Double#MIN_EXPONENT} -1.
46.1025 + * </ul>
46.1026 + * @param d a {@code double} value
46.1027 + * @return the unbiased exponent of the argument
46.1028 + * @since 1.6
46.1029 + */
46.1030 +// public static int getExponent(double d) {
46.1031 +// return sun.misc.FpUtils.getExponent(d);
46.1032 +// }
46.1033 +
46.1034 + /**
46.1035 + * Returns the floating-point number adjacent to the first
46.1036 + * argument in the direction of the second argument. If both
46.1037 + * arguments compare as equal the second argument is returned.
46.1038 + *
46.1039 + * <p>
46.1040 + * Special cases:
46.1041 + * <ul>
46.1042 + * <li> If either argument is a NaN, then NaN is returned.
46.1043 + *
46.1044 + * <li> If both arguments are signed zeros, {@code direction}
46.1045 + * is returned unchanged (as implied by the requirement of
46.1046 + * returning the second argument if the arguments compare as
46.1047 + * equal).
46.1048 + *
46.1049 + * <li> If {@code start} is
46.1050 + * ±{@link Double#MIN_VALUE} and {@code direction}
46.1051 + * has a value such that the result should have a smaller
46.1052 + * magnitude, then a zero with the same sign as {@code start}
46.1053 + * is returned.
46.1054 + *
46.1055 + * <li> If {@code start} is infinite and
46.1056 + * {@code direction} has a value such that the result should
46.1057 + * have a smaller magnitude, {@link Double#MAX_VALUE} with the
46.1058 + * same sign as {@code start} is returned.
46.1059 + *
46.1060 + * <li> If {@code start} is equal to ±
46.1061 + * {@link Double#MAX_VALUE} and {@code direction} has a
46.1062 + * value such that the result should have a larger magnitude, an
46.1063 + * infinity with same sign as {@code start} is returned.
46.1064 + * </ul>
46.1065 + *
46.1066 + * @param start starting floating-point value
46.1067 + * @param direction value indicating which of
46.1068 + * {@code start}'s neighbors or {@code start} should
46.1069 + * be returned
46.1070 + * @return The floating-point number adjacent to {@code start} in the
46.1071 + * direction of {@code direction}.
46.1072 + * @since 1.6
46.1073 + */
46.1074 +// public static double nextAfter(double start, double direction) {
46.1075 +// return sun.misc.FpUtils.nextAfter(start, direction);
46.1076 +// }
46.1077 +
46.1078 + /**
46.1079 + * Returns the floating-point number adjacent to the first
46.1080 + * argument in the direction of the second argument. If both
46.1081 + * arguments compare as equal a value equivalent to the second argument
46.1082 + * is returned.
46.1083 + *
46.1084 + * <p>
46.1085 + * Special cases:
46.1086 + * <ul>
46.1087 + * <li> If either argument is a NaN, then NaN is returned.
46.1088 + *
46.1089 + * <li> If both arguments are signed zeros, a value equivalent
46.1090 + * to {@code direction} is returned.
46.1091 + *
46.1092 + * <li> If {@code start} is
46.1093 + * ±{@link Float#MIN_VALUE} and {@code direction}
46.1094 + * has a value such that the result should have a smaller
46.1095 + * magnitude, then a zero with the same sign as {@code start}
46.1096 + * is returned.
46.1097 + *
46.1098 + * <li> If {@code start} is infinite and
46.1099 + * {@code direction} has a value such that the result should
46.1100 + * have a smaller magnitude, {@link Float#MAX_VALUE} with the
46.1101 + * same sign as {@code start} is returned.
46.1102 + *
46.1103 + * <li> If {@code start} is equal to ±
46.1104 + * {@link Float#MAX_VALUE} and {@code direction} has a
46.1105 + * value such that the result should have a larger magnitude, an
46.1106 + * infinity with same sign as {@code start} is returned.
46.1107 + * </ul>
46.1108 + *
46.1109 + * @param start starting floating-point value
46.1110 + * @param direction value indicating which of
46.1111 + * {@code start}'s neighbors or {@code start} should
46.1112 + * be returned
46.1113 + * @return The floating-point number adjacent to {@code start} in the
46.1114 + * direction of {@code direction}.
46.1115 + * @since 1.6
46.1116 + */
46.1117 +// public static float nextAfter(float start, double direction) {
46.1118 +// return sun.misc.FpUtils.nextAfter(start, direction);
46.1119 +// }
46.1120 +
46.1121 + /**
46.1122 + * Returns the floating-point value adjacent to {@code d} in
46.1123 + * the direction of positive infinity. This method is
46.1124 + * semantically equivalent to {@code nextAfter(d,
46.1125 + * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
46.1126 + * implementation may run faster than its equivalent
46.1127 + * {@code nextAfter} call.
46.1128 + *
46.1129 + * <p>Special Cases:
46.1130 + * <ul>
46.1131 + * <li> If the argument is NaN, the result is NaN.
46.1132 + *
46.1133 + * <li> If the argument is positive infinity, the result is
46.1134 + * positive infinity.
46.1135 + *
46.1136 + * <li> If the argument is zero, the result is
46.1137 + * {@link Double#MIN_VALUE}
46.1138 + *
46.1139 + * </ul>
46.1140 + *
46.1141 + * @param d starting floating-point value
46.1142 + * @return The adjacent floating-point value closer to positive
46.1143 + * infinity.
46.1144 + * @since 1.6
46.1145 + */
46.1146 +// public static double nextUp(double d) {
46.1147 +// return sun.misc.FpUtils.nextUp(d);
46.1148 +// }
46.1149 +
46.1150 + /**
46.1151 + * Returns the floating-point value adjacent to {@code f} in
46.1152 + * the direction of positive infinity. This method is
46.1153 + * semantically equivalent to {@code nextAfter(f,
46.1154 + * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
46.1155 + * implementation may run faster than its equivalent
46.1156 + * {@code nextAfter} call.
46.1157 + *
46.1158 + * <p>Special Cases:
46.1159 + * <ul>
46.1160 + * <li> If the argument is NaN, the result is NaN.
46.1161 + *
46.1162 + * <li> If the argument is positive infinity, the result is
46.1163 + * positive infinity.
46.1164 + *
46.1165 + * <li> If the argument is zero, the result is
46.1166 + * {@link Float#MIN_VALUE}
46.1167 + *
46.1168 + * </ul>
46.1169 + *
46.1170 + * @param f starting floating-point value
46.1171 + * @return The adjacent floating-point value closer to positive
46.1172 + * infinity.
46.1173 + * @since 1.6
46.1174 + */
46.1175 +// public static float nextUp(float f) {
46.1176 +// return sun.misc.FpUtils.nextUp(f);
46.1177 +// }
46.1178 +
46.1179 +
46.1180 + /**
46.1181 + * Return {@code d} ×
46.1182 + * 2<sup>{@code scaleFactor}</sup> rounded as if performed
46.1183 + * by a single correctly rounded floating-point multiply to a
46.1184 + * member of the double value set. See the Java
46.1185 + * Language Specification for a discussion of floating-point
46.1186 + * value sets. If the exponent of the result is between {@link
46.1187 + * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
46.1188 + * answer is calculated exactly. If the exponent of the result
46.1189 + * would be larger than {@code Double.MAX_EXPONENT}, an
46.1190 + * infinity is returned. Note that if the result is subnormal,
46.1191 + * precision may be lost; that is, when {@code scalb(x, n)}
46.1192 + * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
46.1193 + * <i>x</i>. When the result is non-NaN, the result has the same
46.1194 + * sign as {@code d}.
46.1195 + *
46.1196 + * <p>Special cases:
46.1197 + * <ul>
46.1198 + * <li> If the first argument is NaN, NaN is returned.
46.1199 + * <li> If the first argument is infinite, then an infinity of the
46.1200 + * same sign is returned.
46.1201 + * <li> If the first argument is zero, then a zero of the same
46.1202 + * sign is returned.
46.1203 + * </ul>
46.1204 + *
46.1205 + * @param d number to be scaled by a power of two.
46.1206 + * @param scaleFactor power of 2 used to scale {@code d}
46.1207 + * @return {@code d} × 2<sup>{@code scaleFactor}</sup>
46.1208 + * @since 1.6
46.1209 + */
46.1210 +// public static double scalb(double d, int scaleFactor) {
46.1211 +// return sun.misc.FpUtils.scalb(d, scaleFactor);
46.1212 +// }
46.1213 +
46.1214 + /**
46.1215 + * Return {@code f} ×
46.1216 + * 2<sup>{@code scaleFactor}</sup> rounded as if performed
46.1217 + * by a single correctly rounded floating-point multiply to a
46.1218 + * member of the float value set. See the Java
46.1219 + * Language Specification for a discussion of floating-point
46.1220 + * value sets. If the exponent of the result is between {@link
46.1221 + * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
46.1222 + * answer is calculated exactly. If the exponent of the result
46.1223 + * would be larger than {@code Float.MAX_EXPONENT}, an
46.1224 + * infinity is returned. Note that if the result is subnormal,
46.1225 + * precision may be lost; that is, when {@code scalb(x, n)}
46.1226 + * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
46.1227 + * <i>x</i>. When the result is non-NaN, the result has the same
46.1228 + * sign as {@code f}.
46.1229 + *
46.1230 + * <p>Special cases:
46.1231 + * <ul>
46.1232 + * <li> If the first argument is NaN, NaN is returned.
46.1233 + * <li> If the first argument is infinite, then an infinity of the
46.1234 + * same sign is returned.
46.1235 + * <li> If the first argument is zero, then a zero of the same
46.1236 + * sign is returned.
46.1237 + * </ul>
46.1238 + *
46.1239 + * @param f number to be scaled by a power of two.
46.1240 + * @param scaleFactor power of 2 used to scale {@code f}
46.1241 + * @return {@code f} × 2<sup>{@code scaleFactor}</sup>
46.1242 + * @since 1.6
46.1243 + */
46.1244 +// public static float scalb(float f, int scaleFactor) {
46.1245 +// return sun.misc.FpUtils.scalb(f, scaleFactor);
46.1246 +// }
46.1247 +}
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
47.2 +++ b/emul/mini/src/main/java/java/lang/NegativeArraySizeException.java Wed Jan 23 20:39:23 2013 +0100
47.3 @@ -0,0 +1,55 @@
47.4 +/*
47.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
47.7 + *
47.8 + * This code is free software; you can redistribute it and/or modify it
47.9 + * under the terms of the GNU General Public License version 2 only, as
47.10 + * published by the Free Software Foundation. Oracle designates this
47.11 + * particular file as subject to the "Classpath" exception as provided
47.12 + * by Oracle in the LICENSE file that accompanied this code.
47.13 + *
47.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
47.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
47.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
47.17 + * version 2 for more details (a copy is included in the LICENSE file that
47.18 + * accompanied this code).
47.19 + *
47.20 + * You should have received a copy of the GNU General Public License version
47.21 + * 2 along with this work; if not, write to the Free Software Foundation,
47.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
47.23 + *
47.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
47.25 + * or visit www.oracle.com if you need additional information or have any
47.26 + * questions.
47.27 + */
47.28 +
47.29 +package java.lang;
47.30 +
47.31 +/**
47.32 + * Thrown if an application tries to create an array with negative size.
47.33 + *
47.34 + * @author unascribed
47.35 + * @since JDK1.0
47.36 + */
47.37 +public
47.38 +class NegativeArraySizeException extends RuntimeException {
47.39 + private static final long serialVersionUID = -8960118058596991861L;
47.40 +
47.41 + /**
47.42 + * Constructs a <code>NegativeArraySizeException</code> with no
47.43 + * detail message.
47.44 + */
47.45 + public NegativeArraySizeException() {
47.46 + super();
47.47 + }
47.48 +
47.49 + /**
47.50 + * Constructs a <code>NegativeArraySizeException</code> with the
47.51 + * specified detail message.
47.52 + *
47.53 + * @param s the detail message.
47.54 + */
47.55 + public NegativeArraySizeException(String s) {
47.56 + super(s);
47.57 + }
47.58 +}
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
48.2 +++ b/emul/mini/src/main/java/java/lang/NoSuchMethodException.java Wed Jan 23 20:39:23 2013 +0100
48.3 @@ -0,0 +1,53 @@
48.4 +/*
48.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
48.7 + *
48.8 + * This code is free software; you can redistribute it and/or modify it
48.9 + * under the terms of the GNU General Public License version 2 only, as
48.10 + * published by the Free Software Foundation. Oracle designates this
48.11 + * particular file as subject to the "Classpath" exception as provided
48.12 + * by Oracle in the LICENSE file that accompanied this code.
48.13 + *
48.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
48.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
48.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
48.17 + * version 2 for more details (a copy is included in the LICENSE file that
48.18 + * accompanied this code).
48.19 + *
48.20 + * You should have received a copy of the GNU General Public License version
48.21 + * 2 along with this work; if not, write to the Free Software Foundation,
48.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
48.23 + *
48.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
48.25 + * or visit www.oracle.com if you need additional information or have any
48.26 + * questions.
48.27 + */
48.28 +
48.29 +package java.lang;
48.30 +
48.31 +/**
48.32 + * Thrown when a particular method cannot be found.
48.33 + *
48.34 + * @author unascribed
48.35 + * @since JDK1.0
48.36 + */
48.37 +public
48.38 +class NoSuchMethodException extends ReflectiveOperationException {
48.39 + private static final long serialVersionUID = 5034388446362600923L;
48.40 +
48.41 + /**
48.42 + * Constructs a <code>NoSuchMethodException</code> without a detail message.
48.43 + */
48.44 + public NoSuchMethodException() {
48.45 + super();
48.46 + }
48.47 +
48.48 + /**
48.49 + * Constructs a <code>NoSuchMethodException</code> with a detail message.
48.50 + *
48.51 + * @param s the detail message.
48.52 + */
48.53 + public NoSuchMethodException(String s) {
48.54 + super(s);
48.55 + }
48.56 +}
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
49.2 +++ b/emul/mini/src/main/java/java/lang/NullPointerException.java Wed Jan 23 20:39:23 2013 +0100
49.3 @@ -0,0 +1,72 @@
49.4 +/*
49.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
49.7 + *
49.8 + * This code is free software; you can redistribute it and/or modify it
49.9 + * under the terms of the GNU General Public License version 2 only, as
49.10 + * published by the Free Software Foundation. Oracle designates this
49.11 + * particular file as subject to the "Classpath" exception as provided
49.12 + * by Oracle in the LICENSE file that accompanied this code.
49.13 + *
49.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
49.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
49.17 + * version 2 for more details (a copy is included in the LICENSE file that
49.18 + * accompanied this code).
49.19 + *
49.20 + * You should have received a copy of the GNU General Public License version
49.21 + * 2 along with this work; if not, write to the Free Software Foundation,
49.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
49.23 + *
49.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
49.25 + * or visit www.oracle.com if you need additional information or have any
49.26 + * questions.
49.27 + */
49.28 +
49.29 +package java.lang;
49.30 +
49.31 +/**
49.32 + * Thrown when an application attempts to use {@code null} in a
49.33 + * case where an object is required. These include:
49.34 + * <ul>
49.35 + * <li>Calling the instance method of a {@code null} object.
49.36 + * <li>Accessing or modifying the field of a {@code null} object.
49.37 + * <li>Taking the length of {@code null} as if it were an array.
49.38 + * <li>Accessing or modifying the slots of {@code null} as if it
49.39 + * were an array.
49.40 + * <li>Throwing {@code null} as if it were a {@code Throwable}
49.41 + * value.
49.42 + * </ul>
49.43 + * <p>
49.44 + * Applications should throw instances of this class to indicate
49.45 + * other illegal uses of the {@code null} object.
49.46 + *
49.47 + * {@code NullPointerException} objects may be constructed by the
49.48 + * virtual machine as if {@linkplain Throwable#Throwable(String,
49.49 + * Throwable, boolean, boolean) suppression were disabled and/or the
49.50 + * stack trace was not writable}.
49.51 + *
49.52 + * @author unascribed
49.53 + * @since JDK1.0
49.54 + */
49.55 +public
49.56 +class NullPointerException extends RuntimeException {
49.57 + private static final long serialVersionUID = 5162710183389028792L;
49.58 +
49.59 + /**
49.60 + * Constructs a {@code NullPointerException} with no detail message.
49.61 + */
49.62 + public NullPointerException() {
49.63 + super();
49.64 + }
49.65 +
49.66 + /**
49.67 + * Constructs a {@code NullPointerException} with the specified
49.68 + * detail message.
49.69 + *
49.70 + * @param s the detail message.
49.71 + */
49.72 + public NullPointerException(String s) {
49.73 + super(s);
49.74 + }
49.75 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
50.2 +++ b/emul/mini/src/main/java/java/lang/Number.java Wed Jan 23 20:39:23 2013 +0100
50.3 @@ -0,0 +1,118 @@
50.4 +/*
50.5 + * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
50.7 + *
50.8 + * This code is free software; you can redistribute it and/or modify it
50.9 + * under the terms of the GNU General Public License version 2 only, as
50.10 + * published by the Free Software Foundation. Oracle designates this
50.11 + * particular file as subject to the "Classpath" exception as provided
50.12 + * by Oracle in the LICENSE file that accompanied this code.
50.13 + *
50.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
50.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
50.17 + * version 2 for more details (a copy is included in the LICENSE file that
50.18 + * accompanied this code).
50.19 + *
50.20 + * You should have received a copy of the GNU General Public License version
50.21 + * 2 along with this work; if not, write to the Free Software Foundation,
50.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
50.23 + *
50.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
50.25 + * or visit www.oracle.com if you need additional information or have any
50.26 + * questions.
50.27 + */
50.28 +
50.29 +package java.lang;
50.30 +
50.31 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
50.32 +
50.33 +/**
50.34 + * The abstract class <code>Number</code> is the superclass of classes
50.35 + * <code>BigDecimal</code>, <code>BigInteger</code>,
50.36 + * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
50.37 + * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
50.38 + * <p>
50.39 + * Subclasses of <code>Number</code> must provide methods to convert
50.40 + * the represented numeric value to <code>byte</code>, <code>double</code>,
50.41 + * <code>float</code>, <code>int</code>, <code>long</code>, and
50.42 + * <code>short</code>.
50.43 + *
50.44 + * @author Lee Boynton
50.45 + * @author Arthur van Hoff
50.46 + * @see java.lang.Byte
50.47 + * @see java.lang.Double
50.48 + * @see java.lang.Float
50.49 + * @see java.lang.Integer
50.50 + * @see java.lang.Long
50.51 + * @see java.lang.Short
50.52 + * @since JDK1.0
50.53 + */
50.54 +@ExtraJavaScript(
50.55 + resource="/org/apidesign/vm4brwsr/emul/java_lang_Number.js",
50.56 + processByteCode=true
50.57 +)
50.58 +public abstract class Number implements java.io.Serializable {
50.59 + /**
50.60 + * Returns the value of the specified number as an <code>int</code>.
50.61 + * This may involve rounding or truncation.
50.62 + *
50.63 + * @return the numeric value represented by this object after conversion
50.64 + * to type <code>int</code>.
50.65 + */
50.66 + public abstract int intValue();
50.67 +
50.68 + /**
50.69 + * Returns the value of the specified number as a <code>long</code>.
50.70 + * This may involve rounding or truncation.
50.71 + *
50.72 + * @return the numeric value represented by this object after conversion
50.73 + * to type <code>long</code>.
50.74 + */
50.75 + public abstract long longValue();
50.76 +
50.77 + /**
50.78 + * Returns the value of the specified number as a <code>float</code>.
50.79 + * This may involve rounding.
50.80 + *
50.81 + * @return the numeric value represented by this object after conversion
50.82 + * to type <code>float</code>.
50.83 + */
50.84 + public abstract float floatValue();
50.85 +
50.86 + /**
50.87 + * Returns the value of the specified number as a <code>double</code>.
50.88 + * This may involve rounding.
50.89 + *
50.90 + * @return the numeric value represented by this object after conversion
50.91 + * to type <code>double</code>.
50.92 + */
50.93 + public abstract double doubleValue();
50.94 +
50.95 + /**
50.96 + * Returns the value of the specified number as a <code>byte</code>.
50.97 + * This may involve rounding or truncation.
50.98 + *
50.99 + * @return the numeric value represented by this object after conversion
50.100 + * to type <code>byte</code>.
50.101 + * @since JDK1.1
50.102 + */
50.103 + public byte byteValue() {
50.104 + return (byte)intValue();
50.105 + }
50.106 +
50.107 + /**
50.108 + * Returns the value of the specified number as a <code>short</code>.
50.109 + * This may involve rounding or truncation.
50.110 + *
50.111 + * @return the numeric value represented by this object after conversion
50.112 + * to type <code>short</code>.
50.113 + * @since JDK1.1
50.114 + */
50.115 + public short shortValue() {
50.116 + return (short)intValue();
50.117 + }
50.118 +
50.119 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
50.120 + private static final long serialVersionUID = -8742448824652078965L;
50.121 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
51.2 +++ b/emul/mini/src/main/java/java/lang/NumberFormatException.java Wed Jan 23 20:39:23 2013 +0100
51.3 @@ -0,0 +1,67 @@
51.4 +/*
51.5 + * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
51.7 + *
51.8 + * This code is free software; you can redistribute it and/or modify it
51.9 + * under the terms of the GNU General Public License version 2 only, as
51.10 + * published by the Free Software Foundation. Oracle designates this
51.11 + * particular file as subject to the "Classpath" exception as provided
51.12 + * by Oracle in the LICENSE file that accompanied this code.
51.13 + *
51.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
51.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
51.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51.17 + * version 2 for more details (a copy is included in the LICENSE file that
51.18 + * accompanied this code).
51.19 + *
51.20 + * You should have received a copy of the GNU General Public License version
51.21 + * 2 along with this work; if not, write to the Free Software Foundation,
51.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
51.23 + *
51.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
51.25 + * or visit www.oracle.com if you need additional information or have any
51.26 + * questions.
51.27 + */
51.28 +
51.29 +package java.lang;
51.30 +
51.31 +/**
51.32 + * Thrown to indicate that the application has attempted to convert
51.33 + * a string to one of the numeric types, but that the string does not
51.34 + * have the appropriate format.
51.35 + *
51.36 + * @author unascribed
51.37 + * @see java.lang.Integer#toString()
51.38 + * @since JDK1.0
51.39 + */
51.40 +public
51.41 +class NumberFormatException extends IllegalArgumentException {
51.42 + static final long serialVersionUID = -2848938806368998894L;
51.43 +
51.44 + /**
51.45 + * Constructs a <code>NumberFormatException</code> with no detail message.
51.46 + */
51.47 + public NumberFormatException () {
51.48 + super();
51.49 + }
51.50 +
51.51 + /**
51.52 + * Constructs a <code>NumberFormatException</code> with the
51.53 + * specified detail message.
51.54 + *
51.55 + * @param s the detail message.
51.56 + */
51.57 + public NumberFormatException (String s) {
51.58 + super (s);
51.59 + }
51.60 +
51.61 + /**
51.62 + * Factory method for making a <code>NumberFormatException</code>
51.63 + * given the specified input which caused the error.
51.64 + *
51.65 + * @param s the input causing the error
51.66 + */
51.67 + static NumberFormatException forInputString(String s) {
51.68 + return new NumberFormatException("For input string: \"" + s + "\"");
51.69 + }
51.70 +}
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
52.2 +++ b/emul/mini/src/main/java/java/lang/Object.java Wed Jan 23 20:39:23 2013 +0100
52.3 @@ -0,0 +1,595 @@
52.4 +/*
52.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
52.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
52.7 + *
52.8 + * This code is free software; you can redistribute it and/or modify it
52.9 + * under the terms of the GNU General Public License version 2 only, as
52.10 + * published by the Free Software Foundation. Oracle designates this
52.11 + * particular file as subject to the "Classpath" exception as provided
52.12 + * by Oracle in the LICENSE file that accompanied this code.
52.13 + *
52.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
52.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
52.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
52.17 + * version 2 for more details (a copy is included in the LICENSE file that
52.18 + * accompanied this code).
52.19 + *
52.20 + * You should have received a copy of the GNU General Public License version
52.21 + * 2 along with this work; if not, write to the Free Software Foundation,
52.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
52.23 + *
52.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
52.25 + * or visit www.oracle.com if you need additional information or have any
52.26 + * questions.
52.27 + */
52.28 +
52.29 +package java.lang;
52.30 +
52.31 +import java.lang.reflect.Array;
52.32 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
52.33 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
52.34 +
52.35 +/**
52.36 + * Class {@code Object} is the root of the class hierarchy.
52.37 + * Every class has {@code Object} as a superclass. All objects,
52.38 + * including arrays, implement the methods of this class.
52.39 + *
52.40 + * @author unascribed
52.41 + * @see java.lang.Class
52.42 + * @since JDK1.0
52.43 + */
52.44 +@JavaScriptPrototype(container = "Object.prototype", prototype = "new Object")
52.45 +public class Object {
52.46 +
52.47 + private static void registerNatives() {
52.48 + try {
52.49 + Array.get(null, 0);
52.50 + } catch (Throwable ex) {
52.51 + // ignore
52.52 + }
52.53 + }
52.54 + static {
52.55 + registerNatives();
52.56 + }
52.57 +
52.58 + /**
52.59 + * Returns the runtime class of this {@code Object}. The returned
52.60 + * {@code Class} object is the object that is locked by {@code
52.61 + * static synchronized} methods of the represented class.
52.62 + *
52.63 + * <p><b>The actual result type is {@code Class<? extends |X|>}
52.64 + * where {@code |X|} is the erasure of the static type of the
52.65 + * expression on which {@code getClass} is called.</b> For
52.66 + * example, no cast is required in this code fragment:</p>
52.67 + *
52.68 + * <p>
52.69 + * {@code Number n = 0; }<br>
52.70 + * {@code Class<? extends Number> c = n.getClass(); }
52.71 + * </p>
52.72 + *
52.73 + * @return The {@code Class} object that represents the runtime
52.74 + * class of this object.
52.75 + * @see Class Literals, section 15.8.2 of
52.76 + * <cite>The Java™ Language Specification</cite>.
52.77 + */
52.78 + @JavaScriptBody(args={}, body="return this.constructor.$class;")
52.79 + public final native Class<?> getClass();
52.80 +
52.81 + /**
52.82 + * Returns a hash code value for the object. This method is
52.83 + * supported for the benefit of hash tables such as those provided by
52.84 + * {@link java.util.HashMap}.
52.85 + * <p>
52.86 + * The general contract of {@code hashCode} is:
52.87 + * <ul>
52.88 + * <li>Whenever it is invoked on the same object more than once during
52.89 + * an execution of a Java application, the {@code hashCode} method
52.90 + * must consistently return the same integer, provided no information
52.91 + * used in {@code equals} comparisons on the object is modified.
52.92 + * This integer need not remain consistent from one execution of an
52.93 + * application to another execution of the same application.
52.94 + * <li>If two objects are equal according to the {@code equals(Object)}
52.95 + * method, then calling the {@code hashCode} method on each of
52.96 + * the two objects must produce the same integer result.
52.97 + * <li>It is <em>not</em> required that if two objects are unequal
52.98 + * according to the {@link java.lang.Object#equals(java.lang.Object)}
52.99 + * method, then calling the {@code hashCode} method on each of the
52.100 + * two objects must produce distinct integer results. However, the
52.101 + * programmer should be aware that producing distinct integer results
52.102 + * for unequal objects may improve the performance of hash tables.
52.103 + * </ul>
52.104 + * <p>
52.105 + * As much as is reasonably practical, the hashCode method defined by
52.106 + * class {@code Object} does return distinct integers for distinct
52.107 + * objects. (This is typically implemented by converting the internal
52.108 + * address of the object into an integer, but this implementation
52.109 + * technique is not required by the
52.110 + * Java<font size="-2"><sup>TM</sup></font> programming language.)
52.111 + *
52.112 + * @return a hash code value for this object.
52.113 + * @see java.lang.Object#equals(java.lang.Object)
52.114 + * @see java.lang.System#identityHashCode
52.115 + */
52.116 + @JavaScriptBody(args = {}, body =
52.117 + "if (this.$hashCode) return this.$hashCode;\n"
52.118 + + "var h = this.computeHashCode__I();\n"
52.119 + + "return this.$hashCode = h & h;"
52.120 + )
52.121 + public native int hashCode();
52.122 +
52.123 + @JavaScriptBody(args = {}, body = "Math.random() * Math.pow(2, 32);")
52.124 + native int computeHashCode();
52.125 +
52.126 + /**
52.127 + * Indicates whether some other object is "equal to" this one.
52.128 + * <p>
52.129 + * The {@code equals} method implements an equivalence relation
52.130 + * on non-null object references:
52.131 + * <ul>
52.132 + * <li>It is <i>reflexive</i>: for any non-null reference value
52.133 + * {@code x}, {@code x.equals(x)} should return
52.134 + * {@code true}.
52.135 + * <li>It is <i>symmetric</i>: for any non-null reference values
52.136 + * {@code x} and {@code y}, {@code x.equals(y)}
52.137 + * should return {@code true} if and only if
52.138 + * {@code y.equals(x)} returns {@code true}.
52.139 + * <li>It is <i>transitive</i>: for any non-null reference values
52.140 + * {@code x}, {@code y}, and {@code z}, if
52.141 + * {@code x.equals(y)} returns {@code true} and
52.142 + * {@code y.equals(z)} returns {@code true}, then
52.143 + * {@code x.equals(z)} should return {@code true}.
52.144 + * <li>It is <i>consistent</i>: for any non-null reference values
52.145 + * {@code x} and {@code y}, multiple invocations of
52.146 + * {@code x.equals(y)} consistently return {@code true}
52.147 + * or consistently return {@code false}, provided no
52.148 + * information used in {@code equals} comparisons on the
52.149 + * objects is modified.
52.150 + * <li>For any non-null reference value {@code x},
52.151 + * {@code x.equals(null)} should return {@code false}.
52.152 + * </ul>
52.153 + * <p>
52.154 + * The {@code equals} method for class {@code Object} implements
52.155 + * the most discriminating possible equivalence relation on objects;
52.156 + * that is, for any non-null reference values {@code x} and
52.157 + * {@code y}, this method returns {@code true} if and only
52.158 + * if {@code x} and {@code y} refer to the same object
52.159 + * ({@code x == y} has the value {@code true}).
52.160 + * <p>
52.161 + * Note that it is generally necessary to override the {@code hashCode}
52.162 + * method whenever this method is overridden, so as to maintain the
52.163 + * general contract for the {@code hashCode} method, which states
52.164 + * that equal objects must have equal hash codes.
52.165 + *
52.166 + * @param obj the reference object with which to compare.
52.167 + * @return {@code true} if this object is the same as the obj
52.168 + * argument; {@code false} otherwise.
52.169 + * @see #hashCode()
52.170 + * @see java.util.HashMap
52.171 + */
52.172 + public boolean equals(Object obj) {
52.173 + return (this == obj);
52.174 + }
52.175 +
52.176 + /**
52.177 + * Creates and returns a copy of this object. The precise meaning
52.178 + * of "copy" may depend on the class of the object. The general
52.179 + * intent is that, for any object {@code x}, the expression:
52.180 + * <blockquote>
52.181 + * <pre>
52.182 + * x.clone() != x</pre></blockquote>
52.183 + * will be true, and that the expression:
52.184 + * <blockquote>
52.185 + * <pre>
52.186 + * x.clone().getClass() == x.getClass()</pre></blockquote>
52.187 + * will be {@code true}, but these are not absolute requirements.
52.188 + * While it is typically the case that:
52.189 + * <blockquote>
52.190 + * <pre>
52.191 + * x.clone().equals(x)</pre></blockquote>
52.192 + * will be {@code true}, this is not an absolute requirement.
52.193 + * <p>
52.194 + * By convention, the returned object should be obtained by calling
52.195 + * {@code super.clone}. If a class and all of its superclasses (except
52.196 + * {@code Object}) obey this convention, it will be the case that
52.197 + * {@code x.clone().getClass() == x.getClass()}.
52.198 + * <p>
52.199 + * By convention, the object returned by this method should be independent
52.200 + * of this object (which is being cloned). To achieve this independence,
52.201 + * it may be necessary to modify one or more fields of the object returned
52.202 + * by {@code super.clone} before returning it. Typically, this means
52.203 + * copying any mutable objects that comprise the internal "deep structure"
52.204 + * of the object being cloned and replacing the references to these
52.205 + * objects with references to the copies. If a class contains only
52.206 + * primitive fields or references to immutable objects, then it is usually
52.207 + * the case that no fields in the object returned by {@code super.clone}
52.208 + * need to be modified.
52.209 + * <p>
52.210 + * The method {@code clone} for class {@code Object} performs a
52.211 + * specific cloning operation. First, if the class of this object does
52.212 + * not implement the interface {@code Cloneable}, then a
52.213 + * {@code CloneNotSupportedException} is thrown. Note that all arrays
52.214 + * are considered to implement the interface {@code Cloneable} and that
52.215 + * the return type of the {@code clone} method of an array type {@code T[]}
52.216 + * is {@code T[]} where T is any reference or primitive type.
52.217 + * Otherwise, this method creates a new instance of the class of this
52.218 + * object and initializes all its fields with exactly the contents of
52.219 + * the corresponding fields of this object, as if by assignment; the
52.220 + * contents of the fields are not themselves cloned. Thus, this method
52.221 + * performs a "shallow copy" of this object, not a "deep copy" operation.
52.222 + * <p>
52.223 + * The class {@code Object} does not itself implement the interface
52.224 + * {@code Cloneable}, so calling the {@code clone} method on an object
52.225 + * whose class is {@code Object} will result in throwing an
52.226 + * exception at run time.
52.227 + *
52.228 + * @return a clone of this instance.
52.229 + * @exception CloneNotSupportedException if the object's class does not
52.230 + * support the {@code Cloneable} interface. Subclasses
52.231 + * that override the {@code clone} method can also
52.232 + * throw this exception to indicate that an instance cannot
52.233 + * be cloned.
52.234 + * @see java.lang.Cloneable
52.235 + */
52.236 + protected Object clone() throws CloneNotSupportedException {
52.237 + Object ret = clone(this);
52.238 + if (ret == null) {
52.239 + throw new CloneNotSupportedException(getClass().getName());
52.240 + }
52.241 + return ret;
52.242 + }
52.243 +
52.244 + @JavaScriptBody(args = "self", body =
52.245 + "\nif (!self.$instOf_java_lang_Cloneable) {"
52.246 + + "\n return null;"
52.247 + + "\n} else {"
52.248 + + "\n var clone = self.constructor(true);"
52.249 + + "\n var props = Object.getOwnPropertyNames(self);"
52.250 + + "\n for (var i = 0; i < props.length; i++) {"
52.251 + + "\n var p = props[i];"
52.252 + + "\n clone[p] = self[p];"
52.253 + + "\n };"
52.254 + + "\n return clone;"
52.255 + + "\n}"
52.256 + )
52.257 + private static native Object clone(Object self) throws CloneNotSupportedException;
52.258 +
52.259 + /**
52.260 + * Returns a string representation of the object. In general, the
52.261 + * {@code toString} method returns a string that
52.262 + * "textually represents" this object. The result should
52.263 + * be a concise but informative representation that is easy for a
52.264 + * person to read.
52.265 + * It is recommended that all subclasses override this method.
52.266 + * <p>
52.267 + * The {@code toString} method for class {@code Object}
52.268 + * returns a string consisting of the name of the class of which the
52.269 + * object is an instance, the at-sign character `{@code @}', and
52.270 + * the unsigned hexadecimal representation of the hash code of the
52.271 + * object. In other words, this method returns a string equal to the
52.272 + * value of:
52.273 + * <blockquote>
52.274 + * <pre>
52.275 + * getClass().getName() + '@' + Integer.toHexString(hashCode())
52.276 + * </pre></blockquote>
52.277 + *
52.278 + * @return a string representation of the object.
52.279 + */
52.280 + public String toString() {
52.281 + return getClass().getName() + "@" + Integer.toHexString(hashCode());
52.282 + }
52.283 +
52.284 + /**
52.285 + * Wakes up a single thread that is waiting on this object's
52.286 + * monitor. If any threads are waiting on this object, one of them
52.287 + * is chosen to be awakened. The choice is arbitrary and occurs at
52.288 + * the discretion of the implementation. A thread waits on an object's
52.289 + * monitor by calling one of the {@code wait} methods.
52.290 + * <p>
52.291 + * The awakened thread will not be able to proceed until the current
52.292 + * thread relinquishes the lock on this object. The awakened thread will
52.293 + * compete in the usual manner with any other threads that might be
52.294 + * actively competing to synchronize on this object; for example, the
52.295 + * awakened thread enjoys no reliable privilege or disadvantage in being
52.296 + * the next thread to lock this object.
52.297 + * <p>
52.298 + * This method should only be called by a thread that is the owner
52.299 + * of this object's monitor. A thread becomes the owner of the
52.300 + * object's monitor in one of three ways:
52.301 + * <ul>
52.302 + * <li>By executing a synchronized instance method of that object.
52.303 + * <li>By executing the body of a {@code synchronized} statement
52.304 + * that synchronizes on the object.
52.305 + * <li>For objects of type {@code Class,} by executing a
52.306 + * synchronized static method of that class.
52.307 + * </ul>
52.308 + * <p>
52.309 + * Only one thread at a time can own an object's monitor.
52.310 + *
52.311 + * @exception IllegalMonitorStateException if the current thread is not
52.312 + * the owner of this object's monitor.
52.313 + * @see java.lang.Object#notifyAll()
52.314 + * @see java.lang.Object#wait()
52.315 + */
52.316 + public final native void notify();
52.317 +
52.318 + /**
52.319 + * Wakes up all threads that are waiting on this object's monitor. A
52.320 + * thread waits on an object's monitor by calling one of the
52.321 + * {@code wait} methods.
52.322 + * <p>
52.323 + * The awakened threads will not be able to proceed until the current
52.324 + * thread relinquishes the lock on this object. The awakened threads
52.325 + * will compete in the usual manner with any other threads that might
52.326 + * be actively competing to synchronize on this object; for example,
52.327 + * the awakened threads enjoy no reliable privilege or disadvantage in
52.328 + * being the next thread to lock this object.
52.329 + * <p>
52.330 + * This method should only be called by a thread that is the owner
52.331 + * of this object's monitor. See the {@code notify} method for a
52.332 + * description of the ways in which a thread can become the owner of
52.333 + * a monitor.
52.334 + *
52.335 + * @exception IllegalMonitorStateException if the current thread is not
52.336 + * the owner of this object's monitor.
52.337 + * @see java.lang.Object#notify()
52.338 + * @see java.lang.Object#wait()
52.339 + */
52.340 + public final native void notifyAll();
52.341 +
52.342 + /**
52.343 + * Causes the current thread to wait until either another thread invokes the
52.344 + * {@link java.lang.Object#notify()} method or the
52.345 + * {@link java.lang.Object#notifyAll()} method for this object, or a
52.346 + * specified amount of time has elapsed.
52.347 + * <p>
52.348 + * The current thread must own this object's monitor.
52.349 + * <p>
52.350 + * This method causes the current thread (call it <var>T</var>) to
52.351 + * place itself in the wait set for this object and then to relinquish
52.352 + * any and all synchronization claims on this object. Thread <var>T</var>
52.353 + * becomes disabled for thread scheduling purposes and lies dormant
52.354 + * until one of four things happens:
52.355 + * <ul>
52.356 + * <li>Some other thread invokes the {@code notify} method for this
52.357 + * object and thread <var>T</var> happens to be arbitrarily chosen as
52.358 + * the thread to be awakened.
52.359 + * <li>Some other thread invokes the {@code notifyAll} method for this
52.360 + * object.
52.361 + * <li>Some other thread {@linkplain Thread#interrupt() interrupts}
52.362 + * thread <var>T</var>.
52.363 + * <li>The specified amount of real time has elapsed, more or less. If
52.364 + * {@code timeout} is zero, however, then real time is not taken into
52.365 + * consideration and the thread simply waits until notified.
52.366 + * </ul>
52.367 + * The thread <var>T</var> is then removed from the wait set for this
52.368 + * object and re-enabled for thread scheduling. It then competes in the
52.369 + * usual manner with other threads for the right to synchronize on the
52.370 + * object; once it has gained control of the object, all its
52.371 + * synchronization claims on the object are restored to the status quo
52.372 + * ante - that is, to the situation as of the time that the {@code wait}
52.373 + * method was invoked. Thread <var>T</var> then returns from the
52.374 + * invocation of the {@code wait} method. Thus, on return from the
52.375 + * {@code wait} method, the synchronization state of the object and of
52.376 + * thread {@code T} is exactly as it was when the {@code wait} method
52.377 + * was invoked.
52.378 + * <p>
52.379 + * A thread can also wake up without being notified, interrupted, or
52.380 + * timing out, a so-called <i>spurious wakeup</i>. While this will rarely
52.381 + * occur in practice, applications must guard against it by testing for
52.382 + * the condition that should have caused the thread to be awakened, and
52.383 + * continuing to wait if the condition is not satisfied. In other words,
52.384 + * waits should always occur in loops, like this one:
52.385 + * <pre>
52.386 + * synchronized (obj) {
52.387 + * while (<condition does not hold>)
52.388 + * obj.wait(timeout);
52.389 + * ... // Perform action appropriate to condition
52.390 + * }
52.391 + * </pre>
52.392 + * (For more information on this topic, see Section 3.2.3 in Doug Lea's
52.393 + * "Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
52.394 + * 2000), or Item 50 in Joshua Bloch's "Effective Java Programming
52.395 + * Language Guide" (Addison-Wesley, 2001).
52.396 + *
52.397 + * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
52.398 + * interrupted} by any thread before or while it is waiting, then an
52.399 + * {@code InterruptedException} is thrown. This exception is not
52.400 + * thrown until the lock status of this object has been restored as
52.401 + * described above.
52.402 + *
52.403 + * <p>
52.404 + * Note that the {@code wait} method, as it places the current thread
52.405 + * into the wait set for this object, unlocks only this object; any
52.406 + * other objects on which the current thread may be synchronized remain
52.407 + * locked while the thread waits.
52.408 + * <p>
52.409 + * This method should only be called by a thread that is the owner
52.410 + * of this object's monitor. See the {@code notify} method for a
52.411 + * description of the ways in which a thread can become the owner of
52.412 + * a monitor.
52.413 + *
52.414 + * @param timeout the maximum time to wait in milliseconds.
52.415 + * @exception IllegalArgumentException if the value of timeout is
52.416 + * negative.
52.417 + * @exception IllegalMonitorStateException if the current thread is not
52.418 + * the owner of the object's monitor.
52.419 + * @exception InterruptedException if any thread interrupted the
52.420 + * current thread before or while the current thread
52.421 + * was waiting for a notification. The <i>interrupted
52.422 + * status</i> of the current thread is cleared when
52.423 + * this exception is thrown.
52.424 + * @see java.lang.Object#notify()
52.425 + * @see java.lang.Object#notifyAll()
52.426 + */
52.427 + public final native void wait(long timeout) throws InterruptedException;
52.428 +
52.429 + /**
52.430 + * Causes the current thread to wait until another thread invokes the
52.431 + * {@link java.lang.Object#notify()} method or the
52.432 + * {@link java.lang.Object#notifyAll()} method for this object, or
52.433 + * some other thread interrupts the current thread, or a certain
52.434 + * amount of real time has elapsed.
52.435 + * <p>
52.436 + * This method is similar to the {@code wait} method of one
52.437 + * argument, but it allows finer control over the amount of time to
52.438 + * wait for a notification before giving up. The amount of real time,
52.439 + * measured in nanoseconds, is given by:
52.440 + * <blockquote>
52.441 + * <pre>
52.442 + * 1000000*timeout+nanos</pre></blockquote>
52.443 + * <p>
52.444 + * In all other respects, this method does the same thing as the
52.445 + * method {@link #wait(long)} of one argument. In particular,
52.446 + * {@code wait(0, 0)} means the same thing as {@code wait(0)}.
52.447 + * <p>
52.448 + * The current thread must own this object's monitor. The thread
52.449 + * releases ownership of this monitor and waits until either of the
52.450 + * following two conditions has occurred:
52.451 + * <ul>
52.452 + * <li>Another thread notifies threads waiting on this object's monitor
52.453 + * to wake up either through a call to the {@code notify} method
52.454 + * or the {@code notifyAll} method.
52.455 + * <li>The timeout period, specified by {@code timeout}
52.456 + * milliseconds plus {@code nanos} nanoseconds arguments, has
52.457 + * elapsed.
52.458 + * </ul>
52.459 + * <p>
52.460 + * The thread then waits until it can re-obtain ownership of the
52.461 + * monitor and resumes execution.
52.462 + * <p>
52.463 + * As in the one argument version, interrupts and spurious wakeups are
52.464 + * possible, and this method should always be used in a loop:
52.465 + * <pre>
52.466 + * synchronized (obj) {
52.467 + * while (<condition does not hold>)
52.468 + * obj.wait(timeout, nanos);
52.469 + * ... // Perform action appropriate to condition
52.470 + * }
52.471 + * </pre>
52.472 + * This method should only be called by a thread that is the owner
52.473 + * of this object's monitor. See the {@code notify} method for a
52.474 + * description of the ways in which a thread can become the owner of
52.475 + * a monitor.
52.476 + *
52.477 + * @param timeout the maximum time to wait in milliseconds.
52.478 + * @param nanos additional time, in nanoseconds range
52.479 + * 0-999999.
52.480 + * @exception IllegalArgumentException if the value of timeout is
52.481 + * negative or the value of nanos is
52.482 + * not in the range 0-999999.
52.483 + * @exception IllegalMonitorStateException if the current thread is not
52.484 + * the owner of this object's monitor.
52.485 + * @exception InterruptedException if any thread interrupted the
52.486 + * current thread before or while the current thread
52.487 + * was waiting for a notification. The <i>interrupted
52.488 + * status</i> of the current thread is cleared when
52.489 + * this exception is thrown.
52.490 + */
52.491 + public final void wait(long timeout, int nanos) throws InterruptedException {
52.492 + if (timeout < 0) {
52.493 + throw new IllegalArgumentException("timeout value is negative");
52.494 + }
52.495 +
52.496 + if (nanos < 0 || nanos > 999999) {
52.497 + throw new IllegalArgumentException(
52.498 + "nanosecond timeout value out of range");
52.499 + }
52.500 +
52.501 + if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
52.502 + timeout++;
52.503 + }
52.504 +
52.505 + wait(timeout);
52.506 + }
52.507 +
52.508 + /**
52.509 + * Causes the current thread to wait until another thread invokes the
52.510 + * {@link java.lang.Object#notify()} method or the
52.511 + * {@link java.lang.Object#notifyAll()} method for this object.
52.512 + * In other words, this method behaves exactly as if it simply
52.513 + * performs the call {@code wait(0)}.
52.514 + * <p>
52.515 + * The current thread must own this object's monitor. The thread
52.516 + * releases ownership of this monitor and waits until another thread
52.517 + * notifies threads waiting on this object's monitor to wake up
52.518 + * either through a call to the {@code notify} method or the
52.519 + * {@code notifyAll} method. The thread then waits until it can
52.520 + * re-obtain ownership of the monitor and resumes execution.
52.521 + * <p>
52.522 + * As in the one argument version, interrupts and spurious wakeups are
52.523 + * possible, and this method should always be used in a loop:
52.524 + * <pre>
52.525 + * synchronized (obj) {
52.526 + * while (<condition does not hold>)
52.527 + * obj.wait();
52.528 + * ... // Perform action appropriate to condition
52.529 + * }
52.530 + * </pre>
52.531 + * This method should only be called by a thread that is the owner
52.532 + * of this object's monitor. See the {@code notify} method for a
52.533 + * description of the ways in which a thread can become the owner of
52.534 + * a monitor.
52.535 + *
52.536 + * @exception IllegalMonitorStateException if the current thread is not
52.537 + * the owner of the object's monitor.
52.538 + * @exception InterruptedException if any thread interrupted the
52.539 + * current thread before or while the current thread
52.540 + * was waiting for a notification. The <i>interrupted
52.541 + * status</i> of the current thread is cleared when
52.542 + * this exception is thrown.
52.543 + * @see java.lang.Object#notify()
52.544 + * @see java.lang.Object#notifyAll()
52.545 + */
52.546 + public final void wait() throws InterruptedException {
52.547 + wait(0);
52.548 + }
52.549 +
52.550 + /**
52.551 + * Called by the garbage collector on an object when garbage collection
52.552 + * determines that there are no more references to the object.
52.553 + * A subclass overrides the {@code finalize} method to dispose of
52.554 + * system resources or to perform other cleanup.
52.555 + * <p>
52.556 + * The general contract of {@code finalize} is that it is invoked
52.557 + * if and when the Java<font size="-2"><sup>TM</sup></font> virtual
52.558 + * machine has determined that there is no longer any
52.559 + * means by which this object can be accessed by any thread that has
52.560 + * not yet died, except as a result of an action taken by the
52.561 + * finalization of some other object or class which is ready to be
52.562 + * finalized. The {@code finalize} method may take any action, including
52.563 + * making this object available again to other threads; the usual purpose
52.564 + * of {@code finalize}, however, is to perform cleanup actions before
52.565 + * the object is irrevocably discarded. For example, the finalize method
52.566 + * for an object that represents an input/output connection might perform
52.567 + * explicit I/O transactions to break the connection before the object is
52.568 + * permanently discarded.
52.569 + * <p>
52.570 + * The {@code finalize} method of class {@code Object} performs no
52.571 + * special action; it simply returns normally. Subclasses of
52.572 + * {@code Object} may override this definition.
52.573 + * <p>
52.574 + * The Java programming language does not guarantee which thread will
52.575 + * invoke the {@code finalize} method for any given object. It is
52.576 + * guaranteed, however, that the thread that invokes finalize will not
52.577 + * be holding any user-visible synchronization locks when finalize is
52.578 + * invoked. If an uncaught exception is thrown by the finalize method,
52.579 + * the exception is ignored and finalization of that object terminates.
52.580 + * <p>
52.581 + * After the {@code finalize} method has been invoked for an object, no
52.582 + * further action is taken until the Java virtual machine has again
52.583 + * determined that there is no longer any means by which this object can
52.584 + * be accessed by any thread that has not yet died, including possible
52.585 + * actions by other objects or classes which are ready to be finalized,
52.586 + * at which point the object may be discarded.
52.587 + * <p>
52.588 + * The {@code finalize} method is never invoked more than once by a Java
52.589 + * virtual machine for any given object.
52.590 + * <p>
52.591 + * Any exception thrown by the {@code finalize} method causes
52.592 + * the finalization of this object to be halted, but is otherwise
52.593 + * ignored.
52.594 + *
52.595 + * @throws Throwable the {@code Exception} raised by this method
52.596 + */
52.597 + protected void finalize() throws Throwable { }
52.598 +}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
53.2 +++ b/emul/mini/src/main/java/java/lang/OutOfMemoryError.java Wed Jan 23 20:39:23 2013 +0100
53.3 @@ -0,0 +1,60 @@
53.4 +/*
53.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
53.7 + *
53.8 + * This code is free software; you can redistribute it and/or modify it
53.9 + * under the terms of the GNU General Public License version 2 only, as
53.10 + * published by the Free Software Foundation. Oracle designates this
53.11 + * particular file as subject to the "Classpath" exception as provided
53.12 + * by Oracle in the LICENSE file that accompanied this code.
53.13 + *
53.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
53.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
53.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
53.17 + * version 2 for more details (a copy is included in the LICENSE file that
53.18 + * accompanied this code).
53.19 + *
53.20 + * You should have received a copy of the GNU General Public License version
53.21 + * 2 along with this work; if not, write to the Free Software Foundation,
53.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
53.23 + *
53.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
53.25 + * or visit www.oracle.com if you need additional information or have any
53.26 + * questions.
53.27 + */
53.28 +
53.29 +package java.lang;
53.30 +
53.31 +/**
53.32 + * Thrown when the Java Virtual Machine cannot allocate an object
53.33 + * because it is out of memory, and no more memory could be made
53.34 + * available by the garbage collector.
53.35 + *
53.36 + * {@code OutOfMemoryError} objects may be constructed by the virtual
53.37 + * machine as if {@linkplain Throwable#Throwable(String, Throwable,
53.38 + * boolean, boolean) suppression were disabled and/or the stack trace was not
53.39 + * writable}.
53.40 + *
53.41 + * @author unascribed
53.42 + * @since JDK1.0
53.43 + */
53.44 +public class OutOfMemoryError extends VirtualMachineError {
53.45 + private static final long serialVersionUID = 8228564086184010517L;
53.46 +
53.47 + /**
53.48 + * Constructs an {@code OutOfMemoryError} with no detail message.
53.49 + */
53.50 + public OutOfMemoryError() {
53.51 + super();
53.52 + }
53.53 +
53.54 + /**
53.55 + * Constructs an {@code OutOfMemoryError} with the specified
53.56 + * detail message.
53.57 + *
53.58 + * @param s the detail message.
53.59 + */
53.60 + public OutOfMemoryError(String s) {
53.61 + super(s);
53.62 + }
53.63 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
54.2 +++ b/emul/mini/src/main/java/java/lang/ReflectiveOperationException.java Wed Jan 23 20:39:23 2013 +0100
54.3 @@ -0,0 +1,91 @@
54.4 +/*
54.5 + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
54.7 + *
54.8 + * This code is free software; you can redistribute it and/or modify it
54.9 + * under the terms of the GNU General Public License version 2 only, as
54.10 + * published by the Free Software Foundation. Oracle designates this
54.11 + * particular file as subject to the "Classpath" exception as provided
54.12 + * by Oracle in the LICENSE file that accompanied this code.
54.13 + *
54.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
54.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
54.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
54.17 + * version 2 for more details (a copy is included in the LICENSE file that
54.18 + * accompanied this code).
54.19 + *
54.20 + * You should have received a copy of the GNU General Public License version
54.21 + * 2 along with this work; if not, write to the Free Software Foundation,
54.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
54.23 + *
54.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
54.25 + * or visit www.oracle.com if you need additional information or have any
54.26 + * questions.
54.27 + */
54.28 +
54.29 +package java.lang;
54.30 +
54.31 +/**
54.32 + * Common superclass of exceptions thrown by reflective operations in
54.33 + * core reflection.
54.34 + *
54.35 + * @see LinkageError
54.36 + * @since 1.7
54.37 + */
54.38 +public class ReflectiveOperationException extends Exception {
54.39 + static final long serialVersionUID = 123456789L;
54.40 +
54.41 + /**
54.42 + * Constructs a new exception with {@code null} as its detail
54.43 + * message. The cause is not initialized, and may subsequently be
54.44 + * initialized by a call to {@link #initCause}.
54.45 + */
54.46 + public ReflectiveOperationException() {
54.47 + super();
54.48 + }
54.49 +
54.50 + /**
54.51 + * Constructs a new exception with the specified detail message.
54.52 + * The cause is not initialized, and may subsequently be
54.53 + * initialized by a call to {@link #initCause}.
54.54 + *
54.55 + * @param message the detail message. The detail message is saved for
54.56 + * later retrieval by the {@link #getMessage()} method.
54.57 + */
54.58 + public ReflectiveOperationException(String message) {
54.59 + super(message);
54.60 + }
54.61 +
54.62 + /**
54.63 + * Constructs a new exception with the specified detail message
54.64 + * and cause.
54.65 + *
54.66 + * <p>Note that the detail message associated with
54.67 + * {@code cause} is <em>not</em> automatically incorporated in
54.68 + * this exception's detail message.
54.69 + *
54.70 + * @param message the detail message (which is saved for later retrieval
54.71 + * by the {@link #getMessage()} method).
54.72 + * @param cause the cause (which is saved for later retrieval by the
54.73 + * {@link #getCause()} method). (A {@code null} value is
54.74 + * permitted, and indicates that the cause is nonexistent or
54.75 + * unknown.)
54.76 + */
54.77 + public ReflectiveOperationException(String message, Throwable cause) {
54.78 + super(message, cause);
54.79 + }
54.80 +
54.81 + /**
54.82 + * Constructs a new exception with the specified cause and a detail
54.83 + * message of {@code (cause==null ? null : cause.toString())} (which
54.84 + * typically contains the class and detail message of {@code cause}).
54.85 + *
54.86 + * @param cause the cause (which is saved for later retrieval by the
54.87 + * {@link #getCause()} method). (A {@code null} value is
54.88 + * permitted, and indicates that the cause is nonexistent or
54.89 + * unknown.)
54.90 + */
54.91 + public ReflectiveOperationException(Throwable cause) {
54.92 + super(cause);
54.93 + }
54.94 +}
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
55.2 +++ b/emul/mini/src/main/java/java/lang/Runnable.java Wed Jan 23 20:39:23 2013 +0100
55.3 @@ -0,0 +1,69 @@
55.4 +/*
55.5 + * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55.7 + *
55.8 + * This code is free software; you can redistribute it and/or modify it
55.9 + * under the terms of the GNU General Public License version 2 only, as
55.10 + * published by the Free Software Foundation. Oracle designates this
55.11 + * particular file as subject to the "Classpath" exception as provided
55.12 + * by Oracle in the LICENSE file that accompanied this code.
55.13 + *
55.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
55.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
55.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
55.17 + * version 2 for more details (a copy is included in the LICENSE file that
55.18 + * accompanied this code).
55.19 + *
55.20 + * You should have received a copy of the GNU General Public License version
55.21 + * 2 along with this work; if not, write to the Free Software Foundation,
55.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
55.23 + *
55.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
55.25 + * or visit www.oracle.com if you need additional information or have any
55.26 + * questions.
55.27 + */
55.28 +
55.29 +package java.lang;
55.30 +
55.31 +/**
55.32 + * The <code>Runnable</code> interface should be implemented by any
55.33 + * class whose instances are intended to be executed by a thread. The
55.34 + * class must define a method of no arguments called <code>run</code>.
55.35 + * <p>
55.36 + * This interface is designed to provide a common protocol for objects that
55.37 + * wish to execute code while they are active. For example,
55.38 + * <code>Runnable</code> is implemented by class <code>Thread</code>.
55.39 + * Being active simply means that a thread has been started and has not
55.40 + * yet been stopped.
55.41 + * <p>
55.42 + * In addition, <code>Runnable</code> provides the means for a class to be
55.43 + * active while not subclassing <code>Thread</code>. A class that implements
55.44 + * <code>Runnable</code> can run without subclassing <code>Thread</code>
55.45 + * by instantiating a <code>Thread</code> instance and passing itself in
55.46 + * as the target. In most cases, the <code>Runnable</code> interface should
55.47 + * be used if you are only planning to override the <code>run()</code>
55.48 + * method and no other <code>Thread</code> methods.
55.49 + * This is important because classes should not be subclassed
55.50 + * unless the programmer intends on modifying or enhancing the fundamental
55.51 + * behavior of the class.
55.52 + *
55.53 + * @author Arthur van Hoff
55.54 + * @see java.lang.Thread
55.55 + * @see java.util.concurrent.Callable
55.56 + * @since JDK1.0
55.57 + */
55.58 +public
55.59 +interface Runnable {
55.60 + /**
55.61 + * When an object implementing interface <code>Runnable</code> is used
55.62 + * to create a thread, starting the thread causes the object's
55.63 + * <code>run</code> method to be called in that separately executing
55.64 + * thread.
55.65 + * <p>
55.66 + * The general contract of the method <code>run</code> is that it may
55.67 + * take any action whatsoever.
55.68 + *
55.69 + * @see java.lang.Thread#run()
55.70 + */
55.71 + public abstract void run();
55.72 +}
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
56.2 +++ b/emul/mini/src/main/java/java/lang/RuntimeException.java Wed Jan 23 20:39:23 2013 +0100
56.3 @@ -0,0 +1,119 @@
56.4 +/*
56.5 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
56.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
56.7 + *
56.8 + * This code is free software; you can redistribute it and/or modify it
56.9 + * under the terms of the GNU General Public License version 2 only, as
56.10 + * published by the Free Software Foundation. Oracle designates this
56.11 + * particular file as subject to the "Classpath" exception as provided
56.12 + * by Oracle in the LICENSE file that accompanied this code.
56.13 + *
56.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
56.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
56.17 + * version 2 for more details (a copy is included in the LICENSE file that
56.18 + * accompanied this code).
56.19 + *
56.20 + * You should have received a copy of the GNU General Public License version
56.21 + * 2 along with this work; if not, write to the Free Software Foundation,
56.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
56.23 + *
56.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
56.25 + * or visit www.oracle.com if you need additional information or have any
56.26 + * questions.
56.27 + */
56.28 +
56.29 +package java.lang;
56.30 +
56.31 +/**
56.32 + * {@code RuntimeException} is the superclass of those
56.33 + * exceptions that can be thrown during the normal operation of the
56.34 + * Java Virtual Machine.
56.35 + *
56.36 + * <p>{@code RuntimeException} and its subclasses are <em>unchecked
56.37 + * exceptions</em>. Unchecked exceptions do <em>not</em> need to be
56.38 + * declared in a method or constructor's {@code throws} clause if they
56.39 + * can be thrown by the execution of the method or constructor and
56.40 + * propagate outside the method or constructor boundary.
56.41 + *
56.42 + * @author Frank Yellin
56.43 + * @jls 11.2 Compile-Time Checking of Exceptions
56.44 + * @since JDK1.0
56.45 + */
56.46 +public class RuntimeException extends Exception {
56.47 + static final long serialVersionUID = -7034897190745766939L;
56.48 +
56.49 + /** Constructs a new runtime exception with {@code null} as its
56.50 + * detail message. The cause is not initialized, and may subsequently be
56.51 + * initialized by a call to {@link #initCause}.
56.52 + */
56.53 + public RuntimeException() {
56.54 + super();
56.55 + }
56.56 +
56.57 + /** Constructs a new runtime exception with the specified detail message.
56.58 + * The cause is not initialized, and may subsequently be initialized by a
56.59 + * call to {@link #initCause}.
56.60 + *
56.61 + * @param message the detail message. The detail message is saved for
56.62 + * later retrieval by the {@link #getMessage()} method.
56.63 + */
56.64 + public RuntimeException(String message) {
56.65 + super(message);
56.66 + }
56.67 +
56.68 + /**
56.69 + * Constructs a new runtime exception with the specified detail message and
56.70 + * cause. <p>Note that the detail message associated with
56.71 + * {@code cause} is <i>not</i> automatically incorporated in
56.72 + * this runtime exception's detail message.
56.73 + *
56.74 + * @param message the detail message (which is saved for later retrieval
56.75 + * by the {@link #getMessage()} method).
56.76 + * @param cause the cause (which is saved for later retrieval by the
56.77 + * {@link #getCause()} method). (A <tt>null</tt> value is
56.78 + * permitted, and indicates that the cause is nonexistent or
56.79 + * unknown.)
56.80 + * @since 1.4
56.81 + */
56.82 + public RuntimeException(String message, Throwable cause) {
56.83 + super(message, cause);
56.84 + }
56.85 +
56.86 + /** Constructs a new runtime exception with the specified cause and a
56.87 + * detail message of <tt>(cause==null ? null : cause.toString())</tt>
56.88 + * (which typically contains the class and detail message of
56.89 + * <tt>cause</tt>). This constructor is useful for runtime exceptions
56.90 + * that are little more than wrappers for other throwables.
56.91 + *
56.92 + * @param cause the cause (which is saved for later retrieval by the
56.93 + * {@link #getCause()} method). (A <tt>null</tt> value is
56.94 + * permitted, and indicates that the cause is nonexistent or
56.95 + * unknown.)
56.96 + * @since 1.4
56.97 + */
56.98 + public RuntimeException(Throwable cause) {
56.99 + super(cause);
56.100 + }
56.101 +
56.102 + /**
56.103 + * Constructs a new runtime exception with the specified detail
56.104 + * message, cause, suppression enabled or disabled, and writable
56.105 + * stack trace enabled or disabled.
56.106 + *
56.107 + * @param message the detail message.
56.108 + * @param cause the cause. (A {@code null} value is permitted,
56.109 + * and indicates that the cause is nonexistent or unknown.)
56.110 + * @param enableSuppression whether or not suppression is enabled
56.111 + * or disabled
56.112 + * @param writableStackTrace whether or not the stack trace should
56.113 + * be writable
56.114 + *
56.115 + * @since 1.7
56.116 + */
56.117 + protected RuntimeException(String message, Throwable cause,
56.118 + boolean enableSuppression,
56.119 + boolean writableStackTrace) {
56.120 + super(message, cause, enableSuppression, writableStackTrace);
56.121 + }
56.122 +}
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
57.2 +++ b/emul/mini/src/main/java/java/lang/SecurityException.java Wed Jan 23 20:39:23 2013 +0100
57.3 @@ -0,0 +1,84 @@
57.4 +/*
57.5 + * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
57.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
57.7 + *
57.8 + * This code is free software; you can redistribute it and/or modify it
57.9 + * under the terms of the GNU General Public License version 2 only, as
57.10 + * published by the Free Software Foundation. Oracle designates this
57.11 + * particular file as subject to the "Classpath" exception as provided
57.12 + * by Oracle in the LICENSE file that accompanied this code.
57.13 + *
57.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
57.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
57.17 + * version 2 for more details (a copy is included in the LICENSE file that
57.18 + * accompanied this code).
57.19 + *
57.20 + * You should have received a copy of the GNU General Public License version
57.21 + * 2 along with this work; if not, write to the Free Software Foundation,
57.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
57.23 + *
57.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
57.25 + * or visit www.oracle.com if you need additional information or have any
57.26 + * questions.
57.27 + */
57.28 +package java.lang;
57.29 +
57.30 +/**
57.31 + * Thrown by the security manager to indicate a security violation.
57.32 + *
57.33 + * @author unascribed
57.34 + * @see java.lang.SecurityManager
57.35 + * @since JDK1.0
57.36 + */
57.37 +public class SecurityException extends RuntimeException {
57.38 +
57.39 + private static final long serialVersionUID = 6878364983674394167L;
57.40 +
57.41 + /**
57.42 + * Constructs a <code>SecurityException</code> with no detail message.
57.43 + */
57.44 + public SecurityException() {
57.45 + super();
57.46 + }
57.47 +
57.48 + /**
57.49 + * Constructs a <code>SecurityException</code> with the specified
57.50 + * detail message.
57.51 + *
57.52 + * @param s the detail message.
57.53 + */
57.54 + public SecurityException(String s) {
57.55 + super(s);
57.56 + }
57.57 +
57.58 + /**
57.59 + * Creates a <code>SecurityException</code> with the specified
57.60 + * detail message and cause.
57.61 + *
57.62 + * @param message the detail message (which is saved for later retrieval
57.63 + * by the {@link #getMessage()} method).
57.64 + * @param cause the cause (which is saved for later retrieval by the
57.65 + * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
57.66 + * and indicates that the cause is nonexistent or unknown.)
57.67 + * @since 1.5
57.68 + */
57.69 + public SecurityException(String message, Throwable cause) {
57.70 + super(message, cause);
57.71 + }
57.72 +
57.73 + /**
57.74 + * Creates a <code>SecurityException</code> with the specified cause
57.75 + * and a detail message of <tt>(cause==null ? null : cause.toString())</tt>
57.76 + * (which typically contains the class and detail message of
57.77 + * <tt>cause</tt>).
57.78 + *
57.79 + * @param cause the cause (which is saved for later retrieval by the
57.80 + * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
57.81 + * and indicates that the cause is nonexistent or unknown.)
57.82 + * @since 1.5
57.83 + */
57.84 + public SecurityException(Throwable cause) {
57.85 + super(cause);
57.86 + }
57.87 +}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
58.2 +++ b/emul/mini/src/main/java/java/lang/Short.java Wed Jan 23 20:39:23 2013 +0100
58.3 @@ -0,0 +1,468 @@
58.4 +/*
58.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
58.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
58.7 + *
58.8 + * This code is free software; you can redistribute it and/or modify it
58.9 + * under the terms of the GNU General Public License version 2 only, as
58.10 + * published by the Free Software Foundation. Oracle designates this
58.11 + * particular file as subject to the "Classpath" exception as provided
58.12 + * by Oracle in the LICENSE file that accompanied this code.
58.13 + *
58.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
58.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
58.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
58.17 + * version 2 for more details (a copy is included in the LICENSE file that
58.18 + * accompanied this code).
58.19 + *
58.20 + * You should have received a copy of the GNU General Public License version
58.21 + * 2 along with this work; if not, write to the Free Software Foundation,
58.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
58.23 + *
58.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
58.25 + * or visit www.oracle.com if you need additional information or have any
58.26 + * questions.
58.27 + */
58.28 +
58.29 +package java.lang;
58.30 +
58.31 +/**
58.32 + * The {@code Short} class wraps a value of primitive type {@code
58.33 + * short} in an object. An object of type {@code Short} contains a
58.34 + * single field whose type is {@code short}.
58.35 + *
58.36 + * <p>In addition, this class provides several methods for converting
58.37 + * a {@code short} to a {@code String} and a {@code String} to a
58.38 + * {@code short}, as well as other constants and methods useful when
58.39 + * dealing with a {@code short}.
58.40 + *
58.41 + * @author Nakul Saraiya
58.42 + * @author Joseph D. Darcy
58.43 + * @see java.lang.Number
58.44 + * @since JDK1.1
58.45 + */
58.46 +public final class Short extends Number implements Comparable<Short> {
58.47 +
58.48 + /**
58.49 + * A constant holding the minimum value a {@code short} can
58.50 + * have, -2<sup>15</sup>.
58.51 + */
58.52 + public static final short MIN_VALUE = -32768;
58.53 +
58.54 + /**
58.55 + * A constant holding the maximum value a {@code short} can
58.56 + * have, 2<sup>15</sup>-1.
58.57 + */
58.58 + public static final short MAX_VALUE = 32767;
58.59 +
58.60 + /**
58.61 + * The {@code Class} instance representing the primitive type
58.62 + * {@code short}.
58.63 + */
58.64 + public static final Class<Short> TYPE = (Class<Short>) Class.getPrimitiveClass("short");
58.65 +
58.66 + /**
58.67 + * Returns a new {@code String} object representing the
58.68 + * specified {@code short}. The radix is assumed to be 10.
58.69 + *
58.70 + * @param s the {@code short} to be converted
58.71 + * @return the string representation of the specified {@code short}
58.72 + * @see java.lang.Integer#toString(int)
58.73 + */
58.74 + public static String toString(short s) {
58.75 + return Integer.toString((int)s, 10);
58.76 + }
58.77 +
58.78 + /**
58.79 + * Parses the string argument as a signed {@code short} in the
58.80 + * radix specified by the second argument. The characters in the
58.81 + * string must all be digits, of the specified radix (as
58.82 + * determined by whether {@link java.lang.Character#digit(char,
58.83 + * int)} returns a nonnegative value) except that the first
58.84 + * character may be an ASCII minus sign {@code '-'}
58.85 + * (<code>'\u002D'</code>) to indicate a negative value or an
58.86 + * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
58.87 + * indicate a positive value. The resulting {@code short} value
58.88 + * is returned.
58.89 + *
58.90 + * <p>An exception of type {@code NumberFormatException} is
58.91 + * thrown if any of the following situations occurs:
58.92 + * <ul>
58.93 + * <li> The first argument is {@code null} or is a string of
58.94 + * length zero.
58.95 + *
58.96 + * <li> The radix is either smaller than {@link
58.97 + * java.lang.Character#MIN_RADIX} or larger than {@link
58.98 + * java.lang.Character#MAX_RADIX}.
58.99 + *
58.100 + * <li> Any character of the string is not a digit of the
58.101 + * specified radix, except that the first character may be a minus
58.102 + * sign {@code '-'} (<code>'\u002D'</code>) or plus sign
58.103 + * {@code '+'} (<code>'\u002B'</code>) provided that the
58.104 + * string is longer than length 1.
58.105 + *
58.106 + * <li> The value represented by the string is not a value of type
58.107 + * {@code short}.
58.108 + * </ul>
58.109 + *
58.110 + * @param s the {@code String} containing the
58.111 + * {@code short} representation to be parsed
58.112 + * @param radix the radix to be used while parsing {@code s}
58.113 + * @return the {@code short} represented by the string
58.114 + * argument in the specified radix.
58.115 + * @throws NumberFormatException If the {@code String}
58.116 + * does not contain a parsable {@code short}.
58.117 + */
58.118 + public static short parseShort(String s, int radix)
58.119 + throws NumberFormatException {
58.120 + int i = Integer.parseInt(s, radix);
58.121 + if (i < MIN_VALUE || i > MAX_VALUE)
58.122 + throw new NumberFormatException(
58.123 + "Value out of range. Value:\"" + s + "\" Radix:" + radix);
58.124 + return (short)i;
58.125 + }
58.126 +
58.127 + /**
58.128 + * Parses the string argument as a signed decimal {@code
58.129 + * short}. The characters in the string must all be decimal
58.130 + * digits, except that the first character may be an ASCII minus
58.131 + * sign {@code '-'} (<code>'\u002D'</code>) to indicate a
58.132 + * negative value or an ASCII plus sign {@code '+'}
58.133 + * (<code>'\u002B'</code>) to indicate a positive value. The
58.134 + * resulting {@code short} value is returned, exactly as if the
58.135 + * argument and the radix 10 were given as arguments to the {@link
58.136 + * #parseShort(java.lang.String, int)} method.
58.137 + *
58.138 + * @param s a {@code String} containing the {@code short}
58.139 + * representation to be parsed
58.140 + * @return the {@code short} value represented by the
58.141 + * argument in decimal.
58.142 + * @throws NumberFormatException If the string does not
58.143 + * contain a parsable {@code short}.
58.144 + */
58.145 + public static short parseShort(String s) throws NumberFormatException {
58.146 + return parseShort(s, 10);
58.147 + }
58.148 +
58.149 + /**
58.150 + * Returns a {@code Short} object holding the value
58.151 + * extracted from the specified {@code String} when parsed
58.152 + * with the radix given by the second argument. The first argument
58.153 + * is interpreted as representing a signed {@code short} in
58.154 + * the radix specified by the second argument, exactly as if the
58.155 + * argument were given to the {@link #parseShort(java.lang.String,
58.156 + * int)} method. The result is a {@code Short} object that
58.157 + * represents the {@code short} value specified by the string.
58.158 + *
58.159 + * <p>In other words, this method returns a {@code Short} object
58.160 + * equal to the value of:
58.161 + *
58.162 + * <blockquote>
58.163 + * {@code new Short(Short.parseShort(s, radix))}
58.164 + * </blockquote>
58.165 + *
58.166 + * @param s the string to be parsed
58.167 + * @param radix the radix to be used in interpreting {@code s}
58.168 + * @return a {@code Short} object holding the value
58.169 + * represented by the string argument in the
58.170 + * specified radix.
58.171 + * @throws NumberFormatException If the {@code String} does
58.172 + * not contain a parsable {@code short}.
58.173 + */
58.174 + public static Short valueOf(String s, int radix)
58.175 + throws NumberFormatException {
58.176 + return valueOf(parseShort(s, radix));
58.177 + }
58.178 +
58.179 + /**
58.180 + * Returns a {@code Short} object holding the
58.181 + * value given by the specified {@code String}. The argument
58.182 + * is interpreted as representing a signed decimal
58.183 + * {@code short}, exactly as if the argument were given to
58.184 + * the {@link #parseShort(java.lang.String)} method. The result is
58.185 + * a {@code Short} object that represents the
58.186 + * {@code short} value specified by the string.
58.187 + *
58.188 + * <p>In other words, this method returns a {@code Short} object
58.189 + * equal to the value of:
58.190 + *
58.191 + * <blockquote>
58.192 + * {@code new Short(Short.parseShort(s))}
58.193 + * </blockquote>
58.194 + *
58.195 + * @param s the string to be parsed
58.196 + * @return a {@code Short} object holding the value
58.197 + * represented by the string argument
58.198 + * @throws NumberFormatException If the {@code String} does
58.199 + * not contain a parsable {@code short}.
58.200 + */
58.201 + public static Short valueOf(String s) throws NumberFormatException {
58.202 + return valueOf(s, 10);
58.203 + }
58.204 +
58.205 + private static class ShortCache {
58.206 + private ShortCache(){}
58.207 +
58.208 + static final Short cache[] = new Short[-(-128) + 127 + 1];
58.209 +
58.210 + static {
58.211 + for(int i = 0; i < cache.length; i++)
58.212 + cache[i] = new Short((short)(i - 128));
58.213 + }
58.214 + }
58.215 +
58.216 + /**
58.217 + * Returns a {@code Short} instance representing the specified
58.218 + * {@code short} value.
58.219 + * If a new {@code Short} instance is not required, this method
58.220 + * should generally be used in preference to the constructor
58.221 + * {@link #Short(short)}, as this method is likely to yield
58.222 + * significantly better space and time performance by caching
58.223 + * frequently requested values.
58.224 + *
58.225 + * This method will always cache values in the range -128 to 127,
58.226 + * inclusive, and may cache other values outside of this range.
58.227 + *
58.228 + * @param s a short value.
58.229 + * @return a {@code Short} instance representing {@code s}.
58.230 + * @since 1.5
58.231 + */
58.232 + public static Short valueOf(short s) {
58.233 + final int offset = 128;
58.234 + int sAsInt = s;
58.235 + if (sAsInt >= -128 && sAsInt <= 127) { // must cache
58.236 + return ShortCache.cache[sAsInt + offset];
58.237 + }
58.238 + return new Short(s);
58.239 + }
58.240 +
58.241 + /**
58.242 + * Decodes a {@code String} into a {@code Short}.
58.243 + * Accepts decimal, hexadecimal, and octal numbers given by
58.244 + * the following grammar:
58.245 + *
58.246 + * <blockquote>
58.247 + * <dl>
58.248 + * <dt><i>DecodableString:</i>
58.249 + * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
58.250 + * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
58.251 + * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
58.252 + * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
58.253 + * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
58.254 + * <p>
58.255 + * <dt><i>Sign:</i>
58.256 + * <dd>{@code -}
58.257 + * <dd>{@code +}
58.258 + * </dl>
58.259 + * </blockquote>
58.260 + *
58.261 + * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
58.262 + * are as defined in section 3.10.1 of
58.263 + * <cite>The Java™ Language Specification</cite>,
58.264 + * except that underscores are not accepted between digits.
58.265 + *
58.266 + * <p>The sequence of characters following an optional
58.267 + * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
58.268 + * "{@code #}", or leading zero) is parsed as by the {@code
58.269 + * Short.parseShort} method with the indicated radix (10, 16, or
58.270 + * 8). This sequence of characters must represent a positive
58.271 + * value or a {@link NumberFormatException} will be thrown. The
58.272 + * result is negated if first character of the specified {@code
58.273 + * String} is the minus sign. No whitespace characters are
58.274 + * permitted in the {@code String}.
58.275 + *
58.276 + * @param nm the {@code String} to decode.
58.277 + * @return a {@code Short} object holding the {@code short}
58.278 + * value represented by {@code nm}
58.279 + * @throws NumberFormatException if the {@code String} does not
58.280 + * contain a parsable {@code short}.
58.281 + * @see java.lang.Short#parseShort(java.lang.String, int)
58.282 + */
58.283 + public static Short decode(String nm) throws NumberFormatException {
58.284 + int i = Integer.decode(nm);
58.285 + if (i < MIN_VALUE || i > MAX_VALUE)
58.286 + throw new NumberFormatException(
58.287 + "Value " + i + " out of range from input " + nm);
58.288 + return valueOf((short)i);
58.289 + }
58.290 +
58.291 + /**
58.292 + * The value of the {@code Short}.
58.293 + *
58.294 + * @serial
58.295 + */
58.296 + private final short value;
58.297 +
58.298 + /**
58.299 + * Constructs a newly allocated {@code Short} object that
58.300 + * represents the specified {@code short} value.
58.301 + *
58.302 + * @param value the value to be represented by the
58.303 + * {@code Short}.
58.304 + */
58.305 + public Short(short value) {
58.306 + this.value = value;
58.307 + }
58.308 +
58.309 + /**
58.310 + * Constructs a newly allocated {@code Short} object that
58.311 + * represents the {@code short} value indicated by the
58.312 + * {@code String} parameter. The string is converted to a
58.313 + * {@code short} value in exactly the manner used by the
58.314 + * {@code parseShort} method for radix 10.
58.315 + *
58.316 + * @param s the {@code String} to be converted to a
58.317 + * {@code Short}
58.318 + * @throws NumberFormatException If the {@code String}
58.319 + * does not contain a parsable {@code short}.
58.320 + * @see java.lang.Short#parseShort(java.lang.String, int)
58.321 + */
58.322 + public Short(String s) throws NumberFormatException {
58.323 + this.value = parseShort(s, 10);
58.324 + }
58.325 +
58.326 + /**
58.327 + * Returns the value of this {@code Short} as a
58.328 + * {@code byte}.
58.329 + */
58.330 + public byte byteValue() {
58.331 + return (byte)value;
58.332 + }
58.333 +
58.334 + /**
58.335 + * Returns the value of this {@code Short} as a
58.336 + * {@code short}.
58.337 + */
58.338 + public short shortValue() {
58.339 + return value;
58.340 + }
58.341 +
58.342 + /**
58.343 + * Returns the value of this {@code Short} as an
58.344 + * {@code int}.
58.345 + */
58.346 + public int intValue() {
58.347 + return (int)value;
58.348 + }
58.349 +
58.350 + /**
58.351 + * Returns the value of this {@code Short} as a
58.352 + * {@code long}.
58.353 + */
58.354 + public long longValue() {
58.355 + return (long)value;
58.356 + }
58.357 +
58.358 + /**
58.359 + * Returns the value of this {@code Short} as a
58.360 + * {@code float}.
58.361 + */
58.362 + public float floatValue() {
58.363 + return (float)value;
58.364 + }
58.365 +
58.366 + /**
58.367 + * Returns the value of this {@code Short} as a
58.368 + * {@code double}.
58.369 + */
58.370 + public double doubleValue() {
58.371 + return (double)value;
58.372 + }
58.373 +
58.374 + /**
58.375 + * Returns a {@code String} object representing this
58.376 + * {@code Short}'s value. The value is converted to signed
58.377 + * decimal representation and returned as a string, exactly as if
58.378 + * the {@code short} value were given as an argument to the
58.379 + * {@link java.lang.Short#toString(short)} method.
58.380 + *
58.381 + * @return a string representation of the value of this object in
58.382 + * base 10.
58.383 + */
58.384 + public String toString() {
58.385 + return Integer.toString((int)value);
58.386 + }
58.387 +
58.388 + /**
58.389 + * Returns a hash code for this {@code Short}; equal to the result
58.390 + * of invoking {@code intValue()}.
58.391 + *
58.392 + * @return a hash code value for this {@code Short}
58.393 + */
58.394 + public int hashCode() {
58.395 + return (int)value;
58.396 + }
58.397 +
58.398 + /**
58.399 + * Compares this object to the specified object. The result is
58.400 + * {@code true} if and only if the argument is not
58.401 + * {@code null} and is a {@code Short} object that
58.402 + * contains the same {@code short} value as this object.
58.403 + *
58.404 + * @param obj the object to compare with
58.405 + * @return {@code true} if the objects are the same;
58.406 + * {@code false} otherwise.
58.407 + */
58.408 + public boolean equals(Object obj) {
58.409 + if (obj instanceof Short) {
58.410 + return value == ((Short)obj).shortValue();
58.411 + }
58.412 + return false;
58.413 + }
58.414 +
58.415 + /**
58.416 + * Compares two {@code Short} objects numerically.
58.417 + *
58.418 + * @param anotherShort the {@code Short} to be compared.
58.419 + * @return the value {@code 0} if this {@code Short} is
58.420 + * equal to the argument {@code Short}; a value less than
58.421 + * {@code 0} if this {@code Short} is numerically less
58.422 + * than the argument {@code Short}; and a value greater than
58.423 + * {@code 0} if this {@code Short} is numerically
58.424 + * greater than the argument {@code Short} (signed
58.425 + * comparison).
58.426 + * @since 1.2
58.427 + */
58.428 + public int compareTo(Short anotherShort) {
58.429 + return compare(this.value, anotherShort.value);
58.430 + }
58.431 +
58.432 + /**
58.433 + * Compares two {@code short} values numerically.
58.434 + * The value returned is identical to what would be returned by:
58.435 + * <pre>
58.436 + * Short.valueOf(x).compareTo(Short.valueOf(y))
58.437 + * </pre>
58.438 + *
58.439 + * @param x the first {@code short} to compare
58.440 + * @param y the second {@code short} to compare
58.441 + * @return the value {@code 0} if {@code x == y};
58.442 + * a value less than {@code 0} if {@code x < y}; and
58.443 + * a value greater than {@code 0} if {@code x > y}
58.444 + * @since 1.7
58.445 + */
58.446 + public static int compare(short x, short y) {
58.447 + return x - y;
58.448 + }
58.449 +
58.450 + /**
58.451 + * The number of bits used to represent a {@code short} value in two's
58.452 + * complement binary form.
58.453 + * @since 1.5
58.454 + */
58.455 + public static final int SIZE = 16;
58.456 +
58.457 + /**
58.458 + * Returns the value obtained by reversing the order of the bytes in the
58.459 + * two's complement representation of the specified {@code short} value.
58.460 + *
58.461 + * @return the value obtained by reversing (or, equivalently, swapping)
58.462 + * the bytes in the specified {@code short} value.
58.463 + * @since 1.5
58.464 + */
58.465 + public static short reverseBytes(short i) {
58.466 + return (short) (((i & 0xFF00) >> 8) | (i << 8));
58.467 + }
58.468 +
58.469 + /** use serialVersionUID from JDK 1.1. for interoperability */
58.470 + private static final long serialVersionUID = 7515723908773894738L;
58.471 +}
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
59.2 +++ b/emul/mini/src/main/java/java/lang/StackTraceElement.java Wed Jan 23 20:39:23 2013 +0100
59.3 @@ -0,0 +1,223 @@
59.4 +/*
59.5 + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
59.7 + *
59.8 + * This code is free software; you can redistribute it and/or modify it
59.9 + * under the terms of the GNU General Public License version 2 only, as
59.10 + * published by the Free Software Foundation. Oracle designates this
59.11 + * particular file as subject to the "Classpath" exception as provided
59.12 + * by Oracle in the LICENSE file that accompanied this code.
59.13 + *
59.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
59.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
59.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
59.17 + * version 2 for more details (a copy is included in the LICENSE file that
59.18 + * accompanied this code).
59.19 + *
59.20 + * You should have received a copy of the GNU General Public License version
59.21 + * 2 along with this work; if not, write to the Free Software Foundation,
59.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
59.23 + *
59.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
59.25 + * or visit www.oracle.com if you need additional information or have any
59.26 + * questions.
59.27 + */
59.28 +
59.29 +package java.lang;
59.30 +
59.31 +/**
59.32 + * An element in a stack trace, as returned by {@link
59.33 + * Throwable#getStackTrace()}. Each element represents a single stack frame.
59.34 + * All stack frames except for the one at the top of the stack represent
59.35 + * a method invocation. The frame at the top of the stack represents the
59.36 + * execution point at which the stack trace was generated. Typically,
59.37 + * this is the point at which the throwable corresponding to the stack trace
59.38 + * was created.
59.39 + *
59.40 + * @since 1.4
59.41 + * @author Josh Bloch
59.42 + */
59.43 +public final class StackTraceElement implements java.io.Serializable {
59.44 + // Normally initialized by VM (public constructor added in 1.5)
59.45 + private String declaringClass;
59.46 + private String methodName;
59.47 + private String fileName;
59.48 + private int lineNumber;
59.49 +
59.50 + /**
59.51 + * Creates a stack trace element representing the specified execution
59.52 + * point.
59.53 + *
59.54 + * @param declaringClass the fully qualified name of the class containing
59.55 + * the execution point represented by the stack trace element
59.56 + * @param methodName the name of the method containing the execution point
59.57 + * represented by the stack trace element
59.58 + * @param fileName the name of the file containing the execution point
59.59 + * represented by the stack trace element, or {@code null} if
59.60 + * this information is unavailable
59.61 + * @param lineNumber the line number of the source line containing the
59.62 + * execution point represented by this stack trace element, or
59.63 + * a negative number if this information is unavailable. A value
59.64 + * of -2 indicates that the method containing the execution point
59.65 + * is a native method
59.66 + * @throws NullPointerException if {@code declaringClass} or
59.67 + * {@code methodName} is null
59.68 + * @since 1.5
59.69 + */
59.70 + public StackTraceElement(String declaringClass, String methodName,
59.71 + String fileName, int lineNumber) {
59.72 + this.declaringClass = declaringClass;
59.73 + this.methodName = methodName;
59.74 + this.fileName = fileName;
59.75 + this.lineNumber = lineNumber;
59.76 + }
59.77 +
59.78 + /**
59.79 + * Returns the name of the source file containing the execution point
59.80 + * represented by this stack trace element. Generally, this corresponds
59.81 + * to the {@code SourceFile} attribute of the relevant {@code class}
59.82 + * file (as per <i>The Java Virtual Machine Specification</i>, Section
59.83 + * 4.7.7). In some systems, the name may refer to some source code unit
59.84 + * other than a file, such as an entry in source repository.
59.85 + *
59.86 + * @return the name of the file containing the execution point
59.87 + * represented by this stack trace element, or {@code null} if
59.88 + * this information is unavailable.
59.89 + */
59.90 + public String getFileName() {
59.91 + return fileName;
59.92 + }
59.93 +
59.94 + /**
59.95 + * Returns the line number of the source line containing the execution
59.96 + * point represented by this stack trace element. Generally, this is
59.97 + * derived from the {@code LineNumberTable} attribute of the relevant
59.98 + * {@code class} file (as per <i>The Java Virtual Machine
59.99 + * Specification</i>, Section 4.7.8).
59.100 + *
59.101 + * @return the line number of the source line containing the execution
59.102 + * point represented by this stack trace element, or a negative
59.103 + * number if this information is unavailable.
59.104 + */
59.105 + public int getLineNumber() {
59.106 + return lineNumber;
59.107 + }
59.108 +
59.109 + /**
59.110 + * Returns the fully qualified name of the class containing the
59.111 + * execution point represented by this stack trace element.
59.112 + *
59.113 + * @return the fully qualified name of the {@code Class} containing
59.114 + * the execution point represented by this stack trace element.
59.115 + */
59.116 + public String getClassName() {
59.117 + return declaringClass;
59.118 + }
59.119 +
59.120 + /**
59.121 + * Returns the name of the method containing the execution point
59.122 + * represented by this stack trace element. If the execution point is
59.123 + * contained in an instance or class initializer, this method will return
59.124 + * the appropriate <i>special method name</i>, {@code <init>} or
59.125 + * {@code <clinit>}, as per Section 3.9 of <i>The Java Virtual
59.126 + * Machine Specification</i>.
59.127 + *
59.128 + * @return the name of the method containing the execution point
59.129 + * represented by this stack trace element.
59.130 + */
59.131 + public String getMethodName() {
59.132 + return methodName;
59.133 + }
59.134 +
59.135 + /**
59.136 + * Returns true if the method containing the execution point
59.137 + * represented by this stack trace element is a native method.
59.138 + *
59.139 + * @return {@code true} if the method containing the execution point
59.140 + * represented by this stack trace element is a native method.
59.141 + */
59.142 + public boolean isNativeMethod() {
59.143 + return lineNumber == -2;
59.144 + }
59.145 +
59.146 + /**
59.147 + * Returns a string representation of this stack trace element. The
59.148 + * format of this string depends on the implementation, but the following
59.149 + * examples may be regarded as typical:
59.150 + * <ul>
59.151 + * <li>
59.152 + * {@code "MyClass.mash(MyClass.java:9)"} - Here, {@code "MyClass"}
59.153 + * is the <i>fully-qualified name</i> of the class containing the
59.154 + * execution point represented by this stack trace element,
59.155 + * {@code "mash"} is the name of the method containing the execution
59.156 + * point, {@code "MyClass.java"} is the source file containing the
59.157 + * execution point, and {@code "9"} is the line number of the source
59.158 + * line containing the execution point.
59.159 + * <li>
59.160 + * {@code "MyClass.mash(MyClass.java)"} - As above, but the line
59.161 + * number is unavailable.
59.162 + * <li>
59.163 + * {@code "MyClass.mash(Unknown Source)"} - As above, but neither
59.164 + * the file name nor the line number are available.
59.165 + * <li>
59.166 + * {@code "MyClass.mash(Native Method)"} - As above, but neither
59.167 + * the file name nor the line number are available, and the method
59.168 + * containing the execution point is known to be a native method.
59.169 + * </ul>
59.170 + * @see Throwable#printStackTrace()
59.171 + */
59.172 + public String toString() {
59.173 + return getClassName() + "." + methodName +
59.174 + (isNativeMethod() ? "(Native Method)" :
59.175 + (fileName != null && lineNumber >= 0 ?
59.176 + "(" + fileName + ":" + lineNumber + ")" :
59.177 + (fileName != null ? "("+fileName+")" : "(Unknown Source)")));
59.178 + }
59.179 +
59.180 + /**
59.181 + * Returns true if the specified object is another
59.182 + * {@code StackTraceElement} instance representing the same execution
59.183 + * point as this instance. Two stack trace elements {@code a} and
59.184 + * {@code b} are equal if and only if:
59.185 + * <pre>
59.186 + * equals(a.getFileName(), b.getFileName()) &&
59.187 + * a.getLineNumber() == b.getLineNumber()) &&
59.188 + * equals(a.getClassName(), b.getClassName()) &&
59.189 + * equals(a.getMethodName(), b.getMethodName())
59.190 + * </pre>
59.191 + * where {@code equals} has the semantics of {@link
59.192 + * java.util.Objects#equals(Object, Object) Objects.equals}.
59.193 + *
59.194 + * @param obj the object to be compared with this stack trace element.
59.195 + * @return true if the specified object is another
59.196 + * {@code StackTraceElement} instance representing the same
59.197 + * execution point as this instance.
59.198 + */
59.199 + public boolean equals(Object obj) {
59.200 + if (obj==this)
59.201 + return true;
59.202 + if (!(obj instanceof StackTraceElement))
59.203 + return false;
59.204 + StackTraceElement e = (StackTraceElement)obj;
59.205 + return e.declaringClass.equals(declaringClass) &&
59.206 + e.lineNumber == lineNumber &&
59.207 + equals(methodName, e.methodName) &&
59.208 + equals(fileName, e.fileName);
59.209 + }
59.210 +
59.211 + /**
59.212 + * Returns a hash code value for this stack trace element.
59.213 + */
59.214 + public int hashCode() {
59.215 + int result = 31*declaringClass.hashCode() + methodName.hashCode();
59.216 + result = 31*result + (fileName == null ? 0 : fileName.hashCode());
59.217 + result = 31*result + lineNumber;
59.218 + return result;
59.219 + }
59.220 +
59.221 + private static boolean equals(Object a, Object b) {
59.222 + return (a == b) || (a != null && a.equals(b));
59.223 + }
59.224 +
59.225 + private static final long serialVersionUID = 6992337162326171013L;
59.226 +}
60.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
60.2 +++ b/emul/mini/src/main/java/java/lang/String.java Wed Jan 23 20:39:23 2013 +0100
60.3 @@ -0,0 +1,3009 @@
60.4 +/*
60.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
60.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
60.7 + *
60.8 + * This code is free software; you can redistribute it and/or modify it
60.9 + * under the terms of the GNU General Public License version 2 only, as
60.10 + * published by the Free Software Foundation. Oracle designates this
60.11 + * particular file as subject to the "Classpath" exception as provided
60.12 + * by Oracle in the LICENSE file that accompanied this code.
60.13 + *
60.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
60.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
60.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
60.17 + * version 2 for more details (a copy is included in the LICENSE file that
60.18 + * accompanied this code).
60.19 + *
60.20 + * You should have received a copy of the GNU General Public License version
60.21 + * 2 along with this work; if not, write to the Free Software Foundation,
60.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
60.23 + *
60.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
60.25 + * or visit www.oracle.com if you need additional information or have any
60.26 + * questions.
60.27 + */
60.28 +
60.29 +package java.lang;
60.30 +
60.31 +import java.util.Comparator;
60.32 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
60.33 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
60.34 +import org.apidesign.bck2brwsr.core.JavaScriptOnly;
60.35 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
60.36 +
60.37 +/**
60.38 + * The <code>String</code> class represents character strings. All
60.39 + * string literals in Java programs, such as <code>"abc"</code>, are
60.40 + * implemented as instances of this class.
60.41 + * <p>
60.42 + * Strings are constant; their values cannot be changed after they
60.43 + * are created. String buffers support mutable strings.
60.44 + * Because String objects are immutable they can be shared. For example:
60.45 + * <p><blockquote><pre>
60.46 + * String str = "abc";
60.47 + * </pre></blockquote><p>
60.48 + * is equivalent to:
60.49 + * <p><blockquote><pre>
60.50 + * char data[] = {'a', 'b', 'c'};
60.51 + * String str = new String(data);
60.52 + * </pre></blockquote><p>
60.53 + * Here are some more examples of how strings can be used:
60.54 + * <p><blockquote><pre>
60.55 + * System.out.println("abc");
60.56 + * String cde = "cde";
60.57 + * System.out.println("abc" + cde);
60.58 + * String c = "abc".substring(2,3);
60.59 + * String d = cde.substring(1, 2);
60.60 + * </pre></blockquote>
60.61 + * <p>
60.62 + * The class <code>String</code> includes methods for examining
60.63 + * individual characters of the sequence, for comparing strings, for
60.64 + * searching strings, for extracting substrings, and for creating a
60.65 + * copy of a string with all characters translated to uppercase or to
60.66 + * lowercase. Case mapping is based on the Unicode Standard version
60.67 + * specified by the {@link java.lang.Character Character} class.
60.68 + * <p>
60.69 + * The Java language provides special support for the string
60.70 + * concatenation operator ( + ), and for conversion of
60.71 + * other objects to strings. String concatenation is implemented
60.72 + * through the <code>StringBuilder</code>(or <code>StringBuffer</code>)
60.73 + * class and its <code>append</code> method.
60.74 + * String conversions are implemented through the method
60.75 + * <code>toString</code>, defined by <code>Object</code> and
60.76 + * inherited by all classes in Java. For additional information on
60.77 + * string concatenation and conversion, see Gosling, Joy, and Steele,
60.78 + * <i>The Java Language Specification</i>.
60.79 + *
60.80 + * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
60.81 + * or method in this class will cause a {@link NullPointerException} to be
60.82 + * thrown.
60.83 + *
60.84 + * <p>A <code>String</code> represents a string in the UTF-16 format
60.85 + * in which <em>supplementary characters</em> are represented by <em>surrogate
60.86 + * pairs</em> (see the section <a href="Character.html#unicode">Unicode
60.87 + * Character Representations</a> in the <code>Character</code> class for
60.88 + * more information).
60.89 + * Index values refer to <code>char</code> code units, so a supplementary
60.90 + * character uses two positions in a <code>String</code>.
60.91 + * <p>The <code>String</code> class provides methods for dealing with
60.92 + * Unicode code points (i.e., characters), in addition to those for
60.93 + * dealing with Unicode code units (i.e., <code>char</code> values).
60.94 + *
60.95 + * @author Lee Boynton
60.96 + * @author Arthur van Hoff
60.97 + * @author Martin Buchholz
60.98 + * @author Ulf Zibis
60.99 + * @see java.lang.Object#toString()
60.100 + * @see java.lang.StringBuffer
60.101 + * @see java.lang.StringBuilder
60.102 + * @see java.nio.charset.Charset
60.103 + * @since JDK1.0
60.104 + */
60.105 +
60.106 +@ExtraJavaScript(
60.107 + resource="/org/apidesign/vm4brwsr/emul/java_lang_String.js",
60.108 + processByteCode=true
60.109 +)
60.110 +@JavaScriptPrototype(container = "String.prototype", prototype = "new String")
60.111 +public final class String
60.112 + implements java.io.Serializable, Comparable<String>, CharSequence
60.113 +{
60.114 + /** real string to delegate to */
60.115 + private Object r;
60.116 +
60.117 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
60.118 + private static final long serialVersionUID = -6849794470754667710L;
60.119 +
60.120 + @JavaScriptOnly(name="toString", value="function() { return this.fld_r; }")
60.121 + private static void jsToString() {
60.122 + }
60.123 +
60.124 + @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
60.125 + private static void jsValudOf() {
60.126 + }
60.127 +
60.128 + /**
60.129 + * Class String is special cased within the Serialization Stream Protocol.
60.130 + *
60.131 + * A String instance is written initially into an ObjectOutputStream in the
60.132 + * following format:
60.133 + * <pre>
60.134 + * <code>TC_STRING</code> (utf String)
60.135 + * </pre>
60.136 + * The String is written by method <code>DataOutput.writeUTF</code>.
60.137 + * A new handle is generated to refer to all future references to the
60.138 + * string instance within the stream.
60.139 + */
60.140 +// private static final ObjectStreamField[] serialPersistentFields =
60.141 +// new ObjectStreamField[0];
60.142 +
60.143 + /**
60.144 + * Initializes a newly created {@code String} object so that it represents
60.145 + * an empty character sequence. Note that use of this constructor is
60.146 + * unnecessary since Strings are immutable.
60.147 + */
60.148 + public String() {
60.149 + this.r = "";
60.150 + }
60.151 +
60.152 + /**
60.153 + * Initializes a newly created {@code String} object so that it represents
60.154 + * the same sequence of characters as the argument; in other words, the
60.155 + * newly created string is a copy of the argument string. Unless an
60.156 + * explicit copy of {@code original} is needed, use of this constructor is
60.157 + * unnecessary since Strings are immutable.
60.158 + *
60.159 + * @param original
60.160 + * A {@code String}
60.161 + */
60.162 + public String(String original) {
60.163 + this.r = original.toString();
60.164 + }
60.165 +
60.166 + /**
60.167 + * Allocates a new {@code String} so that it represents the sequence of
60.168 + * characters currently contained in the character array argument. The
60.169 + * contents of the character array are copied; subsequent modification of
60.170 + * the character array does not affect the newly created string.
60.171 + *
60.172 + * @param value
60.173 + * The initial value of the string
60.174 + */
60.175 + @JavaScriptBody(args = { "charArr" }, body=
60.176 + "for (var i = 0; i < charArr.length; i++) {\n"
60.177 + + " if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n"
60.178 + + "}\n"
60.179 + + "this.fld_r = charArr.join('');\n"
60.180 + )
60.181 + public String(char value[]) {
60.182 + }
60.183 +
60.184 + /**
60.185 + * Allocates a new {@code String} that contains characters from a subarray
60.186 + * of the character array argument. The {@code offset} argument is the
60.187 + * index of the first character of the subarray and the {@code count}
60.188 + * argument specifies the length of the subarray. The contents of the
60.189 + * subarray are copied; subsequent modification of the character array does
60.190 + * not affect the newly created string.
60.191 + *
60.192 + * @param value
60.193 + * Array that is the source of characters
60.194 + *
60.195 + * @param offset
60.196 + * The initial offset
60.197 + *
60.198 + * @param count
60.199 + * The length
60.200 + *
60.201 + * @throws IndexOutOfBoundsException
60.202 + * If the {@code offset} and {@code count} arguments index
60.203 + * characters outside the bounds of the {@code value} array
60.204 + */
60.205 + @JavaScriptBody(args = { "charArr", "off", "cnt" }, body =
60.206 + "var up = off + cnt;\n" +
60.207 + "for (var i = off; i < up; i++) {\n" +
60.208 + " if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n" +
60.209 + "}\n" +
60.210 + "this.fld_r = charArr.slice(off, up).join(\"\");\n"
60.211 + )
60.212 + public String(char value[], int offset, int count) {
60.213 + }
60.214 +
60.215 + /**
60.216 + * Allocates a new {@code String} that contains characters from a subarray
60.217 + * of the <a href="Character.html#unicode">Unicode code point</a> array
60.218 + * argument. The {@code offset} argument is the index of the first code
60.219 + * point of the subarray and the {@code count} argument specifies the
60.220 + * length of the subarray. The contents of the subarray are converted to
60.221 + * {@code char}s; subsequent modification of the {@code int} array does not
60.222 + * affect the newly created string.
60.223 + *
60.224 + * @param codePoints
60.225 + * Array that is the source of Unicode code points
60.226 + *
60.227 + * @param offset
60.228 + * The initial offset
60.229 + *
60.230 + * @param count
60.231 + * The length
60.232 + *
60.233 + * @throws IllegalArgumentException
60.234 + * If any invalid Unicode code point is found in {@code
60.235 + * codePoints}
60.236 + *
60.237 + * @throws IndexOutOfBoundsException
60.238 + * If the {@code offset} and {@code count} arguments index
60.239 + * characters outside the bounds of the {@code codePoints} array
60.240 + *
60.241 + * @since 1.5
60.242 + */
60.243 + public String(int[] codePoints, int offset, int count) {
60.244 + if (offset < 0) {
60.245 + throw new StringIndexOutOfBoundsException(offset);
60.246 + }
60.247 + if (count < 0) {
60.248 + throw new StringIndexOutOfBoundsException(count);
60.249 + }
60.250 + // Note: offset or count might be near -1>>>1.
60.251 + if (offset > codePoints.length - count) {
60.252 + throw new StringIndexOutOfBoundsException(offset + count);
60.253 + }
60.254 +
60.255 + final int end = offset + count;
60.256 +
60.257 + // Pass 1: Compute precise size of char[]
60.258 + int n = count;
60.259 + for (int i = offset; i < end; i++) {
60.260 + int c = codePoints[i];
60.261 + if (Character.isBmpCodePoint(c))
60.262 + continue;
60.263 + else if (Character.isValidCodePoint(c))
60.264 + n++;
60.265 + else throw new IllegalArgumentException(Integer.toString(c));
60.266 + }
60.267 +
60.268 + // Pass 2: Allocate and fill in char[]
60.269 + final char[] v = new char[n];
60.270 +
60.271 + for (int i = offset, j = 0; i < end; i++, j++) {
60.272 + int c = codePoints[i];
60.273 + if (Character.isBmpCodePoint(c))
60.274 + v[j] = (char) c;
60.275 + else
60.276 + Character.toSurrogates(c, v, j++);
60.277 + }
60.278 +
60.279 + this.r = new String(v, 0, n);
60.280 + }
60.281 +
60.282 + /**
60.283 + * Allocates a new {@code String} constructed from a subarray of an array
60.284 + * of 8-bit integer values.
60.285 + *
60.286 + * <p> The {@code offset} argument is the index of the first byte of the
60.287 + * subarray, and the {@code count} argument specifies the length of the
60.288 + * subarray.
60.289 + *
60.290 + * <p> Each {@code byte} in the subarray is converted to a {@code char} as
60.291 + * specified in the method above.
60.292 + *
60.293 + * @deprecated This method does not properly convert bytes into characters.
60.294 + * As of JDK 1.1, the preferred way to do this is via the
60.295 + * {@code String} constructors that take a {@link
60.296 + * java.nio.charset.Charset}, charset name, or that use the platform's
60.297 + * default charset.
60.298 + *
60.299 + * @param ascii
60.300 + * The bytes to be converted to characters
60.301 + *
60.302 + * @param hibyte
60.303 + * The top 8 bits of each 16-bit Unicode code unit
60.304 + *
60.305 + * @param offset
60.306 + * The initial offset
60.307 + * @param count
60.308 + * The length
60.309 + *
60.310 + * @throws IndexOutOfBoundsException
60.311 + * If the {@code offset} or {@code count} argument is invalid
60.312 + *
60.313 + * @see #String(byte[], int)
60.314 + * @see #String(byte[], int, int, java.lang.String)
60.315 + * @see #String(byte[], int, int, java.nio.charset.Charset)
60.316 + * @see #String(byte[], int, int)
60.317 + * @see #String(byte[], java.lang.String)
60.318 + * @see #String(byte[], java.nio.charset.Charset)
60.319 + * @see #String(byte[])
60.320 + */
60.321 + @Deprecated
60.322 + public String(byte ascii[], int hibyte, int offset, int count) {
60.323 + checkBounds(ascii, offset, count);
60.324 + char value[] = new char[count];
60.325 +
60.326 + if (hibyte == 0) {
60.327 + for (int i = count ; i-- > 0 ;) {
60.328 + value[i] = (char) (ascii[i + offset] & 0xff);
60.329 + }
60.330 + } else {
60.331 + hibyte <<= 8;
60.332 + for (int i = count ; i-- > 0 ;) {
60.333 + value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
60.334 + }
60.335 + }
60.336 + this.r = new String(value, 0, count);
60.337 + }
60.338 +
60.339 + /**
60.340 + * Allocates a new {@code String} containing characters constructed from
60.341 + * an array of 8-bit integer values. Each character <i>c</i>in the
60.342 + * resulting string is constructed from the corresponding component
60.343 + * <i>b</i> in the byte array such that:
60.344 + *
60.345 + * <blockquote><pre>
60.346 + * <b><i>c</i></b> == (char)(((hibyte & 0xff) << 8)
60.347 + * | (<b><i>b</i></b> & 0xff))
60.348 + * </pre></blockquote>
60.349 + *
60.350 + * @deprecated This method does not properly convert bytes into
60.351 + * characters. As of JDK 1.1, the preferred way to do this is via the
60.352 + * {@code String} constructors that take a {@link
60.353 + * java.nio.charset.Charset}, charset name, or that use the platform's
60.354 + * default charset.
60.355 + *
60.356 + * @param ascii
60.357 + * The bytes to be converted to characters
60.358 + *
60.359 + * @param hibyte
60.360 + * The top 8 bits of each 16-bit Unicode code unit
60.361 + *
60.362 + * @see #String(byte[], int, int, java.lang.String)
60.363 + * @see #String(byte[], int, int, java.nio.charset.Charset)
60.364 + * @see #String(byte[], int, int)
60.365 + * @see #String(byte[], java.lang.String)
60.366 + * @see #String(byte[], java.nio.charset.Charset)
60.367 + * @see #String(byte[])
60.368 + */
60.369 + @Deprecated
60.370 + public String(byte ascii[], int hibyte) {
60.371 + this(ascii, hibyte, 0, ascii.length);
60.372 + }
60.373 +
60.374 + /* Common private utility method used to bounds check the byte array
60.375 + * and requested offset & length values used by the String(byte[],..)
60.376 + * constructors.
60.377 + */
60.378 + private static void checkBounds(byte[] bytes, int offset, int length) {
60.379 + if (length < 0)
60.380 + throw new StringIndexOutOfBoundsException(length);
60.381 + if (offset < 0)
60.382 + throw new StringIndexOutOfBoundsException(offset);
60.383 + if (offset > bytes.length - length)
60.384 + throw new StringIndexOutOfBoundsException(offset + length);
60.385 + }
60.386 +
60.387 + /**
60.388 + * Constructs a new {@code String} by decoding the specified subarray of
60.389 + * bytes using the specified charset. The length of the new {@code String}
60.390 + * is a function of the charset, and hence may not be equal to the length
60.391 + * of the subarray.
60.392 + *
60.393 + * <p> The behavior of this constructor when the given bytes are not valid
60.394 + * in the given charset is unspecified. The {@link
60.395 + * java.nio.charset.CharsetDecoder} class should be used when more control
60.396 + * over the decoding process is required.
60.397 + *
60.398 + * @param bytes
60.399 + * The bytes to be decoded into characters
60.400 + *
60.401 + * @param offset
60.402 + * The index of the first byte to decode
60.403 + *
60.404 + * @param length
60.405 + * The number of bytes to decode
60.406 +
60.407 + * @param charsetName
60.408 + * The name of a supported {@linkplain java.nio.charset.Charset
60.409 + * charset}
60.410 + *
60.411 + * @throws UnsupportedEncodingException
60.412 + * If the named charset is not supported
60.413 + *
60.414 + * @throws IndexOutOfBoundsException
60.415 + * If the {@code offset} and {@code length} arguments index
60.416 + * characters outside the bounds of the {@code bytes} array
60.417 + *
60.418 + * @since JDK1.1
60.419 + */
60.420 +// public String(byte bytes[], int offset, int length, String charsetName)
60.421 +// throws UnsupportedEncodingException
60.422 +// {
60.423 +// if (charsetName == null)
60.424 +// throw new NullPointerException("charsetName");
60.425 +// checkBounds(bytes, offset, length);
60.426 +// char[] v = StringCoding.decode(charsetName, bytes, offset, length);
60.427 +// this.offset = 0;
60.428 +// this.count = v.length;
60.429 +// this.value = v;
60.430 +// }
60.431 +
60.432 + /**
60.433 + * Constructs a new {@code String} by decoding the specified subarray of
60.434 + * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
60.435 + * The length of the new {@code String} is a function of the charset, and
60.436 + * hence may not be equal to the length of the subarray.
60.437 + *
60.438 + * <p> This method always replaces malformed-input and unmappable-character
60.439 + * sequences with this charset's default replacement string. The {@link
60.440 + * java.nio.charset.CharsetDecoder} class should be used when more control
60.441 + * over the decoding process is required.
60.442 + *
60.443 + * @param bytes
60.444 + * The bytes to be decoded into characters
60.445 + *
60.446 + * @param offset
60.447 + * The index of the first byte to decode
60.448 + *
60.449 + * @param length
60.450 + * The number of bytes to decode
60.451 + *
60.452 + * @param charset
60.453 + * The {@linkplain java.nio.charset.Charset charset} to be used to
60.454 + * decode the {@code bytes}
60.455 + *
60.456 + * @throws IndexOutOfBoundsException
60.457 + * If the {@code offset} and {@code length} arguments index
60.458 + * characters outside the bounds of the {@code bytes} array
60.459 + *
60.460 + * @since 1.6
60.461 + */
60.462 + /* don't want dependnecy on Charset
60.463 + public String(byte bytes[], int offset, int length, Charset charset) {
60.464 + if (charset == null)
60.465 + throw new NullPointerException("charset");
60.466 + checkBounds(bytes, offset, length);
60.467 + char[] v = StringCoding.decode(charset, bytes, offset, length);
60.468 + this.offset = 0;
60.469 + this.count = v.length;
60.470 + this.value = v;
60.471 + }
60.472 + */
60.473 +
60.474 + /**
60.475 + * Constructs a new {@code String} by decoding the specified array of bytes
60.476 + * using the specified {@linkplain java.nio.charset.Charset charset}. The
60.477 + * length of the new {@code String} is a function of the charset, and hence
60.478 + * may not be equal to the length of the byte array.
60.479 + *
60.480 + * <p> The behavior of this constructor when the given bytes are not valid
60.481 + * in the given charset is unspecified. The {@link
60.482 + * java.nio.charset.CharsetDecoder} class should be used when more control
60.483 + * over the decoding process is required.
60.484 + *
60.485 + * @param bytes
60.486 + * The bytes to be decoded into characters
60.487 + *
60.488 + * @param charsetName
60.489 + * The name of a supported {@linkplain java.nio.charset.Charset
60.490 + * charset}
60.491 + *
60.492 + * @throws UnsupportedEncodingException
60.493 + * If the named charset is not supported
60.494 + *
60.495 + * @since JDK1.1
60.496 + */
60.497 +// public String(byte bytes[], String charsetName)
60.498 +// throws UnsupportedEncodingException
60.499 +// {
60.500 +// this(bytes, 0, bytes.length, charsetName);
60.501 +// }
60.502 +
60.503 + /**
60.504 + * Constructs a new {@code String} by decoding the specified array of
60.505 + * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
60.506 + * The length of the new {@code String} is a function of the charset, and
60.507 + * hence may not be equal to the length of the byte array.
60.508 + *
60.509 + * <p> This method always replaces malformed-input and unmappable-character
60.510 + * sequences with this charset's default replacement string. The {@link
60.511 + * java.nio.charset.CharsetDecoder} class should be used when more control
60.512 + * over the decoding process is required.
60.513 + *
60.514 + * @param bytes
60.515 + * The bytes to be decoded into characters
60.516 + *
60.517 + * @param charset
60.518 + * The {@linkplain java.nio.charset.Charset charset} to be used to
60.519 + * decode the {@code bytes}
60.520 + *
60.521 + * @since 1.6
60.522 + */
60.523 + /* don't want dep on Charset
60.524 + public String(byte bytes[], Charset charset) {
60.525 + this(bytes, 0, bytes.length, charset);
60.526 + }
60.527 + */
60.528 +
60.529 + /**
60.530 + * Constructs a new {@code String} by decoding the specified subarray of
60.531 + * bytes using the platform's default charset. The length of the new
60.532 + * {@code String} is a function of the charset, and hence may not be equal
60.533 + * to the length of the subarray.
60.534 + *
60.535 + * <p> The behavior of this constructor when the given bytes are not valid
60.536 + * in the default charset is unspecified. The {@link
60.537 + * java.nio.charset.CharsetDecoder} class should be used when more control
60.538 + * over the decoding process is required.
60.539 + *
60.540 + * @param bytes
60.541 + * The bytes to be decoded into characters
60.542 + *
60.543 + * @param offset
60.544 + * The index of the first byte to decode
60.545 + *
60.546 + * @param length
60.547 + * The number of bytes to decode
60.548 + *
60.549 + * @throws IndexOutOfBoundsException
60.550 + * If the {@code offset} and the {@code length} arguments index
60.551 + * characters outside the bounds of the {@code bytes} array
60.552 + *
60.553 + * @since JDK1.1
60.554 + */
60.555 + public String(byte bytes[], int offset, int length) {
60.556 + checkBounds(bytes, offset, length);
60.557 + char[] v = new char[length];
60.558 + for (int i = 0; i < length; i++) {
60.559 + v[i] = (char)bytes[offset++];
60.560 + }
60.561 + this.r = new String(v, 0, v.length);
60.562 + }
60.563 +
60.564 + /**
60.565 + * Constructs a new {@code String} by decoding the specified array of bytes
60.566 + * using the platform's default charset. The length of the new {@code
60.567 + * String} is a function of the charset, and hence may not be equal to the
60.568 + * length of the byte array.
60.569 + *
60.570 + * <p> The behavior of this constructor when the given bytes are not valid
60.571 + * in the default charset is unspecified. The {@link
60.572 + * java.nio.charset.CharsetDecoder} class should be used when more control
60.573 + * over the decoding process is required.
60.574 + *
60.575 + * @param bytes
60.576 + * The bytes to be decoded into characters
60.577 + *
60.578 + * @since JDK1.1
60.579 + */
60.580 + public String(byte bytes[]) {
60.581 + this(bytes, 0, bytes.length);
60.582 + }
60.583 +
60.584 + /**
60.585 + * Allocates a new string that contains the sequence of characters
60.586 + * currently contained in the string buffer argument. The contents of the
60.587 + * string buffer are copied; subsequent modification of the string buffer
60.588 + * does not affect the newly created string.
60.589 + *
60.590 + * @param buffer
60.591 + * A {@code StringBuffer}
60.592 + */
60.593 + public String(StringBuffer buffer) {
60.594 + this.r = buffer.toString();
60.595 + }
60.596 +
60.597 + /**
60.598 + * Allocates a new string that contains the sequence of characters
60.599 + * currently contained in the string builder argument. The contents of the
60.600 + * string builder are copied; subsequent modification of the string builder
60.601 + * does not affect the newly created string.
60.602 + *
60.603 + * <p> This constructor is provided to ease migration to {@code
60.604 + * StringBuilder}. Obtaining a string from a string builder via the {@code
60.605 + * toString} method is likely to run faster and is generally preferred.
60.606 + *
60.607 + * @param builder
60.608 + * A {@code StringBuilder}
60.609 + *
60.610 + * @since 1.5
60.611 + */
60.612 + public String(StringBuilder builder) {
60.613 + this.r = builder.toString();
60.614 + }
60.615 +
60.616 + /**
60.617 + * Returns the length of this string.
60.618 + * The length is equal to the number of <a href="Character.html#unicode">Unicode
60.619 + * code units</a> in the string.
60.620 + *
60.621 + * @return the length of the sequence of characters represented by this
60.622 + * object.
60.623 + */
60.624 + @JavaScriptBody(args = {}, body = "return this.toString().length;")
60.625 + public int length() {
60.626 + throw new UnsupportedOperationException();
60.627 + }
60.628 +
60.629 + /**
60.630 + * Returns <tt>true</tt> if, and only if, {@link #length()} is <tt>0</tt>.
60.631 + *
60.632 + * @return <tt>true</tt> if {@link #length()} is <tt>0</tt>, otherwise
60.633 + * <tt>false</tt>
60.634 + *
60.635 + * @since 1.6
60.636 + */
60.637 + @JavaScriptBody(args = {}, body="return this.toString().length === 0;")
60.638 + public boolean isEmpty() {
60.639 + return length() == 0;
60.640 + }
60.641 +
60.642 + /**
60.643 + * Returns the <code>char</code> value at the
60.644 + * specified index. An index ranges from <code>0</code> to
60.645 + * <code>length() - 1</code>. The first <code>char</code> value of the sequence
60.646 + * is at index <code>0</code>, the next at index <code>1</code>,
60.647 + * and so on, as for array indexing.
60.648 + *
60.649 + * <p>If the <code>char</code> value specified by the index is a
60.650 + * <a href="Character.html#unicode">surrogate</a>, the surrogate
60.651 + * value is returned.
60.652 + *
60.653 + * @param index the index of the <code>char</code> value.
60.654 + * @return the <code>char</code> value at the specified index of this string.
60.655 + * The first <code>char</code> value is at index <code>0</code>.
60.656 + * @exception IndexOutOfBoundsException if the <code>index</code>
60.657 + * argument is negative or not less than the length of this
60.658 + * string.
60.659 + */
60.660 + @JavaScriptBody(args = { "index" },
60.661 + body = "return this.toString().charCodeAt(index);"
60.662 + )
60.663 + public char charAt(int index) {
60.664 + throw new UnsupportedOperationException();
60.665 + }
60.666 +
60.667 + /**
60.668 + * Returns the character (Unicode code point) at the specified
60.669 + * index. The index refers to <code>char</code> values
60.670 + * (Unicode code units) and ranges from <code>0</code> to
60.671 + * {@link #length()}<code> - 1</code>.
60.672 + *
60.673 + * <p> If the <code>char</code> value specified at the given index
60.674 + * is in the high-surrogate range, the following index is less
60.675 + * than the length of this <code>String</code>, and the
60.676 + * <code>char</code> value at the following index is in the
60.677 + * low-surrogate range, then the supplementary code point
60.678 + * corresponding to this surrogate pair is returned. Otherwise,
60.679 + * the <code>char</code> value at the given index is returned.
60.680 + *
60.681 + * @param index the index to the <code>char</code> values
60.682 + * @return the code point value of the character at the
60.683 + * <code>index</code>
60.684 + * @exception IndexOutOfBoundsException if the <code>index</code>
60.685 + * argument is negative or not less than the length of this
60.686 + * string.
60.687 + * @since 1.5
60.688 + */
60.689 + public int codePointAt(int index) {
60.690 + if ((index < 0) || (index >= length())) {
60.691 + throw new StringIndexOutOfBoundsException(index);
60.692 + }
60.693 + return Character.codePointAtImpl(toCharArray(), offset() + index, offset() + length());
60.694 + }
60.695 +
60.696 + /**
60.697 + * Returns the character (Unicode code point) before the specified
60.698 + * index. The index refers to <code>char</code> values
60.699 + * (Unicode code units) and ranges from <code>1</code> to {@link
60.700 + * CharSequence#length() length}.
60.701 + *
60.702 + * <p> If the <code>char</code> value at <code>(index - 1)</code>
60.703 + * is in the low-surrogate range, <code>(index - 2)</code> is not
60.704 + * negative, and the <code>char</code> value at <code>(index -
60.705 + * 2)</code> is in the high-surrogate range, then the
60.706 + * supplementary code point value of the surrogate pair is
60.707 + * returned. If the <code>char</code> value at <code>index -
60.708 + * 1</code> is an unpaired low-surrogate or a high-surrogate, the
60.709 + * surrogate value is returned.
60.710 + *
60.711 + * @param index the index following the code point that should be returned
60.712 + * @return the Unicode code point value before the given index.
60.713 + * @exception IndexOutOfBoundsException if the <code>index</code>
60.714 + * argument is less than 1 or greater than the length
60.715 + * of this string.
60.716 + * @since 1.5
60.717 + */
60.718 + public int codePointBefore(int index) {
60.719 + int i = index - 1;
60.720 + if ((i < 0) || (i >= length())) {
60.721 + throw new StringIndexOutOfBoundsException(index);
60.722 + }
60.723 + return Character.codePointBeforeImpl(toCharArray(), offset() + index, offset());
60.724 + }
60.725 +
60.726 + /**
60.727 + * Returns the number of Unicode code points in the specified text
60.728 + * range of this <code>String</code>. The text range begins at the
60.729 + * specified <code>beginIndex</code> and extends to the
60.730 + * <code>char</code> at index <code>endIndex - 1</code>. Thus the
60.731 + * length (in <code>char</code>s) of the text range is
60.732 + * <code>endIndex-beginIndex</code>. Unpaired surrogates within
60.733 + * the text range count as one code point each.
60.734 + *
60.735 + * @param beginIndex the index to the first <code>char</code> of
60.736 + * the text range.
60.737 + * @param endIndex the index after the last <code>char</code> of
60.738 + * the text range.
60.739 + * @return the number of Unicode code points in the specified text
60.740 + * range
60.741 + * @exception IndexOutOfBoundsException if the
60.742 + * <code>beginIndex</code> is negative, or <code>endIndex</code>
60.743 + * is larger than the length of this <code>String</code>, or
60.744 + * <code>beginIndex</code> is larger than <code>endIndex</code>.
60.745 + * @since 1.5
60.746 + */
60.747 + public int codePointCount(int beginIndex, int endIndex) {
60.748 + if (beginIndex < 0 || endIndex > length() || beginIndex > endIndex) {
60.749 + throw new IndexOutOfBoundsException();
60.750 + }
60.751 + return Character.codePointCountImpl(toCharArray(), offset()+beginIndex, endIndex-beginIndex);
60.752 + }
60.753 +
60.754 + /**
60.755 + * Returns the index within this <code>String</code> that is
60.756 + * offset from the given <code>index</code> by
60.757 + * <code>codePointOffset</code> code points. Unpaired surrogates
60.758 + * within the text range given by <code>index</code> and
60.759 + * <code>codePointOffset</code> count as one code point each.
60.760 + *
60.761 + * @param index the index to be offset
60.762 + * @param codePointOffset the offset in code points
60.763 + * @return the index within this <code>String</code>
60.764 + * @exception IndexOutOfBoundsException if <code>index</code>
60.765 + * is negative or larger then the length of this
60.766 + * <code>String</code>, or if <code>codePointOffset</code> is positive
60.767 + * and the substring starting with <code>index</code> has fewer
60.768 + * than <code>codePointOffset</code> code points,
60.769 + * or if <code>codePointOffset</code> is negative and the substring
60.770 + * before <code>index</code> has fewer than the absolute value
60.771 + * of <code>codePointOffset</code> code points.
60.772 + * @since 1.5
60.773 + */
60.774 + public int offsetByCodePoints(int index, int codePointOffset) {
60.775 + if (index < 0 || index > length()) {
60.776 + throw new IndexOutOfBoundsException();
60.777 + }
60.778 + return Character.offsetByCodePointsImpl(toCharArray(), offset(), length(),
60.779 + offset()+index, codePointOffset) - offset();
60.780 + }
60.781 +
60.782 + /**
60.783 + * Copy characters from this string into dst starting at dstBegin.
60.784 + * This method doesn't perform any range checking.
60.785 + */
60.786 + @JavaScriptBody(args = { "arr", "to" }, body =
60.787 + "var s = this.toString();\n" +
60.788 + "for (var i = 0; i < s.length; i++) {\n" +
60.789 + " arr[to++] = s[i];\n" +
60.790 + "}"
60.791 + )
60.792 + void getChars(char dst[], int dstBegin) {
60.793 + AbstractStringBuilder.arraycopy(toCharArray(), offset(), dst, dstBegin, length());
60.794 + }
60.795 +
60.796 + /**
60.797 + * Copies characters from this string into the destination character
60.798 + * array.
60.799 + * <p>
60.800 + * The first character to be copied is at index <code>srcBegin</code>;
60.801 + * the last character to be copied is at index <code>srcEnd-1</code>
60.802 + * (thus the total number of characters to be copied is
60.803 + * <code>srcEnd-srcBegin</code>). The characters are copied into the
60.804 + * subarray of <code>dst</code> starting at index <code>dstBegin</code>
60.805 + * and ending at index:
60.806 + * <p><blockquote><pre>
60.807 + * dstbegin + (srcEnd-srcBegin) - 1
60.808 + * </pre></blockquote>
60.809 + *
60.810 + * @param srcBegin index of the first character in the string
60.811 + * to copy.
60.812 + * @param srcEnd index after the last character in the string
60.813 + * to copy.
60.814 + * @param dst the destination array.
60.815 + * @param dstBegin the start offset in the destination array.
60.816 + * @exception IndexOutOfBoundsException If any of the following
60.817 + * is true:
60.818 + * <ul><li><code>srcBegin</code> is negative.
60.819 + * <li><code>srcBegin</code> is greater than <code>srcEnd</code>
60.820 + * <li><code>srcEnd</code> is greater than the length of this
60.821 + * string
60.822 + * <li><code>dstBegin</code> is negative
60.823 + * <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
60.824 + * <code>dst.length</code></ul>
60.825 + */
60.826 + @JavaScriptBody(args = { "beg", "end", "arr", "dst" }, body=
60.827 + "var s = this.toString();\n" +
60.828 + "while (beg < end) {\n" +
60.829 + " arr[dst++] = s[beg++];\n" +
60.830 + "}\n"
60.831 + )
60.832 + public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
60.833 + if (srcBegin < 0) {
60.834 + throw new StringIndexOutOfBoundsException(srcBegin);
60.835 + }
60.836 + if (srcEnd > length()) {
60.837 + throw new StringIndexOutOfBoundsException(srcEnd);
60.838 + }
60.839 + if (srcBegin > srcEnd) {
60.840 + throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
60.841 + }
60.842 + AbstractStringBuilder.arraycopy(toCharArray(), offset() + srcBegin, dst, dstBegin,
60.843 + srcEnd - srcBegin);
60.844 + }
60.845 +
60.846 + /**
60.847 + * Copies characters from this string into the destination byte array. Each
60.848 + * byte receives the 8 low-order bits of the corresponding character. The
60.849 + * eight high-order bits of each character are not copied and do not
60.850 + * participate in the transfer in any way.
60.851 + *
60.852 + * <p> The first character to be copied is at index {@code srcBegin}; the
60.853 + * last character to be copied is at index {@code srcEnd-1}. The total
60.854 + * number of characters to be copied is {@code srcEnd-srcBegin}. The
60.855 + * characters, converted to bytes, are copied into the subarray of {@code
60.856 + * dst} starting at index {@code dstBegin} and ending at index:
60.857 + *
60.858 + * <blockquote><pre>
60.859 + * dstbegin + (srcEnd-srcBegin) - 1
60.860 + * </pre></blockquote>
60.861 + *
60.862 + * @deprecated This method does not properly convert characters into
60.863 + * bytes. As of JDK 1.1, the preferred way to do this is via the
60.864 + * {@link #getBytes()} method, which uses the platform's default charset.
60.865 + *
60.866 + * @param srcBegin
60.867 + * Index of the first character in the string to copy
60.868 + *
60.869 + * @param srcEnd
60.870 + * Index after the last character in the string to copy
60.871 + *
60.872 + * @param dst
60.873 + * The destination array
60.874 + *
60.875 + * @param dstBegin
60.876 + * The start offset in the destination array
60.877 + *
60.878 + * @throws IndexOutOfBoundsException
60.879 + * If any of the following is true:
60.880 + * <ul>
60.881 + * <li> {@code srcBegin} is negative
60.882 + * <li> {@code srcBegin} is greater than {@code srcEnd}
60.883 + * <li> {@code srcEnd} is greater than the length of this String
60.884 + * <li> {@code dstBegin} is negative
60.885 + * <li> {@code dstBegin+(srcEnd-srcBegin)} is larger than {@code
60.886 + * dst.length}
60.887 + * </ul>
60.888 + */
60.889 + @Deprecated
60.890 + public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) {
60.891 + if (srcBegin < 0) {
60.892 + throw new StringIndexOutOfBoundsException(srcBegin);
60.893 + }
60.894 + if (srcEnd > length()) {
60.895 + throw new StringIndexOutOfBoundsException(srcEnd);
60.896 + }
60.897 + if (srcBegin > srcEnd) {
60.898 + throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
60.899 + }
60.900 + int j = dstBegin;
60.901 + int n = offset() + srcEnd;
60.902 + int i = offset() + srcBegin;
60.903 + char[] val = toCharArray(); /* avoid getfield opcode */
60.904 +
60.905 + while (i < n) {
60.906 + dst[j++] = (byte)val[i++];
60.907 + }
60.908 + }
60.909 +
60.910 + /**
60.911 + * Encodes this {@code String} into a sequence of bytes using the named
60.912 + * charset, storing the result into a new byte array.
60.913 + *
60.914 + * <p> The behavior of this method when this string cannot be encoded in
60.915 + * the given charset is unspecified. The {@link
60.916 + * java.nio.charset.CharsetEncoder} class should be used when more control
60.917 + * over the encoding process is required.
60.918 + *
60.919 + * @param charsetName
60.920 + * The name of a supported {@linkplain java.nio.charset.Charset
60.921 + * charset}
60.922 + *
60.923 + * @return The resultant byte array
60.924 + *
60.925 + * @throws UnsupportedEncodingException
60.926 + * If the named charset is not supported
60.927 + *
60.928 + * @since JDK1.1
60.929 + */
60.930 +// public byte[] getBytes(String charsetName)
60.931 +// throws UnsupportedEncodingException
60.932 +// {
60.933 +// if (charsetName == null) throw new NullPointerException();
60.934 +// return StringCoding.encode(charsetName, value, offset, count);
60.935 +// }
60.936 +
60.937 + /**
60.938 + * Encodes this {@code String} into a sequence of bytes using the given
60.939 + * {@linkplain java.nio.charset.Charset charset}, storing the result into a
60.940 + * new byte array.
60.941 + *
60.942 + * <p> This method always replaces malformed-input and unmappable-character
60.943 + * sequences with this charset's default replacement byte array. The
60.944 + * {@link java.nio.charset.CharsetEncoder} class should be used when more
60.945 + * control over the encoding process is required.
60.946 + *
60.947 + * @param charset
60.948 + * The {@linkplain java.nio.charset.Charset} to be used to encode
60.949 + * the {@code String}
60.950 + *
60.951 + * @return The resultant byte array
60.952 + *
60.953 + * @since 1.6
60.954 + */
60.955 + /* don't want dep on Charset
60.956 + public byte[] getBytes(Charset charset) {
60.957 + if (charset == null) throw new NullPointerException();
60.958 + return StringCoding.encode(charset, value, offset, count);
60.959 + }
60.960 + */
60.961 +
60.962 + /**
60.963 + * Encodes this {@code String} into a sequence of bytes using the
60.964 + * platform's default charset, storing the result into a new byte array.
60.965 + *
60.966 + * <p> The behavior of this method when this string cannot be encoded in
60.967 + * the default charset is unspecified. The {@link
60.968 + * java.nio.charset.CharsetEncoder} class should be used when more control
60.969 + * over the encoding process is required.
60.970 + *
60.971 + * @return The resultant byte array
60.972 + *
60.973 + * @since JDK1.1
60.974 + */
60.975 + public byte[] getBytes() {
60.976 + byte[] arr = new byte[length()];
60.977 + for (int i = 0; i < arr.length; i++) {
60.978 + final char v = charAt(i);
60.979 + arr[i] = (byte)v;
60.980 + }
60.981 + return arr;
60.982 + }
60.983 +
60.984 + /**
60.985 + * Compares this string to the specified object. The result is {@code
60.986 + * true} if and only if the argument is not {@code null} and is a {@code
60.987 + * String} object that represents the same sequence of characters as this
60.988 + * object.
60.989 + *
60.990 + * @param anObject
60.991 + * The object to compare this {@code String} against
60.992 + *
60.993 + * @return {@code true} if the given object represents a {@code String}
60.994 + * equivalent to this string, {@code false} otherwise
60.995 + *
60.996 + * @see #compareTo(String)
60.997 + * @see #equalsIgnoreCase(String)
60.998 + */
60.999 + @JavaScriptBody(args = { "obj" }, body =
60.1000 + "return obj != null && obj.$instOf_java_lang_String && "
60.1001 + + "this.toString() === obj.toString();"
60.1002 + )
60.1003 + public boolean equals(Object anObject) {
60.1004 + if (this == anObject) {
60.1005 + return true;
60.1006 + }
60.1007 + if (anObject instanceof String) {
60.1008 + String anotherString = (String)anObject;
60.1009 + int n = length();
60.1010 + if (n == anotherString.length()) {
60.1011 + char v1[] = toCharArray();
60.1012 + char v2[] = anotherString.toCharArray();
60.1013 + int i = offset();
60.1014 + int j = anotherString.offset();
60.1015 + while (n-- != 0) {
60.1016 + if (v1[i++] != v2[j++])
60.1017 + return false;
60.1018 + }
60.1019 + return true;
60.1020 + }
60.1021 + }
60.1022 + return false;
60.1023 + }
60.1024 +
60.1025 + /**
60.1026 + * Compares this string to the specified {@code StringBuffer}. The result
60.1027 + * is {@code true} if and only if this {@code String} represents the same
60.1028 + * sequence of characters as the specified {@code StringBuffer}.
60.1029 + *
60.1030 + * @param sb
60.1031 + * The {@code StringBuffer} to compare this {@code String} against
60.1032 + *
60.1033 + * @return {@code true} if this {@code String} represents the same
60.1034 + * sequence of characters as the specified {@code StringBuffer},
60.1035 + * {@code false} otherwise
60.1036 + *
60.1037 + * @since 1.4
60.1038 + */
60.1039 + public boolean contentEquals(StringBuffer sb) {
60.1040 + synchronized(sb) {
60.1041 + return contentEquals((CharSequence)sb);
60.1042 + }
60.1043 + }
60.1044 +
60.1045 + /**
60.1046 + * Compares this string to the specified {@code CharSequence}. The result
60.1047 + * is {@code true} if and only if this {@code String} represents the same
60.1048 + * sequence of char values as the specified sequence.
60.1049 + *
60.1050 + * @param cs
60.1051 + * The sequence to compare this {@code String} against
60.1052 + *
60.1053 + * @return {@code true} if this {@code String} represents the same
60.1054 + * sequence of char values as the specified sequence, {@code
60.1055 + * false} otherwise
60.1056 + *
60.1057 + * @since 1.5
60.1058 + */
60.1059 + public boolean contentEquals(CharSequence cs) {
60.1060 + if (length() != cs.length())
60.1061 + return false;
60.1062 + // Argument is a StringBuffer, StringBuilder
60.1063 + if (cs instanceof AbstractStringBuilder) {
60.1064 + char v1[] = toCharArray();
60.1065 + char v2[] = ((AbstractStringBuilder)cs).getValue();
60.1066 + int i = offset();
60.1067 + int j = 0;
60.1068 + int n = length();
60.1069 + while (n-- != 0) {
60.1070 + if (v1[i++] != v2[j++])
60.1071 + return false;
60.1072 + }
60.1073 + return true;
60.1074 + }
60.1075 + // Argument is a String
60.1076 + if (cs.equals(this))
60.1077 + return true;
60.1078 + // Argument is a generic CharSequence
60.1079 + char v1[] = toCharArray();
60.1080 + int i = offset();
60.1081 + int j = 0;
60.1082 + int n = length();
60.1083 + while (n-- != 0) {
60.1084 + if (v1[i++] != cs.charAt(j++))
60.1085 + return false;
60.1086 + }
60.1087 + return true;
60.1088 + }
60.1089 +
60.1090 + /**
60.1091 + * Compares this {@code String} to another {@code String}, ignoring case
60.1092 + * considerations. Two strings are considered equal ignoring case if they
60.1093 + * are of the same length and corresponding characters in the two strings
60.1094 + * are equal ignoring case.
60.1095 + *
60.1096 + * <p> Two characters {@code c1} and {@code c2} are considered the same
60.1097 + * ignoring case if at least one of the following is true:
60.1098 + * <ul>
60.1099 + * <li> The two characters are the same (as compared by the
60.1100 + * {@code ==} operator)
60.1101 + * <li> Applying the method {@link
60.1102 + * java.lang.Character#toUpperCase(char)} to each character
60.1103 + * produces the same result
60.1104 + * <li> Applying the method {@link
60.1105 + * java.lang.Character#toLowerCase(char)} to each character
60.1106 + * produces the same result
60.1107 + * </ul>
60.1108 + *
60.1109 + * @param anotherString
60.1110 + * The {@code String} to compare this {@code String} against
60.1111 + *
60.1112 + * @return {@code true} if the argument is not {@code null} and it
60.1113 + * represents an equivalent {@code String} ignoring case; {@code
60.1114 + * false} otherwise
60.1115 + *
60.1116 + * @see #equals(Object)
60.1117 + */
60.1118 + public boolean equalsIgnoreCase(String anotherString) {
60.1119 + return (this == anotherString) ? true :
60.1120 + (anotherString != null) && (anotherString.length() == length()) &&
60.1121 + regionMatches(true, 0, anotherString, 0, length());
60.1122 + }
60.1123 +
60.1124 + /**
60.1125 + * Compares two strings lexicographically.
60.1126 + * The comparison is based on the Unicode value of each character in
60.1127 + * the strings. The character sequence represented by this
60.1128 + * <code>String</code> object is compared lexicographically to the
60.1129 + * character sequence represented by the argument string. The result is
60.1130 + * a negative integer if this <code>String</code> object
60.1131 + * lexicographically precedes the argument string. The result is a
60.1132 + * positive integer if this <code>String</code> object lexicographically
60.1133 + * follows the argument string. The result is zero if the strings
60.1134 + * are equal; <code>compareTo</code> returns <code>0</code> exactly when
60.1135 + * the {@link #equals(Object)} method would return <code>true</code>.
60.1136 + * <p>
60.1137 + * This is the definition of lexicographic ordering. If two strings are
60.1138 + * different, then either they have different characters at some index
60.1139 + * that is a valid index for both strings, or their lengths are different,
60.1140 + * or both. If they have different characters at one or more index
60.1141 + * positions, let <i>k</i> be the smallest such index; then the string
60.1142 + * whose character at position <i>k</i> has the smaller value, as
60.1143 + * determined by using the < operator, lexicographically precedes the
60.1144 + * other string. In this case, <code>compareTo</code> returns the
60.1145 + * difference of the two character values at position <code>k</code> in
60.1146 + * the two string -- that is, the value:
60.1147 + * <blockquote><pre>
60.1148 + * this.charAt(k)-anotherString.charAt(k)
60.1149 + * </pre></blockquote>
60.1150 + * If there is no index position at which they differ, then the shorter
60.1151 + * string lexicographically precedes the longer string. In this case,
60.1152 + * <code>compareTo</code> returns the difference of the lengths of the
60.1153 + * strings -- that is, the value:
60.1154 + * <blockquote><pre>
60.1155 + * this.length()-anotherString.length()
60.1156 + * </pre></blockquote>
60.1157 + *
60.1158 + * @param anotherString the <code>String</code> to be compared.
60.1159 + * @return the value <code>0</code> if the argument string is equal to
60.1160 + * this string; a value less than <code>0</code> if this string
60.1161 + * is lexicographically less than the string argument; and a
60.1162 + * value greater than <code>0</code> if this string is
60.1163 + * lexicographically greater than the string argument.
60.1164 + */
60.1165 + public int compareTo(String anotherString) {
60.1166 + int len1 = length();
60.1167 + int len2 = anotherString.length();
60.1168 + int n = Math.min(len1, len2);
60.1169 + char v1[] = toCharArray();
60.1170 + char v2[] = anotherString.toCharArray();
60.1171 + int i = offset();
60.1172 + int j = anotherString.offset();
60.1173 +
60.1174 + if (i == j) {
60.1175 + int k = i;
60.1176 + int lim = n + i;
60.1177 + while (k < lim) {
60.1178 + char c1 = v1[k];
60.1179 + char c2 = v2[k];
60.1180 + if (c1 != c2) {
60.1181 + return c1 - c2;
60.1182 + }
60.1183 + k++;
60.1184 + }
60.1185 + } else {
60.1186 + while (n-- != 0) {
60.1187 + char c1 = v1[i++];
60.1188 + char c2 = v2[j++];
60.1189 + if (c1 != c2) {
60.1190 + return c1 - c2;
60.1191 + }
60.1192 + }
60.1193 + }
60.1194 + return len1 - len2;
60.1195 + }
60.1196 +
60.1197 + /**
60.1198 + * A Comparator that orders <code>String</code> objects as by
60.1199 + * <code>compareToIgnoreCase</code>. This comparator is serializable.
60.1200 + * <p>
60.1201 + * Note that this Comparator does <em>not</em> take locale into account,
60.1202 + * and will result in an unsatisfactory ordering for certain locales.
60.1203 + * The java.text package provides <em>Collators</em> to allow
60.1204 + * locale-sensitive ordering.
60.1205 + *
60.1206 + * @see java.text.Collator#compare(String, String)
60.1207 + * @since 1.2
60.1208 + */
60.1209 + public static final Comparator<String> CASE_INSENSITIVE_ORDER
60.1210 + = new CaseInsensitiveComparator();
60.1211 +
60.1212 + private static int offset() {
60.1213 + return 0;
60.1214 + }
60.1215 +
60.1216 + private static class CaseInsensitiveComparator
60.1217 + implements Comparator<String>, java.io.Serializable {
60.1218 + // use serialVersionUID from JDK 1.2.2 for interoperability
60.1219 + private static final long serialVersionUID = 8575799808933029326L;
60.1220 +
60.1221 + public int compare(String s1, String s2) {
60.1222 + int n1 = s1.length();
60.1223 + int n2 = s2.length();
60.1224 + int min = Math.min(n1, n2);
60.1225 + for (int i = 0; i < min; i++) {
60.1226 + char c1 = s1.charAt(i);
60.1227 + char c2 = s2.charAt(i);
60.1228 + if (c1 != c2) {
60.1229 + c1 = Character.toUpperCase(c1);
60.1230 + c2 = Character.toUpperCase(c2);
60.1231 + if (c1 != c2) {
60.1232 + c1 = Character.toLowerCase(c1);
60.1233 + c2 = Character.toLowerCase(c2);
60.1234 + if (c1 != c2) {
60.1235 + // No overflow because of numeric promotion
60.1236 + return c1 - c2;
60.1237 + }
60.1238 + }
60.1239 + }
60.1240 + }
60.1241 + return n1 - n2;
60.1242 + }
60.1243 + }
60.1244 +
60.1245 + /**
60.1246 + * Compares two strings lexicographically, ignoring case
60.1247 + * differences. This method returns an integer whose sign is that of
60.1248 + * calling <code>compareTo</code> with normalized versions of the strings
60.1249 + * where case differences have been eliminated by calling
60.1250 + * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
60.1251 + * each character.
60.1252 + * <p>
60.1253 + * Note that this method does <em>not</em> take locale into account,
60.1254 + * and will result in an unsatisfactory ordering for certain locales.
60.1255 + * The java.text package provides <em>collators</em> to allow
60.1256 + * locale-sensitive ordering.
60.1257 + *
60.1258 + * @param str the <code>String</code> to be compared.
60.1259 + * @return a negative integer, zero, or a positive integer as the
60.1260 + * specified String is greater than, equal to, or less
60.1261 + * than this String, ignoring case considerations.
60.1262 + * @see java.text.Collator#compare(String, String)
60.1263 + * @since 1.2
60.1264 + */
60.1265 + public int compareToIgnoreCase(String str) {
60.1266 + return CASE_INSENSITIVE_ORDER.compare(this, str);
60.1267 + }
60.1268 +
60.1269 + /**
60.1270 + * Tests if two string regions are equal.
60.1271 + * <p>
60.1272 + * A substring of this <tt>String</tt> object is compared to a substring
60.1273 + * of the argument other. The result is true if these substrings
60.1274 + * represent identical character sequences. The substring of this
60.1275 + * <tt>String</tt> object to be compared begins at index <tt>toffset</tt>
60.1276 + * and has length <tt>len</tt>. The substring of other to be compared
60.1277 + * begins at index <tt>ooffset</tt> and has length <tt>len</tt>. The
60.1278 + * result is <tt>false</tt> if and only if at least one of the following
60.1279 + * is true:
60.1280 + * <ul><li><tt>toffset</tt> is negative.
60.1281 + * <li><tt>ooffset</tt> is negative.
60.1282 + * <li><tt>toffset+len</tt> is greater than the length of this
60.1283 + * <tt>String</tt> object.
60.1284 + * <li><tt>ooffset+len</tt> is greater than the length of the other
60.1285 + * argument.
60.1286 + * <li>There is some nonnegative integer <i>k</i> less than <tt>len</tt>
60.1287 + * such that:
60.1288 + * <tt>this.charAt(toffset+<i>k</i>) != other.charAt(ooffset+<i>k</i>)</tt>
60.1289 + * </ul>
60.1290 + *
60.1291 + * @param toffset the starting offset of the subregion in this string.
60.1292 + * @param other the string argument.
60.1293 + * @param ooffset the starting offset of the subregion in the string
60.1294 + * argument.
60.1295 + * @param len the number of characters to compare.
60.1296 + * @return <code>true</code> if the specified subregion of this string
60.1297 + * exactly matches the specified subregion of the string argument;
60.1298 + * <code>false</code> otherwise.
60.1299 + */
60.1300 + public boolean regionMatches(int toffset, String other, int ooffset,
60.1301 + int len) {
60.1302 + char ta[] = toCharArray();
60.1303 + int to = offset() + toffset;
60.1304 + char pa[] = other.toCharArray();
60.1305 + int po = other.offset() + ooffset;
60.1306 + // Note: toffset, ooffset, or len might be near -1>>>1.
60.1307 + if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len)
60.1308 + || (ooffset > (long)other.length() - len)) {
60.1309 + return false;
60.1310 + }
60.1311 + while (len-- > 0) {
60.1312 + if (ta[to++] != pa[po++]) {
60.1313 + return false;
60.1314 + }
60.1315 + }
60.1316 + return true;
60.1317 + }
60.1318 +
60.1319 + /**
60.1320 + * Tests if two string regions are equal.
60.1321 + * <p>
60.1322 + * A substring of this <tt>String</tt> object is compared to a substring
60.1323 + * of the argument <tt>other</tt>. The result is <tt>true</tt> if these
60.1324 + * substrings represent character sequences that are the same, ignoring
60.1325 + * case if and only if <tt>ignoreCase</tt> is true. The substring of
60.1326 + * this <tt>String</tt> object to be compared begins at index
60.1327 + * <tt>toffset</tt> and has length <tt>len</tt>. The substring of
60.1328 + * <tt>other</tt> to be compared begins at index <tt>ooffset</tt> and
60.1329 + * has length <tt>len</tt>. The result is <tt>false</tt> if and only if
60.1330 + * at least one of the following is true:
60.1331 + * <ul><li><tt>toffset</tt> is negative.
60.1332 + * <li><tt>ooffset</tt> is negative.
60.1333 + * <li><tt>toffset+len</tt> is greater than the length of this
60.1334 + * <tt>String</tt> object.
60.1335 + * <li><tt>ooffset+len</tt> is greater than the length of the other
60.1336 + * argument.
60.1337 + * <li><tt>ignoreCase</tt> is <tt>false</tt> and there is some nonnegative
60.1338 + * integer <i>k</i> less than <tt>len</tt> such that:
60.1339 + * <blockquote><pre>
60.1340 + * this.charAt(toffset+k) != other.charAt(ooffset+k)
60.1341 + * </pre></blockquote>
60.1342 + * <li><tt>ignoreCase</tt> is <tt>true</tt> and there is some nonnegative
60.1343 + * integer <i>k</i> less than <tt>len</tt> such that:
60.1344 + * <blockquote><pre>
60.1345 + * Character.toLowerCase(this.charAt(toffset+k)) !=
60.1346 + Character.toLowerCase(other.charAt(ooffset+k))
60.1347 + * </pre></blockquote>
60.1348 + * and:
60.1349 + * <blockquote><pre>
60.1350 + * Character.toUpperCase(this.charAt(toffset+k)) !=
60.1351 + * Character.toUpperCase(other.charAt(ooffset+k))
60.1352 + * </pre></blockquote>
60.1353 + * </ul>
60.1354 + *
60.1355 + * @param ignoreCase if <code>true</code>, ignore case when comparing
60.1356 + * characters.
60.1357 + * @param toffset the starting offset of the subregion in this
60.1358 + * string.
60.1359 + * @param other the string argument.
60.1360 + * @param ooffset the starting offset of the subregion in the string
60.1361 + * argument.
60.1362 + * @param len the number of characters to compare.
60.1363 + * @return <code>true</code> if the specified subregion of this string
60.1364 + * matches the specified subregion of the string argument;
60.1365 + * <code>false</code> otherwise. Whether the matching is exact
60.1366 + * or case insensitive depends on the <code>ignoreCase</code>
60.1367 + * argument.
60.1368 + */
60.1369 + public boolean regionMatches(boolean ignoreCase, int toffset,
60.1370 + String other, int ooffset, int len) {
60.1371 + char ta[] = toCharArray();
60.1372 + int to = offset() + toffset;
60.1373 + char pa[] = other.toCharArray();
60.1374 + int po = other.offset() + ooffset;
60.1375 + // Note: toffset, ooffset, or len might be near -1>>>1.
60.1376 + if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) ||
60.1377 + (ooffset > (long)other.length() - len)) {
60.1378 + return false;
60.1379 + }
60.1380 + while (len-- > 0) {
60.1381 + char c1 = ta[to++];
60.1382 + char c2 = pa[po++];
60.1383 + if (c1 == c2) {
60.1384 + continue;
60.1385 + }
60.1386 + if (ignoreCase) {
60.1387 + // If characters don't match but case may be ignored,
60.1388 + // try converting both characters to uppercase.
60.1389 + // If the results match, then the comparison scan should
60.1390 + // continue.
60.1391 + char u1 = Character.toUpperCase(c1);
60.1392 + char u2 = Character.toUpperCase(c2);
60.1393 + if (u1 == u2) {
60.1394 + continue;
60.1395 + }
60.1396 + // Unfortunately, conversion to uppercase does not work properly
60.1397 + // for the Georgian alphabet, which has strange rules about case
60.1398 + // conversion. So we need to make one last check before
60.1399 + // exiting.
60.1400 + if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
60.1401 + continue;
60.1402 + }
60.1403 + }
60.1404 + return false;
60.1405 + }
60.1406 + return true;
60.1407 + }
60.1408 +
60.1409 + /**
60.1410 + * Tests if the substring of this string beginning at the
60.1411 + * specified index starts with the specified prefix.
60.1412 + *
60.1413 + * @param prefix the prefix.
60.1414 + * @param toffset where to begin looking in this string.
60.1415 + * @return <code>true</code> if the character sequence represented by the
60.1416 + * argument is a prefix of the substring of this object starting
60.1417 + * at index <code>toffset</code>; <code>false</code> otherwise.
60.1418 + * The result is <code>false</code> if <code>toffset</code> is
60.1419 + * negative or greater than the length of this
60.1420 + * <code>String</code> object; otherwise the result is the same
60.1421 + * as the result of the expression
60.1422 + * <pre>
60.1423 + * this.substring(toffset).startsWith(prefix)
60.1424 + * </pre>
60.1425 + */
60.1426 + @JavaScriptBody(args = { "find", "from" }, body=
60.1427 + "find = find.toString();\n" +
60.1428 + "return this.toString().substring(from, from + find.length) === find;\n"
60.1429 + )
60.1430 + public boolean startsWith(String prefix, int toffset) {
60.1431 + char ta[] = toCharArray();
60.1432 + int to = offset() + toffset;
60.1433 + char pa[] = prefix.toCharArray();
60.1434 + int po = prefix.offset();
60.1435 + int pc = prefix.length();
60.1436 + // Note: toffset might be near -1>>>1.
60.1437 + if ((toffset < 0) || (toffset > length() - pc)) {
60.1438 + return false;
60.1439 + }
60.1440 + while (--pc >= 0) {
60.1441 + if (ta[to++] != pa[po++]) {
60.1442 + return false;
60.1443 + }
60.1444 + }
60.1445 + return true;
60.1446 + }
60.1447 +
60.1448 + /**
60.1449 + * Tests if this string starts with the specified prefix.
60.1450 + *
60.1451 + * @param prefix the prefix.
60.1452 + * @return <code>true</code> if the character sequence represented by the
60.1453 + * argument is a prefix of the character sequence represented by
60.1454 + * this string; <code>false</code> otherwise.
60.1455 + * Note also that <code>true</code> will be returned if the
60.1456 + * argument is an empty string or is equal to this
60.1457 + * <code>String</code> object as determined by the
60.1458 + * {@link #equals(Object)} method.
60.1459 + * @since 1. 0
60.1460 + */
60.1461 + public boolean startsWith(String prefix) {
60.1462 + return startsWith(prefix, 0);
60.1463 + }
60.1464 +
60.1465 + /**
60.1466 + * Tests if this string ends with the specified suffix.
60.1467 + *
60.1468 + * @param suffix the suffix.
60.1469 + * @return <code>true</code> if the character sequence represented by the
60.1470 + * argument is a suffix of the character sequence represented by
60.1471 + * this object; <code>false</code> otherwise. Note that the
60.1472 + * result will be <code>true</code> if the argument is the
60.1473 + * empty string or is equal to this <code>String</code> object
60.1474 + * as determined by the {@link #equals(Object)} method.
60.1475 + */
60.1476 + public boolean endsWith(String suffix) {
60.1477 + return startsWith(suffix, length() - suffix.length());
60.1478 + }
60.1479 +
60.1480 + /**
60.1481 + * Returns a hash code for this string. The hash code for a
60.1482 + * <code>String</code> object is computed as
60.1483 + * <blockquote><pre>
60.1484 + * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
60.1485 + * </pre></blockquote>
60.1486 + * using <code>int</code> arithmetic, where <code>s[i]</code> is the
60.1487 + * <i>i</i>th character of the string, <code>n</code> is the length of
60.1488 + * the string, and <code>^</code> indicates exponentiation.
60.1489 + * (The hash value of the empty string is zero.)
60.1490 + *
60.1491 + * @return a hash code value for this object.
60.1492 + */
60.1493 + public int hashCode() {
60.1494 + return super.hashCode();
60.1495 + }
60.1496 + int computeHashCode() {
60.1497 + int h = 0;
60.1498 + if (h == 0 && length() > 0) {
60.1499 + int off = offset();
60.1500 + int len = length();
60.1501 +
60.1502 + for (int i = 0; i < len; i++) {
60.1503 + h = 31*h + charAt(off++);
60.1504 + }
60.1505 + }
60.1506 + return h;
60.1507 + }
60.1508 +
60.1509 + /**
60.1510 + * Returns the index within this string of the first occurrence of
60.1511 + * the specified character. If a character with value
60.1512 + * <code>ch</code> occurs in the character sequence represented by
60.1513 + * this <code>String</code> object, then the index (in Unicode
60.1514 + * code units) of the first such occurrence is returned. For
60.1515 + * values of <code>ch</code> in the range from 0 to 0xFFFF
60.1516 + * (inclusive), this is the smallest value <i>k</i> such that:
60.1517 + * <blockquote><pre>
60.1518 + * this.charAt(<i>k</i>) == ch
60.1519 + * </pre></blockquote>
60.1520 + * is true. For other values of <code>ch</code>, it is the
60.1521 + * smallest value <i>k</i> such that:
60.1522 + * <blockquote><pre>
60.1523 + * this.codePointAt(<i>k</i>) == ch
60.1524 + * </pre></blockquote>
60.1525 + * is true. In either case, if no such character occurs in this
60.1526 + * string, then <code>-1</code> is returned.
60.1527 + *
60.1528 + * @param ch a character (Unicode code point).
60.1529 + * @return the index of the first occurrence of the character in the
60.1530 + * character sequence represented by this object, or
60.1531 + * <code>-1</code> if the character does not occur.
60.1532 + */
60.1533 + public int indexOf(int ch) {
60.1534 + return indexOf(ch, 0);
60.1535 + }
60.1536 +
60.1537 + /**
60.1538 + * Returns the index within this string of the first occurrence of the
60.1539 + * specified character, starting the search at the specified index.
60.1540 + * <p>
60.1541 + * If a character with value <code>ch</code> occurs in the
60.1542 + * character sequence represented by this <code>String</code>
60.1543 + * object at an index no smaller than <code>fromIndex</code>, then
60.1544 + * the index of the first such occurrence is returned. For values
60.1545 + * of <code>ch</code> in the range from 0 to 0xFFFF (inclusive),
60.1546 + * this is the smallest value <i>k</i> such that:
60.1547 + * <blockquote><pre>
60.1548 + * (this.charAt(<i>k</i>) == ch) && (<i>k</i> >= fromIndex)
60.1549 + * </pre></blockquote>
60.1550 + * is true. For other values of <code>ch</code>, it is the
60.1551 + * smallest value <i>k</i> such that:
60.1552 + * <blockquote><pre>
60.1553 + * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> >= fromIndex)
60.1554 + * </pre></blockquote>
60.1555 + * is true. In either case, if no such character occurs in this
60.1556 + * string at or after position <code>fromIndex</code>, then
60.1557 + * <code>-1</code> is returned.
60.1558 + *
60.1559 + * <p>
60.1560 + * There is no restriction on the value of <code>fromIndex</code>. If it
60.1561 + * is negative, it has the same effect as if it were zero: this entire
60.1562 + * string may be searched. If it is greater than the length of this
60.1563 + * string, it has the same effect as if it were equal to the length of
60.1564 + * this string: <code>-1</code> is returned.
60.1565 + *
60.1566 + * <p>All indices are specified in <code>char</code> values
60.1567 + * (Unicode code units).
60.1568 + *
60.1569 + * @param ch a character (Unicode code point).
60.1570 + * @param fromIndex the index to start the search from.
60.1571 + * @return the index of the first occurrence of the character in the
60.1572 + * character sequence represented by this object that is greater
60.1573 + * than or equal to <code>fromIndex</code>, or <code>-1</code>
60.1574 + * if the character does not occur.
60.1575 + */
60.1576 + @JavaScriptBody(args = { "ch", "from" }, body =
60.1577 + "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
60.1578 + "return this.toString().indexOf(ch, from);\n"
60.1579 + )
60.1580 + public int indexOf(int ch, int fromIndex) {
60.1581 + if (fromIndex < 0) {
60.1582 + fromIndex = 0;
60.1583 + } else if (fromIndex >= length()) {
60.1584 + // Note: fromIndex might be near -1>>>1.
60.1585 + return -1;
60.1586 + }
60.1587 +
60.1588 + if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
60.1589 + // handle most cases here (ch is a BMP code point or a
60.1590 + // negative value (invalid code point))
60.1591 + final char[] value = this.toCharArray();
60.1592 + final int offset = this.offset();
60.1593 + final int max = offset + length();
60.1594 + for (int i = offset + fromIndex; i < max ; i++) {
60.1595 + if (value[i] == ch) {
60.1596 + return i - offset;
60.1597 + }
60.1598 + }
60.1599 + return -1;
60.1600 + } else {
60.1601 + return indexOfSupplementary(ch, fromIndex);
60.1602 + }
60.1603 + }
60.1604 +
60.1605 + /**
60.1606 + * Handles (rare) calls of indexOf with a supplementary character.
60.1607 + */
60.1608 + private int indexOfSupplementary(int ch, int fromIndex) {
60.1609 + if (Character.isValidCodePoint(ch)) {
60.1610 + final char[] value = this.toCharArray();
60.1611 + final int offset = this.offset();
60.1612 + final char hi = Character.highSurrogate(ch);
60.1613 + final char lo = Character.lowSurrogate(ch);
60.1614 + final int max = offset + length() - 1;
60.1615 + for (int i = offset + fromIndex; i < max; i++) {
60.1616 + if (value[i] == hi && value[i+1] == lo) {
60.1617 + return i - offset;
60.1618 + }
60.1619 + }
60.1620 + }
60.1621 + return -1;
60.1622 + }
60.1623 +
60.1624 + /**
60.1625 + * Returns the index within this string of the last occurrence of
60.1626 + * the specified character. For values of <code>ch</code> in the
60.1627 + * range from 0 to 0xFFFF (inclusive), the index (in Unicode code
60.1628 + * units) returned is the largest value <i>k</i> such that:
60.1629 + * <blockquote><pre>
60.1630 + * this.charAt(<i>k</i>) == ch
60.1631 + * </pre></blockquote>
60.1632 + * is true. For other values of <code>ch</code>, it is the
60.1633 + * largest value <i>k</i> such that:
60.1634 + * <blockquote><pre>
60.1635 + * this.codePointAt(<i>k</i>) == ch
60.1636 + * </pre></blockquote>
60.1637 + * is true. In either case, if no such character occurs in this
60.1638 + * string, then <code>-1</code> is returned. The
60.1639 + * <code>String</code> is searched backwards starting at the last
60.1640 + * character.
60.1641 + *
60.1642 + * @param ch a character (Unicode code point).
60.1643 + * @return the index of the last occurrence of the character in the
60.1644 + * character sequence represented by this object, or
60.1645 + * <code>-1</code> if the character does not occur.
60.1646 + */
60.1647 + public int lastIndexOf(int ch) {
60.1648 + return lastIndexOf(ch, length() - 1);
60.1649 + }
60.1650 +
60.1651 + /**
60.1652 + * Returns the index within this string of the last occurrence of
60.1653 + * the specified character, searching backward starting at the
60.1654 + * specified index. For values of <code>ch</code> in the range
60.1655 + * from 0 to 0xFFFF (inclusive), the index returned is the largest
60.1656 + * value <i>k</i> such that:
60.1657 + * <blockquote><pre>
60.1658 + * (this.charAt(<i>k</i>) == ch) && (<i>k</i> <= fromIndex)
60.1659 + * </pre></blockquote>
60.1660 + * is true. For other values of <code>ch</code>, it is the
60.1661 + * largest value <i>k</i> such that:
60.1662 + * <blockquote><pre>
60.1663 + * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> <= fromIndex)
60.1664 + * </pre></blockquote>
60.1665 + * is true. In either case, if no such character occurs in this
60.1666 + * string at or before position <code>fromIndex</code>, then
60.1667 + * <code>-1</code> is returned.
60.1668 + *
60.1669 + * <p>All indices are specified in <code>char</code> values
60.1670 + * (Unicode code units).
60.1671 + *
60.1672 + * @param ch a character (Unicode code point).
60.1673 + * @param fromIndex the index to start the search from. There is no
60.1674 + * restriction on the value of <code>fromIndex</code>. If it is
60.1675 + * greater than or equal to the length of this string, it has
60.1676 + * the same effect as if it were equal to one less than the
60.1677 + * length of this string: this entire string may be searched.
60.1678 + * If it is negative, it has the same effect as if it were -1:
60.1679 + * -1 is returned.
60.1680 + * @return the index of the last occurrence of the character in the
60.1681 + * character sequence represented by this object that is less
60.1682 + * than or equal to <code>fromIndex</code>, or <code>-1</code>
60.1683 + * if the character does not occur before that point.
60.1684 + */
60.1685 + @JavaScriptBody(args = { "ch", "from" }, body =
60.1686 + "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
60.1687 + "return this.toString().lastIndexOf(ch, from);"
60.1688 + )
60.1689 + public int lastIndexOf(int ch, int fromIndex) {
60.1690 + if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
60.1691 + // handle most cases here (ch is a BMP code point or a
60.1692 + // negative value (invalid code point))
60.1693 + final char[] value = this.toCharArray();
60.1694 + final int offset = this.offset();
60.1695 + int i = offset + Math.min(fromIndex, length() - 1);
60.1696 + for (; i >= offset ; i--) {
60.1697 + if (value[i] == ch) {
60.1698 + return i - offset;
60.1699 + }
60.1700 + }
60.1701 + return -1;
60.1702 + } else {
60.1703 + return lastIndexOfSupplementary(ch, fromIndex);
60.1704 + }
60.1705 + }
60.1706 +
60.1707 + /**
60.1708 + * Handles (rare) calls of lastIndexOf with a supplementary character.
60.1709 + */
60.1710 + private int lastIndexOfSupplementary(int ch, int fromIndex) {
60.1711 + if (Character.isValidCodePoint(ch)) {
60.1712 + final char[] value = this.toCharArray();
60.1713 + final int offset = this.offset();
60.1714 + char hi = Character.highSurrogate(ch);
60.1715 + char lo = Character.lowSurrogate(ch);
60.1716 + int i = offset + Math.min(fromIndex, length() - 2);
60.1717 + for (; i >= offset; i--) {
60.1718 + if (value[i] == hi && value[i+1] == lo) {
60.1719 + return i - offset;
60.1720 + }
60.1721 + }
60.1722 + }
60.1723 + return -1;
60.1724 + }
60.1725 +
60.1726 + /**
60.1727 + * Returns the index within this string of the first occurrence of the
60.1728 + * specified substring.
60.1729 + *
60.1730 + * <p>The returned index is the smallest value <i>k</i> for which:
60.1731 + * <blockquote><pre>
60.1732 + * this.startsWith(str, <i>k</i>)
60.1733 + * </pre></blockquote>
60.1734 + * If no such value of <i>k</i> exists, then {@code -1} is returned.
60.1735 + *
60.1736 + * @param str the substring to search for.
60.1737 + * @return the index of the first occurrence of the specified substring,
60.1738 + * or {@code -1} if there is no such occurrence.
60.1739 + */
60.1740 + public int indexOf(String str) {
60.1741 + return indexOf(str, 0);
60.1742 + }
60.1743 +
60.1744 + /**
60.1745 + * Returns the index within this string of the first occurrence of the
60.1746 + * specified substring, starting at the specified index.
60.1747 + *
60.1748 + * <p>The returned index is the smallest value <i>k</i> for which:
60.1749 + * <blockquote><pre>
60.1750 + * <i>k</i> >= fromIndex && this.startsWith(str, <i>k</i>)
60.1751 + * </pre></blockquote>
60.1752 + * If no such value of <i>k</i> exists, then {@code -1} is returned.
60.1753 + *
60.1754 + * @param str the substring to search for.
60.1755 + * @param fromIndex the index from which to start the search.
60.1756 + * @return the index of the first occurrence of the specified substring,
60.1757 + * starting at the specified index,
60.1758 + * or {@code -1} if there is no such occurrence.
60.1759 + */
60.1760 + @JavaScriptBody(args = { "str", "fromIndex" }, body =
60.1761 + "return this.toString().indexOf(str.toString(), fromIndex);"
60.1762 + )
60.1763 + public native int indexOf(String str, int fromIndex);
60.1764 +
60.1765 + /**
60.1766 + * Returns the index within this string of the last occurrence of the
60.1767 + * specified substring. The last occurrence of the empty string ""
60.1768 + * is considered to occur at the index value {@code this.length()}.
60.1769 + *
60.1770 + * <p>The returned index is the largest value <i>k</i> for which:
60.1771 + * <blockquote><pre>
60.1772 + * this.startsWith(str, <i>k</i>)
60.1773 + * </pre></blockquote>
60.1774 + * If no such value of <i>k</i> exists, then {@code -1} is returned.
60.1775 + *
60.1776 + * @param str the substring to search for.
60.1777 + * @return the index of the last occurrence of the specified substring,
60.1778 + * or {@code -1} if there is no such occurrence.
60.1779 + */
60.1780 + public int lastIndexOf(String str) {
60.1781 + return lastIndexOf(str, length());
60.1782 + }
60.1783 +
60.1784 + /**
60.1785 + * Returns the index within this string of the last occurrence of the
60.1786 + * specified substring, searching backward starting at the specified index.
60.1787 + *
60.1788 + * <p>The returned index is the largest value <i>k</i> for which:
60.1789 + * <blockquote><pre>
60.1790 + * <i>k</i> <= fromIndex && this.startsWith(str, <i>k</i>)
60.1791 + * </pre></blockquote>
60.1792 + * If no such value of <i>k</i> exists, then {@code -1} is returned.
60.1793 + *
60.1794 + * @param str the substring to search for.
60.1795 + * @param fromIndex the index to start the search from.
60.1796 + * @return the index of the last occurrence of the specified substring,
60.1797 + * searching backward from the specified index,
60.1798 + * or {@code -1} if there is no such occurrence.
60.1799 + */
60.1800 + @JavaScriptBody(args = { "s", "from" }, body =
60.1801 + "return this.toString().lastIndexOf(s.toString(), from);"
60.1802 + )
60.1803 + public int lastIndexOf(String str, int fromIndex) {
60.1804 + return lastIndexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
60.1805 + }
60.1806 +
60.1807 + /**
60.1808 + * Code shared by String and StringBuffer to do searches. The
60.1809 + * source is the character array being searched, and the target
60.1810 + * is the string being searched for.
60.1811 + *
60.1812 + * @param source the characters being searched.
60.1813 + * @param sourceOffset offset of the source string.
60.1814 + * @param sourceCount count of the source string.
60.1815 + * @param target the characters being searched for.
60.1816 + * @param targetOffset offset of the target string.
60.1817 + * @param targetCount count of the target string.
60.1818 + * @param fromIndex the index to begin searching from.
60.1819 + */
60.1820 + static int lastIndexOf(char[] source, int sourceOffset, int sourceCount,
60.1821 + char[] target, int targetOffset, int targetCount,
60.1822 + int fromIndex) {
60.1823 + /*
60.1824 + * Check arguments; return immediately where possible. For
60.1825 + * consistency, don't check for null str.
60.1826 + */
60.1827 + int rightIndex = sourceCount - targetCount;
60.1828 + if (fromIndex < 0) {
60.1829 + return -1;
60.1830 + }
60.1831 + if (fromIndex > rightIndex) {
60.1832 + fromIndex = rightIndex;
60.1833 + }
60.1834 + /* Empty string always matches. */
60.1835 + if (targetCount == 0) {
60.1836 + return fromIndex;
60.1837 + }
60.1838 +
60.1839 + int strLastIndex = targetOffset + targetCount - 1;
60.1840 + char strLastChar = target[strLastIndex];
60.1841 + int min = sourceOffset + targetCount - 1;
60.1842 + int i = min + fromIndex;
60.1843 +
60.1844 + startSearchForLastChar:
60.1845 + while (true) {
60.1846 + while (i >= min && source[i] != strLastChar) {
60.1847 + i--;
60.1848 + }
60.1849 + if (i < min) {
60.1850 + return -1;
60.1851 + }
60.1852 + int j = i - 1;
60.1853 + int start = j - (targetCount - 1);
60.1854 + int k = strLastIndex - 1;
60.1855 +
60.1856 + while (j > start) {
60.1857 + if (source[j--] != target[k--]) {
60.1858 + i--;
60.1859 + continue startSearchForLastChar;
60.1860 + }
60.1861 + }
60.1862 + return start - sourceOffset + 1;
60.1863 + }
60.1864 + }
60.1865 +
60.1866 + /**
60.1867 + * Returns a new string that is a substring of this string. The
60.1868 + * substring begins with the character at the specified index and
60.1869 + * extends to the end of this string. <p>
60.1870 + * Examples:
60.1871 + * <blockquote><pre>
60.1872 + * "unhappy".substring(2) returns "happy"
60.1873 + * "Harbison".substring(3) returns "bison"
60.1874 + * "emptiness".substring(9) returns "" (an empty string)
60.1875 + * </pre></blockquote>
60.1876 + *
60.1877 + * @param beginIndex the beginning index, inclusive.
60.1878 + * @return the specified substring.
60.1879 + * @exception IndexOutOfBoundsException if
60.1880 + * <code>beginIndex</code> is negative or larger than the
60.1881 + * length of this <code>String</code> object.
60.1882 + */
60.1883 + public String substring(int beginIndex) {
60.1884 + return substring(beginIndex, length());
60.1885 + }
60.1886 +
60.1887 + /**
60.1888 + * Returns a new string that is a substring of this string. The
60.1889 + * substring begins at the specified <code>beginIndex</code> and
60.1890 + * extends to the character at index <code>endIndex - 1</code>.
60.1891 + * Thus the length of the substring is <code>endIndex-beginIndex</code>.
60.1892 + * <p>
60.1893 + * Examples:
60.1894 + * <blockquote><pre>
60.1895 + * "hamburger".substring(4, 8) returns "urge"
60.1896 + * "smiles".substring(1, 5) returns "mile"
60.1897 + * </pre></blockquote>
60.1898 + *
60.1899 + * @param beginIndex the beginning index, inclusive.
60.1900 + * @param endIndex the ending index, exclusive.
60.1901 + * @return the specified substring.
60.1902 + * @exception IndexOutOfBoundsException if the
60.1903 + * <code>beginIndex</code> is negative, or
60.1904 + * <code>endIndex</code> is larger than the length of
60.1905 + * this <code>String</code> object, or
60.1906 + * <code>beginIndex</code> is larger than
60.1907 + * <code>endIndex</code>.
60.1908 + */
60.1909 + @JavaScriptBody(args = { "beginIndex", "endIndex" }, body =
60.1910 + "return this.toString().substring(beginIndex, endIndex);"
60.1911 + )
60.1912 + public String substring(int beginIndex, int endIndex) {
60.1913 + if (beginIndex < 0) {
60.1914 + throw new StringIndexOutOfBoundsException(beginIndex);
60.1915 + }
60.1916 + if (endIndex > length()) {
60.1917 + throw new StringIndexOutOfBoundsException(endIndex);
60.1918 + }
60.1919 + if (beginIndex > endIndex) {
60.1920 + throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
60.1921 + }
60.1922 + return ((beginIndex == 0) && (endIndex == length())) ? this :
60.1923 + new String(toCharArray(), offset() + beginIndex, endIndex - beginIndex);
60.1924 + }
60.1925 +
60.1926 + /**
60.1927 + * Returns a new character sequence that is a subsequence of this sequence.
60.1928 + *
60.1929 + * <p> An invocation of this method of the form
60.1930 + *
60.1931 + * <blockquote><pre>
60.1932 + * str.subSequence(begin, end)</pre></blockquote>
60.1933 + *
60.1934 + * behaves in exactly the same way as the invocation
60.1935 + *
60.1936 + * <blockquote><pre>
60.1937 + * str.substring(begin, end)</pre></blockquote>
60.1938 + *
60.1939 + * This method is defined so that the <tt>String</tt> class can implement
60.1940 + * the {@link CharSequence} interface. </p>
60.1941 + *
60.1942 + * @param beginIndex the begin index, inclusive.
60.1943 + * @param endIndex the end index, exclusive.
60.1944 + * @return the specified subsequence.
60.1945 + *
60.1946 + * @throws IndexOutOfBoundsException
60.1947 + * if <tt>beginIndex</tt> or <tt>endIndex</tt> are negative,
60.1948 + * if <tt>endIndex</tt> is greater than <tt>length()</tt>,
60.1949 + * or if <tt>beginIndex</tt> is greater than <tt>startIndex</tt>
60.1950 + *
60.1951 + * @since 1.4
60.1952 + * @spec JSR-51
60.1953 + */
60.1954 + public CharSequence subSequence(int beginIndex, int endIndex) {
60.1955 + return this.substring(beginIndex, endIndex);
60.1956 + }
60.1957 +
60.1958 + /**
60.1959 + * Concatenates the specified string to the end of this string.
60.1960 + * <p>
60.1961 + * If the length of the argument string is <code>0</code>, then this
60.1962 + * <code>String</code> object is returned. Otherwise, a new
60.1963 + * <code>String</code> object is created, representing a character
60.1964 + * sequence that is the concatenation of the character sequence
60.1965 + * represented by this <code>String</code> object and the character
60.1966 + * sequence represented by the argument string.<p>
60.1967 + * Examples:
60.1968 + * <blockquote><pre>
60.1969 + * "cares".concat("s") returns "caress"
60.1970 + * "to".concat("get").concat("her") returns "together"
60.1971 + * </pre></blockquote>
60.1972 + *
60.1973 + * @param str the <code>String</code> that is concatenated to the end
60.1974 + * of this <code>String</code>.
60.1975 + * @return a string that represents the concatenation of this object's
60.1976 + * characters followed by the string argument's characters.
60.1977 + */
60.1978 + public String concat(String str) {
60.1979 + int otherLen = str.length();
60.1980 + if (otherLen == 0) {
60.1981 + return this;
60.1982 + }
60.1983 + char buf[] = new char[length() + otherLen];
60.1984 + getChars(0, length(), buf, 0);
60.1985 + str.getChars(0, otherLen, buf, length());
60.1986 + return new String(buf, 0, length() + otherLen);
60.1987 + }
60.1988 +
60.1989 + /**
60.1990 + * Returns a new string resulting from replacing all occurrences of
60.1991 + * <code>oldChar</code> in this string with <code>newChar</code>.
60.1992 + * <p>
60.1993 + * If the character <code>oldChar</code> does not occur in the
60.1994 + * character sequence represented by this <code>String</code> object,
60.1995 + * then a reference to this <code>String</code> object is returned.
60.1996 + * Otherwise, a new <code>String</code> object is created that
60.1997 + * represents a character sequence identical to the character sequence
60.1998 + * represented by this <code>String</code> object, except that every
60.1999 + * occurrence of <code>oldChar</code> is replaced by an occurrence
60.2000 + * of <code>newChar</code>.
60.2001 + * <p>
60.2002 + * Examples:
60.2003 + * <blockquote><pre>
60.2004 + * "mesquite in your cellar".replace('e', 'o')
60.2005 + * returns "mosquito in your collar"
60.2006 + * "the war of baronets".replace('r', 'y')
60.2007 + * returns "the way of bayonets"
60.2008 + * "sparring with a purple porpoise".replace('p', 't')
60.2009 + * returns "starring with a turtle tortoise"
60.2010 + * "JonL".replace('q', 'x') returns "JonL" (no change)
60.2011 + * </pre></blockquote>
60.2012 + *
60.2013 + * @param oldChar the old character.
60.2014 + * @param newChar the new character.
60.2015 + * @return a string derived from this string by replacing every
60.2016 + * occurrence of <code>oldChar</code> with <code>newChar</code>.
60.2017 + */
60.2018 + @JavaScriptBody(args = { "arg1", "arg2" }, body =
60.2019 + "if (typeof arg1 === 'number') arg1 = String.fromCharCode(arg1);\n" +
60.2020 + "if (typeof arg2 === 'number') arg2 = String.fromCharCode(arg2);\n" +
60.2021 + "var s = this.toString();\n" +
60.2022 + "for (;;) {\n" +
60.2023 + " var ret = s.replace(arg1, arg2);\n" +
60.2024 + " if (ret === s) {\n" +
60.2025 + " return ret;\n" +
60.2026 + " }\n" +
60.2027 + " s = ret;\n" +
60.2028 + "}"
60.2029 + )
60.2030 + public String replace(char oldChar, char newChar) {
60.2031 + if (oldChar != newChar) {
60.2032 + int len = length();
60.2033 + int i = -1;
60.2034 + char[] val = toCharArray(); /* avoid getfield opcode */
60.2035 + int off = offset(); /* avoid getfield opcode */
60.2036 +
60.2037 + while (++i < len) {
60.2038 + if (val[off + i] == oldChar) {
60.2039 + break;
60.2040 + }
60.2041 + }
60.2042 + if (i < len) {
60.2043 + char buf[] = new char[len];
60.2044 + for (int j = 0 ; j < i ; j++) {
60.2045 + buf[j] = val[off+j];
60.2046 + }
60.2047 + while (i < len) {
60.2048 + char c = val[off + i];
60.2049 + buf[i] = (c == oldChar) ? newChar : c;
60.2050 + i++;
60.2051 + }
60.2052 + return new String(buf, 0, len);
60.2053 + }
60.2054 + }
60.2055 + return this;
60.2056 + }
60.2057 +
60.2058 + /**
60.2059 + * Tells whether or not this string matches the given <a
60.2060 + * href="../util/regex/Pattern.html#sum">regular expression</a>.
60.2061 + *
60.2062 + * <p> An invocation of this method of the form
60.2063 + * <i>str</i><tt>.matches(</tt><i>regex</i><tt>)</tt> yields exactly the
60.2064 + * same result as the expression
60.2065 + *
60.2066 + * <blockquote><tt> {@link java.util.regex.Pattern}.{@link
60.2067 + * java.util.regex.Pattern#matches(String,CharSequence)
60.2068 + * matches}(</tt><i>regex</i><tt>,</tt> <i>str</i><tt>)</tt></blockquote>
60.2069 + *
60.2070 + * @param regex
60.2071 + * the regular expression to which this string is to be matched
60.2072 + *
60.2073 + * @return <tt>true</tt> if, and only if, this string matches the
60.2074 + * given regular expression
60.2075 + *
60.2076 + * @throws PatternSyntaxException
60.2077 + * if the regular expression's syntax is invalid
60.2078 + *
60.2079 + * @see java.util.regex.Pattern
60.2080 + *
60.2081 + * @since 1.4
60.2082 + * @spec JSR-51
60.2083 + */
60.2084 + @JavaScriptBody(args = { "regex" }, body =
60.2085 + "var self = this.toString();\n"
60.2086 + + "var re = new RegExp(regex.toString());\n"
60.2087 + + "var r = re.exec(self);\n"
60.2088 + + "return r != null && r.length > 0 && self.length == r[0].length;"
60.2089 + )
60.2090 + public boolean matches(String regex) {
60.2091 + throw new UnsupportedOperationException();
60.2092 + }
60.2093 +
60.2094 + /**
60.2095 + * Returns true if and only if this string contains the specified
60.2096 + * sequence of char values.
60.2097 + *
60.2098 + * @param s the sequence to search for
60.2099 + * @return true if this string contains <code>s</code>, false otherwise
60.2100 + * @throws NullPointerException if <code>s</code> is <code>null</code>
60.2101 + * @since 1.5
60.2102 + */
60.2103 + public boolean contains(CharSequence s) {
60.2104 + return indexOf(s.toString()) > -1;
60.2105 + }
60.2106 +
60.2107 + /**
60.2108 + * Replaces the first substring of this string that matches the given <a
60.2109 + * href="../util/regex/Pattern.html#sum">regular expression</a> with the
60.2110 + * given replacement.
60.2111 + *
60.2112 + * <p> An invocation of this method of the form
60.2113 + * <i>str</i><tt>.replaceFirst(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
60.2114 + * yields exactly the same result as the expression
60.2115 + *
60.2116 + * <blockquote><tt>
60.2117 + * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
60.2118 + * compile}(</tt><i>regex</i><tt>).{@link
60.2119 + * java.util.regex.Pattern#matcher(java.lang.CharSequence)
60.2120 + * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceFirst
60.2121 + * replaceFirst}(</tt><i>repl</i><tt>)</tt></blockquote>
60.2122 + *
60.2123 + *<p>
60.2124 + * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
60.2125 + * replacement string may cause the results to be different than if it were
60.2126 + * being treated as a literal replacement string; see
60.2127 + * {@link java.util.regex.Matcher#replaceFirst}.
60.2128 + * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
60.2129 + * meaning of these characters, if desired.
60.2130 + *
60.2131 + * @param regex
60.2132 + * the regular expression to which this string is to be matched
60.2133 + * @param replacement
60.2134 + * the string to be substituted for the first match
60.2135 + *
60.2136 + * @return The resulting <tt>String</tt>
60.2137 + *
60.2138 + * @throws PatternSyntaxException
60.2139 + * if the regular expression's syntax is invalid
60.2140 + *
60.2141 + * @see java.util.regex.Pattern
60.2142 + *
60.2143 + * @since 1.4
60.2144 + * @spec JSR-51
60.2145 + */
60.2146 + public String replaceFirst(String regex, String replacement) {
60.2147 + throw new UnsupportedOperationException();
60.2148 + }
60.2149 +
60.2150 + /**
60.2151 + * Replaces each substring of this string that matches the given <a
60.2152 + * href="../util/regex/Pattern.html#sum">regular expression</a> with the
60.2153 + * given replacement.
60.2154 + *
60.2155 + * <p> An invocation of this method of the form
60.2156 + * <i>str</i><tt>.replaceAll(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
60.2157 + * yields exactly the same result as the expression
60.2158 + *
60.2159 + * <blockquote><tt>
60.2160 + * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
60.2161 + * compile}(</tt><i>regex</i><tt>).{@link
60.2162 + * java.util.regex.Pattern#matcher(java.lang.CharSequence)
60.2163 + * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceAll
60.2164 + * replaceAll}(</tt><i>repl</i><tt>)</tt></blockquote>
60.2165 + *
60.2166 + *<p>
60.2167 + * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
60.2168 + * replacement string may cause the results to be different than if it were
60.2169 + * being treated as a literal replacement string; see
60.2170 + * {@link java.util.regex.Matcher#replaceAll Matcher.replaceAll}.
60.2171 + * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
60.2172 + * meaning of these characters, if desired.
60.2173 + *
60.2174 + * @param regex
60.2175 + * the regular expression to which this string is to be matched
60.2176 + * @param replacement
60.2177 + * the string to be substituted for each match
60.2178 + *
60.2179 + * @return The resulting <tt>String</tt>
60.2180 + *
60.2181 + * @throws PatternSyntaxException
60.2182 + * if the regular expression's syntax is invalid
60.2183 + *
60.2184 + * @see java.util.regex.Pattern
60.2185 + *
60.2186 + * @since 1.4
60.2187 + * @spec JSR-51
60.2188 + */
60.2189 + public String replaceAll(String regex, String replacement) {
60.2190 + throw new UnsupportedOperationException();
60.2191 + }
60.2192 +
60.2193 + /**
60.2194 + * Replaces each substring of this string that matches the literal target
60.2195 + * sequence with the specified literal replacement sequence. The
60.2196 + * replacement proceeds from the beginning of the string to the end, for
60.2197 + * example, replacing "aa" with "b" in the string "aaa" will result in
60.2198 + * "ba" rather than "ab".
60.2199 + *
60.2200 + * @param target The sequence of char values to be replaced
60.2201 + * @param replacement The replacement sequence of char values
60.2202 + * @return The resulting string
60.2203 + * @throws NullPointerException if <code>target</code> or
60.2204 + * <code>replacement</code> is <code>null</code>.
60.2205 + * @since 1.5
60.2206 + */
60.2207 + public String replace(CharSequence target, CharSequence replacement) {
60.2208 + throw new UnsupportedOperationException("This one should be supported, but without dep on rest of regexp");
60.2209 + }
60.2210 +
60.2211 + /**
60.2212 + * Splits this string around matches of the given
60.2213 + * <a href="../util/regex/Pattern.html#sum">regular expression</a>.
60.2214 + *
60.2215 + * <p> The array returned by this method contains each substring of this
60.2216 + * string that is terminated by another substring that matches the given
60.2217 + * expression or is terminated by the end of the string. The substrings in
60.2218 + * the array are in the order in which they occur in this string. If the
60.2219 + * expression does not match any part of the input then the resulting array
60.2220 + * has just one element, namely this string.
60.2221 + *
60.2222 + * <p> The <tt>limit</tt> parameter controls the number of times the
60.2223 + * pattern is applied and therefore affects the length of the resulting
60.2224 + * array. If the limit <i>n</i> is greater than zero then the pattern
60.2225 + * will be applied at most <i>n</i> - 1 times, the array's
60.2226 + * length will be no greater than <i>n</i>, and the array's last entry
60.2227 + * will contain all input beyond the last matched delimiter. If <i>n</i>
60.2228 + * is non-positive then the pattern will be applied as many times as
60.2229 + * possible and the array can have any length. If <i>n</i> is zero then
60.2230 + * the pattern will be applied as many times as possible, the array can
60.2231 + * have any length, and trailing empty strings will be discarded.
60.2232 + *
60.2233 + * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the
60.2234 + * following results with these parameters:
60.2235 + *
60.2236 + * <blockquote><table cellpadding=1 cellspacing=0 summary="Split example showing regex, limit, and result">
60.2237 + * <tr>
60.2238 + * <th>Regex</th>
60.2239 + * <th>Limit</th>
60.2240 + * <th>Result</th>
60.2241 + * </tr>
60.2242 + * <tr><td align=center>:</td>
60.2243 + * <td align=center>2</td>
60.2244 + * <td><tt>{ "boo", "and:foo" }</tt></td></tr>
60.2245 + * <tr><td align=center>:</td>
60.2246 + * <td align=center>5</td>
60.2247 + * <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
60.2248 + * <tr><td align=center>:</td>
60.2249 + * <td align=center>-2</td>
60.2250 + * <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
60.2251 + * <tr><td align=center>o</td>
60.2252 + * <td align=center>5</td>
60.2253 + * <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
60.2254 + * <tr><td align=center>o</td>
60.2255 + * <td align=center>-2</td>
60.2256 + * <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
60.2257 + * <tr><td align=center>o</td>
60.2258 + * <td align=center>0</td>
60.2259 + * <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
60.2260 + * </table></blockquote>
60.2261 + *
60.2262 + * <p> An invocation of this method of the form
60.2263 + * <i>str.</i><tt>split(</tt><i>regex</i><tt>,</tt> <i>n</i><tt>)</tt>
60.2264 + * yields the same result as the expression
60.2265 + *
60.2266 + * <blockquote>
60.2267 + * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
60.2268 + * compile}<tt>(</tt><i>regex</i><tt>)</tt>.{@link
60.2269 + * java.util.regex.Pattern#split(java.lang.CharSequence,int)
60.2270 + * split}<tt>(</tt><i>str</i><tt>,</tt> <i>n</i><tt>)</tt>
60.2271 + * </blockquote>
60.2272 + *
60.2273 + *
60.2274 + * @param regex
60.2275 + * the delimiting regular expression
60.2276 + *
60.2277 + * @param limit
60.2278 + * the result threshold, as described above
60.2279 + *
60.2280 + * @return the array of strings computed by splitting this string
60.2281 + * around matches of the given regular expression
60.2282 + *
60.2283 + * @throws PatternSyntaxException
60.2284 + * if the regular expression's syntax is invalid
60.2285 + *
60.2286 + * @see java.util.regex.Pattern
60.2287 + *
60.2288 + * @since 1.4
60.2289 + * @spec JSR-51
60.2290 + */
60.2291 + public String[] split(String regex, int limit) {
60.2292 + throw new UnsupportedOperationException("Needs regexp");
60.2293 + }
60.2294 +
60.2295 + /**
60.2296 + * Splits this string around matches of the given <a
60.2297 + * href="../util/regex/Pattern.html#sum">regular expression</a>.
60.2298 + *
60.2299 + * <p> This method works as if by invoking the two-argument {@link
60.2300 + * #split(String, int) split} method with the given expression and a limit
60.2301 + * argument of zero. Trailing empty strings are therefore not included in
60.2302 + * the resulting array.
60.2303 + *
60.2304 + * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the following
60.2305 + * results with these expressions:
60.2306 + *
60.2307 + * <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
60.2308 + * <tr>
60.2309 + * <th>Regex</th>
60.2310 + * <th>Result</th>
60.2311 + * </tr>
60.2312 + * <tr><td align=center>:</td>
60.2313 + * <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
60.2314 + * <tr><td align=center>o</td>
60.2315 + * <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
60.2316 + * </table></blockquote>
60.2317 + *
60.2318 + *
60.2319 + * @param regex
60.2320 + * the delimiting regular expression
60.2321 + *
60.2322 + * @return the array of strings computed by splitting this string
60.2323 + * around matches of the given regular expression
60.2324 + *
60.2325 + * @throws PatternSyntaxException
60.2326 + * if the regular expression's syntax is invalid
60.2327 + *
60.2328 + * @see java.util.regex.Pattern
60.2329 + *
60.2330 + * @since 1.4
60.2331 + * @spec JSR-51
60.2332 + */
60.2333 + public String[] split(String regex) {
60.2334 + return split(regex, 0);
60.2335 + }
60.2336 +
60.2337 + /**
60.2338 + * Converts all of the characters in this <code>String</code> to lower
60.2339 + * case using the rules of the given <code>Locale</code>. Case mapping is based
60.2340 + * on the Unicode Standard version specified by the {@link java.lang.Character Character}
60.2341 + * class. Since case mappings are not always 1:1 char mappings, the resulting
60.2342 + * <code>String</code> may be a different length than the original <code>String</code>.
60.2343 + * <p>
60.2344 + * Examples of lowercase mappings are in the following table:
60.2345 + * <table border="1" summary="Lowercase mapping examples showing language code of locale, upper case, lower case, and description">
60.2346 + * <tr>
60.2347 + * <th>Language Code of Locale</th>
60.2348 + * <th>Upper Case</th>
60.2349 + * <th>Lower Case</th>
60.2350 + * <th>Description</th>
60.2351 + * </tr>
60.2352 + * <tr>
60.2353 + * <td>tr (Turkish)</td>
60.2354 + * <td>\u0130</td>
60.2355 + * <td>\u0069</td>
60.2356 + * <td>capital letter I with dot above -> small letter i</td>
60.2357 + * </tr>
60.2358 + * <tr>
60.2359 + * <td>tr (Turkish)</td>
60.2360 + * <td>\u0049</td>
60.2361 + * <td>\u0131</td>
60.2362 + * <td>capital letter I -> small letter dotless i </td>
60.2363 + * </tr>
60.2364 + * <tr>
60.2365 + * <td>(all)</td>
60.2366 + * <td>French Fries</td>
60.2367 + * <td>french fries</td>
60.2368 + * <td>lowercased all chars in String</td>
60.2369 + * </tr>
60.2370 + * <tr>
60.2371 + * <td>(all)</td>
60.2372 + * <td><img src="doc-files/capiota.gif" alt="capiota"><img src="doc-files/capchi.gif" alt="capchi">
60.2373 + * <img src="doc-files/captheta.gif" alt="captheta"><img src="doc-files/capupsil.gif" alt="capupsil">
60.2374 + * <img src="doc-files/capsigma.gif" alt="capsigma"></td>
60.2375 + * <td><img src="doc-files/iota.gif" alt="iota"><img src="doc-files/chi.gif" alt="chi">
60.2376 + * <img src="doc-files/theta.gif" alt="theta"><img src="doc-files/upsilon.gif" alt="upsilon">
60.2377 + * <img src="doc-files/sigma1.gif" alt="sigma"></td>
60.2378 + * <td>lowercased all chars in String</td>
60.2379 + * </tr>
60.2380 + * </table>
60.2381 + *
60.2382 + * @param locale use the case transformation rules for this locale
60.2383 + * @return the <code>String</code>, converted to lowercase.
60.2384 + * @see java.lang.String#toLowerCase()
60.2385 + * @see java.lang.String#toUpperCase()
60.2386 + * @see java.lang.String#toUpperCase(Locale)
60.2387 + * @since 1.1
60.2388 + */
60.2389 +// public String toLowerCase(Locale locale) {
60.2390 +// if (locale == null) {
60.2391 +// throw new NullPointerException();
60.2392 +// }
60.2393 +//
60.2394 +// int firstUpper;
60.2395 +//
60.2396 +// /* Now check if there are any characters that need to be changed. */
60.2397 +// scan: {
60.2398 +// for (firstUpper = 0 ; firstUpper < count; ) {
60.2399 +// char c = value[offset+firstUpper];
60.2400 +// if ((c >= Character.MIN_HIGH_SURROGATE) &&
60.2401 +// (c <= Character.MAX_HIGH_SURROGATE)) {
60.2402 +// int supplChar = codePointAt(firstUpper);
60.2403 +// if (supplChar != Character.toLowerCase(supplChar)) {
60.2404 +// break scan;
60.2405 +// }
60.2406 +// firstUpper += Character.charCount(supplChar);
60.2407 +// } else {
60.2408 +// if (c != Character.toLowerCase(c)) {
60.2409 +// break scan;
60.2410 +// }
60.2411 +// firstUpper++;
60.2412 +// }
60.2413 +// }
60.2414 +// return this;
60.2415 +// }
60.2416 +//
60.2417 +// char[] result = new char[count];
60.2418 +// int resultOffset = 0; /* result may grow, so i+resultOffset
60.2419 +// * is the write location in result */
60.2420 +//
60.2421 +// /* Just copy the first few lowerCase characters. */
60.2422 +// arraycopy(value, offset, result, 0, firstUpper);
60.2423 +//
60.2424 +// String lang = locale.getLanguage();
60.2425 +// boolean localeDependent =
60.2426 +// (lang == "tr" || lang == "az" || lang == "lt");
60.2427 +// char[] lowerCharArray;
60.2428 +// int lowerChar;
60.2429 +// int srcChar;
60.2430 +// int srcCount;
60.2431 +// for (int i = firstUpper; i < count; i += srcCount) {
60.2432 +// srcChar = (int)value[offset+i];
60.2433 +// if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
60.2434 +// (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
60.2435 +// srcChar = codePointAt(i);
60.2436 +// srcCount = Character.charCount(srcChar);
60.2437 +// } else {
60.2438 +// srcCount = 1;
60.2439 +// }
60.2440 +// if (localeDependent || srcChar == '\u03A3') { // GREEK CAPITAL LETTER SIGMA
60.2441 +// lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale);
60.2442 +// } else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT
60.2443 +// lowerChar = Character.ERROR;
60.2444 +// } else {
60.2445 +// lowerChar = Character.toLowerCase(srcChar);
60.2446 +// }
60.2447 +// if ((lowerChar == Character.ERROR) ||
60.2448 +// (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
60.2449 +// if (lowerChar == Character.ERROR) {
60.2450 +// if (!localeDependent && srcChar == '\u0130') {
60.2451 +// lowerCharArray =
60.2452 +// ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH);
60.2453 +// } else {
60.2454 +// lowerCharArray =
60.2455 +// ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale);
60.2456 +// }
60.2457 +// } else if (srcCount == 2) {
60.2458 +// resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount;
60.2459 +// continue;
60.2460 +// } else {
60.2461 +// lowerCharArray = Character.toChars(lowerChar);
60.2462 +// }
60.2463 +//
60.2464 +// /* Grow result if needed */
60.2465 +// int mapLen = lowerCharArray.length;
60.2466 +// if (mapLen > srcCount) {
60.2467 +// char[] result2 = new char[result.length + mapLen - srcCount];
60.2468 +// arraycopy(result, 0, result2, 0,
60.2469 +// i + resultOffset);
60.2470 +// result = result2;
60.2471 +// }
60.2472 +// for (int x=0; x<mapLen; ++x) {
60.2473 +// result[i+resultOffset+x] = lowerCharArray[x];
60.2474 +// }
60.2475 +// resultOffset += (mapLen - srcCount);
60.2476 +// } else {
60.2477 +// result[i+resultOffset] = (char)lowerChar;
60.2478 +// }
60.2479 +// }
60.2480 +// return new String(0, count+resultOffset, result);
60.2481 +// }
60.2482 +
60.2483 + /**
60.2484 + * Converts all of the characters in this <code>String</code> to lower
60.2485 + * case using the rules of the default locale. This is equivalent to calling
60.2486 + * <code>toLowerCase(Locale.getDefault())</code>.
60.2487 + * <p>
60.2488 + * <b>Note:</b> This method is locale sensitive, and may produce unexpected
60.2489 + * results if used for strings that are intended to be interpreted locale
60.2490 + * independently.
60.2491 + * Examples are programming language identifiers, protocol keys, and HTML
60.2492 + * tags.
60.2493 + * For instance, <code>"TITLE".toLowerCase()</code> in a Turkish locale
60.2494 + * returns <code>"t\u005Cu0131tle"</code>, where '\u005Cu0131' is the
60.2495 + * LATIN SMALL LETTER DOTLESS I character.
60.2496 + * To obtain correct results for locale insensitive strings, use
60.2497 + * <code>toLowerCase(Locale.ENGLISH)</code>.
60.2498 + * <p>
60.2499 + * @return the <code>String</code>, converted to lowercase.
60.2500 + * @see java.lang.String#toLowerCase(Locale)
60.2501 + */
60.2502 + @JavaScriptBody(args = {}, body = "return this.toLowerCase();")
60.2503 + public String toLowerCase() {
60.2504 + throw new UnsupportedOperationException("Should be supported but without connection to locale");
60.2505 + }
60.2506 +
60.2507 + /**
60.2508 + * Converts all of the characters in this <code>String</code> to upper
60.2509 + * case using the rules of the given <code>Locale</code>. Case mapping is based
60.2510 + * on the Unicode Standard version specified by the {@link java.lang.Character Character}
60.2511 + * class. Since case mappings are not always 1:1 char mappings, the resulting
60.2512 + * <code>String</code> may be a different length than the original <code>String</code>.
60.2513 + * <p>
60.2514 + * Examples of locale-sensitive and 1:M case mappings are in the following table.
60.2515 + * <p>
60.2516 + * <table border="1" summary="Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description.">
60.2517 + * <tr>
60.2518 + * <th>Language Code of Locale</th>
60.2519 + * <th>Lower Case</th>
60.2520 + * <th>Upper Case</th>
60.2521 + * <th>Description</th>
60.2522 + * </tr>
60.2523 + * <tr>
60.2524 + * <td>tr (Turkish)</td>
60.2525 + * <td>\u0069</td>
60.2526 + * <td>\u0130</td>
60.2527 + * <td>small letter i -> capital letter I with dot above</td>
60.2528 + * </tr>
60.2529 + * <tr>
60.2530 + * <td>tr (Turkish)</td>
60.2531 + * <td>\u0131</td>
60.2532 + * <td>\u0049</td>
60.2533 + * <td>small letter dotless i -> capital letter I</td>
60.2534 + * </tr>
60.2535 + * <tr>
60.2536 + * <td>(all)</td>
60.2537 + * <td>\u00df</td>
60.2538 + * <td>\u0053 \u0053</td>
60.2539 + * <td>small letter sharp s -> two letters: SS</td>
60.2540 + * </tr>
60.2541 + * <tr>
60.2542 + * <td>(all)</td>
60.2543 + * <td>Fahrvergnügen</td>
60.2544 + * <td>FAHRVERGNÜGEN</td>
60.2545 + * <td></td>
60.2546 + * </tr>
60.2547 + * </table>
60.2548 + * @param locale use the case transformation rules for this locale
60.2549 + * @return the <code>String</code>, converted to uppercase.
60.2550 + * @see java.lang.String#toUpperCase()
60.2551 + * @see java.lang.String#toLowerCase()
60.2552 + * @see java.lang.String#toLowerCase(Locale)
60.2553 + * @since 1.1
60.2554 + */
60.2555 + /* not for javascript
60.2556 + public String toUpperCase(Locale locale) {
60.2557 + if (locale == null) {
60.2558 + throw new NullPointerException();
60.2559 + }
60.2560 +
60.2561 + int firstLower;
60.2562 +
60.2563 + // Now check if there are any characters that need to be changed.
60.2564 + scan: {
60.2565 + for (firstLower = 0 ; firstLower < count; ) {
60.2566 + int c = (int)value[offset+firstLower];
60.2567 + int srcCount;
60.2568 + if ((c >= Character.MIN_HIGH_SURROGATE) &&
60.2569 + (c <= Character.MAX_HIGH_SURROGATE)) {
60.2570 + c = codePointAt(firstLower);
60.2571 + srcCount = Character.charCount(c);
60.2572 + } else {
60.2573 + srcCount = 1;
60.2574 + }
60.2575 + int upperCaseChar = Character.toUpperCaseEx(c);
60.2576 + if ((upperCaseChar == Character.ERROR) ||
60.2577 + (c != upperCaseChar)) {
60.2578 + break scan;
60.2579 + }
60.2580 + firstLower += srcCount;
60.2581 + }
60.2582 + return this;
60.2583 + }
60.2584 +
60.2585 + char[] result = new char[count]; /* may grow *
60.2586 + int resultOffset = 0; /* result may grow, so i+resultOffset
60.2587 + * is the write location in result *
60.2588 +
60.2589 + /* Just copy the first few upperCase characters. *
60.2590 + arraycopy(value, offset, result, 0, firstLower);
60.2591 +
60.2592 + String lang = locale.getLanguage();
60.2593 + boolean localeDependent =
60.2594 + (lang == "tr" || lang == "az" || lang == "lt");
60.2595 + char[] upperCharArray;
60.2596 + int upperChar;
60.2597 + int srcChar;
60.2598 + int srcCount;
60.2599 + for (int i = firstLower; i < count; i += srcCount) {
60.2600 + srcChar = (int)value[offset+i];
60.2601 + if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
60.2602 + (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
60.2603 + srcChar = codePointAt(i);
60.2604 + srcCount = Character.charCount(srcChar);
60.2605 + } else {
60.2606 + srcCount = 1;
60.2607 + }
60.2608 + if (localeDependent) {
60.2609 + upperChar = ConditionalSpecialCasing.toUpperCaseEx(this, i, locale);
60.2610 + } else {
60.2611 + upperChar = Character.toUpperCaseEx(srcChar);
60.2612 + }
60.2613 + if ((upperChar == Character.ERROR) ||
60.2614 + (upperChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
60.2615 + if (upperChar == Character.ERROR) {
60.2616 + if (localeDependent) {
60.2617 + upperCharArray =
60.2618 + ConditionalSpecialCasing.toUpperCaseCharArray(this, i, locale);
60.2619 + } else {
60.2620 + upperCharArray = Character.toUpperCaseCharArray(srcChar);
60.2621 + }
60.2622 + } else if (srcCount == 2) {
60.2623 + resultOffset += Character.toChars(upperChar, result, i + resultOffset) - srcCount;
60.2624 + continue;
60.2625 + } else {
60.2626 + upperCharArray = Character.toChars(upperChar);
60.2627 + }
60.2628 +
60.2629 + /* Grow result if needed *
60.2630 + int mapLen = upperCharArray.length;
60.2631 + if (mapLen > srcCount) {
60.2632 + char[] result2 = new char[result.length + mapLen - srcCount];
60.2633 + arraycopy(result, 0, result2, 0,
60.2634 + i + resultOffset);
60.2635 + result = result2;
60.2636 + }
60.2637 + for (int x=0; x<mapLen; ++x) {
60.2638 + result[i+resultOffset+x] = upperCharArray[x];
60.2639 + }
60.2640 + resultOffset += (mapLen - srcCount);
60.2641 + } else {
60.2642 + result[i+resultOffset] = (char)upperChar;
60.2643 + }
60.2644 + }
60.2645 + return new String(0, count+resultOffset, result);
60.2646 + }
60.2647 + */
60.2648 +
60.2649 + /**
60.2650 + * Converts all of the characters in this <code>String</code> to upper
60.2651 + * case using the rules of the default locale. This method is equivalent to
60.2652 + * <code>toUpperCase(Locale.getDefault())</code>.
60.2653 + * <p>
60.2654 + * <b>Note:</b> This method is locale sensitive, and may produce unexpected
60.2655 + * results if used for strings that are intended to be interpreted locale
60.2656 + * independently.
60.2657 + * Examples are programming language identifiers, protocol keys, and HTML
60.2658 + * tags.
60.2659 + * For instance, <code>"title".toUpperCase()</code> in a Turkish locale
60.2660 + * returns <code>"T\u005Cu0130TLE"</code>, where '\u005Cu0130' is the
60.2661 + * LATIN CAPITAL LETTER I WITH DOT ABOVE character.
60.2662 + * To obtain correct results for locale insensitive strings, use
60.2663 + * <code>toUpperCase(Locale.ENGLISH)</code>.
60.2664 + * <p>
60.2665 + * @return the <code>String</code>, converted to uppercase.
60.2666 + * @see java.lang.String#toUpperCase(Locale)
60.2667 + */
60.2668 + @JavaScriptBody(args = {}, body = "return this.toUpperCase();")
60.2669 + public String toUpperCase() {
60.2670 + throw new UnsupportedOperationException();
60.2671 + }
60.2672 +
60.2673 + /**
60.2674 + * Returns a copy of the string, with leading and trailing whitespace
60.2675 + * omitted.
60.2676 + * <p>
60.2677 + * If this <code>String</code> object represents an empty character
60.2678 + * sequence, or the first and last characters of character sequence
60.2679 + * represented by this <code>String</code> object both have codes
60.2680 + * greater than <code>'\u0020'</code> (the space character), then a
60.2681 + * reference to this <code>String</code> object is returned.
60.2682 + * <p>
60.2683 + * Otherwise, if there is no character with a code greater than
60.2684 + * <code>'\u0020'</code> in the string, then a new
60.2685 + * <code>String</code> object representing an empty string is created
60.2686 + * and returned.
60.2687 + * <p>
60.2688 + * Otherwise, let <i>k</i> be the index of the first character in the
60.2689 + * string whose code is greater than <code>'\u0020'</code>, and let
60.2690 + * <i>m</i> be the index of the last character in the string whose code
60.2691 + * is greater than <code>'\u0020'</code>. A new <code>String</code>
60.2692 + * object is created, representing the substring of this string that
60.2693 + * begins with the character at index <i>k</i> and ends with the
60.2694 + * character at index <i>m</i>-that is, the result of
60.2695 + * <code>this.substring(<i>k</i>, <i>m</i>+1)</code>.
60.2696 + * <p>
60.2697 + * This method may be used to trim whitespace (as defined above) from
60.2698 + * the beginning and end of a string.
60.2699 + *
60.2700 + * @return A copy of this string with leading and trailing white
60.2701 + * space removed, or this string if it has no leading or
60.2702 + * trailing white space.
60.2703 + */
60.2704 + public String trim() {
60.2705 + int len = length();
60.2706 + int st = 0;
60.2707 + int off = offset(); /* avoid getfield opcode */
60.2708 + char[] val = toCharArray(); /* avoid getfield opcode */
60.2709 +
60.2710 + while ((st < len) && (val[off + st] <= ' ')) {
60.2711 + st++;
60.2712 + }
60.2713 + while ((st < len) && (val[off + len - 1] <= ' ')) {
60.2714 + len--;
60.2715 + }
60.2716 + return ((st > 0) || (len < length())) ? substring(st, len) : this;
60.2717 + }
60.2718 +
60.2719 + /**
60.2720 + * This object (which is already a string!) is itself returned.
60.2721 + *
60.2722 + * @return the string itself.
60.2723 + */
60.2724 + @JavaScriptBody(args = {}, body = "return this.toString();")
60.2725 + public String toString() {
60.2726 + return this;
60.2727 + }
60.2728 +
60.2729 + /**
60.2730 + * Converts this string to a new character array.
60.2731 + *
60.2732 + * @return a newly allocated character array whose length is the length
60.2733 + * of this string and whose contents are initialized to contain
60.2734 + * the character sequence represented by this string.
60.2735 + */
60.2736 + public char[] toCharArray() {
60.2737 + char result[] = new char[length()];
60.2738 + getChars(0, length(), result, 0);
60.2739 + return result;
60.2740 + }
60.2741 +
60.2742 + /**
60.2743 + * Returns a formatted string using the specified format string and
60.2744 + * arguments.
60.2745 + *
60.2746 + * <p> The locale always used is the one returned by {@link
60.2747 + * java.util.Locale#getDefault() Locale.getDefault()}.
60.2748 + *
60.2749 + * @param format
60.2750 + * A <a href="../util/Formatter.html#syntax">format string</a>
60.2751 + *
60.2752 + * @param args
60.2753 + * Arguments referenced by the format specifiers in the format
60.2754 + * string. If there are more arguments than format specifiers, the
60.2755 + * extra arguments are ignored. The number of arguments is
60.2756 + * variable and may be zero. The maximum number of arguments is
60.2757 + * limited by the maximum dimension of a Java array as defined by
60.2758 + * <cite>The Java™ Virtual Machine Specification</cite>.
60.2759 + * The behaviour on a
60.2760 + * <tt>null</tt> argument depends on the <a
60.2761 + * href="../util/Formatter.html#syntax">conversion</a>.
60.2762 + *
60.2763 + * @throws IllegalFormatException
60.2764 + * If a format string contains an illegal syntax, a format
60.2765 + * specifier that is incompatible with the given arguments,
60.2766 + * insufficient arguments given the format string, or other
60.2767 + * illegal conditions. For specification of all possible
60.2768 + * formatting errors, see the <a
60.2769 + * href="../util/Formatter.html#detail">Details</a> section of the
60.2770 + * formatter class specification.
60.2771 + *
60.2772 + * @throws NullPointerException
60.2773 + * If the <tt>format</tt> is <tt>null</tt>
60.2774 + *
60.2775 + * @return A formatted string
60.2776 + *
60.2777 + * @see java.util.Formatter
60.2778 + * @since 1.5
60.2779 + */
60.2780 + public static String format(String format, Object ... args) {
60.2781 + throw new UnsupportedOperationException();
60.2782 + }
60.2783 +
60.2784 + /**
60.2785 + * Returns a formatted string using the specified locale, format string,
60.2786 + * and arguments.
60.2787 + *
60.2788 + * @param l
60.2789 + * The {@linkplain java.util.Locale locale} to apply during
60.2790 + * formatting. If <tt>l</tt> is <tt>null</tt> then no localization
60.2791 + * is applied.
60.2792 + *
60.2793 + * @param format
60.2794 + * A <a href="../util/Formatter.html#syntax">format string</a>
60.2795 + *
60.2796 + * @param args
60.2797 + * Arguments referenced by the format specifiers in the format
60.2798 + * string. If there are more arguments than format specifiers, the
60.2799 + * extra arguments are ignored. The number of arguments is
60.2800 + * variable and may be zero. The maximum number of arguments is
60.2801 + * limited by the maximum dimension of a Java array as defined by
60.2802 + * <cite>The Java™ Virtual Machine Specification</cite>.
60.2803 + * The behaviour on a
60.2804 + * <tt>null</tt> argument depends on the <a
60.2805 + * href="../util/Formatter.html#syntax">conversion</a>.
60.2806 + *
60.2807 + * @throws IllegalFormatException
60.2808 + * If a format string contains an illegal syntax, a format
60.2809 + * specifier that is incompatible with the given arguments,
60.2810 + * insufficient arguments given the format string, or other
60.2811 + * illegal conditions. For specification of all possible
60.2812 + * formatting errors, see the <a
60.2813 + * href="../util/Formatter.html#detail">Details</a> section of the
60.2814 + * formatter class specification
60.2815 + *
60.2816 + * @throws NullPointerException
60.2817 + * If the <tt>format</tt> is <tt>null</tt>
60.2818 + *
60.2819 + * @return A formatted string
60.2820 + *
60.2821 + * @see java.util.Formatter
60.2822 + * @since 1.5
60.2823 + */
60.2824 +// public static String format(Locale l, String format, Object ... args) {
60.2825 +// return new Formatter(l).format(format, args).toString();
60.2826 +// }
60.2827 +
60.2828 + /**
60.2829 + * Returns the string representation of the <code>Object</code> argument.
60.2830 + *
60.2831 + * @param obj an <code>Object</code>.
60.2832 + * @return if the argument is <code>null</code>, then a string equal to
60.2833 + * <code>"null"</code>; otherwise, the value of
60.2834 + * <code>obj.toString()</code> is returned.
60.2835 + * @see java.lang.Object#toString()
60.2836 + */
60.2837 + public static String valueOf(Object obj) {
60.2838 + return (obj == null) ? "null" : obj.toString();
60.2839 + }
60.2840 +
60.2841 + /**
60.2842 + * Returns the string representation of the <code>char</code> array
60.2843 + * argument. The contents of the character array are copied; subsequent
60.2844 + * modification of the character array does not affect the newly
60.2845 + * created string.
60.2846 + *
60.2847 + * @param data a <code>char</code> array.
60.2848 + * @return a newly allocated string representing the same sequence of
60.2849 + * characters contained in the character array argument.
60.2850 + */
60.2851 + public static String valueOf(char data[]) {
60.2852 + return new String(data);
60.2853 + }
60.2854 +
60.2855 + /**
60.2856 + * Returns the string representation of a specific subarray of the
60.2857 + * <code>char</code> array argument.
60.2858 + * <p>
60.2859 + * The <code>offset</code> argument is the index of the first
60.2860 + * character of the subarray. The <code>count</code> argument
60.2861 + * specifies the length of the subarray. The contents of the subarray
60.2862 + * are copied; subsequent modification of the character array does not
60.2863 + * affect the newly created string.
60.2864 + *
60.2865 + * @param data the character array.
60.2866 + * @param offset the initial offset into the value of the
60.2867 + * <code>String</code>.
60.2868 + * @param count the length of the value of the <code>String</code>.
60.2869 + * @return a string representing the sequence of characters contained
60.2870 + * in the subarray of the character array argument.
60.2871 + * @exception IndexOutOfBoundsException if <code>offset</code> is
60.2872 + * negative, or <code>count</code> is negative, or
60.2873 + * <code>offset+count</code> is larger than
60.2874 + * <code>data.length</code>.
60.2875 + */
60.2876 + public static String valueOf(char data[], int offset, int count) {
60.2877 + return new String(data, offset, count);
60.2878 + }
60.2879 +
60.2880 + /**
60.2881 + * Returns a String that represents the character sequence in the
60.2882 + * array specified.
60.2883 + *
60.2884 + * @param data the character array.
60.2885 + * @param offset initial offset of the subarray.
60.2886 + * @param count length of the subarray.
60.2887 + * @return a <code>String</code> that contains the characters of the
60.2888 + * specified subarray of the character array.
60.2889 + */
60.2890 + public static String copyValueOf(char data[], int offset, int count) {
60.2891 + // All public String constructors now copy the data.
60.2892 + return new String(data, offset, count);
60.2893 + }
60.2894 +
60.2895 + /**
60.2896 + * Returns a String that represents the character sequence in the
60.2897 + * array specified.
60.2898 + *
60.2899 + * @param data the character array.
60.2900 + * @return a <code>String</code> that contains the characters of the
60.2901 + * character array.
60.2902 + */
60.2903 + public static String copyValueOf(char data[]) {
60.2904 + return copyValueOf(data, 0, data.length);
60.2905 + }
60.2906 +
60.2907 + /**
60.2908 + * Returns the string representation of the <code>boolean</code> argument.
60.2909 + *
60.2910 + * @param b a <code>boolean</code>.
60.2911 + * @return if the argument is <code>true</code>, a string equal to
60.2912 + * <code>"true"</code> is returned; otherwise, a string equal to
60.2913 + * <code>"false"</code> is returned.
60.2914 + */
60.2915 + public static String valueOf(boolean b) {
60.2916 + return b ? "true" : "false";
60.2917 + }
60.2918 +
60.2919 + /**
60.2920 + * Returns the string representation of the <code>char</code>
60.2921 + * argument.
60.2922 + *
60.2923 + * @param c a <code>char</code>.
60.2924 + * @return a string of length <code>1</code> containing
60.2925 + * as its single character the argument <code>c</code>.
60.2926 + */
60.2927 + public static String valueOf(char c) {
60.2928 + char data[] = {c};
60.2929 + return new String(data, 0, 1);
60.2930 + }
60.2931 +
60.2932 + /**
60.2933 + * Returns the string representation of the <code>int</code> argument.
60.2934 + * <p>
60.2935 + * The representation is exactly the one returned by the
60.2936 + * <code>Integer.toString</code> method of one argument.
60.2937 + *
60.2938 + * @param i an <code>int</code>.
60.2939 + * @return a string representation of the <code>int</code> argument.
60.2940 + * @see java.lang.Integer#toString(int, int)
60.2941 + */
60.2942 + public static String valueOf(int i) {
60.2943 + return Integer.toString(i);
60.2944 + }
60.2945 +
60.2946 + /**
60.2947 + * Returns the string representation of the <code>long</code> argument.
60.2948 + * <p>
60.2949 + * The representation is exactly the one returned by the
60.2950 + * <code>Long.toString</code> method of one argument.
60.2951 + *
60.2952 + * @param l a <code>long</code>.
60.2953 + * @return a string representation of the <code>long</code> argument.
60.2954 + * @see java.lang.Long#toString(long)
60.2955 + */
60.2956 + public static String valueOf(long l) {
60.2957 + return Long.toString(l);
60.2958 + }
60.2959 +
60.2960 + /**
60.2961 + * Returns the string representation of the <code>float</code> argument.
60.2962 + * <p>
60.2963 + * The representation is exactly the one returned by the
60.2964 + * <code>Float.toString</code> method of one argument.
60.2965 + *
60.2966 + * @param f a <code>float</code>.
60.2967 + * @return a string representation of the <code>float</code> argument.
60.2968 + * @see java.lang.Float#toString(float)
60.2969 + */
60.2970 + public static String valueOf(float f) {
60.2971 + return Float.toString(f);
60.2972 + }
60.2973 +
60.2974 + /**
60.2975 + * Returns the string representation of the <code>double</code> argument.
60.2976 + * <p>
60.2977 + * The representation is exactly the one returned by the
60.2978 + * <code>Double.toString</code> method of one argument.
60.2979 + *
60.2980 + * @param d a <code>double</code>.
60.2981 + * @return a string representation of the <code>double</code> argument.
60.2982 + * @see java.lang.Double#toString(double)
60.2983 + */
60.2984 + public static String valueOf(double d) {
60.2985 + return Double.toString(d);
60.2986 + }
60.2987 +
60.2988 + /**
60.2989 + * Returns a canonical representation for the string object.
60.2990 + * <p>
60.2991 + * A pool of strings, initially empty, is maintained privately by the
60.2992 + * class <code>String</code>.
60.2993 + * <p>
60.2994 + * When the intern method is invoked, if the pool already contains a
60.2995 + * string equal to this <code>String</code> object as determined by
60.2996 + * the {@link #equals(Object)} method, then the string from the pool is
60.2997 + * returned. Otherwise, this <code>String</code> object is added to the
60.2998 + * pool and a reference to this <code>String</code> object is returned.
60.2999 + * <p>
60.3000 + * It follows that for any two strings <code>s</code> and <code>t</code>,
60.3001 + * <code>s.intern() == t.intern()</code> is <code>true</code>
60.3002 + * if and only if <code>s.equals(t)</code> is <code>true</code>.
60.3003 + * <p>
60.3004 + * All literal strings and string-valued constant expressions are
60.3005 + * interned. String literals are defined in section 3.10.5 of the
60.3006 + * <cite>The Java™ Language Specification</cite>.
60.3007 + *
60.3008 + * @return a string that has the same contents as this string, but is
60.3009 + * guaranteed to be from a pool of unique strings.
60.3010 + */
60.3011 + public native String intern();
60.3012 +}
61.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
61.2 +++ b/emul/mini/src/main/java/java/lang/StringBuffer.java Wed Jan 23 20:39:23 2013 +0100
61.3 @@ -0,0 +1,604 @@
61.4 +/*
61.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
61.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
61.7 + *
61.8 + * This code is free software; you can redistribute it and/or modify it
61.9 + * under the terms of the GNU General Public License version 2 only, as
61.10 + * published by the Free Software Foundation. Oracle designates this
61.11 + * particular file as subject to the "Classpath" exception as provided
61.12 + * by Oracle in the LICENSE file that accompanied this code.
61.13 + *
61.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
61.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
61.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
61.17 + * version 2 for more details (a copy is included in the LICENSE file that
61.18 + * accompanied this code).
61.19 + *
61.20 + * You should have received a copy of the GNU General Public License version
61.21 + * 2 along with this work; if not, write to the Free Software Foundation,
61.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
61.23 + *
61.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
61.25 + * or visit www.oracle.com if you need additional information or have any
61.26 + * questions.
61.27 + */
61.28 +
61.29 +package java.lang;
61.30 +
61.31 +
61.32 +/**
61.33 + * A thread-safe, mutable sequence of characters.
61.34 + * A string buffer is like a {@link String}, but can be modified. At any
61.35 + * point in time it contains some particular sequence of characters, but
61.36 + * the length and content of the sequence can be changed through certain
61.37 + * method calls.
61.38 + * <p>
61.39 + * String buffers are safe for use by multiple threads. The methods
61.40 + * are synchronized where necessary so that all the operations on any
61.41 + * particular instance behave as if they occur in some serial order
61.42 + * that is consistent with the order of the method calls made by each of
61.43 + * the individual threads involved.
61.44 + * <p>
61.45 + * The principal operations on a <code>StringBuffer</code> are the
61.46 + * <code>append</code> and <code>insert</code> methods, which are
61.47 + * overloaded so as to accept data of any type. Each effectively
61.48 + * converts a given datum to a string and then appends or inserts the
61.49 + * characters of that string to the string buffer. The
61.50 + * <code>append</code> method always adds these characters at the end
61.51 + * of the buffer; the <code>insert</code> method adds the characters at
61.52 + * a specified point.
61.53 + * <p>
61.54 + * For example, if <code>z</code> refers to a string buffer object
61.55 + * whose current contents are "<code>start</code>", then
61.56 + * the method call <code>z.append("le")</code> would cause the string
61.57 + * buffer to contain "<code>startle</code>", whereas
61.58 + * <code>z.insert(4, "le")</code> would alter the string buffer to
61.59 + * contain "<code>starlet</code>".
61.60 + * <p>
61.61 + * In general, if sb refers to an instance of a <code>StringBuffer</code>,
61.62 + * then <code>sb.append(x)</code> has the same effect as
61.63 + * <code>sb.insert(sb.length(), x)</code>.
61.64 + * <p>
61.65 + * Whenever an operation occurs involving a source sequence (such as
61.66 + * appending or inserting from a source sequence) this class synchronizes
61.67 + * only on the string buffer performing the operation, not on the source.
61.68 + * <p>
61.69 + * Every string buffer has a capacity. As long as the length of the
61.70 + * character sequence contained in the string buffer does not exceed
61.71 + * the capacity, it is not necessary to allocate a new internal
61.72 + * buffer array. If the internal buffer overflows, it is
61.73 + * automatically made larger.
61.74 + *
61.75 + * As of release JDK 5, this class has been supplemented with an equivalent
61.76 + * class designed for use by a single thread, {@link StringBuilder}. The
61.77 + * <tt>StringBuilder</tt> class should generally be used in preference to
61.78 + * this one, as it supports all of the same operations but it is faster, as
61.79 + * it performs no synchronization.
61.80 + *
61.81 + * @author Arthur van Hoff
61.82 + * @see java.lang.StringBuilder
61.83 + * @see java.lang.String
61.84 + * @since JDK1.0
61.85 + */
61.86 + public final class StringBuffer
61.87 + extends AbstractStringBuilder
61.88 + implements java.io.Serializable, CharSequence
61.89 +{
61.90 +
61.91 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
61.92 + static final long serialVersionUID = 3388685877147921107L;
61.93 +
61.94 + /**
61.95 + * Constructs a string buffer with no characters in it and an
61.96 + * initial capacity of 16 characters.
61.97 + */
61.98 + public StringBuffer() {
61.99 + super(16);
61.100 + }
61.101 +
61.102 + /**
61.103 + * Constructs a string buffer with no characters in it and
61.104 + * the specified initial capacity.
61.105 + *
61.106 + * @param capacity the initial capacity.
61.107 + * @exception NegativeArraySizeException if the <code>capacity</code>
61.108 + * argument is less than <code>0</code>.
61.109 + */
61.110 + public StringBuffer(int capacity) {
61.111 + super(capacity);
61.112 + }
61.113 +
61.114 + /**
61.115 + * Constructs a string buffer initialized to the contents of the
61.116 + * specified string. The initial capacity of the string buffer is
61.117 + * <code>16</code> plus the length of the string argument.
61.118 + *
61.119 + * @param str the initial contents of the buffer.
61.120 + * @exception NullPointerException if <code>str</code> is <code>null</code>
61.121 + */
61.122 + public StringBuffer(String str) {
61.123 + super(str.length() + 16);
61.124 + append(str);
61.125 + }
61.126 +
61.127 + /**
61.128 + * Constructs a string buffer that contains the same characters
61.129 + * as the specified <code>CharSequence</code>. The initial capacity of
61.130 + * the string buffer is <code>16</code> plus the length of the
61.131 + * <code>CharSequence</code> argument.
61.132 + * <p>
61.133 + * If the length of the specified <code>CharSequence</code> is
61.134 + * less than or equal to zero, then an empty buffer of capacity
61.135 + * <code>16</code> is returned.
61.136 + *
61.137 + * @param seq the sequence to copy.
61.138 + * @exception NullPointerException if <code>seq</code> is <code>null</code>
61.139 + * @since 1.5
61.140 + */
61.141 + public StringBuffer(CharSequence seq) {
61.142 + this(seq.length() + 16);
61.143 + append(seq);
61.144 + }
61.145 +
61.146 + public synchronized int length() {
61.147 + return count;
61.148 + }
61.149 +
61.150 + public synchronized int capacity() {
61.151 + return value.length;
61.152 + }
61.153 +
61.154 +
61.155 + public synchronized void ensureCapacity(int minimumCapacity) {
61.156 + if (minimumCapacity > value.length) {
61.157 + expandCapacity(minimumCapacity);
61.158 + }
61.159 + }
61.160 +
61.161 + /**
61.162 + * @since 1.5
61.163 + */
61.164 + public synchronized void trimToSize() {
61.165 + super.trimToSize();
61.166 + }
61.167 +
61.168 + /**
61.169 + * @throws IndexOutOfBoundsException {@inheritDoc}
61.170 + * @see #length()
61.171 + */
61.172 + public synchronized void setLength(int newLength) {
61.173 + super.setLength(newLength);
61.174 + }
61.175 +
61.176 + /**
61.177 + * @throws IndexOutOfBoundsException {@inheritDoc}
61.178 + * @see #length()
61.179 + */
61.180 + public synchronized char charAt(int index) {
61.181 + if ((index < 0) || (index >= count))
61.182 + throw new StringIndexOutOfBoundsException(index);
61.183 + return value[index];
61.184 + }
61.185 +
61.186 + /**
61.187 + * @since 1.5
61.188 + */
61.189 + public synchronized int codePointAt(int index) {
61.190 + return super.codePointAt(index);
61.191 + }
61.192 +
61.193 + /**
61.194 + * @since 1.5
61.195 + */
61.196 + public synchronized int codePointBefore(int index) {
61.197 + return super.codePointBefore(index);
61.198 + }
61.199 +
61.200 + /**
61.201 + * @since 1.5
61.202 + */
61.203 + public synchronized int codePointCount(int beginIndex, int endIndex) {
61.204 + return super.codePointCount(beginIndex, endIndex);
61.205 + }
61.206 +
61.207 + /**
61.208 + * @since 1.5
61.209 + */
61.210 + public synchronized int offsetByCodePoints(int index, int codePointOffset) {
61.211 + return super.offsetByCodePoints(index, codePointOffset);
61.212 + }
61.213 +
61.214 + /**
61.215 + * @throws NullPointerException {@inheritDoc}
61.216 + * @throws IndexOutOfBoundsException {@inheritDoc}
61.217 + */
61.218 + public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
61.219 + int dstBegin)
61.220 + {
61.221 + super.getChars(srcBegin, srcEnd, dst, dstBegin);
61.222 + }
61.223 +
61.224 + /**
61.225 + * @throws IndexOutOfBoundsException {@inheritDoc}
61.226 + * @see #length()
61.227 + */
61.228 + public synchronized void setCharAt(int index, char ch) {
61.229 + if ((index < 0) || (index >= count))
61.230 + throw new StringIndexOutOfBoundsException(index);
61.231 + value[index] = ch;
61.232 + }
61.233 +
61.234 + public synchronized StringBuffer append(Object obj) {
61.235 + super.append(String.valueOf(obj));
61.236 + return this;
61.237 + }
61.238 +
61.239 + public synchronized StringBuffer append(String str) {
61.240 + super.append(str);
61.241 + return this;
61.242 + }
61.243 +
61.244 + /**
61.245 + * Appends the specified <tt>StringBuffer</tt> to this sequence.
61.246 + * <p>
61.247 + * The characters of the <tt>StringBuffer</tt> argument are appended,
61.248 + * in order, to the contents of this <tt>StringBuffer</tt>, increasing the
61.249 + * length of this <tt>StringBuffer</tt> by the length of the argument.
61.250 + * If <tt>sb</tt> is <tt>null</tt>, then the four characters
61.251 + * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
61.252 + * <p>
61.253 + * Let <i>n</i> be the length of the old character sequence, the one
61.254 + * contained in the <tt>StringBuffer</tt> just prior to execution of the
61.255 + * <tt>append</tt> method. Then the character at index <i>k</i> in
61.256 + * the new character sequence is equal to the character at index <i>k</i>
61.257 + * in the old character sequence, if <i>k</i> is less than <i>n</i>;
61.258 + * otherwise, it is equal to the character at index <i>k-n</i> in the
61.259 + * argument <code>sb</code>.
61.260 + * <p>
61.261 + * This method synchronizes on <code>this</code> (the destination)
61.262 + * object but does not synchronize on the source (<code>sb</code>).
61.263 + *
61.264 + * @param sb the <tt>StringBuffer</tt> to append.
61.265 + * @return a reference to this object.
61.266 + * @since 1.4
61.267 + */
61.268 + public synchronized StringBuffer append(StringBuffer sb) {
61.269 + super.append(sb);
61.270 + return this;
61.271 + }
61.272 +
61.273 +
61.274 + /**
61.275 + * Appends the specified <code>CharSequence</code> to this
61.276 + * sequence.
61.277 + * <p>
61.278 + * The characters of the <code>CharSequence</code> argument are appended,
61.279 + * in order, increasing the length of this sequence by the length of the
61.280 + * argument.
61.281 + *
61.282 + * <p>The result of this method is exactly the same as if it were an
61.283 + * invocation of this.append(s, 0, s.length());
61.284 + *
61.285 + * <p>This method synchronizes on this (the destination)
61.286 + * object but does not synchronize on the source (<code>s</code>).
61.287 + *
61.288 + * <p>If <code>s</code> is <code>null</code>, then the four characters
61.289 + * <code>"null"</code> are appended.
61.290 + *
61.291 + * @param s the <code>CharSequence</code> to append.
61.292 + * @return a reference to this object.
61.293 + * @since 1.5
61.294 + */
61.295 + public StringBuffer append(CharSequence s) {
61.296 + // Note, synchronization achieved via other invocations
61.297 + if (s == null)
61.298 + s = "null";
61.299 + if (s instanceof String)
61.300 + return this.append((String)s);
61.301 + if (s instanceof StringBuffer)
61.302 + return this.append((StringBuffer)s);
61.303 + return this.append(s, 0, s.length());
61.304 + }
61.305 +
61.306 + /**
61.307 + * @throws IndexOutOfBoundsException {@inheritDoc}
61.308 + * @since 1.5
61.309 + */
61.310 + public synchronized StringBuffer append(CharSequence s, int start, int end)
61.311 + {
61.312 + super.append(s, start, end);
61.313 + return this;
61.314 + }
61.315 +
61.316 + public synchronized StringBuffer append(char[] str) {
61.317 + super.append(str);
61.318 + return this;
61.319 + }
61.320 +
61.321 + /**
61.322 + * @throws IndexOutOfBoundsException {@inheritDoc}
61.323 + */
61.324 + public synchronized StringBuffer append(char[] str, int offset, int len) {
61.325 + super.append(str, offset, len);
61.326 + return this;
61.327 + }
61.328 +
61.329 + public synchronized StringBuffer append(boolean b) {
61.330 + super.append(b);
61.331 + return this;
61.332 + }
61.333 +
61.334 + public synchronized StringBuffer append(char c) {
61.335 + super.append(c);
61.336 + return this;
61.337 + }
61.338 +
61.339 + public synchronized StringBuffer append(int i) {
61.340 + super.append(i);
61.341 + return this;
61.342 + }
61.343 +
61.344 + /**
61.345 + * @since 1.5
61.346 + */
61.347 + public synchronized StringBuffer appendCodePoint(int codePoint) {
61.348 + super.appendCodePoint(codePoint);
61.349 + return this;
61.350 + }
61.351 +
61.352 + public synchronized StringBuffer append(long lng) {
61.353 + super.append(lng);
61.354 + return this;
61.355 + }
61.356 +
61.357 + public synchronized StringBuffer append(float f) {
61.358 + super.append(f);
61.359 + return this;
61.360 + }
61.361 +
61.362 + public synchronized StringBuffer append(double d) {
61.363 + super.append(d);
61.364 + return this;
61.365 + }
61.366 +
61.367 + /**
61.368 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.369 + * @since 1.2
61.370 + */
61.371 + public synchronized StringBuffer delete(int start, int end) {
61.372 + super.delete(start, end);
61.373 + return this;
61.374 + }
61.375 +
61.376 + /**
61.377 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.378 + * @since 1.2
61.379 + */
61.380 + public synchronized StringBuffer deleteCharAt(int index) {
61.381 + super.deleteCharAt(index);
61.382 + return this;
61.383 + }
61.384 +
61.385 + /**
61.386 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.387 + * @since 1.2
61.388 + */
61.389 + public synchronized StringBuffer replace(int start, int end, String str) {
61.390 + super.replace(start, end, str);
61.391 + return this;
61.392 + }
61.393 +
61.394 + /**
61.395 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.396 + * @since 1.2
61.397 + */
61.398 + public synchronized String substring(int start) {
61.399 + return substring(start, count);
61.400 + }
61.401 +
61.402 + /**
61.403 + * @throws IndexOutOfBoundsException {@inheritDoc}
61.404 + * @since 1.4
61.405 + */
61.406 + public synchronized CharSequence subSequence(int start, int end) {
61.407 + return super.substring(start, end);
61.408 + }
61.409 +
61.410 + /**
61.411 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.412 + * @since 1.2
61.413 + */
61.414 + public synchronized String substring(int start, int end) {
61.415 + return super.substring(start, end);
61.416 + }
61.417 +
61.418 + /**
61.419 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.420 + * @since 1.2
61.421 + */
61.422 + public synchronized StringBuffer insert(int index, char[] str, int offset,
61.423 + int len)
61.424 + {
61.425 + super.insert(index, str, offset, len);
61.426 + return this;
61.427 + }
61.428 +
61.429 + /**
61.430 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.431 + */
61.432 + public synchronized StringBuffer insert(int offset, Object obj) {
61.433 + super.insert(offset, String.valueOf(obj));
61.434 + return this;
61.435 + }
61.436 +
61.437 + /**
61.438 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.439 + */
61.440 + public synchronized StringBuffer insert(int offset, String str) {
61.441 + super.insert(offset, str);
61.442 + return this;
61.443 + }
61.444 +
61.445 + /**
61.446 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.447 + */
61.448 + public synchronized StringBuffer insert(int offset, char[] str) {
61.449 + super.insert(offset, str);
61.450 + return this;
61.451 + }
61.452 +
61.453 + /**
61.454 + * @throws IndexOutOfBoundsException {@inheritDoc}
61.455 + * @since 1.5
61.456 + */
61.457 + public StringBuffer insert(int dstOffset, CharSequence s) {
61.458 + // Note, synchronization achieved via other invocations
61.459 + if (s == null)
61.460 + s = "null";
61.461 + if (s instanceof String)
61.462 + return this.insert(dstOffset, (String)s);
61.463 + return this.insert(dstOffset, s, 0, s.length());
61.464 + }
61.465 +
61.466 + /**
61.467 + * @throws IndexOutOfBoundsException {@inheritDoc}
61.468 + * @since 1.5
61.469 + */
61.470 + public synchronized StringBuffer insert(int dstOffset, CharSequence s,
61.471 + int start, int end)
61.472 + {
61.473 + super.insert(dstOffset, s, start, end);
61.474 + return this;
61.475 + }
61.476 +
61.477 + /**
61.478 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.479 + */
61.480 + public StringBuffer insert(int offset, boolean b) {
61.481 + return insert(offset, String.valueOf(b));
61.482 + }
61.483 +
61.484 + /**
61.485 + * @throws IndexOutOfBoundsException {@inheritDoc}
61.486 + */
61.487 + public synchronized StringBuffer insert(int offset, char c) {
61.488 + super.insert(offset, c);
61.489 + return this;
61.490 + }
61.491 +
61.492 + /**
61.493 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.494 + */
61.495 + public StringBuffer insert(int offset, int i) {
61.496 + return insert(offset, String.valueOf(i));
61.497 + }
61.498 +
61.499 + /**
61.500 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.501 + */
61.502 + public StringBuffer insert(int offset, long l) {
61.503 + return insert(offset, String.valueOf(l));
61.504 + }
61.505 +
61.506 + /**
61.507 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.508 + */
61.509 + public StringBuffer insert(int offset, float f) {
61.510 + return insert(offset, String.valueOf(f));
61.511 + }
61.512 +
61.513 + /**
61.514 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
61.515 + */
61.516 + public StringBuffer insert(int offset, double d) {
61.517 + return insert(offset, String.valueOf(d));
61.518 + }
61.519 +
61.520 + /**
61.521 + * @throws NullPointerException {@inheritDoc}
61.522 + * @since 1.4
61.523 + */
61.524 + public int indexOf(String str) {
61.525 + return indexOf(str, 0);
61.526 + }
61.527 +
61.528 + /**
61.529 + * @throws NullPointerException {@inheritDoc}
61.530 + * @since 1.4
61.531 + */
61.532 + public synchronized int indexOf(String str, int fromIndex) {
61.533 + return super.indexOf(str, fromIndex);
61.534 + }
61.535 +
61.536 + /**
61.537 + * @throws NullPointerException {@inheritDoc}
61.538 + * @since 1.4
61.539 + */
61.540 + public int lastIndexOf(String str) {
61.541 + // Note, synchronization achieved via other invocations
61.542 + return lastIndexOf(str, count);
61.543 + }
61.544 +
61.545 + /**
61.546 + * @throws NullPointerException {@inheritDoc}
61.547 + * @since 1.4
61.548 + */
61.549 + public synchronized int lastIndexOf(String str, int fromIndex) {
61.550 + return String.lastIndexOf(value, 0, count,
61.551 + str.toCharArray(), 0, str.length(), fromIndex);
61.552 + }
61.553 +
61.554 + /**
61.555 + * @since JDK1.0.2
61.556 + */
61.557 + public synchronized StringBuffer reverse() {
61.558 + super.reverse();
61.559 + return this;
61.560 + }
61.561 +
61.562 + public synchronized String toString() {
61.563 + return new String(value, 0, count);
61.564 + }
61.565 +
61.566 +// /**
61.567 +// * Serializable fields for StringBuffer.
61.568 +// *
61.569 +// * @serialField value char[]
61.570 +// * The backing character array of this StringBuffer.
61.571 +// * @serialField count int
61.572 +// * The number of characters in this StringBuffer.
61.573 +// * @serialField shared boolean
61.574 +// * A flag indicating whether the backing array is shared.
61.575 +// * The value is ignored upon deserialization.
61.576 +// */
61.577 +// private static final java.io.ObjectStreamField[] serialPersistentFields =
61.578 +// {
61.579 +// new java.io.ObjectStreamField("value", char[].class),
61.580 +// new java.io.ObjectStreamField("count", Integer.TYPE),
61.581 +// new java.io.ObjectStreamField("shared", Boolean.TYPE),
61.582 +// };
61.583 +//
61.584 +// /**
61.585 +// * readObject is called to restore the state of the StringBuffer from
61.586 +// * a stream.
61.587 +// */
61.588 +// private synchronized void writeObject(java.io.ObjectOutputStream s)
61.589 +// throws java.io.IOException {
61.590 +// java.io.ObjectOutputStream.PutField fields = s.putFields();
61.591 +// fields.put("value", value);
61.592 +// fields.put("count", count);
61.593 +// fields.put("shared", false);
61.594 +// s.writeFields();
61.595 +// }
61.596 +//
61.597 +// /**
61.598 +// * readObject is called to restore the state of the StringBuffer from
61.599 +// * a stream.
61.600 +// */
61.601 +// private void readObject(java.io.ObjectInputStream s)
61.602 +// throws java.io.IOException, ClassNotFoundException {
61.603 +// java.io.ObjectInputStream.GetField fields = s.readFields();
61.604 +// value = (char[])fields.get("value", null);
61.605 +// count = fields.get("count", 0);
61.606 +// }
61.607 +}
62.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
62.2 +++ b/emul/mini/src/main/java/java/lang/StringBuilder.java Wed Jan 23 20:39:23 2013 +0100
62.3 @@ -0,0 +1,436 @@
62.4 +/*
62.5 + * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
62.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
62.7 + *
62.8 + * This code is free software; you can redistribute it and/or modify it
62.9 + * under the terms of the GNU General Public License version 2 only, as
62.10 + * published by the Free Software Foundation. Oracle designates this
62.11 + * particular file as subject to the "Classpath" exception as provided
62.12 + * by Oracle in the LICENSE file that accompanied this code.
62.13 + *
62.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
62.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
62.17 + * version 2 for more details (a copy is included in the LICENSE file that
62.18 + * accompanied this code).
62.19 + *
62.20 + * You should have received a copy of the GNU General Public License version
62.21 + * 2 along with this work; if not, write to the Free Software Foundation,
62.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
62.23 + *
62.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
62.25 + * or visit www.oracle.com if you need additional information or have any
62.26 + * questions.
62.27 + */
62.28 +
62.29 +package java.lang;
62.30 +
62.31 +
62.32 +/**
62.33 + * A mutable sequence of characters. This class provides an API compatible
62.34 + * with <code>StringBuffer</code>, but with no guarantee of synchronization.
62.35 + * This class is designed for use as a drop-in replacement for
62.36 + * <code>StringBuffer</code> in places where the string buffer was being
62.37 + * used by a single thread (as is generally the case). Where possible,
62.38 + * it is recommended that this class be used in preference to
62.39 + * <code>StringBuffer</code> as it will be faster under most implementations.
62.40 + *
62.41 + * <p>The principal operations on a <code>StringBuilder</code> are the
62.42 + * <code>append</code> and <code>insert</code> methods, which are
62.43 + * overloaded so as to accept data of any type. Each effectively
62.44 + * converts a given datum to a string and then appends or inserts the
62.45 + * characters of that string to the string builder. The
62.46 + * <code>append</code> method always adds these characters at the end
62.47 + * of the builder; the <code>insert</code> method adds the characters at
62.48 + * a specified point.
62.49 + * <p>
62.50 + * For example, if <code>z</code> refers to a string builder object
62.51 + * whose current contents are "<code>start</code>", then
62.52 + * the method call <code>z.append("le")</code> would cause the string
62.53 + * builder to contain "<code>startle</code>", whereas
62.54 + * <code>z.insert(4, "le")</code> would alter the string builder to
62.55 + * contain "<code>starlet</code>".
62.56 + * <p>
62.57 + * In general, if sb refers to an instance of a <code>StringBuilder</code>,
62.58 + * then <code>sb.append(x)</code> has the same effect as
62.59 + * <code>sb.insert(sb.length(), x)</code>.
62.60 + *
62.61 + * Every string builder has a capacity. As long as the length of the
62.62 + * character sequence contained in the string builder does not exceed
62.63 + * the capacity, it is not necessary to allocate a new internal
62.64 + * buffer. If the internal buffer overflows, it is automatically made larger.
62.65 + *
62.66 + * <p>Instances of <code>StringBuilder</code> are not safe for
62.67 + * use by multiple threads. If such synchronization is required then it is
62.68 + * recommended that {@link java.lang.StringBuffer} be used.
62.69 + *
62.70 + * @author Michael McCloskey
62.71 + * @see java.lang.StringBuffer
62.72 + * @see java.lang.String
62.73 + * @since 1.5
62.74 + */
62.75 +public final class StringBuilder
62.76 + extends AbstractStringBuilder
62.77 + implements java.io.Serializable, CharSequence
62.78 +{
62.79 +
62.80 + /** use serialVersionUID for interoperability */
62.81 + static final long serialVersionUID = 4383685877147921099L;
62.82 +
62.83 + /**
62.84 + * Constructs a string builder with no characters in it and an
62.85 + * initial capacity of 16 characters.
62.86 + */
62.87 + public StringBuilder() {
62.88 + super(16);
62.89 + }
62.90 +
62.91 + /**
62.92 + * Constructs a string builder with no characters in it and an
62.93 + * initial capacity specified by the <code>capacity</code> argument.
62.94 + *
62.95 + * @param capacity the initial capacity.
62.96 + * @throws NegativeArraySizeException if the <code>capacity</code>
62.97 + * argument is less than <code>0</code>.
62.98 + */
62.99 + public StringBuilder(int capacity) {
62.100 + super(capacity);
62.101 + }
62.102 +
62.103 + /**
62.104 + * Constructs a string builder initialized to the contents of the
62.105 + * specified string. The initial capacity of the string builder is
62.106 + * <code>16</code> plus the length of the string argument.
62.107 + *
62.108 + * @param str the initial contents of the buffer.
62.109 + * @throws NullPointerException if <code>str</code> is <code>null</code>
62.110 + */
62.111 + public StringBuilder(String str) {
62.112 + super(str.length() + 16);
62.113 + append(str);
62.114 + }
62.115 +
62.116 + /**
62.117 + * Constructs a string builder that contains the same characters
62.118 + * as the specified <code>CharSequence</code>. The initial capacity of
62.119 + * the string builder is <code>16</code> plus the length of the
62.120 + * <code>CharSequence</code> argument.
62.121 + *
62.122 + * @param seq the sequence to copy.
62.123 + * @throws NullPointerException if <code>seq</code> is <code>null</code>
62.124 + */
62.125 + public StringBuilder(CharSequence seq) {
62.126 + this(seq.length() + 16);
62.127 + append(seq);
62.128 + }
62.129 +
62.130 + public StringBuilder append(Object obj) {
62.131 + return append(String.valueOf(obj));
62.132 + }
62.133 +
62.134 + public StringBuilder append(String str) {
62.135 + super.append(str);
62.136 + return this;
62.137 + }
62.138 +
62.139 + // Appends the specified string builder to this sequence.
62.140 + private StringBuilder append(StringBuilder sb) {
62.141 + if (sb == null)
62.142 + return append("null");
62.143 + int len = sb.length();
62.144 + int newcount = count + len;
62.145 + if (newcount > value.length)
62.146 + expandCapacity(newcount);
62.147 + sb.getChars(0, len, value, count);
62.148 + count = newcount;
62.149 + return this;
62.150 + }
62.151 +
62.152 + /**
62.153 + * Appends the specified <tt>StringBuffer</tt> to this sequence.
62.154 + * <p>
62.155 + * The characters of the <tt>StringBuffer</tt> argument are appended,
62.156 + * in order, to this sequence, increasing the
62.157 + * length of this sequence by the length of the argument.
62.158 + * If <tt>sb</tt> is <tt>null</tt>, then the four characters
62.159 + * <tt>"null"</tt> are appended to this sequence.
62.160 + * <p>
62.161 + * Let <i>n</i> be the length of this character sequence just prior to
62.162 + * execution of the <tt>append</tt> method. Then the character at index
62.163 + * <i>k</i> in the new character sequence is equal to the character at
62.164 + * index <i>k</i> in the old character sequence, if <i>k</i> is less than
62.165 + * <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i>
62.166 + * in the argument <code>sb</code>.
62.167 + *
62.168 + * @param sb the <tt>StringBuffer</tt> to append.
62.169 + * @return a reference to this object.
62.170 + */
62.171 + public StringBuilder append(StringBuffer sb) {
62.172 + super.append(sb);
62.173 + return this;
62.174 + }
62.175 +
62.176 + /**
62.177 + */
62.178 + public StringBuilder append(CharSequence s) {
62.179 + if (s == null)
62.180 + s = "null";
62.181 + if (s instanceof String)
62.182 + return this.append((String)s);
62.183 + if (s instanceof StringBuffer)
62.184 + return this.append((StringBuffer)s);
62.185 + if (s instanceof StringBuilder)
62.186 + return this.append((StringBuilder)s);
62.187 + return this.append(s, 0, s.length());
62.188 + }
62.189 +
62.190 + /**
62.191 + * @throws IndexOutOfBoundsException {@inheritDoc}
62.192 + */
62.193 + public StringBuilder append(CharSequence s, int start, int end) {
62.194 + super.append(s, start, end);
62.195 + return this;
62.196 + }
62.197 +
62.198 + public StringBuilder append(char[] str) {
62.199 + super.append(str);
62.200 + return this;
62.201 + }
62.202 +
62.203 + /**
62.204 + * @throws IndexOutOfBoundsException {@inheritDoc}
62.205 + */
62.206 + public StringBuilder append(char[] str, int offset, int len) {
62.207 + super.append(str, offset, len);
62.208 + return this;
62.209 + }
62.210 +
62.211 + public StringBuilder append(boolean b) {
62.212 + super.append(b);
62.213 + return this;
62.214 + }
62.215 +
62.216 + public StringBuilder append(char c) {
62.217 + super.append(c);
62.218 + return this;
62.219 + }
62.220 +
62.221 + public StringBuilder append(int i) {
62.222 + super.append(i);
62.223 + return this;
62.224 + }
62.225 +
62.226 + public StringBuilder append(long lng) {
62.227 + super.append(lng);
62.228 + return this;
62.229 + }
62.230 +
62.231 + public StringBuilder append(float f) {
62.232 + super.append(f);
62.233 + return this;
62.234 + }
62.235 +
62.236 + public StringBuilder append(double d) {
62.237 + super.append(d);
62.238 + return this;
62.239 + }
62.240 +
62.241 + /**
62.242 + * @since 1.5
62.243 + */
62.244 + public StringBuilder appendCodePoint(int codePoint) {
62.245 + super.appendCodePoint(codePoint);
62.246 + return this;
62.247 + }
62.248 +
62.249 + /**
62.250 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.251 + */
62.252 + public StringBuilder delete(int start, int end) {
62.253 + super.delete(start, end);
62.254 + return this;
62.255 + }
62.256 +
62.257 + /**
62.258 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.259 + */
62.260 + public StringBuilder deleteCharAt(int index) {
62.261 + super.deleteCharAt(index);
62.262 + return this;
62.263 + }
62.264 +
62.265 + /**
62.266 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.267 + */
62.268 + public StringBuilder replace(int start, int end, String str) {
62.269 + super.replace(start, end, str);
62.270 + return this;
62.271 + }
62.272 +
62.273 + /**
62.274 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.275 + */
62.276 + public StringBuilder insert(int index, char[] str, int offset,
62.277 + int len)
62.278 + {
62.279 + super.insert(index, str, offset, len);
62.280 + return this;
62.281 + }
62.282 +
62.283 + /**
62.284 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.285 + */
62.286 + public StringBuilder insert(int offset, Object obj) {
62.287 + return insert(offset, String.valueOf(obj));
62.288 + }
62.289 +
62.290 + /**
62.291 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.292 + */
62.293 + public StringBuilder insert(int offset, String str) {
62.294 + super.insert(offset, str);
62.295 + return this;
62.296 + }
62.297 +
62.298 + /**
62.299 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.300 + */
62.301 + public StringBuilder insert(int offset, char[] str) {
62.302 + super.insert(offset, str);
62.303 + return this;
62.304 + }
62.305 +
62.306 + /**
62.307 + * @throws IndexOutOfBoundsException {@inheritDoc}
62.308 + */
62.309 + public StringBuilder insert(int dstOffset, CharSequence s) {
62.310 + if (s == null)
62.311 + s = "null";
62.312 + if (s instanceof String)
62.313 + return this.insert(dstOffset, (String)s);
62.314 + return this.insert(dstOffset, s, 0, s.length());
62.315 + }
62.316 +
62.317 + /**
62.318 + * @throws IndexOutOfBoundsException {@inheritDoc}
62.319 + */
62.320 + public StringBuilder insert(int dstOffset, CharSequence s,
62.321 + int start, int end)
62.322 + {
62.323 + super.insert(dstOffset, s, start, end);
62.324 + return this;
62.325 + }
62.326 +
62.327 + /**
62.328 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.329 + */
62.330 + public StringBuilder insert(int offset, boolean b) {
62.331 + super.insert(offset, b);
62.332 + return this;
62.333 + }
62.334 +
62.335 + /**
62.336 + * @throws IndexOutOfBoundsException {@inheritDoc}
62.337 + */
62.338 + public StringBuilder insert(int offset, char c) {
62.339 + super.insert(offset, c);
62.340 + return this;
62.341 + }
62.342 +
62.343 + /**
62.344 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.345 + */
62.346 + public StringBuilder insert(int offset, int i) {
62.347 + return insert(offset, String.valueOf(i));
62.348 + }
62.349 +
62.350 + /**
62.351 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.352 + */
62.353 + public StringBuilder insert(int offset, long l) {
62.354 + return insert(offset, String.valueOf(l));
62.355 + }
62.356 +
62.357 + /**
62.358 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.359 + */
62.360 + public StringBuilder insert(int offset, float f) {
62.361 + return insert(offset, String.valueOf(f));
62.362 + }
62.363 +
62.364 + /**
62.365 + * @throws StringIndexOutOfBoundsException {@inheritDoc}
62.366 + */
62.367 + public StringBuilder insert(int offset, double d) {
62.368 + return insert(offset, String.valueOf(d));
62.369 + }
62.370 +
62.371 + /**
62.372 + * @throws NullPointerException {@inheritDoc}
62.373 + */
62.374 + public int indexOf(String str) {
62.375 + return indexOf(str, 0);
62.376 + }
62.377 +
62.378 + /**
62.379 + * @throws NullPointerException {@inheritDoc}
62.380 + */
62.381 + public int indexOf(String str, int fromIndex) {
62.382 + return super.indexOf(str, fromIndex);
62.383 + }
62.384 +
62.385 + /**
62.386 + * @throws NullPointerException {@inheritDoc}
62.387 + */
62.388 + public int lastIndexOf(String str) {
62.389 + return lastIndexOf(str, count);
62.390 + }
62.391 +
62.392 + /**
62.393 + * @throws NullPointerException {@inheritDoc}
62.394 + */
62.395 + public int lastIndexOf(String str, int fromIndex) {
62.396 + return String.lastIndexOf(value, 0, count,
62.397 + str.toCharArray(), 0, str.length(), fromIndex);
62.398 + }
62.399 +
62.400 + public StringBuilder reverse() {
62.401 + super.reverse();
62.402 + return this;
62.403 + }
62.404 +
62.405 + public String toString() {
62.406 + // Create a copy, don't share the array
62.407 + return new String(value, 0, count);
62.408 + }
62.409 +
62.410 + /**
62.411 + * Save the state of the <tt>StringBuilder</tt> instance to a stream
62.412 + * (that is, serialize it).
62.413 + *
62.414 + * @serialData the number of characters currently stored in the string
62.415 + * builder (<tt>int</tt>), followed by the characters in the
62.416 + * string builder (<tt>char[]</tt>). The length of the
62.417 + * <tt>char</tt> array may be greater than the number of
62.418 + * characters currently stored in the string builder, in which
62.419 + * case extra characters are ignored.
62.420 + */
62.421 +// private void writeObject(java.io.ObjectOutputStream s)
62.422 +// throws java.io.IOException {
62.423 +// s.defaultWriteObject();
62.424 +// s.writeInt(count);
62.425 +// s.writeObject(value);
62.426 +// }
62.427 +
62.428 + /**
62.429 + * readObject is called to restore the state of the StringBuffer from
62.430 + * a stream.
62.431 + */
62.432 +// private void readObject(java.io.ObjectInputStream s)
62.433 +// throws java.io.IOException, ClassNotFoundException {
62.434 +// s.defaultReadObject();
62.435 +// count = s.readInt();
62.436 +// value = (char[]) s.readObject();
62.437 +// }
62.438 +
62.439 +}
63.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
63.2 +++ b/emul/mini/src/main/java/java/lang/StringIndexOutOfBoundsException.java Wed Jan 23 20:39:23 2013 +0100
63.3 @@ -0,0 +1,71 @@
63.4 +/*
63.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
63.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
63.7 + *
63.8 + * This code is free software; you can redistribute it and/or modify it
63.9 + * under the terms of the GNU General Public License version 2 only, as
63.10 + * published by the Free Software Foundation. Oracle designates this
63.11 + * particular file as subject to the "Classpath" exception as provided
63.12 + * by Oracle in the LICENSE file that accompanied this code.
63.13 + *
63.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
63.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63.17 + * version 2 for more details (a copy is included in the LICENSE file that
63.18 + * accompanied this code).
63.19 + *
63.20 + * You should have received a copy of the GNU General Public License version
63.21 + * 2 along with this work; if not, write to the Free Software Foundation,
63.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
63.23 + *
63.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
63.25 + * or visit www.oracle.com if you need additional information or have any
63.26 + * questions.
63.27 + */
63.28 +
63.29 +package java.lang;
63.30 +
63.31 +/**
63.32 + * Thrown by <code>String</code> methods to indicate that an index
63.33 + * is either negative or greater than the size of the string. For
63.34 + * some methods such as the charAt method, this exception also is
63.35 + * thrown when the index is equal to the size of the string.
63.36 + *
63.37 + * @author unascribed
63.38 + * @see java.lang.String#charAt(int)
63.39 + * @since JDK1.0
63.40 + */
63.41 +public
63.42 +class StringIndexOutOfBoundsException extends IndexOutOfBoundsException {
63.43 + private static final long serialVersionUID = -6762910422159637258L;
63.44 +
63.45 + /**
63.46 + * Constructs a <code>StringIndexOutOfBoundsException</code> with no
63.47 + * detail message.
63.48 + *
63.49 + * @since JDK1.0.
63.50 + */
63.51 + public StringIndexOutOfBoundsException() {
63.52 + super();
63.53 + }
63.54 +
63.55 + /**
63.56 + * Constructs a <code>StringIndexOutOfBoundsException</code> with
63.57 + * the specified detail message.
63.58 + *
63.59 + * @param s the detail message.
63.60 + */
63.61 + public StringIndexOutOfBoundsException(String s) {
63.62 + super(s);
63.63 + }
63.64 +
63.65 + /**
63.66 + * Constructs a new <code>StringIndexOutOfBoundsException</code>
63.67 + * class with an argument indicating the illegal index.
63.68 + *
63.69 + * @param index the illegal index.
63.70 + */
63.71 + public StringIndexOutOfBoundsException(int index) {
63.72 + super("String index out of range: " + index);
63.73 + }
63.74 +}
64.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
64.2 +++ b/emul/mini/src/main/java/java/lang/Throwable.java Wed Jan 23 20:39:23 2013 +0100
64.3 @@ -0,0 +1,1088 @@
64.4 +/*
64.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
64.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
64.7 + *
64.8 + * This code is free software; you can redistribute it and/or modify it
64.9 + * under the terms of the GNU General Public License version 2 only, as
64.10 + * published by the Free Software Foundation. Oracle designates this
64.11 + * particular file as subject to the "Classpath" exception as provided
64.12 + * by Oracle in the LICENSE file that accompanied this code.
64.13 + *
64.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
64.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
64.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
64.17 + * version 2 for more details (a copy is included in the LICENSE file that
64.18 + * accompanied this code).
64.19 + *
64.20 + * You should have received a copy of the GNU General Public License version
64.21 + * 2 along with this work; if not, write to the Free Software Foundation,
64.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
64.23 + *
64.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
64.25 + * or visit www.oracle.com if you need additional information or have any
64.26 + * questions.
64.27 + */
64.28 +
64.29 +package java.lang;
64.30 +import java.io.*;
64.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
64.32 +import org.apidesign.bck2brwsr.core.JavaScriptOnly;
64.33 +
64.34 +/**
64.35 + * The {@code Throwable} class is the superclass of all errors and
64.36 + * exceptions in the Java language. Only objects that are instances of this
64.37 + * class (or one of its subclasses) are thrown by the Java Virtual Machine or
64.38 + * can be thrown by the Java {@code throw} statement. Similarly, only
64.39 + * this class or one of its subclasses can be the argument type in a
64.40 + * {@code catch} clause.
64.41 + *
64.42 + * For the purposes of compile-time checking of exceptions, {@code
64.43 + * Throwable} and any subclass of {@code Throwable} that is not also a
64.44 + * subclass of either {@link RuntimeException} or {@link Error} are
64.45 + * regarded as checked exceptions.
64.46 + *
64.47 + * <p>Instances of two subclasses, {@link java.lang.Error} and
64.48 + * {@link java.lang.Exception}, are conventionally used to indicate
64.49 + * that exceptional situations have occurred. Typically, these instances
64.50 + * are freshly created in the context of the exceptional situation so
64.51 + * as to include relevant information (such as stack trace data).
64.52 + *
64.53 + * <p>A throwable contains a snapshot of the execution stack of its
64.54 + * thread at the time it was created. It can also contain a message
64.55 + * string that gives more information about the error. Over time, a
64.56 + * throwable can {@linkplain Throwable#addSuppressed suppress} other
64.57 + * throwables from being propagated. Finally, the throwable can also
64.58 + * contain a <i>cause</i>: another throwable that caused this
64.59 + * throwable to be constructed. The recording of this causal information
64.60 + * is referred to as the <i>chained exception</i> facility, as the
64.61 + * cause can, itself, have a cause, and so on, leading to a "chain" of
64.62 + * exceptions, each caused by another.
64.63 + *
64.64 + * <p>One reason that a throwable may have a cause is that the class that
64.65 + * throws it is built atop a lower layered abstraction, and an operation on
64.66 + * the upper layer fails due to a failure in the lower layer. It would be bad
64.67 + * design to let the throwable thrown by the lower layer propagate outward, as
64.68 + * it is generally unrelated to the abstraction provided by the upper layer.
64.69 + * Further, doing so would tie the API of the upper layer to the details of
64.70 + * its implementation, assuming the lower layer's exception was a checked
64.71 + * exception. Throwing a "wrapped exception" (i.e., an exception containing a
64.72 + * cause) allows the upper layer to communicate the details of the failure to
64.73 + * its caller without incurring either of these shortcomings. It preserves
64.74 + * the flexibility to change the implementation of the upper layer without
64.75 + * changing its API (in particular, the set of exceptions thrown by its
64.76 + * methods).
64.77 + *
64.78 + * <p>A second reason that a throwable may have a cause is that the method
64.79 + * that throws it must conform to a general-purpose interface that does not
64.80 + * permit the method to throw the cause directly. For example, suppose
64.81 + * a persistent collection conforms to the {@link java.util.Collection
64.82 + * Collection} interface, and that its persistence is implemented atop
64.83 + * {@code java.io}. Suppose the internals of the {@code add} method
64.84 + * can throw an {@link java.io.IOException IOException}. The implementation
64.85 + * can communicate the details of the {@code IOException} to its caller
64.86 + * while conforming to the {@code Collection} interface by wrapping the
64.87 + * {@code IOException} in an appropriate unchecked exception. (The
64.88 + * specification for the persistent collection should indicate that it is
64.89 + * capable of throwing such exceptions.)
64.90 + *
64.91 + * <p>A cause can be associated with a throwable in two ways: via a
64.92 + * constructor that takes the cause as an argument, or via the
64.93 + * {@link #initCause(Throwable)} method. New throwable classes that
64.94 + * wish to allow causes to be associated with them should provide constructors
64.95 + * that take a cause and delegate (perhaps indirectly) to one of the
64.96 + * {@code Throwable} constructors that takes a cause.
64.97 + *
64.98 + * Because the {@code initCause} method is public, it allows a cause to be
64.99 + * associated with any throwable, even a "legacy throwable" whose
64.100 + * implementation predates the addition of the exception chaining mechanism to
64.101 + * {@code Throwable}.
64.102 + *
64.103 + * <p>By convention, class {@code Throwable} and its subclasses have two
64.104 + * constructors, one that takes no arguments and one that takes a
64.105 + * {@code String} argument that can be used to produce a detail message.
64.106 + * Further, those subclasses that might likely have a cause associated with
64.107 + * them should have two more constructors, one that takes a
64.108 + * {@code Throwable} (the cause), and one that takes a
64.109 + * {@code String} (the detail message) and a {@code Throwable} (the
64.110 + * cause).
64.111 + *
64.112 + * @author unascribed
64.113 + * @author Josh Bloch (Added exception chaining and programmatic access to
64.114 + * stack trace in 1.4.)
64.115 + * @jls 11.2 Compile-Time Checking of Exceptions
64.116 + * @since JDK1.0
64.117 + */
64.118 +public class Throwable implements Serializable {
64.119 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
64.120 + private static final long serialVersionUID = -3042686055658047285L;
64.121 +
64.122 + /**
64.123 + * Native code saves some indication of the stack backtrace in this slot.
64.124 + */
64.125 + private transient Object backtrace;
64.126 +
64.127 + /**
64.128 + * Specific details about the Throwable. For example, for
64.129 + * {@code FileNotFoundException}, this contains the name of
64.130 + * the file that could not be found.
64.131 + *
64.132 + * @serial
64.133 + */
64.134 + private String detailMessage;
64.135 +
64.136 +
64.137 + /**
64.138 + * Holder class to defer initializing sentinel objects only used
64.139 + * for serialization.
64.140 + */
64.141 + private static class SentinelHolder {
64.142 + /**
64.143 + * {@linkplain #setStackTrace(StackTraceElement[]) Setting the
64.144 + * stack trace} to a one-element array containing this sentinel
64.145 + * value indicates future attempts to set the stack trace will be
64.146 + * ignored. The sentinal is equal to the result of calling:<br>
64.147 + * {@code new StackTraceElement("", "", null, Integer.MIN_VALUE)}
64.148 + */
64.149 + public static final StackTraceElement STACK_TRACE_ELEMENT_SENTINEL =
64.150 + new StackTraceElement("", "", null, Integer.MIN_VALUE);
64.151 +
64.152 + /**
64.153 + * Sentinel value used in the serial form to indicate an immutable
64.154 + * stack trace.
64.155 + */
64.156 + public static final StackTraceElement[] STACK_TRACE_SENTINEL =
64.157 + new StackTraceElement[] {STACK_TRACE_ELEMENT_SENTINEL};
64.158 + }
64.159 +
64.160 + /**
64.161 + * A shared value for an empty stack.
64.162 + */
64.163 + private static final StackTraceElement[] UNASSIGNED_STACK = new StackTraceElement[0];
64.164 +
64.165 + /*
64.166 + * To allow Throwable objects to be made immutable and safely
64.167 + * reused by the JVM, such as OutOfMemoryErrors, fields of
64.168 + * Throwable that are writable in response to user actions, cause,
64.169 + * stackTrace, and suppressedExceptions obey the following
64.170 + * protocol:
64.171 + *
64.172 + * 1) The fields are initialized to a non-null sentinel value
64.173 + * which indicates the value has logically not been set.
64.174 + *
64.175 + * 2) Writing a null to the field indicates further writes
64.176 + * are forbidden
64.177 + *
64.178 + * 3) The sentinel value may be replaced with another non-null
64.179 + * value.
64.180 + *
64.181 + * For example, implementations of the HotSpot JVM have
64.182 + * preallocated OutOfMemoryError objects to provide for better
64.183 + * diagnosability of that situation. These objects are created
64.184 + * without calling the constructor for that class and the fields
64.185 + * in question are initialized to null. To support this
64.186 + * capability, any new fields added to Throwable that require
64.187 + * being initialized to a non-null value require a coordinated JVM
64.188 + * change.
64.189 + */
64.190 +
64.191 + /**
64.192 + * The throwable that caused this throwable to get thrown, or null if this
64.193 + * throwable was not caused by another throwable, or if the causative
64.194 + * throwable is unknown. If this field is equal to this throwable itself,
64.195 + * it indicates that the cause of this throwable has not yet been
64.196 + * initialized.
64.197 + *
64.198 + * @serial
64.199 + * @since 1.4
64.200 + */
64.201 + private Throwable cause = this;
64.202 +
64.203 + /**
64.204 + * The stack trace, as returned by {@link #getStackTrace()}.
64.205 + *
64.206 + * The field is initialized to a zero-length array. A {@code
64.207 + * null} value of this field indicates subsequent calls to {@link
64.208 + * #setStackTrace(StackTraceElement[])} and {@link
64.209 + * #fillInStackTrace()} will be be no-ops.
64.210 + *
64.211 + * @serial
64.212 + * @since 1.4
64.213 + */
64.214 + private StackTraceElement[] stackTrace = UNASSIGNED_STACK;
64.215 +
64.216 + // Setting this static field introduces an acceptable
64.217 + // initialization dependency on a few java.util classes.
64.218 +// I don't think this dependency is acceptable
64.219 +// private static final List<Throwable> SUPPRESSED_SENTINEL =
64.220 +// Collections.unmodifiableList(new ArrayList<Throwable>(0));
64.221 +
64.222 + /**
64.223 + * The list of suppressed exceptions, as returned by {@link
64.224 + * #getSuppressed()}. The list is initialized to a zero-element
64.225 + * unmodifiable sentinel list. When a serialized Throwable is
64.226 + * read in, if the {@code suppressedExceptions} field points to a
64.227 + * zero-element list, the field is reset to the sentinel value.
64.228 + *
64.229 + * @serial
64.230 + * @since 1.7
64.231 + */
64.232 +// private List<Throwable> suppressedExceptions = SUPPRESSED_SENTINEL;
64.233 +
64.234 + /** Message for trying to suppress a null exception. */
64.235 + private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception.";
64.236 +
64.237 + /** Message for trying to suppress oneself. */
64.238 + private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted";
64.239 +
64.240 + /** Caption for labeling causative exception stack traces */
64.241 + @JavaScriptOnly(name="toString", value="function() { return this.toString__Ljava_lang_String_2().toString(); }")
64.242 + private static void jsToString() {
64.243 + }
64.244 +
64.245 + @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
64.246 + private static void jsValudOf() {
64.247 + }
64.248 + private static final String CAUSE_CAPTION = "Caused by: ";
64.249 +
64.250 + /** Caption for labeling suppressed exception stack traces */
64.251 + private static final String SUPPRESSED_CAPTION = "Suppressed: ";
64.252 +
64.253 + /**
64.254 + * Constructs a new throwable with {@code null} as its detail message.
64.255 + * The cause is not initialized, and may subsequently be initialized by a
64.256 + * call to {@link #initCause}.
64.257 + *
64.258 + * <p>The {@link #fillInStackTrace()} method is called to initialize
64.259 + * the stack trace data in the newly created throwable.
64.260 + */
64.261 + public Throwable() {
64.262 + fillInStackTrace();
64.263 + }
64.264 +
64.265 + /**
64.266 + * Constructs a new throwable with the specified detail message. The
64.267 + * cause is not initialized, and may subsequently be initialized by
64.268 + * a call to {@link #initCause}.
64.269 + *
64.270 + * <p>The {@link #fillInStackTrace()} method is called to initialize
64.271 + * the stack trace data in the newly created throwable.
64.272 + *
64.273 + * @param message the detail message. The detail message is saved for
64.274 + * later retrieval by the {@link #getMessage()} method.
64.275 + */
64.276 + public Throwable(String message) {
64.277 + fillInStackTrace();
64.278 + detailMessage = message;
64.279 + }
64.280 +
64.281 + /**
64.282 + * Constructs a new throwable with the specified detail message and
64.283 + * cause. <p>Note that the detail message associated with
64.284 + * {@code cause} is <i>not</i> automatically incorporated in
64.285 + * this throwable's detail message.
64.286 + *
64.287 + * <p>The {@link #fillInStackTrace()} method is called to initialize
64.288 + * the stack trace data in the newly created throwable.
64.289 + *
64.290 + * @param message the detail message (which is saved for later retrieval
64.291 + * by the {@link #getMessage()} method).
64.292 + * @param cause the cause (which is saved for later retrieval by the
64.293 + * {@link #getCause()} method). (A {@code null} value is
64.294 + * permitted, and indicates that the cause is nonexistent or
64.295 + * unknown.)
64.296 + * @since 1.4
64.297 + */
64.298 + public Throwable(String message, Throwable cause) {
64.299 + fillInStackTrace();
64.300 + detailMessage = message;
64.301 + this.cause = cause;
64.302 + }
64.303 +
64.304 + /**
64.305 + * Constructs a new throwable with the specified cause and a detail
64.306 + * message of {@code (cause==null ? null : cause.toString())} (which
64.307 + * typically contains the class and detail message of {@code cause}).
64.308 + * This constructor is useful for throwables that are little more than
64.309 + * wrappers for other throwables (for example, {@link
64.310 + * java.security.PrivilegedActionException}).
64.311 + *
64.312 + * <p>The {@link #fillInStackTrace()} method is called to initialize
64.313 + * the stack trace data in the newly created throwable.
64.314 + *
64.315 + * @param cause the cause (which is saved for later retrieval by the
64.316 + * {@link #getCause()} method). (A {@code null} value is
64.317 + * permitted, and indicates that the cause is nonexistent or
64.318 + * unknown.)
64.319 + * @since 1.4
64.320 + */
64.321 + public Throwable(Throwable cause) {
64.322 + fillInStackTrace();
64.323 + detailMessage = (cause==null ? null : cause.toString());
64.324 + this.cause = cause;
64.325 + }
64.326 +
64.327 + /**
64.328 + * Constructs a new throwable with the specified detail message,
64.329 + * cause, {@linkplain #addSuppressed suppression} enabled or
64.330 + * disabled, and writable stack trace enabled or disabled. If
64.331 + * suppression is disabled, {@link #getSuppressed} for this object
64.332 + * will return a zero-length array and calls to {@link
64.333 + * #addSuppressed} that would otherwise append an exception to the
64.334 + * suppressed list will have no effect. If the writable stack
64.335 + * trace is false, this constructor will not call {@link
64.336 + * #fillInStackTrace()}, a {@code null} will be written to the
64.337 + * {@code stackTrace} field, and subsequent calls to {@code
64.338 + * fillInStackTrace} and {@link
64.339 + * #setStackTrace(StackTraceElement[])} will not set the stack
64.340 + * trace. If the writable stack trace is false, {@link
64.341 + * #getStackTrace} will return a zero length array.
64.342 + *
64.343 + * <p>Note that the other constructors of {@code Throwable} treat
64.344 + * suppression as being enabled and the stack trace as being
64.345 + * writable. Subclasses of {@code Throwable} should document any
64.346 + * conditions under which suppression is disabled and document
64.347 + * conditions under which the stack trace is not writable.
64.348 + * Disabling of suppression should only occur in exceptional
64.349 + * circumstances where special requirements exist, such as a
64.350 + * virtual machine reusing exception objects under low-memory
64.351 + * situations. Circumstances where a given exception object is
64.352 + * repeatedly caught and rethrown, such as to implement control
64.353 + * flow between two sub-systems, is another situation where
64.354 + * immutable throwable objects would be appropriate.
64.355 + *
64.356 + * @param message the detail message.
64.357 + * @param cause the cause. (A {@code null} value is permitted,
64.358 + * and indicates that the cause is nonexistent or unknown.)
64.359 + * @param enableSuppression whether or not suppression is enabled or disabled
64.360 + * @param writableStackTrace whether or not the stack trace should be
64.361 + * writable
64.362 + *
64.363 + * @see OutOfMemoryError
64.364 + * @see NullPointerException
64.365 + * @see ArithmeticException
64.366 + * @since 1.7
64.367 + */
64.368 + protected Throwable(String message, Throwable cause,
64.369 + boolean enableSuppression,
64.370 + boolean writableStackTrace) {
64.371 + if (writableStackTrace) {
64.372 + fillInStackTrace();
64.373 + } else {
64.374 + stackTrace = null;
64.375 + }
64.376 + detailMessage = message;
64.377 + this.cause = cause;
64.378 +// if (!enableSuppression)
64.379 +// suppressedExceptions = null;
64.380 + }
64.381 +
64.382 + /**
64.383 + * Returns the detail message string of this throwable.
64.384 + *
64.385 + * @return the detail message string of this {@code Throwable} instance
64.386 + * (which may be {@code null}).
64.387 + */
64.388 + public String getMessage() {
64.389 + return detailMessage;
64.390 + }
64.391 +
64.392 + /**
64.393 + * Creates a localized description of this throwable.
64.394 + * Subclasses may override this method in order to produce a
64.395 + * locale-specific message. For subclasses that do not override this
64.396 + * method, the default implementation returns the same result as
64.397 + * {@code getMessage()}.
64.398 + *
64.399 + * @return The localized description of this throwable.
64.400 + * @since JDK1.1
64.401 + */
64.402 + public String getLocalizedMessage() {
64.403 + return getMessage();
64.404 + }
64.405 +
64.406 + /**
64.407 + * Returns the cause of this throwable or {@code null} if the
64.408 + * cause is nonexistent or unknown. (The cause is the throwable that
64.409 + * caused this throwable to get thrown.)
64.410 + *
64.411 + * <p>This implementation returns the cause that was supplied via one of
64.412 + * the constructors requiring a {@code Throwable}, or that was set after
64.413 + * creation with the {@link #initCause(Throwable)} method. While it is
64.414 + * typically unnecessary to override this method, a subclass can override
64.415 + * it to return a cause set by some other means. This is appropriate for
64.416 + * a "legacy chained throwable" that predates the addition of chained
64.417 + * exceptions to {@code Throwable}. Note that it is <i>not</i>
64.418 + * necessary to override any of the {@code PrintStackTrace} methods,
64.419 + * all of which invoke the {@code getCause} method to determine the
64.420 + * cause of a throwable.
64.421 + *
64.422 + * @return the cause of this throwable or {@code null} if the
64.423 + * cause is nonexistent or unknown.
64.424 + * @since 1.4
64.425 + */
64.426 + public synchronized Throwable getCause() {
64.427 + return (cause==this ? null : cause);
64.428 + }
64.429 +
64.430 + /**
64.431 + * Initializes the <i>cause</i> of this throwable to the specified value.
64.432 + * (The cause is the throwable that caused this throwable to get thrown.)
64.433 + *
64.434 + * <p>This method can be called at most once. It is generally called from
64.435 + * within the constructor, or immediately after creating the
64.436 + * throwable. If this throwable was created
64.437 + * with {@link #Throwable(Throwable)} or
64.438 + * {@link #Throwable(String,Throwable)}, this method cannot be called
64.439 + * even once.
64.440 + *
64.441 + * <p>An example of using this method on a legacy throwable type
64.442 + * without other support for setting the cause is:
64.443 + *
64.444 + * <pre>
64.445 + * try {
64.446 + * lowLevelOp();
64.447 + * } catch (LowLevelException le) {
64.448 + * throw (HighLevelException)
64.449 + * new HighLevelException().initCause(le); // Legacy constructor
64.450 + * }
64.451 + * </pre>
64.452 + *
64.453 + * @param cause the cause (which is saved for later retrieval by the
64.454 + * {@link #getCause()} method). (A {@code null} value is
64.455 + * permitted, and indicates that the cause is nonexistent or
64.456 + * unknown.)
64.457 + * @return a reference to this {@code Throwable} instance.
64.458 + * @throws IllegalArgumentException if {@code cause} is this
64.459 + * throwable. (A throwable cannot be its own cause.)
64.460 + * @throws IllegalStateException if this throwable was
64.461 + * created with {@link #Throwable(Throwable)} or
64.462 + * {@link #Throwable(String,Throwable)}, or this method has already
64.463 + * been called on this throwable.
64.464 + * @since 1.4
64.465 + */
64.466 + public synchronized Throwable initCause(Throwable cause) {
64.467 + if (this.cause != this)
64.468 + throw new IllegalStateException("Can't overwrite cause");
64.469 + if (cause == this)
64.470 + throw new IllegalArgumentException("Self-causation not permitted");
64.471 + this.cause = cause;
64.472 + return this;
64.473 + }
64.474 +
64.475 + /**
64.476 + * Returns a short description of this throwable.
64.477 + * The result is the concatenation of:
64.478 + * <ul>
64.479 + * <li> the {@linkplain Class#getName() name} of the class of this object
64.480 + * <li> ": " (a colon and a space)
64.481 + * <li> the result of invoking this object's {@link #getLocalizedMessage}
64.482 + * method
64.483 + * </ul>
64.484 + * If {@code getLocalizedMessage} returns {@code null}, then just
64.485 + * the class name is returned.
64.486 + *
64.487 + * @return a string representation of this throwable.
64.488 + */
64.489 + public String toString() {
64.490 + String s = getClass().getName();
64.491 + String message = getLocalizedMessage();
64.492 + return (message != null) ? (s + ": " + message) : s;
64.493 + }
64.494 +
64.495 + /**
64.496 + * Prints this throwable and its backtrace to the
64.497 + * standard error stream. This method prints a stack trace for this
64.498 + * {@code Throwable} object on the error output stream that is
64.499 + * the value of the field {@code System.err}. The first line of
64.500 + * output contains the result of the {@link #toString()} method for
64.501 + * this object. Remaining lines represent data previously recorded by
64.502 + * the method {@link #fillInStackTrace()}. The format of this
64.503 + * information depends on the implementation, but the following
64.504 + * example may be regarded as typical:
64.505 + * <blockquote><pre>
64.506 + * java.lang.NullPointerException
64.507 + * at MyClass.mash(MyClass.java:9)
64.508 + * at MyClass.crunch(MyClass.java:6)
64.509 + * at MyClass.main(MyClass.java:3)
64.510 + * </pre></blockquote>
64.511 + * This example was produced by running the program:
64.512 + * <pre>
64.513 + * class MyClass {
64.514 + * public static void main(String[] args) {
64.515 + * crunch(null);
64.516 + * }
64.517 + * static void crunch(int[] a) {
64.518 + * mash(a);
64.519 + * }
64.520 + * static void mash(int[] b) {
64.521 + * System.out.println(b[0]);
64.522 + * }
64.523 + * }
64.524 + * </pre>
64.525 + * The backtrace for a throwable with an initialized, non-null cause
64.526 + * should generally include the backtrace for the cause. The format
64.527 + * of this information depends on the implementation, but the following
64.528 + * example may be regarded as typical:
64.529 + * <pre>
64.530 + * HighLevelException: MidLevelException: LowLevelException
64.531 + * at Junk.a(Junk.java:13)
64.532 + * at Junk.main(Junk.java:4)
64.533 + * Caused by: MidLevelException: LowLevelException
64.534 + * at Junk.c(Junk.java:23)
64.535 + * at Junk.b(Junk.java:17)
64.536 + * at Junk.a(Junk.java:11)
64.537 + * ... 1 more
64.538 + * Caused by: LowLevelException
64.539 + * at Junk.e(Junk.java:30)
64.540 + * at Junk.d(Junk.java:27)
64.541 + * at Junk.c(Junk.java:21)
64.542 + * ... 3 more
64.543 + * </pre>
64.544 + * Note the presence of lines containing the characters {@code "..."}.
64.545 + * These lines indicate that the remainder of the stack trace for this
64.546 + * exception matches the indicated number of frames from the bottom of the
64.547 + * stack trace of the exception that was caused by this exception (the
64.548 + * "enclosing" exception). This shorthand can greatly reduce the length
64.549 + * of the output in the common case where a wrapped exception is thrown
64.550 + * from same method as the "causative exception" is caught. The above
64.551 + * example was produced by running the program:
64.552 + * <pre>
64.553 + * public class Junk {
64.554 + * public static void main(String args[]) {
64.555 + * try {
64.556 + * a();
64.557 + * } catch(HighLevelException e) {
64.558 + * e.printStackTrace();
64.559 + * }
64.560 + * }
64.561 + * static void a() throws HighLevelException {
64.562 + * try {
64.563 + * b();
64.564 + * } catch(MidLevelException e) {
64.565 + * throw new HighLevelException(e);
64.566 + * }
64.567 + * }
64.568 + * static void b() throws MidLevelException {
64.569 + * c();
64.570 + * }
64.571 + * static void c() throws MidLevelException {
64.572 + * try {
64.573 + * d();
64.574 + * } catch(LowLevelException e) {
64.575 + * throw new MidLevelException(e);
64.576 + * }
64.577 + * }
64.578 + * static void d() throws LowLevelException {
64.579 + * e();
64.580 + * }
64.581 + * static void e() throws LowLevelException {
64.582 + * throw new LowLevelException();
64.583 + * }
64.584 + * }
64.585 + *
64.586 + * class HighLevelException extends Exception {
64.587 + * HighLevelException(Throwable cause) { super(cause); }
64.588 + * }
64.589 + *
64.590 + * class MidLevelException extends Exception {
64.591 + * MidLevelException(Throwable cause) { super(cause); }
64.592 + * }
64.593 + *
64.594 + * class LowLevelException extends Exception {
64.595 + * }
64.596 + * </pre>
64.597 + * As of release 7, the platform supports the notion of
64.598 + * <i>suppressed exceptions</i> (in conjunction with the {@code
64.599 + * try}-with-resources statement). Any exceptions that were
64.600 + * suppressed in order to deliver an exception are printed out
64.601 + * beneath the stack trace. The format of this information
64.602 + * depends on the implementation, but the following example may be
64.603 + * regarded as typical:
64.604 + *
64.605 + * <pre>
64.606 + * Exception in thread "main" java.lang.Exception: Something happened
64.607 + * at Foo.bar(Foo.java:10)
64.608 + * at Foo.main(Foo.java:5)
64.609 + * Suppressed: Resource$CloseFailException: Resource ID = 0
64.610 + * at Resource.close(Resource.java:26)
64.611 + * at Foo.bar(Foo.java:9)
64.612 + * ... 1 more
64.613 + * </pre>
64.614 + * Note that the "... n more" notation is used on suppressed exceptions
64.615 + * just at it is used on causes. Unlike causes, suppressed exceptions are
64.616 + * indented beyond their "containing exceptions."
64.617 + *
64.618 + * <p>An exception can have both a cause and one or more suppressed
64.619 + * exceptions:
64.620 + * <pre>
64.621 + * Exception in thread "main" java.lang.Exception: Main block
64.622 + * at Foo3.main(Foo3.java:7)
64.623 + * Suppressed: Resource$CloseFailException: Resource ID = 2
64.624 + * at Resource.close(Resource.java:26)
64.625 + * at Foo3.main(Foo3.java:5)
64.626 + * Suppressed: Resource$CloseFailException: Resource ID = 1
64.627 + * at Resource.close(Resource.java:26)
64.628 + * at Foo3.main(Foo3.java:5)
64.629 + * Caused by: java.lang.Exception: I did it
64.630 + * at Foo3.main(Foo3.java:8)
64.631 + * </pre>
64.632 + * Likewise, a suppressed exception can have a cause:
64.633 + * <pre>
64.634 + * Exception in thread "main" java.lang.Exception: Main block
64.635 + * at Foo4.main(Foo4.java:6)
64.636 + * Suppressed: Resource2$CloseFailException: Resource ID = 1
64.637 + * at Resource2.close(Resource2.java:20)
64.638 + * at Foo4.main(Foo4.java:5)
64.639 + * Caused by: java.lang.Exception: Rats, you caught me
64.640 + * at Resource2$CloseFailException.<init>(Resource2.java:45)
64.641 + * ... 2 more
64.642 + * </pre>
64.643 + */
64.644 +// public void printStackTrace() {
64.645 +// printStackTrace(System.err);
64.646 +// }
64.647 +//
64.648 +// /**
64.649 +// * Prints this throwable and its backtrace to the specified print stream.
64.650 +// *
64.651 +// * @param s {@code PrintStream} to use for output
64.652 +// */
64.653 +// public void printStackTrace(PrintStream s) {
64.654 +// printStackTrace(new WrappedPrintStream(s));
64.655 +// }
64.656 +//
64.657 +// private void printStackTrace(PrintStreamOrWriter s) {
64.658 +// // Guard against malicious overrides of Throwable.equals by
64.659 +// // using a Set with identity equality semantics.
64.660 +//// Set<Throwable> dejaVu =
64.661 +//// Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
64.662 +//// dejaVu.add(this);
64.663 +//
64.664 +// synchronized (s.lock()) {
64.665 +// // Print our stack trace
64.666 +// s.println(this);
64.667 +// StackTraceElement[] trace = getOurStackTrace();
64.668 +// for (StackTraceElement traceElement : trace)
64.669 +// s.println("\tat " + traceElement);
64.670 +//
64.671 +// // Print suppressed exceptions, if any
64.672 +//// for (Throwable se : getSuppressed())
64.673 +//// se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
64.674 +//
64.675 +// // Print cause, if any
64.676 +// Throwable ourCause = getCause();
64.677 +//// if (ourCause != null)
64.678 +//// ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
64.679 +// }
64.680 +// }
64.681 +//
64.682 +// /**
64.683 +// * Print our stack trace as an enclosed exception for the specified
64.684 +// * stack trace.
64.685 +// */
64.686 +// private void printEnclosedStackTrace(PrintStreamOrWriter s,
64.687 +// StackTraceElement[] enclosingTrace,
64.688 +// String caption,
64.689 +// String prefix,
64.690 +// Object dejaVu) {
64.691 +// assert Thread.holdsLock(s.lock());
64.692 +// {
64.693 +// // Compute number of frames in common between this and enclosing trace
64.694 +// StackTraceElement[] trace = getOurStackTrace();
64.695 +// int m = trace.length - 1;
64.696 +// int n = enclosingTrace.length - 1;
64.697 +// while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
64.698 +// m--; n--;
64.699 +// }
64.700 +// int framesInCommon = trace.length - 1 - m;
64.701 +//
64.702 +// // Print our stack trace
64.703 +// s.println(prefix + caption + this);
64.704 +// for (int i = 0; i <= m; i++)
64.705 +// s.println(prefix + "\tat " + trace[i]);
64.706 +// if (framesInCommon != 0)
64.707 +// s.println(prefix + "\t... " + framesInCommon + " more");
64.708 +//
64.709 +// // Print suppressed exceptions, if any
64.710 +// for (Throwable se : getSuppressed())
64.711 +// se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION,
64.712 +// prefix +"\t", dejaVu);
64.713 +//
64.714 +// // Print cause, if any
64.715 +// Throwable ourCause = getCause();
64.716 +// if (ourCause != null)
64.717 +// ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, prefix, dejaVu);
64.718 +// }
64.719 +// }
64.720 +//
64.721 +// /**
64.722 +// * Prints this throwable and its backtrace to the specified
64.723 +// * print writer.
64.724 +// *
64.725 +// * @param s {@code PrintWriter} to use for output
64.726 +// * @since JDK1.1
64.727 +// */
64.728 +// public void printStackTrace(PrintWriter s) {
64.729 +// printStackTrace(new WrappedPrintWriter(s));
64.730 +// }
64.731 +//
64.732 +// /**
64.733 +// * Wrapper class for PrintStream and PrintWriter to enable a single
64.734 +// * implementation of printStackTrace.
64.735 +// */
64.736 +// private abstract static class PrintStreamOrWriter {
64.737 +// /** Returns the object to be locked when using this StreamOrWriter */
64.738 +// abstract Object lock();
64.739 +//
64.740 +// /** Prints the specified string as a line on this StreamOrWriter */
64.741 +// abstract void println(Object o);
64.742 +// }
64.743 +//
64.744 +// private static class WrappedPrintStream extends PrintStreamOrWriter {
64.745 +// private final PrintStream printStream;
64.746 +//
64.747 +// WrappedPrintStream(PrintStream printStream) {
64.748 +// this.printStream = printStream;
64.749 +// }
64.750 +//
64.751 +// Object lock() {
64.752 +// return printStream;
64.753 +// }
64.754 +//
64.755 +// void println(Object o) {
64.756 +// printStream.println(o);
64.757 +// }
64.758 +// }
64.759 +//
64.760 +// private static class WrappedPrintWriter extends PrintStreamOrWriter {
64.761 +// private final PrintWriter printWriter;
64.762 +//
64.763 +// WrappedPrintWriter(PrintWriter printWriter) {
64.764 +// this.printWriter = printWriter;
64.765 +// }
64.766 +//
64.767 +// Object lock() {
64.768 +// return printWriter;
64.769 +// }
64.770 +//
64.771 +// void println(Object o) {
64.772 +// printWriter.println(o);
64.773 +// }
64.774 +// }
64.775 +
64.776 + /**
64.777 + * Fills in the execution stack trace. This method records within this
64.778 + * {@code Throwable} object information about the current state of
64.779 + * the stack frames for the current thread.
64.780 + *
64.781 + * <p>If the stack trace of this {@code Throwable} {@linkplain
64.782 + * Throwable#Throwable(String, Throwable, boolean, boolean) is not
64.783 + * writable}, calling this method has no effect.
64.784 + *
64.785 + * @return a reference to this {@code Throwable} instance.
64.786 + * @see java.lang.Throwable#printStackTrace()
64.787 + */
64.788 + public synchronized Throwable fillInStackTrace() {
64.789 + if (stackTrace != null ||
64.790 + backtrace != null /* Out of protocol state */ ) {
64.791 + fillInStackTrace(0);
64.792 + stackTrace = UNASSIGNED_STACK;
64.793 + }
64.794 + return this;
64.795 + }
64.796 +
64.797 + @JavaScriptBody(args = { "dummy" }, body = "")
64.798 + private native Throwable fillInStackTrace(int dummy);
64.799 +
64.800 + /**
64.801 + * Provides programmatic access to the stack trace information printed by
64.802 + * {@link #printStackTrace()}. Returns an array of stack trace elements,
64.803 + * each representing one stack frame. The zeroth element of the array
64.804 + * (assuming the array's length is non-zero) represents the top of the
64.805 + * stack, which is the last method invocation in the sequence. Typically,
64.806 + * this is the point at which this throwable was created and thrown.
64.807 + * The last element of the array (assuming the array's length is non-zero)
64.808 + * represents the bottom of the stack, which is the first method invocation
64.809 + * in the sequence.
64.810 + *
64.811 + * <p>Some virtual machines may, under some circumstances, omit one
64.812 + * or more stack frames from the stack trace. In the extreme case,
64.813 + * a virtual machine that has no stack trace information concerning
64.814 + * this throwable is permitted to return a zero-length array from this
64.815 + * method. Generally speaking, the array returned by this method will
64.816 + * contain one element for every frame that would be printed by
64.817 + * {@code printStackTrace}. Writes to the returned array do not
64.818 + * affect future calls to this method.
64.819 + *
64.820 + * @return an array of stack trace elements representing the stack trace
64.821 + * pertaining to this throwable.
64.822 + * @since 1.4
64.823 + */
64.824 + public StackTraceElement[] getStackTrace() {
64.825 + return getOurStackTrace().clone();
64.826 + }
64.827 +
64.828 + private synchronized StackTraceElement[] getOurStackTrace() {
64.829 + // Initialize stack trace field with information from
64.830 + // backtrace if this is the first call to this method
64.831 + if (stackTrace == UNASSIGNED_STACK ||
64.832 + (stackTrace == null && backtrace != null) /* Out of protocol state */) {
64.833 + int depth = getStackTraceDepth();
64.834 + stackTrace = new StackTraceElement[depth];
64.835 + for (int i=0; i < depth; i++)
64.836 + stackTrace[i] = getStackTraceElement(i);
64.837 + } else if (stackTrace == null) {
64.838 + return UNASSIGNED_STACK;
64.839 + }
64.840 + return stackTrace;
64.841 + }
64.842 +
64.843 + /**
64.844 + * Sets the stack trace elements that will be returned by
64.845 + * {@link #getStackTrace()} and printed by {@link #printStackTrace()}
64.846 + * and related methods.
64.847 + *
64.848 + * This method, which is designed for use by RPC frameworks and other
64.849 + * advanced systems, allows the client to override the default
64.850 + * stack trace that is either generated by {@link #fillInStackTrace()}
64.851 + * when a throwable is constructed or deserialized when a throwable is
64.852 + * read from a serialization stream.
64.853 + *
64.854 + * <p>If the stack trace of this {@code Throwable} {@linkplain
64.855 + * Throwable#Throwable(String, Throwable, boolean, boolean) is not
64.856 + * writable}, calling this method has no effect other than
64.857 + * validating its argument.
64.858 + *
64.859 + * @param stackTrace the stack trace elements to be associated with
64.860 + * this {@code Throwable}. The specified array is copied by this
64.861 + * call; changes in the specified array after the method invocation
64.862 + * returns will have no affect on this {@code Throwable}'s stack
64.863 + * trace.
64.864 + *
64.865 + * @throws NullPointerException if {@code stackTrace} is
64.866 + * {@code null} or if any of the elements of
64.867 + * {@code stackTrace} are {@code null}
64.868 + *
64.869 + * @since 1.4
64.870 + */
64.871 + public void setStackTrace(StackTraceElement[] stackTrace) {
64.872 + // Validate argument
64.873 + StackTraceElement[] defensiveCopy = stackTrace.clone();
64.874 + for (int i = 0; i < defensiveCopy.length; i++) {
64.875 + if (defensiveCopy[i] == null)
64.876 + throw new NullPointerException("stackTrace[" + i + "]");
64.877 + }
64.878 +
64.879 + synchronized (this) {
64.880 + if (this.stackTrace == null && // Immutable stack
64.881 + backtrace == null) // Test for out of protocol state
64.882 + return;
64.883 + this.stackTrace = defensiveCopy;
64.884 + }
64.885 + }
64.886 +
64.887 + /**
64.888 + * Returns the number of elements in the stack trace (or 0 if the stack
64.889 + * trace is unavailable).
64.890 + *
64.891 + * package-protection for use by SharedSecrets.
64.892 + */
64.893 + native int getStackTraceDepth();
64.894 +
64.895 + /**
64.896 + * Returns the specified element of the stack trace.
64.897 + *
64.898 + * package-protection for use by SharedSecrets.
64.899 + *
64.900 + * @param index index of the element to return.
64.901 + * @throws IndexOutOfBoundsException if {@code index < 0 ||
64.902 + * index >= getStackTraceDepth() }
64.903 + */
64.904 + native StackTraceElement getStackTraceElement(int index);
64.905 +
64.906 + /**
64.907 + * Reads a {@code Throwable} from a stream, enforcing
64.908 + * well-formedness constraints on fields. Null entries and
64.909 + * self-pointers are not allowed in the list of {@code
64.910 + * suppressedExceptions}. Null entries are not allowed for stack
64.911 + * trace elements. A null stack trace in the serial form results
64.912 + * in a zero-length stack element array. A single-element stack
64.913 + * trace whose entry is equal to {@code new StackTraceElement("",
64.914 + * "", null, Integer.MIN_VALUE)} results in a {@code null} {@code
64.915 + * stackTrace} field.
64.916 + *
64.917 + * Note that there are no constraints on the value the {@code
64.918 + * cause} field can hold; both {@code null} and {@code this} are
64.919 + * valid values for the field.
64.920 + */
64.921 +// private void readObject(ObjectInputStream s)
64.922 +// throws IOException, ClassNotFoundException {
64.923 +// s.defaultReadObject(); // read in all fields
64.924 +// if (suppressedExceptions != null) {
64.925 +// List<Throwable> suppressed = null;
64.926 +// if (suppressedExceptions.isEmpty()) {
64.927 +// // Use the sentinel for a zero-length list
64.928 +// suppressed = SUPPRESSED_SENTINEL;
64.929 +// } else { // Copy Throwables to new list
64.930 +// suppressed = new ArrayList<Throwable>(1);
64.931 +// for (Throwable t : suppressedExceptions) {
64.932 +// // Enforce constraints on suppressed exceptions in
64.933 +// // case of corrupt or malicious stream.
64.934 +// if (t == null)
64.935 +// throw new NullPointerException(NULL_CAUSE_MESSAGE);
64.936 +// if (t == this)
64.937 +// throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
64.938 +// suppressed.add(t);
64.939 +// }
64.940 +// }
64.941 +// suppressedExceptions = suppressed;
64.942 +// } // else a null suppressedExceptions field remains null
64.943 +//
64.944 +// /*
64.945 +// * For zero-length stack traces, use a clone of
64.946 +// * UNASSIGNED_STACK rather than UNASSIGNED_STACK itself to
64.947 +// * allow identity comparison against UNASSIGNED_STACK in
64.948 +// * getOurStackTrace. The identity of UNASSIGNED_STACK in
64.949 +// * stackTrace indicates to the getOurStackTrace method that
64.950 +// * the stackTrace needs to be constructed from the information
64.951 +// * in backtrace.
64.952 +// */
64.953 +// if (stackTrace != null) {
64.954 +// if (stackTrace.length == 0) {
64.955 +// stackTrace = UNASSIGNED_STACK.clone();
64.956 +// } else if (stackTrace.length == 1 &&
64.957 +// // Check for the marker of an immutable stack trace
64.958 +// SentinelHolder.STACK_TRACE_ELEMENT_SENTINEL.equals(stackTrace[0])) {
64.959 +// stackTrace = null;
64.960 +// } else { // Verify stack trace elements are non-null.
64.961 +// for(StackTraceElement ste : stackTrace) {
64.962 +// if (ste == null)
64.963 +// throw new NullPointerException("null StackTraceElement in serial stream. ");
64.964 +// }
64.965 +// }
64.966 +// } else {
64.967 +// // A null stackTrace field in the serial form can result
64.968 +// // from an exception serialized without that field in
64.969 +// // older JDK releases; treat such exceptions as having
64.970 +// // empty stack traces.
64.971 +// stackTrace = UNASSIGNED_STACK.clone();
64.972 +// }
64.973 +// }
64.974 +
64.975 + /**
64.976 + * Write a {@code Throwable} object to a stream.
64.977 + *
64.978 + * A {@code null} stack trace field is represented in the serial
64.979 + * form as a one-element array whose element is equal to {@code
64.980 + * new StackTraceElement("", "", null, Integer.MIN_VALUE)}.
64.981 + */
64.982 +// private synchronized void writeObject(ObjectOutputStream s)
64.983 +// throws IOException {
64.984 +// // Ensure that the stackTrace field is initialized to a
64.985 +// // non-null value, if appropriate. As of JDK 7, a null stack
64.986 +// // trace field is a valid value indicating the stack trace
64.987 +// // should not be set.
64.988 +// getOurStackTrace();
64.989 +//
64.990 +// StackTraceElement[] oldStackTrace = stackTrace;
64.991 +// try {
64.992 +// if (stackTrace == null)
64.993 +// stackTrace = SentinelHolder.STACK_TRACE_SENTINEL;
64.994 +// s.defaultWriteObject();
64.995 +// } finally {
64.996 +// stackTrace = oldStackTrace;
64.997 +// }
64.998 +// }
64.999 +
64.1000 + /**
64.1001 + * Appends the specified exception to the exceptions that were
64.1002 + * suppressed in order to deliver this exception. This method is
64.1003 + * thread-safe and typically called (automatically and implicitly)
64.1004 + * by the {@code try}-with-resources statement.
64.1005 + *
64.1006 + * <p>The suppression behavior is enabled <em>unless</em> disabled
64.1007 + * {@linkplain #Throwable(String, Throwable, boolean, boolean) via
64.1008 + * a constructor}. When suppression is disabled, this method does
64.1009 + * nothing other than to validate its argument.
64.1010 + *
64.1011 + * <p>Note that when one exception {@linkplain
64.1012 + * #initCause(Throwable) causes} another exception, the first
64.1013 + * exception is usually caught and then the second exception is
64.1014 + * thrown in response. In other words, there is a causal
64.1015 + * connection between the two exceptions.
64.1016 + *
64.1017 + * In contrast, there are situations where two independent
64.1018 + * exceptions can be thrown in sibling code blocks, in particular
64.1019 + * in the {@code try} block of a {@code try}-with-resources
64.1020 + * statement and the compiler-generated {@code finally} block
64.1021 + * which closes the resource.
64.1022 + *
64.1023 + * In these situations, only one of the thrown exceptions can be
64.1024 + * propagated. In the {@code try}-with-resources statement, when
64.1025 + * there are two such exceptions, the exception originating from
64.1026 + * the {@code try} block is propagated and the exception from the
64.1027 + * {@code finally} block is added to the list of exceptions
64.1028 + * suppressed by the exception from the {@code try} block. As an
64.1029 + * exception unwinds the stack, it can accumulate multiple
64.1030 + * suppressed exceptions.
64.1031 + *
64.1032 + * <p>An exception may have suppressed exceptions while also being
64.1033 + * caused by another exception. Whether or not an exception has a
64.1034 + * cause is semantically known at the time of its creation, unlike
64.1035 + * whether or not an exception will suppress other exceptions
64.1036 + * which is typically only determined after an exception is
64.1037 + * thrown.
64.1038 + *
64.1039 + * <p>Note that programmer written code is also able to take
64.1040 + * advantage of calling this method in situations where there are
64.1041 + * multiple sibling exceptions and only one can be propagated.
64.1042 + *
64.1043 + * @param exception the exception to be added to the list of
64.1044 + * suppressed exceptions
64.1045 + * @throws IllegalArgumentException if {@code exception} is this
64.1046 + * throwable; a throwable cannot suppress itself.
64.1047 + * @throws NullPointerException if {@code exception} is {@code null}
64.1048 + * @since 1.7
64.1049 + */
64.1050 + public final synchronized void addSuppressed(Throwable exception) {
64.1051 + if (exception == this)
64.1052 + throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
64.1053 +
64.1054 + if (exception == null)
64.1055 + throw new NullPointerException(NULL_CAUSE_MESSAGE);
64.1056 +
64.1057 +// if (suppressedExceptions == null) // Suppressed exceptions not recorded
64.1058 +// return;
64.1059 +//
64.1060 +// if (suppressedExceptions == SUPPRESSED_SENTINEL)
64.1061 +// suppressedExceptions = new ArrayList<Throwable>(1);
64.1062 +//
64.1063 +// suppressedExceptions.add(exception);
64.1064 + }
64.1065 +
64.1066 + private static final Throwable[] EMPTY_THROWABLE_ARRAY = new Throwable[0];
64.1067 +
64.1068 + /**
64.1069 + * Returns an array containing all of the exceptions that were
64.1070 + * suppressed, typically by the {@code try}-with-resources
64.1071 + * statement, in order to deliver this exception.
64.1072 + *
64.1073 + * If no exceptions were suppressed or {@linkplain
64.1074 + * #Throwable(String, Throwable, boolean, boolean) suppression is
64.1075 + * disabled}, an empty array is returned. This method is
64.1076 + * thread-safe. Writes to the returned array do not affect future
64.1077 + * calls to this method.
64.1078 + *
64.1079 + * @return an array containing all of the exceptions that were
64.1080 + * suppressed to deliver this exception.
64.1081 + * @since 1.7
64.1082 + */
64.1083 + public final synchronized Throwable[] getSuppressed() {
64.1084 + return new Throwable[0];
64.1085 +// if (suppressedExceptions == SUPPRESSED_SENTINEL ||
64.1086 +// suppressedExceptions == null)
64.1087 +// return EMPTY_THROWABLE_ARRAY;
64.1088 +// else
64.1089 +// return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY);
64.1090 + }
64.1091 +}
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
65.2 +++ b/emul/mini/src/main/java/java/lang/VirtualMachineError.java Wed Jan 23 20:39:23 2013 +0100
65.3 @@ -0,0 +1,54 @@
65.4 +/*
65.5 + * Copyright (c) 1995, 1997, Oracle and/or its affiliates. All rights reserved.
65.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65.7 + *
65.8 + * This code is free software; you can redistribute it and/or modify it
65.9 + * under the terms of the GNU General Public License version 2 only, as
65.10 + * published by the Free Software Foundation. Oracle designates this
65.11 + * particular file as subject to the "Classpath" exception as provided
65.12 + * by Oracle in the LICENSE file that accompanied this code.
65.13 + *
65.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
65.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
65.17 + * version 2 for more details (a copy is included in the LICENSE file that
65.18 + * accompanied this code).
65.19 + *
65.20 + * You should have received a copy of the GNU General Public License version
65.21 + * 2 along with this work; if not, write to the Free Software Foundation,
65.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65.23 + *
65.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65.25 + * or visit www.oracle.com if you need additional information or have any
65.26 + * questions.
65.27 + */
65.28 +
65.29 +package java.lang;
65.30 +
65.31 +/**
65.32 + * Thrown to indicate that the Java Virtual Machine is broken or has
65.33 + * run out of resources necessary for it to continue operating.
65.34 + *
65.35 + *
65.36 + * @author Frank Yellin
65.37 + * @since JDK1.0
65.38 + */
65.39 +abstract public
65.40 +class VirtualMachineError extends Error {
65.41 + /**
65.42 + * Constructs a <code>VirtualMachineError</code> with no detail message.
65.43 + */
65.44 + public VirtualMachineError() {
65.45 + super();
65.46 + }
65.47 +
65.48 + /**
65.49 + * Constructs a <code>VirtualMachineError</code> with the specified
65.50 + * detail message.
65.51 + *
65.52 + * @param s the detail message.
65.53 + */
65.54 + public VirtualMachineError(String s) {
65.55 + super(s);
65.56 + }
65.57 +}
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
66.2 +++ b/emul/mini/src/main/java/java/lang/Void.java Wed Jan 23 20:39:23 2013 +0100
66.3 @@ -0,0 +1,49 @@
66.4 +/*
66.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
66.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66.7 + *
66.8 + * This code is free software; you can redistribute it and/or modify it
66.9 + * under the terms of the GNU General Public License version 2 only, as
66.10 + * published by the Free Software Foundation. Oracle designates this
66.11 + * particular file as subject to the "Classpath" exception as provided
66.12 + * by Oracle in the LICENSE file that accompanied this code.
66.13 + *
66.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
66.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
66.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
66.17 + * version 2 for more details (a copy is included in the LICENSE file that
66.18 + * accompanied this code).
66.19 + *
66.20 + * You should have received a copy of the GNU General Public License version
66.21 + * 2 along with this work; if not, write to the Free Software Foundation,
66.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
66.23 + *
66.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
66.25 + * or visit www.oracle.com if you need additional information or have any
66.26 + * questions.
66.27 + */
66.28 +
66.29 +package java.lang;
66.30 +
66.31 +/**
66.32 + * The {@code Void} class is an uninstantiable placeholder class to hold a
66.33 + * reference to the {@code Class} object representing the Java keyword
66.34 + * void.
66.35 + *
66.36 + * @author unascribed
66.37 + * @since JDK1.1
66.38 + */
66.39 +public final
66.40 +class Void {
66.41 +
66.42 + /**
66.43 + * The {@code Class} object representing the pseudo-type corresponding to
66.44 + * the keyword {@code void}.
66.45 + */
66.46 + public static final Class<Void> TYPE = Class.getPrimitiveClass("void");
66.47 +
66.48 + /*
66.49 + * The Void class cannot be instantiated.
66.50 + */
66.51 + private Void() {}
66.52 +}
67.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
67.2 +++ b/emul/mini/src/main/java/java/lang/annotation/Annotation.java Wed Jan 23 20:39:23 2013 +0100
67.3 @@ -0,0 +1,131 @@
67.4 +/*
67.5 + * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
67.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
67.7 + *
67.8 + * This code is free software; you can redistribute it and/or modify it
67.9 + * under the terms of the GNU General Public License version 2 only, as
67.10 + * published by the Free Software Foundation. Oracle designates this
67.11 + * particular file as subject to the "Classpath" exception as provided
67.12 + * by Oracle in the LICENSE file that accompanied this code.
67.13 + *
67.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
67.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
67.17 + * version 2 for more details (a copy is included in the LICENSE file that
67.18 + * accompanied this code).
67.19 + *
67.20 + * You should have received a copy of the GNU General Public License version
67.21 + * 2 along with this work; if not, write to the Free Software Foundation,
67.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
67.23 + *
67.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
67.25 + * or visit www.oracle.com if you need additional information or have any
67.26 + * questions.
67.27 + */
67.28 +
67.29 +package java.lang.annotation;
67.30 +
67.31 +/**
67.32 + * The common interface extended by all annotation types. Note that an
67.33 + * interface that manually extends this one does <i>not</i> define
67.34 + * an annotation type. Also note that this interface does not itself
67.35 + * define an annotation type.
67.36 + *
67.37 + * More information about annotation types can be found in section 9.6 of
67.38 + * <cite>The Java™ Language Specification</cite>.
67.39 + *
67.40 + * @author Josh Bloch
67.41 + * @since 1.5
67.42 + */
67.43 +public interface Annotation {
67.44 + /**
67.45 + * Returns true if the specified object represents an annotation
67.46 + * that is logically equivalent to this one. In other words,
67.47 + * returns true if the specified object is an instance of the same
67.48 + * annotation type as this instance, all of whose members are equal
67.49 + * to the corresponding member of this annotation, as defined below:
67.50 + * <ul>
67.51 + * <li>Two corresponding primitive typed members whose values are
67.52 + * <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
67.53 + * unless their type is <tt>float</tt> or <tt>double</tt>.
67.54 + *
67.55 + * <li>Two corresponding <tt>float</tt> members whose values
67.56 + * are <tt>x</tt> and <tt>y</tt> are considered equal if
67.57 + * <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
67.58 + * (Unlike the <tt>==</tt> operator, NaN is considered equal
67.59 + * to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
67.60 + *
67.61 + * <li>Two corresponding <tt>double</tt> members whose values
67.62 + * are <tt>x</tt> and <tt>y</tt> are considered equal if
67.63 + * <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
67.64 + * (Unlike the <tt>==</tt> operator, NaN is considered equal
67.65 + * to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
67.66 + *
67.67 + * <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
67.68 + * annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
67.69 + * are considered equal if <tt>x.equals(y)</tt>. (Note that this
67.70 + * definition is recursive for annotation typed members.)
67.71 + *
67.72 + * <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
67.73 + * are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
67.74 + * appropriate overloading of {@link java.util.Arrays#equals}.
67.75 + * </ul>
67.76 + *
67.77 + * @return true if the specified object represents an annotation
67.78 + * that is logically equivalent to this one, otherwise false
67.79 + */
67.80 + boolean equals(Object obj);
67.81 +
67.82 + /**
67.83 + * Returns the hash code of this annotation, as defined below:
67.84 + *
67.85 + * <p>The hash code of an annotation is the sum of the hash codes
67.86 + * of its members (including those with default values), as defined
67.87 + * below:
67.88 + *
67.89 + * The hash code of an annotation member is (127 times the hash code
67.90 + * of the member-name as computed by {@link String#hashCode()}) XOR
67.91 + * the hash code of the member-value, as defined below:
67.92 + *
67.93 + * <p>The hash code of a member-value depends on its type:
67.94 + * <ul>
67.95 + * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
67.96 + * <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
67.97 + * <tt><i>WrapperType</i></tt> is the wrapper type corresponding
67.98 + * to the primitive type of <tt><i>v</i></tt> ({@link Byte},
67.99 + * {@link Character}, {@link Double}, {@link Float}, {@link Integer},
67.100 + * {@link Long}, {@link Short}, or {@link Boolean}).
67.101 + *
67.102 + * <li>The hash code of a string, enum, class, or annotation member-value
67.103 + I <tt><i>v</i></tt> is computed as by calling
67.104 + * <tt><i>v</i>.hashCode()</tt>. (In the case of annotation
67.105 + * member values, this is a recursive definition.)
67.106 + *
67.107 + * <li>The hash code of an array member-value is computed by calling
67.108 + * the appropriate overloading of
67.109 + * {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
67.110 + * on the value. (There is one overloading for each primitive
67.111 + * type, and one for object reference types.)
67.112 + * </ul>
67.113 + *
67.114 + * @return the hash code of this annotation
67.115 + */
67.116 + int hashCode();
67.117 +
67.118 + /**
67.119 + * Returns a string representation of this annotation. The details
67.120 + * of the representation are implementation-dependent, but the following
67.121 + * may be regarded as typical:
67.122 + * <pre>
67.123 + * @com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
67.124 + * </pre>
67.125 + *
67.126 + * @return a string representation of this annotation
67.127 + */
67.128 + String toString();
67.129 +
67.130 + /**
67.131 + * Returns the annotation type of this annotation.
67.132 + */
67.133 + Class<? extends Annotation> annotationType();
67.134 +}
68.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
68.2 +++ b/emul/mini/src/main/java/java/lang/annotation/Documented.java Wed Jan 23 20:39:23 2013 +0100
68.3 @@ -0,0 +1,43 @@
68.4 +/*
68.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
68.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
68.7 + *
68.8 + * This code is free software; you can redistribute it and/or modify it
68.9 + * under the terms of the GNU General Public License version 2 only, as
68.10 + * published by the Free Software Foundation. Oracle designates this
68.11 + * particular file as subject to the "Classpath" exception as provided
68.12 + * by Oracle in the LICENSE file that accompanied this code.
68.13 + *
68.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
68.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
68.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
68.17 + * version 2 for more details (a copy is included in the LICENSE file that
68.18 + * accompanied this code).
68.19 + *
68.20 + * You should have received a copy of the GNU General Public License version
68.21 + * 2 along with this work; if not, write to the Free Software Foundation,
68.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
68.23 + *
68.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
68.25 + * or visit www.oracle.com if you need additional information or have any
68.26 + * questions.
68.27 + */
68.28 +
68.29 +package java.lang.annotation;
68.30 +
68.31 +/**
68.32 + * Indicates that annotations with a type are to be documented by javadoc
68.33 + * and similar tools by default. This type should be used to annotate the
68.34 + * declarations of types whose annotations affect the use of annotated
68.35 + * elements by their clients. If a type declaration is annotated with
68.36 + * Documented, its annotations become part of the public API
68.37 + * of the annotated elements.
68.38 + *
68.39 + * @author Joshua Bloch
68.40 + * @since 1.5
68.41 + */
68.42 +@Documented
68.43 +@Retention(RetentionPolicy.RUNTIME)
68.44 +@Target(ElementType.ANNOTATION_TYPE)
68.45 +public @interface Documented {
68.46 +}
69.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
69.2 +++ b/emul/mini/src/main/java/java/lang/annotation/ElementType.java Wed Jan 23 20:39:23 2013 +0100
69.3 @@ -0,0 +1,63 @@
69.4 +/*
69.5 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
69.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
69.7 + *
69.8 + * This code is free software; you can redistribute it and/or modify it
69.9 + * under the terms of the GNU General Public License version 2 only, as
69.10 + * published by the Free Software Foundation. Oracle designates this
69.11 + * particular file as subject to the "Classpath" exception as provided
69.12 + * by Oracle in the LICENSE file that accompanied this code.
69.13 + *
69.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
69.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
69.17 + * version 2 for more details (a copy is included in the LICENSE file that
69.18 + * accompanied this code).
69.19 + *
69.20 + * You should have received a copy of the GNU General Public License version
69.21 + * 2 along with this work; if not, write to the Free Software Foundation,
69.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
69.23 + *
69.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
69.25 + * or visit www.oracle.com if you need additional information or have any
69.26 + * questions.
69.27 + */
69.28 +
69.29 +package java.lang.annotation;
69.30 +
69.31 +/**
69.32 + * A program element type. The constants of this enumerated type
69.33 + * provide a simple classification of the declared elements in a
69.34 + * Java program.
69.35 + *
69.36 + * <p>These constants are used with the {@link Target} meta-annotation type
69.37 + * to specify where it is legal to use an annotation type.
69.38 + *
69.39 + * @author Joshua Bloch
69.40 + * @since 1.5
69.41 + */
69.42 +public enum ElementType {
69.43 + /** Class, interface (including annotation type), or enum declaration */
69.44 + TYPE,
69.45 +
69.46 + /** Field declaration (includes enum constants) */
69.47 + FIELD,
69.48 +
69.49 + /** Method declaration */
69.50 + METHOD,
69.51 +
69.52 + /** Parameter declaration */
69.53 + PARAMETER,
69.54 +
69.55 + /** Constructor declaration */
69.56 + CONSTRUCTOR,
69.57 +
69.58 + /** Local variable declaration */
69.59 + LOCAL_VARIABLE,
69.60 +
69.61 + /** Annotation type declaration */
69.62 + ANNOTATION_TYPE,
69.63 +
69.64 + /** Package declaration */
69.65 + PACKAGE
69.66 +}
70.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
70.2 +++ b/emul/mini/src/main/java/java/lang/annotation/Retention.java Wed Jan 23 20:39:23 2013 +0100
70.3 @@ -0,0 +1,47 @@
70.4 +/*
70.5 + * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
70.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
70.7 + *
70.8 + * This code is free software; you can redistribute it and/or modify it
70.9 + * under the terms of the GNU General Public License version 2 only, as
70.10 + * published by the Free Software Foundation. Oracle designates this
70.11 + * particular file as subject to the "Classpath" exception as provided
70.12 + * by Oracle in the LICENSE file that accompanied this code.
70.13 + *
70.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
70.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
70.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
70.17 + * version 2 for more details (a copy is included in the LICENSE file that
70.18 + * accompanied this code).
70.19 + *
70.20 + * You should have received a copy of the GNU General Public License version
70.21 + * 2 along with this work; if not, write to the Free Software Foundation,
70.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
70.23 + *
70.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
70.25 + * or visit www.oracle.com if you need additional information or have any
70.26 + * questions.
70.27 + */
70.28 +
70.29 +package java.lang.annotation;
70.30 +
70.31 +/**
70.32 + * Indicates how long annotations with the annotated type are to
70.33 + * be retained. If no Retention annotation is present on
70.34 + * an annotation type declaration, the retention policy defaults to
70.35 + * {@code RetentionPolicy.CLASS}.
70.36 + *
70.37 + * <p>A Retention meta-annotation has effect only if the
70.38 + * meta-annotated type is used directly for annotation. It has no
70.39 + * effect if the meta-annotated type is used as a member type in
70.40 + * another annotation type.
70.41 + *
70.42 + * @author Joshua Bloch
70.43 + * @since 1.5
70.44 + */
70.45 +@Documented
70.46 +@Retention(RetentionPolicy.RUNTIME)
70.47 +@Target(ElementType.ANNOTATION_TYPE)
70.48 +public @interface Retention {
70.49 + RetentionPolicy value();
70.50 +}
71.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
71.2 +++ b/emul/mini/src/main/java/java/lang/annotation/RetentionPolicy.java Wed Jan 23 20:39:23 2013 +0100
71.3 @@ -0,0 +1,57 @@
71.4 +/*
71.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
71.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
71.7 + *
71.8 + * This code is free software; you can redistribute it and/or modify it
71.9 + * under the terms of the GNU General Public License version 2 only, as
71.10 + * published by the Free Software Foundation. Oracle designates this
71.11 + * particular file as subject to the "Classpath" exception as provided
71.12 + * by Oracle in the LICENSE file that accompanied this code.
71.13 + *
71.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
71.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
71.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
71.17 + * version 2 for more details (a copy is included in the LICENSE file that
71.18 + * accompanied this code).
71.19 + *
71.20 + * You should have received a copy of the GNU General Public License version
71.21 + * 2 along with this work; if not, write to the Free Software Foundation,
71.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
71.23 + *
71.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
71.25 + * or visit www.oracle.com if you need additional information or have any
71.26 + * questions.
71.27 + */
71.28 +
71.29 +package java.lang.annotation;
71.30 +
71.31 +/**
71.32 + * Annotation retention policy. The constants of this enumerated type
71.33 + * describe the various policies for retaining annotations. They are used
71.34 + * in conjunction with the {@link Retention} meta-annotation type to specify
71.35 + * how long annotations are to be retained.
71.36 + *
71.37 + * @author Joshua Bloch
71.38 + * @since 1.5
71.39 + */
71.40 +public enum RetentionPolicy {
71.41 + /**
71.42 + * Annotations are to be discarded by the compiler.
71.43 + */
71.44 + SOURCE,
71.45 +
71.46 + /**
71.47 + * Annotations are to be recorded in the class file by the compiler
71.48 + * but need not be retained by the VM at run time. This is the default
71.49 + * behavior.
71.50 + */
71.51 + CLASS,
71.52 +
71.53 + /**
71.54 + * Annotations are to be recorded in the class file by the compiler and
71.55 + * retained by the VM at run time, so they may be read reflectively.
71.56 + *
71.57 + * @see java.lang.reflect.AnnotatedElement
71.58 + */
71.59 + RUNTIME
71.60 +}
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
72.2 +++ b/emul/mini/src/main/java/java/lang/annotation/Target.java Wed Jan 23 20:39:23 2013 +0100
72.3 @@ -0,0 +1,68 @@
72.4 +/*
72.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
72.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72.7 + *
72.8 + * This code is free software; you can redistribute it and/or modify it
72.9 + * under the terms of the GNU General Public License version 2 only, as
72.10 + * published by the Free Software Foundation. Oracle designates this
72.11 + * particular file as subject to the "Classpath" exception as provided
72.12 + * by Oracle in the LICENSE file that accompanied this code.
72.13 + *
72.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
72.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
72.17 + * version 2 for more details (a copy is included in the LICENSE file that
72.18 + * accompanied this code).
72.19 + *
72.20 + * You should have received a copy of the GNU General Public License version
72.21 + * 2 along with this work; if not, write to the Free Software Foundation,
72.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72.23 + *
72.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
72.25 + * or visit www.oracle.com if you need additional information or have any
72.26 + * questions.
72.27 + */
72.28 +
72.29 +package java.lang.annotation;
72.30 +
72.31 +/**
72.32 + * Indicates the kinds of program element to which an annotation type
72.33 + * is applicable. If a Target meta-annotation is not present on an
72.34 + * annotation type declaration, the declared type may be used on any
72.35 + * program element. If such a meta-annotation is present, the compiler
72.36 + * will enforce the specified usage restriction.
72.37 + *
72.38 + * For example, this meta-annotation indicates that the declared type is
72.39 + * itself a meta-annotation type. It can only be used on annotation type
72.40 + * declarations:
72.41 + * <pre>
72.42 + * @Target(ElementType.ANNOTATION_TYPE)
72.43 + * public @interface MetaAnnotationType {
72.44 + * ...
72.45 + * }
72.46 + * </pre>
72.47 + * This meta-annotation indicates that the declared type is intended solely
72.48 + * for use as a member type in complex annotation type declarations. It
72.49 + * cannot be used to annotate anything directly:
72.50 + * <pre>
72.51 + * @Target({})
72.52 + * public @interface MemberType {
72.53 + * ...
72.54 + * }
72.55 + * </pre>
72.56 + * It is a compile-time error for a single ElementType constant to
72.57 + * appear more than once in a Target annotation. For example, the
72.58 + * following meta-annotation is illegal:
72.59 + * <pre>
72.60 + * @Target({ElementType.FIELD, ElementType.METHOD, ElementType.FIELD})
72.61 + * public @interface Bogus {
72.62 + * ...
72.63 + * }
72.64 + * </pre>
72.65 + */
72.66 +@Documented
72.67 +@Retention(RetentionPolicy.RUNTIME)
72.68 +@Target(ElementType.ANNOTATION_TYPE)
72.69 +public @interface Target {
72.70 + ElementType[] value();
72.71 +}
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
73.2 +++ b/emul/mini/src/main/java/java/lang/annotation/UnsupportedOperationException.java Wed Jan 23 20:39:23 2013 +0100
73.3 @@ -0,0 +1,94 @@
73.4 +/*
73.5 + * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
73.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
73.7 + *
73.8 + * This code is free software; you can redistribute it and/or modify it
73.9 + * under the terms of the GNU General Public License version 2 only, as
73.10 + * published by the Free Software Foundation. Oracle designates this
73.11 + * particular file as subject to the "Classpath" exception as provided
73.12 + * by Oracle in the LICENSE file that accompanied this code.
73.13 + *
73.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
73.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
73.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
73.17 + * version 2 for more details (a copy is included in the LICENSE file that
73.18 + * accompanied this code).
73.19 + *
73.20 + * You should have received a copy of the GNU General Public License version
73.21 + * 2 along with this work; if not, write to the Free Software Foundation,
73.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
73.23 + *
73.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
73.25 + * or visit www.oracle.com if you need additional information or have any
73.26 + * questions.
73.27 + */
73.28 +
73.29 +package java.lang;
73.30 +
73.31 +/**
73.32 + * Thrown to indicate that the requested operation is not supported.<p>
73.33 + *
73.34 + * This class is a member of the
73.35 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
73.36 + * Java Collections Framework</a>.
73.37 + *
73.38 + * @author Josh Bloch
73.39 + * @since 1.2
73.40 + */
73.41 +public class UnsupportedOperationException extends RuntimeException {
73.42 + /**
73.43 + * Constructs an UnsupportedOperationException with no detail message.
73.44 + */
73.45 + public UnsupportedOperationException() {
73.46 + }
73.47 +
73.48 + /**
73.49 + * Constructs an UnsupportedOperationException with the specified
73.50 + * detail message.
73.51 + *
73.52 + * @param message the detail message
73.53 + */
73.54 + public UnsupportedOperationException(String message) {
73.55 + super(message);
73.56 + }
73.57 +
73.58 + /**
73.59 + * Constructs a new exception with the specified detail message and
73.60 + * cause.
73.61 + *
73.62 + * <p>Note that the detail message associated with <code>cause</code> is
73.63 + * <i>not</i> automatically incorporated in this exception's detail
73.64 + * message.
73.65 + *
73.66 + * @param message the detail message (which is saved for later retrieval
73.67 + * by the {@link Throwable#getMessage()} method).
73.68 + * @param cause the cause (which is saved for later retrieval by the
73.69 + * {@link Throwable#getCause()} method). (A <tt>null</tt> value
73.70 + * is permitted, and indicates that the cause is nonexistent or
73.71 + * unknown.)
73.72 + * @since 1.5
73.73 + */
73.74 + public UnsupportedOperationException(String message, Throwable cause) {
73.75 + super(message, cause);
73.76 + }
73.77 +
73.78 + /**
73.79 + * Constructs a new exception with the specified cause and a detail
73.80 + * message of <tt>(cause==null ? null : cause.toString())</tt> (which
73.81 + * typically contains the class and detail message of <tt>cause</tt>).
73.82 + * This constructor is useful for exceptions that are little more than
73.83 + * wrappers for other throwables (for example, {@link
73.84 + * java.security.PrivilegedActionException}).
73.85 + *
73.86 + * @param cause the cause (which is saved for later retrieval by the
73.87 + * {@link Throwable#getCause()} method). (A <tt>null</tt> value is
73.88 + * permitted, and indicates that the cause is nonexistent or
73.89 + * unknown.)
73.90 + * @since 1.5
73.91 + */
73.92 + public UnsupportedOperationException(Throwable cause) {
73.93 + super(cause);
73.94 + }
73.95 +
73.96 + static final long serialVersionUID = -1242599979055084673L;
73.97 +}
74.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
74.2 +++ b/emul/mini/src/main/java/java/lang/reflect/AccessibleObject.java Wed Jan 23 20:39:23 2013 +0100
74.3 @@ -0,0 +1,167 @@
74.4 +/*
74.5 + * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
74.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74.7 + *
74.8 + * This code is free software; you can redistribute it and/or modify it
74.9 + * under the terms of the GNU General Public License version 2 only, as
74.10 + * published by the Free Software Foundation. Oracle designates this
74.11 + * particular file as subject to the "Classpath" exception as provided
74.12 + * by Oracle in the LICENSE file that accompanied this code.
74.13 + *
74.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
74.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74.17 + * version 2 for more details (a copy is included in the LICENSE file that
74.18 + * accompanied this code).
74.19 + *
74.20 + * You should have received a copy of the GNU General Public License version
74.21 + * 2 along with this work; if not, write to the Free Software Foundation,
74.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
74.23 + *
74.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
74.25 + * or visit www.oracle.com if you need additional information or have any
74.26 + * questions.
74.27 + */
74.28 +
74.29 +package java.lang.reflect;
74.30 +
74.31 +import java.lang.annotation.Annotation;
74.32 +
74.33 +/**
74.34 + * The AccessibleObject class is the base class for Field, Method and
74.35 + * Constructor objects. It provides the ability to flag a reflected
74.36 + * object as suppressing default Java language access control checks
74.37 + * when it is used. The access checks--for public, default (package)
74.38 + * access, protected, and private members--are performed when Fields,
74.39 + * Methods or Constructors are used to set or get fields, to invoke
74.40 + * methods, or to create and initialize new instances of classes,
74.41 + * respectively.
74.42 + *
74.43 + * <p>Setting the {@code accessible} flag in a reflected object
74.44 + * permits sophisticated applications with sufficient privilege, such
74.45 + * as Java Object Serialization or other persistence mechanisms, to
74.46 + * manipulate objects in a manner that would normally be prohibited.
74.47 + *
74.48 + * <p>By default, a reflected object is <em>not</em> accessible.
74.49 + *
74.50 + * @see Field
74.51 + * @see Method
74.52 + * @see Constructor
74.53 + * @see ReflectPermission
74.54 + *
74.55 + * @since 1.2
74.56 + */
74.57 +public class AccessibleObject implements AnnotatedElement {
74.58 +
74.59 + /**
74.60 + * Convenience method to set the {@code accessible} flag for an
74.61 + * array of objects with a single security check (for efficiency).
74.62 + *
74.63 + * <p>First, if there is a security manager, its
74.64 + * {@code checkPermission} method is called with a
74.65 + * {@code ReflectPermission("suppressAccessChecks")} permission.
74.66 + *
74.67 + * <p>A {@code SecurityException} is raised if {@code flag} is
74.68 + * {@code true} but accessibility of any of the elements of the input
74.69 + * {@code array} may not be changed (for example, if the element
74.70 + * object is a {@link Constructor} object for the class {@link
74.71 + * java.lang.Class}). In the event of such a SecurityException, the
74.72 + * accessibility of objects is set to {@code flag} for array elements
74.73 + * upto (and excluding) the element for which the exception occurred; the
74.74 + * accessibility of elements beyond (and including) the element for which
74.75 + * the exception occurred is unchanged.
74.76 + *
74.77 + * @param array the array of AccessibleObjects
74.78 + * @param flag the new value for the {@code accessible} flag
74.79 + * in each object
74.80 + * @throws SecurityException if the request is denied.
74.81 + * @see SecurityManager#checkPermission
74.82 + * @see java.lang.RuntimePermission
74.83 + */
74.84 + public static void setAccessible(AccessibleObject[] array, boolean flag)
74.85 + throws SecurityException {
74.86 + throw new SecurityException();
74.87 + }
74.88 +
74.89 + /**
74.90 + * Set the {@code accessible} flag for this object to
74.91 + * the indicated boolean value. A value of {@code true} indicates that
74.92 + * the reflected object should suppress Java language access
74.93 + * checking when it is used. A value of {@code false} indicates
74.94 + * that the reflected object should enforce Java language access checks.
74.95 + *
74.96 + * <p>First, if there is a security manager, its
74.97 + * {@code checkPermission} method is called with a
74.98 + * {@code ReflectPermission("suppressAccessChecks")} permission.
74.99 + *
74.100 + * <p>A {@code SecurityException} is raised if {@code flag} is
74.101 + * {@code true} but accessibility of this object may not be changed
74.102 + * (for example, if this element object is a {@link Constructor} object for
74.103 + * the class {@link java.lang.Class}).
74.104 + *
74.105 + * <p>A {@code SecurityException} is raised if this object is a {@link
74.106 + * java.lang.reflect.Constructor} object for the class
74.107 + * {@code java.lang.Class}, and {@code flag} is true.
74.108 + *
74.109 + * @param flag the new value for the {@code accessible} flag
74.110 + * @throws SecurityException if the request is denied.
74.111 + * @see SecurityManager#checkPermission
74.112 + * @see java.lang.RuntimePermission
74.113 + */
74.114 + public void setAccessible(boolean flag) throws SecurityException {
74.115 + throw new SecurityException();
74.116 + }
74.117 +
74.118 + /**
74.119 + * Get the value of the {@code accessible} flag for this object.
74.120 + *
74.121 + * @return the value of the object's {@code accessible} flag
74.122 + */
74.123 + public boolean isAccessible() {
74.124 + return override;
74.125 + }
74.126 +
74.127 + /**
74.128 + * Constructor: only used by the Java Virtual Machine.
74.129 + */
74.130 + protected AccessibleObject() {}
74.131 +
74.132 + // Indicates whether language-level access checks are overridden
74.133 + // by this object. Initializes to "false". This field is used by
74.134 + // Field, Method, and Constructor.
74.135 + //
74.136 + // NOTE: for security purposes, this field must not be visible
74.137 + // outside this package.
74.138 + boolean override;
74.139 +
74.140 + /**
74.141 + * @throws NullPointerException {@inheritDoc}
74.142 + * @since 1.5
74.143 + */
74.144 + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
74.145 + throw new AssertionError("All subclasses should override this method");
74.146 + }
74.147 +
74.148 + /**
74.149 + * @throws NullPointerException {@inheritDoc}
74.150 + * @since 1.5
74.151 + */
74.152 + public boolean isAnnotationPresent(
74.153 + Class<? extends Annotation> annotationClass) {
74.154 + return getAnnotation(annotationClass) != null;
74.155 + }
74.156 +
74.157 + /**
74.158 + * @since 1.5
74.159 + */
74.160 + public Annotation[] getAnnotations() {
74.161 + return getDeclaredAnnotations();
74.162 + }
74.163 +
74.164 + /**
74.165 + * @since 1.5
74.166 + */
74.167 + public Annotation[] getDeclaredAnnotations() {
74.168 + throw new AssertionError("All subclasses should override this method");
74.169 + }
74.170 +}
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
75.2 +++ b/emul/mini/src/main/java/java/lang/reflect/AnnotatedElement.java Wed Jan 23 20:39:23 2013 +0100
75.3 @@ -0,0 +1,112 @@
75.4 +/*
75.5 + * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
75.7 + *
75.8 + * This code is free software; you can redistribute it and/or modify it
75.9 + * under the terms of the GNU General Public License version 2 only, as
75.10 + * published by the Free Software Foundation. Oracle designates this
75.11 + * particular file as subject to the "Classpath" exception as provided
75.12 + * by Oracle in the LICENSE file that accompanied this code.
75.13 + *
75.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
75.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
75.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
75.17 + * version 2 for more details (a copy is included in the LICENSE file that
75.18 + * accompanied this code).
75.19 + *
75.20 + * You should have received a copy of the GNU General Public License version
75.21 + * 2 along with this work; if not, write to the Free Software Foundation,
75.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
75.23 + *
75.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
75.25 + * or visit www.oracle.com if you need additional information or have any
75.26 + * questions.
75.27 + */
75.28 +
75.29 +package java.lang.reflect;
75.30 +
75.31 +import java.lang.annotation.Annotation;
75.32 +
75.33 +/**
75.34 + * Represents an annotated element of the program currently running in this
75.35 + * VM. This interface allows annotations to be read reflectively. All
75.36 + * annotations returned by methods in this interface are immutable and
75.37 + * serializable. It is permissible for the caller to modify the
75.38 + * arrays returned by accessors for array-valued enum members; it will
75.39 + * have no affect on the arrays returned to other callers.
75.40 + *
75.41 + * <p>If an annotation returned by a method in this interface contains
75.42 + * (directly or indirectly) a {@link Class}-valued member referring to
75.43 + * a class that is not accessible in this VM, attempting to read the class
75.44 + * by calling the relevant Class-returning method on the returned annotation
75.45 + * will result in a {@link TypeNotPresentException}.
75.46 + *
75.47 + * <p>Similarly, attempting to read an enum-valued member will result in
75.48 + * a {@link EnumConstantNotPresentException} if the enum constant in the
75.49 + * annotation is no longer present in the enum type.
75.50 + *
75.51 + * <p>Finally, Attempting to read a member whose definition has evolved
75.52 + * incompatibly will result in a {@link
75.53 + * java.lang.annotation.AnnotationTypeMismatchException} or an
75.54 + * {@link java.lang.annotation.IncompleteAnnotationException}.
75.55 + *
75.56 + * @see java.lang.EnumConstantNotPresentException
75.57 + * @see java.lang.TypeNotPresentException
75.58 + * @see java.lang.annotation.AnnotationFormatError
75.59 + * @see java.lang.annotation.AnnotationTypeMismatchException
75.60 + * @see java.lang.annotation.IncompleteAnnotationException
75.61 + * @since 1.5
75.62 + * @author Josh Bloch
75.63 + */
75.64 +public interface AnnotatedElement {
75.65 + /**
75.66 + * Returns true if an annotation for the specified type
75.67 + * is present on this element, else false. This method
75.68 + * is designed primarily for convenient access to marker annotations.
75.69 + *
75.70 + * @param annotationClass the Class object corresponding to the
75.71 + * annotation type
75.72 + * @return true if an annotation for the specified annotation
75.73 + * type is present on this element, else false
75.74 + * @throws NullPointerException if the given annotation class is null
75.75 + * @since 1.5
75.76 + */
75.77 + boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
75.78 +
75.79 + /**
75.80 + * Returns this element's annotation for the specified type if
75.81 + * such an annotation is present, else null.
75.82 + *
75.83 + * @param annotationClass the Class object corresponding to the
75.84 + * annotation type
75.85 + * @return this element's annotation for the specified annotation type if
75.86 + * present on this element, else null
75.87 + * @throws NullPointerException if the given annotation class is null
75.88 + * @since 1.5
75.89 + */
75.90 + <T extends Annotation> T getAnnotation(Class<T> annotationClass);
75.91 +
75.92 + /**
75.93 + * Returns all annotations present on this element. (Returns an array
75.94 + * of length zero if this element has no annotations.) The caller of
75.95 + * this method is free to modify the returned array; it will have no
75.96 + * effect on the arrays returned to other callers.
75.97 + *
75.98 + * @return all annotations present on this element
75.99 + * @since 1.5
75.100 + */
75.101 + Annotation[] getAnnotations();
75.102 +
75.103 + /**
75.104 + * Returns all annotations that are directly present on this
75.105 + * element. Unlike the other methods in this interface, this method
75.106 + * ignores inherited annotations. (Returns an array of length zero if
75.107 + * no annotations are directly present on this element.) The caller of
75.108 + * this method is free to modify the returned array; it will have no
75.109 + * effect on the arrays returned to other callers.
75.110 + *
75.111 + * @return All annotations directly present on this element
75.112 + * @since 1.5
75.113 + */
75.114 + Annotation[] getDeclaredAnnotations();
75.115 +}
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
76.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Array.java Wed Jan 23 20:39:23 2013 +0100
76.3 @@ -0,0 +1,659 @@
76.4 +/*
76.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
76.7 + *
76.8 + * This code is free software; you can redistribute it and/or modify it
76.9 + * under the terms of the GNU General Public License version 2 only, as
76.10 + * published by the Free Software Foundation. Oracle designates this
76.11 + * particular file as subject to the "Classpath" exception as provided
76.12 + * by Oracle in the LICENSE file that accompanied this code.
76.13 + *
76.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
76.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
76.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
76.17 + * version 2 for more details (a copy is included in the LICENSE file that
76.18 + * accompanied this code).
76.19 + *
76.20 + * You should have received a copy of the GNU General Public License version
76.21 + * 2 along with this work; if not, write to the Free Software Foundation,
76.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
76.23 + *
76.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
76.25 + * or visit www.oracle.com if you need additional information or have any
76.26 + * questions.
76.27 + */
76.28 +
76.29 +package java.lang.reflect;
76.30 +
76.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
76.32 +import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
76.33 +
76.34 +/**
76.35 + * The {@code Array} class provides static methods to dynamically create and
76.36 + * access Java arrays.
76.37 + *
76.38 + * <p>{@code Array} permits widening conversions to occur during a get or set
76.39 + * operation, but throws an {@code IllegalArgumentException} if a narrowing
76.40 + * conversion would occur.
76.41 + *
76.42 + * @author Nakul Saraiya
76.43 + */
76.44 +@JavaScriptPrototype(prototype = "new Array", container = "Array.prototype")
76.45 +public final
76.46 +class Array {
76.47 +
76.48 + /**
76.49 + * Constructor. Class Array is not instantiable.
76.50 + */
76.51 + private Array() {}
76.52 +
76.53 + /**
76.54 + * Creates a new array with the specified component type and
76.55 + * length.
76.56 + * Invoking this method is equivalent to creating an array
76.57 + * as follows:
76.58 + * <blockquote>
76.59 + * <pre>
76.60 + * int[] x = {length};
76.61 + * Array.newInstance(componentType, x);
76.62 + * </pre>
76.63 + * </blockquote>
76.64 + *
76.65 + * @param componentType the {@code Class} object representing the
76.66 + * component type of the new array
76.67 + * @param length the length of the new array
76.68 + * @return the new array
76.69 + * @exception NullPointerException if the specified
76.70 + * {@code componentType} parameter is null
76.71 + * @exception IllegalArgumentException if componentType is {@link Void#TYPE}
76.72 + * @exception NegativeArraySizeException if the specified {@code length}
76.73 + * is negative
76.74 + */
76.75 + public static Object newInstance(Class<?> componentType, int length)
76.76 + throws NegativeArraySizeException {
76.77 + if (length < 0) {
76.78 + throw new NegativeArraySizeException();
76.79 + }
76.80 + String sig = findSignature(componentType);
76.81 + return newArray(componentType.isPrimitive(), sig, length);
76.82 + }
76.83 +
76.84 + private static String findSignature(Class<?> type) {
76.85 + if (type == Integer.TYPE) {
76.86 + return "[I";
76.87 + }
76.88 + if (type == Long.TYPE) {
76.89 + return "[J";
76.90 + }
76.91 + if (type == Double.TYPE) {
76.92 + return "[D";
76.93 + }
76.94 + if (type == Float.TYPE) {
76.95 + return "[F";
76.96 + }
76.97 + if (type == Byte.TYPE) {
76.98 + return "[B";
76.99 + }
76.100 + if (type == Boolean.TYPE) {
76.101 + return "[Z";
76.102 + }
76.103 + if (type == Short.TYPE) {
76.104 + return "[S";
76.105 + }
76.106 + if (type == Character.TYPE) {
76.107 + return "[C";
76.108 + }
76.109 + if (type.getName().equals("void")) {
76.110 + throw new IllegalStateException("Can't create array for " + type);
76.111 + }
76.112 + return "[L" + type.getName() + ";";
76.113 + }
76.114 + /**
76.115 + * Creates a new array
76.116 + * with the specified component type and dimensions.
76.117 + * If {@code componentType}
76.118 + * represents a non-array class or interface, the new array
76.119 + * has {@code dimensions.length} dimensions and
76.120 + * {@code componentType} as its component type. If
76.121 + * {@code componentType} represents an array class, the
76.122 + * number of dimensions of the new array is equal to the sum
76.123 + * of {@code dimensions.length} and the number of
76.124 + * dimensions of {@code componentType}. In this case, the
76.125 + * component type of the new array is the component type of
76.126 + * {@code componentType}.
76.127 + *
76.128 + * <p>The number of dimensions of the new array must not
76.129 + * exceed the number of array dimensions supported by the
76.130 + * implementation (typically 255).
76.131 + *
76.132 + * @param componentType the {@code Class} object representing the component
76.133 + * type of the new array
76.134 + * @param dimensions an array of {@code int} representing the dimensions of
76.135 + * the new array
76.136 + * @return the new array
76.137 + * @exception NullPointerException if the specified
76.138 + * {@code componentType} argument is null
76.139 + * @exception IllegalArgumentException if the specified {@code dimensions}
76.140 + * argument is a zero-dimensional array, or if the number of
76.141 + * requested dimensions exceeds the limit on the number of array dimensions
76.142 + * supported by the implementation (typically 255), or if componentType
76.143 + * is {@link Void#TYPE}.
76.144 + * @exception NegativeArraySizeException if any of the components in
76.145 + * the specified {@code dimensions} argument is negative.
76.146 + */
76.147 + public static Object newInstance(Class<?> componentType, int... dimensions)
76.148 + throws IllegalArgumentException, NegativeArraySizeException {
76.149 + StringBuilder sig = new StringBuilder();
76.150 + for (int i = 1; i < dimensions.length; i++) {
76.151 + sig.append('[');
76.152 + }
76.153 + sig.append(findSignature(componentType));
76.154 + return multiNewArray(sig.toString(), dimensions, 0);
76.155 + }
76.156 +
76.157 + /**
76.158 + * Returns the length of the specified array object, as an {@code int}.
76.159 + *
76.160 + * @param array the array
76.161 + * @return the length of the array
76.162 + * @exception IllegalArgumentException if the object argument is not
76.163 + * an array
76.164 + */
76.165 + public static int getLength(Object array)
76.166 + throws IllegalArgumentException {
76.167 + if (!array.getClass().isArray()) {
76.168 + throw new IllegalArgumentException("Argument is not an array");
76.169 + }
76.170 + return length(array);
76.171 + }
76.172 +
76.173 + @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
76.174 + private static native int length(Object arr);
76.175 +
76.176 + /**
76.177 + * Returns the value of the indexed component in the specified
76.178 + * array object. The value is automatically wrapped in an object
76.179 + * if it has a primitive type.
76.180 + *
76.181 + * @param array the array
76.182 + * @param index the index
76.183 + * @return the (possibly wrapped) value of the indexed component in
76.184 + * the specified array
76.185 + * @exception NullPointerException If the specified object is null
76.186 + * @exception IllegalArgumentException If the specified object is not
76.187 + * an array
76.188 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.189 + * argument is negative, or if it is greater than or equal to the
76.190 + * length of the specified array
76.191 + */
76.192 + public static Object get(Object array, int index)
76.193 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.194 + final Class<?> t = array.getClass().getComponentType();
76.195 + if (t.isPrimitive()) {
76.196 + return Array.fromPrimitive(t, array, index);
76.197 + } else {
76.198 + return ((Object[])array)[index];
76.199 + }
76.200 + }
76.201 +
76.202 + /**
76.203 + * Returns the value of the indexed component in the specified
76.204 + * array object, as a {@code boolean}.
76.205 + *
76.206 + * @param array the array
76.207 + * @param index the index
76.208 + * @return the value of the indexed component in the specified array
76.209 + * @exception NullPointerException If the specified object is null
76.210 + * @exception IllegalArgumentException If the specified object is not
76.211 + * an array, or if the indexed element cannot be converted to the
76.212 + * return type by an identity or widening conversion
76.213 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.214 + * argument is negative, or if it is greater than or equal to the
76.215 + * length of the specified array
76.216 + * @see Array#get
76.217 + */
76.218 + public static native boolean getBoolean(Object array, int index)
76.219 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
76.220 +
76.221 + /**
76.222 + * Returns the value of the indexed component in the specified
76.223 + * array object, as a {@code byte}.
76.224 + *
76.225 + * @param array the array
76.226 + * @param index the index
76.227 + * @return the value of the indexed component in the specified array
76.228 + * @exception NullPointerException If the specified object is null
76.229 + * @exception IllegalArgumentException If the specified object is not
76.230 + * an array, or if the indexed element cannot be converted to the
76.231 + * return type by an identity or widening conversion
76.232 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.233 + * argument is negative, or if it is greater than or equal to the
76.234 + * length of the specified array
76.235 + * @see Array#get
76.236 + */
76.237 + public static byte getByte(Object array, int index)
76.238 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.239 + if (array.getClass().getComponentType() != Byte.TYPE) {
76.240 + throw new IllegalArgumentException();
76.241 + }
76.242 + byte[] arr = (byte[]) array;
76.243 + return arr[index];
76.244 + }
76.245 +
76.246 + /**
76.247 + * Returns the value of the indexed component in the specified
76.248 + * array object, as a {@code char}.
76.249 + *
76.250 + * @param array the array
76.251 + * @param index the index
76.252 + * @return the value of the indexed component in the specified array
76.253 + * @exception NullPointerException If the specified object is null
76.254 + * @exception IllegalArgumentException If the specified object is not
76.255 + * an array, or if the indexed element cannot be converted to the
76.256 + * return type by an identity or widening conversion
76.257 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.258 + * argument is negative, or if it is greater than or equal to the
76.259 + * length of the specified array
76.260 + * @see Array#get
76.261 + */
76.262 + public static native char getChar(Object array, int index)
76.263 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
76.264 +
76.265 + /**
76.266 + * Returns the value of the indexed component in the specified
76.267 + * array object, as a {@code short}.
76.268 + *
76.269 + * @param array the array
76.270 + * @param index the index
76.271 + * @return the value of the indexed component in the specified array
76.272 + * @exception NullPointerException If the specified object is null
76.273 + * @exception IllegalArgumentException If the specified object is not
76.274 + * an array, or if the indexed element cannot be converted to the
76.275 + * return type by an identity or widening conversion
76.276 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.277 + * argument is negative, or if it is greater than or equal to the
76.278 + * length of the specified array
76.279 + * @see Array#get
76.280 + */
76.281 + public static short getShort(Object array, int index)
76.282 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.283 + final Class<?> t = array.getClass().getComponentType();
76.284 + if (t == Short.TYPE) {
76.285 + short[] arr = (short[]) array;
76.286 + return arr[index];
76.287 + }
76.288 + return getByte(array, index);
76.289 + }
76.290 +
76.291 + /**
76.292 + * Returns the value of the indexed component in the specified
76.293 + * array object, as an {@code int}.
76.294 + *
76.295 + * @param array the array
76.296 + * @param index the index
76.297 + * @return the value of the indexed component in the specified array
76.298 + * @exception NullPointerException If the specified object is null
76.299 + * @exception IllegalArgumentException If the specified object is not
76.300 + * an array, or if the indexed element cannot be converted to the
76.301 + * return type by an identity or widening conversion
76.302 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.303 + * argument is negative, or if it is greater than or equal to the
76.304 + * length of the specified array
76.305 + * @see Array#get
76.306 + */
76.307 + public static int getInt(Object array, int index)
76.308 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.309 + final Class<?> t = array.getClass().getComponentType();
76.310 + if (t == Integer.TYPE) {
76.311 + int[] arr = (int[]) array;
76.312 + return arr[index];
76.313 + }
76.314 + return getShort(array, index);
76.315 + }
76.316 +
76.317 + /**
76.318 + * Returns the value of the indexed component in the specified
76.319 + * array object, as a {@code long}.
76.320 + *
76.321 + * @param array the array
76.322 + * @param index the index
76.323 + * @return the value of the indexed component in the specified array
76.324 + * @exception NullPointerException If the specified object is null
76.325 + * @exception IllegalArgumentException If the specified object is not
76.326 + * an array, or if the indexed element cannot be converted to the
76.327 + * return type by an identity or widening conversion
76.328 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.329 + * argument is negative, or if it is greater than or equal to the
76.330 + * length of the specified array
76.331 + * @see Array#get
76.332 + */
76.333 + public static long getLong(Object array, int index)
76.334 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.335 + final Class<?> t = array.getClass().getComponentType();
76.336 + if (t == Long.TYPE) {
76.337 + long[] arr = (long[]) array;
76.338 + return arr[index];
76.339 + }
76.340 + return getInt(array, index);
76.341 + }
76.342 +
76.343 + /**
76.344 + * Returns the value of the indexed component in the specified
76.345 + * array object, as a {@code float}.
76.346 + *
76.347 + * @param array the array
76.348 + * @param index the index
76.349 + * @return the value of the indexed component in the specified array
76.350 + * @exception NullPointerException If the specified object is null
76.351 + * @exception IllegalArgumentException If the specified object is not
76.352 + * an array, or if the indexed element cannot be converted to the
76.353 + * return type by an identity or widening conversion
76.354 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.355 + * argument is negative, or if it is greater than or equal to the
76.356 + * length of the specified array
76.357 + * @see Array#get
76.358 + */
76.359 + public static float getFloat(Object array, int index)
76.360 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.361 + final Class<?> t = array.getClass().getComponentType();
76.362 + if (t == Float.TYPE) {
76.363 + float[] arr = (float[]) array;
76.364 + return arr[index];
76.365 + }
76.366 + return getLong(array, index);
76.367 + }
76.368 +
76.369 + /**
76.370 + * Returns the value of the indexed component in the specified
76.371 + * array object, as a {@code double}.
76.372 + *
76.373 + * @param array the array
76.374 + * @param index the index
76.375 + * @return the value of the indexed component in the specified array
76.376 + * @exception NullPointerException If the specified object is null
76.377 + * @exception IllegalArgumentException If the specified object is not
76.378 + * an array, or if the indexed element cannot be converted to the
76.379 + * return type by an identity or widening conversion
76.380 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.381 + * argument is negative, or if it is greater than or equal to the
76.382 + * length of the specified array
76.383 + * @see Array#get
76.384 + */
76.385 + public static double getDouble(Object array, int index)
76.386 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.387 + final Class<?> t = array.getClass().getComponentType();
76.388 + if (t == Double.TYPE) {
76.389 + double[] arr = (double[]) array;
76.390 + return arr[index];
76.391 + }
76.392 + return getFloat(array, index);
76.393 + }
76.394 +
76.395 + /**
76.396 + * Sets the value of the indexed component of the specified array
76.397 + * object to the specified new value. The new value is first
76.398 + * automatically unwrapped if the array has a primitive component
76.399 + * type.
76.400 + * @param array the array
76.401 + * @param index the index into the array
76.402 + * @param value the new value of the indexed component
76.403 + * @exception NullPointerException If the specified object argument
76.404 + * is null
76.405 + * @exception IllegalArgumentException If the specified object argument
76.406 + * is not an array, or if the array component type is primitive and
76.407 + * an unwrapping conversion fails
76.408 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.409 + * argument is negative, or if it is greater than or equal to
76.410 + * the length of the specified array
76.411 + */
76.412 + public static void set(Object array, int index, Object value)
76.413 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.414 + if (array.getClass().getComponentType().isPrimitive()) {
76.415 + throw new IllegalArgumentException();
76.416 + } else {
76.417 + Object[] arr = (Object[])array;
76.418 + arr[index] = value;
76.419 + }
76.420 + }
76.421 +
76.422 + /**
76.423 + * Sets the value of the indexed component of the specified array
76.424 + * object to the specified {@code boolean} value.
76.425 + * @param array the array
76.426 + * @param index the index into the array
76.427 + * @param z the new value of the indexed component
76.428 + * @exception NullPointerException If the specified object argument
76.429 + * is null
76.430 + * @exception IllegalArgumentException If the specified object argument
76.431 + * is not an array, or if the specified value cannot be converted
76.432 + * to the underlying array's component type by an identity or a
76.433 + * primitive widening conversion
76.434 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.435 + * argument is negative, or if it is greater than or equal to
76.436 + * the length of the specified array
76.437 + * @see Array#set
76.438 + */
76.439 + public static native void setBoolean(Object array, int index, boolean z)
76.440 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
76.441 +
76.442 + /**
76.443 + * Sets the value of the indexed component of the specified array
76.444 + * object to the specified {@code byte} value.
76.445 + * @param array the array
76.446 + * @param index the index into the array
76.447 + * @param b the new value of the indexed component
76.448 + * @exception NullPointerException If the specified object argument
76.449 + * is null
76.450 + * @exception IllegalArgumentException If the specified object argument
76.451 + * is not an array, or if the specified value cannot be converted
76.452 + * to the underlying array's component type by an identity or a
76.453 + * primitive widening conversion
76.454 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.455 + * argument is negative, or if it is greater than or equal to
76.456 + * the length of the specified array
76.457 + * @see Array#set
76.458 + */
76.459 + public static void setByte(Object array, int index, byte b)
76.460 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.461 + Class<?> t = array.getClass().getComponentType();
76.462 + if (t == Byte.TYPE) {
76.463 + byte[] arr = (byte[]) array;
76.464 + arr[index] = b;
76.465 + } else {
76.466 + setShort(array, index, b);
76.467 + }
76.468 + }
76.469 +
76.470 + /**
76.471 + * Sets the value of the indexed component of the specified array
76.472 + * object to the specified {@code char} value.
76.473 + * @param array the array
76.474 + * @param index the index into the array
76.475 + * @param c the new value of the indexed component
76.476 + * @exception NullPointerException If the specified object argument
76.477 + * is null
76.478 + * @exception IllegalArgumentException If the specified object argument
76.479 + * is not an array, or if the specified value cannot be converted
76.480 + * to the underlying array's component type by an identity or a
76.481 + * primitive widening conversion
76.482 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.483 + * argument is negative, or if it is greater than or equal to
76.484 + * the length of the specified array
76.485 + * @see Array#set
76.486 + */
76.487 + public static native void setChar(Object array, int index, char c)
76.488 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
76.489 +
76.490 + /**
76.491 + * Sets the value of the indexed component of the specified array
76.492 + * object to the specified {@code short} value.
76.493 + * @param array the array
76.494 + * @param index the index into the array
76.495 + * @param s the new value of the indexed component
76.496 + * @exception NullPointerException If the specified object argument
76.497 + * is null
76.498 + * @exception IllegalArgumentException If the specified object argument
76.499 + * is not an array, or if the specified value cannot be converted
76.500 + * to the underlying array's component type by an identity or a
76.501 + * primitive widening conversion
76.502 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.503 + * argument is negative, or if it is greater than or equal to
76.504 + * the length of the specified array
76.505 + * @see Array#set
76.506 + */
76.507 + public static void setShort(Object array, int index, short s)
76.508 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.509 + Class<?> t = array.getClass().getComponentType();
76.510 + if (t == Short.TYPE) {
76.511 + short[] arr = (short[]) array;
76.512 + arr[index] = s;
76.513 + } else {
76.514 + setInt(array, index, s);
76.515 + }
76.516 +
76.517 + }
76.518 +
76.519 + /**
76.520 + * Sets the value of the indexed component of the specified array
76.521 + * object to the specified {@code int} value.
76.522 + * @param array the array
76.523 + * @param index the index into the array
76.524 + * @param i the new value of the indexed component
76.525 + * @exception NullPointerException If the specified object argument
76.526 + * is null
76.527 + * @exception IllegalArgumentException If the specified object argument
76.528 + * is not an array, or if the specified value cannot be converted
76.529 + * to the underlying array's component type by an identity or a
76.530 + * primitive widening conversion
76.531 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.532 + * argument is negative, or if it is greater than or equal to
76.533 + * the length of the specified array
76.534 + * @see Array#set
76.535 + */
76.536 + public static void setInt(Object array, int index, int i)
76.537 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.538 + Class<?> t = array.getClass().getComponentType();
76.539 + if (t == Integer.TYPE) {
76.540 + long[] arr = (long[]) array;
76.541 + arr[index] = i;
76.542 + } else {
76.543 + setLong(array, index, i);
76.544 + }
76.545 + }
76.546 +
76.547 + /**
76.548 + * Sets the value of the indexed component of the specified array
76.549 + * object to the specified {@code long} value.
76.550 + * @param array the array
76.551 + * @param index the index into the array
76.552 + * @param l the new value of the indexed component
76.553 + * @exception NullPointerException If the specified object argument
76.554 + * is null
76.555 + * @exception IllegalArgumentException If the specified object argument
76.556 + * is not an array, or if the specified value cannot be converted
76.557 + * to the underlying array's component type by an identity or a
76.558 + * primitive widening conversion
76.559 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.560 + * argument is negative, or if it is greater than or equal to
76.561 + * the length of the specified array
76.562 + * @see Array#set
76.563 + */
76.564 + public static void setLong(Object array, int index, long l)
76.565 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.566 + Class<?> t = array.getClass().getComponentType();
76.567 + if (t == Long.TYPE) {
76.568 + long[] arr = (long[]) array;
76.569 + arr[index] = l;
76.570 + } else {
76.571 + setFloat(array, index, l);
76.572 + }
76.573 + }
76.574 +
76.575 + /**
76.576 + * Sets the value of the indexed component of the specified array
76.577 + * object to the specified {@code float} value.
76.578 + * @param array the array
76.579 + * @param index the index into the array
76.580 + * @param f the new value of the indexed component
76.581 + * @exception NullPointerException If the specified object argument
76.582 + * is null
76.583 + * @exception IllegalArgumentException If the specified object argument
76.584 + * is not an array, or if the specified value cannot be converted
76.585 + * to the underlying array's component type by an identity or a
76.586 + * primitive widening conversion
76.587 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.588 + * argument is negative, or if it is greater than or equal to
76.589 + * the length of the specified array
76.590 + * @see Array#set
76.591 + */
76.592 + public static void setFloat(Object array, int index, float f)
76.593 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.594 + Class<?> t = array.getClass().getComponentType();
76.595 + if (t == Float.TYPE) {
76.596 + float[] arr = (float[])array;
76.597 + arr[index] = f;
76.598 + } else {
76.599 + setDouble(array, index, f);
76.600 + }
76.601 + }
76.602 +
76.603 + /**
76.604 + * Sets the value of the indexed component of the specified array
76.605 + * object to the specified {@code double} value.
76.606 + * @param array the array
76.607 + * @param index the index into the array
76.608 + * @param d the new value of the indexed component
76.609 + * @exception NullPointerException If the specified object argument
76.610 + * is null
76.611 + * @exception IllegalArgumentException If the specified object argument
76.612 + * is not an array, or if the specified value cannot be converted
76.613 + * to the underlying array's component type by an identity or a
76.614 + * primitive widening conversion
76.615 + * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
76.616 + * argument is negative, or if it is greater than or equal to
76.617 + * the length of the specified array
76.618 + * @see Array#set
76.619 + */
76.620 + public static void setDouble(Object array, int index, double d)
76.621 + throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
76.622 + Class<?> t = array.getClass().getComponentType();
76.623 + if (t == Double.TYPE) {
76.624 + double[] arr = (double[])array;
76.625 + arr[index] = d;
76.626 + } else {
76.627 + throw new IllegalArgumentException("argument type mismatch");
76.628 + }
76.629 + }
76.630 +
76.631 + /*
76.632 + * Private
76.633 + */
76.634 +
76.635 + @JavaScriptBody(args = { "primitive", "sig", "length" }, body =
76.636 + "var arr = new Array(length);\n"
76.637 + + "var value = primitive ? 0 : null;\n"
76.638 + + "for(var i = 0; i < length; i++) arr[i] = value;\n"
76.639 + + "arr.jvmName = sig;\n"
76.640 + + "return arr;"
76.641 + )
76.642 + private static native Object newArray(boolean primitive, String sig, int length);
76.643 +
76.644 + private static Object multiNewArray(String sig, int[] dims, int index)
76.645 + throws IllegalArgumentException, NegativeArraySizeException {
76.646 + if (dims.length == index + 1) {
76.647 + return newArray(sig.length() == 2, sig, dims[index]);
76.648 + }
76.649 + Object[] arr = (Object[]) newArray(false, sig, dims[index]);
76.650 + String compsig = sig.substring(1);
76.651 + for (int i = 0; i < arr.length; i++) {
76.652 + arr[i] = multiNewArray(compsig, dims, index + 1);
76.653 + }
76.654 + return arr;
76.655 + }
76.656 + private static Object fromPrimitive(Class<?> t, Object array, int index) {
76.657 + return Method.fromPrimitive(t, atArray(array, index));
76.658 + }
76.659 +
76.660 + @JavaScriptBody(args = { "array", "index" }, body = "return array[index]")
76.661 + private static native Object atArray(Object array, int index);
76.662 +}
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
77.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Field.java Wed Jan 23 20:39:23 2013 +0100
77.3 @@ -0,0 +1,953 @@
77.4 +/*
77.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
77.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
77.7 + *
77.8 + * This code is free software; you can redistribute it and/or modify it
77.9 + * under the terms of the GNU General Public License version 2 only, as
77.10 + * published by the Free Software Foundation. Oracle designates this
77.11 + * particular file as subject to the "Classpath" exception as provided
77.12 + * by Oracle in the LICENSE file that accompanied this code.
77.13 + *
77.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
77.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
77.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
77.17 + * version 2 for more details (a copy is included in the LICENSE file that
77.18 + * accompanied this code).
77.19 + *
77.20 + * You should have received a copy of the GNU General Public License version
77.21 + * 2 along with this work; if not, write to the Free Software Foundation,
77.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
77.23 + *
77.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
77.25 + * or visit www.oracle.com if you need additional information or have any
77.26 + * questions.
77.27 + */
77.28 +
77.29 +package java.lang.reflect;
77.30 +
77.31 +import java.lang.annotation.Annotation;
77.32 +
77.33 +
77.34 +/**
77.35 + * A {@code Field} provides information about, and dynamic access to, a
77.36 + * single field of a class or an interface. The reflected field may
77.37 + * be a class (static) field or an instance field.
77.38 + *
77.39 + * <p>A {@code Field} permits widening conversions to occur during a get or
77.40 + * set access operation, but throws an {@code IllegalArgumentException} if a
77.41 + * narrowing conversion would occur.
77.42 + *
77.43 + * @see Member
77.44 + * @see java.lang.Class
77.45 + * @see java.lang.Class#getFields()
77.46 + * @see java.lang.Class#getField(String)
77.47 + * @see java.lang.Class#getDeclaredFields()
77.48 + * @see java.lang.Class#getDeclaredField(String)
77.49 + *
77.50 + * @author Kenneth Russell
77.51 + * @author Nakul Saraiya
77.52 + */
77.53 +public final
77.54 +class Field extends AccessibleObject implements Member {
77.55 +
77.56 + private Class<?> clazz;
77.57 + private int slot;
77.58 + // This is guaranteed to be interned by the VM in the 1.4
77.59 + // reflection implementation
77.60 + private String name;
77.61 + private Class<?> type;
77.62 + private int modifiers;
77.63 + // Generics and annotations support
77.64 + private transient String signature;
77.65 + private byte[] annotations;
77.66 + // For sharing of FieldAccessors. This branching structure is
77.67 + // currently only two levels deep (i.e., one root Field and
77.68 + // potentially many Field objects pointing to it.)
77.69 + private Field root;
77.70 +
77.71 + // Generics infrastructure
77.72 +
77.73 + private String getGenericSignature() {return signature;}
77.74 +
77.75 +
77.76 + /**
77.77 + * Package-private constructor used by ReflectAccess to enable
77.78 + * instantiation of these objects in Java code from the java.lang
77.79 + * package via sun.reflect.LangReflectAccess.
77.80 + */
77.81 + Field(Class<?> declaringClass,
77.82 + String name,
77.83 + Class<?> type,
77.84 + int modifiers,
77.85 + int slot,
77.86 + String signature,
77.87 + byte[] annotations)
77.88 + {
77.89 + this.clazz = declaringClass;
77.90 + this.name = name;
77.91 + this.type = type;
77.92 + this.modifiers = modifiers;
77.93 + this.slot = slot;
77.94 + this.signature = signature;
77.95 + this.annotations = annotations;
77.96 + }
77.97 +
77.98 + /**
77.99 + * Package-private routine (exposed to java.lang.Class via
77.100 + * ReflectAccess) which returns a copy of this Field. The copy's
77.101 + * "root" field points to this Field.
77.102 + */
77.103 + Field copy() {
77.104 + // This routine enables sharing of FieldAccessor objects
77.105 + // among Field objects which refer to the same underlying
77.106 + // method in the VM. (All of this contortion is only necessary
77.107 + // because of the "accessibility" bit in AccessibleObject,
77.108 + // which implicitly requires that new java.lang.reflect
77.109 + // objects be fabricated for each reflective call on Class
77.110 + // objects.)
77.111 + Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
77.112 + res.root = this;
77.113 + return res;
77.114 + }
77.115 +
77.116 + /**
77.117 + * Returns the {@code Class} object representing the class or interface
77.118 + * that declares the field represented by this {@code Field} object.
77.119 + */
77.120 + public Class<?> getDeclaringClass() {
77.121 + return clazz;
77.122 + }
77.123 +
77.124 + /**
77.125 + * Returns the name of the field represented by this {@code Field} object.
77.126 + */
77.127 + public String getName() {
77.128 + return name;
77.129 + }
77.130 +
77.131 + /**
77.132 + * Returns the Java language modifiers for the field represented
77.133 + * by this {@code Field} object, as an integer. The {@code Modifier} class should
77.134 + * be used to decode the modifiers.
77.135 + *
77.136 + * @see Modifier
77.137 + */
77.138 + public int getModifiers() {
77.139 + return modifiers;
77.140 + }
77.141 +
77.142 + /**
77.143 + * Returns {@code true} if this field represents an element of
77.144 + * an enumerated type; returns {@code false} otherwise.
77.145 + *
77.146 + * @return {@code true} if and only if this field represents an element of
77.147 + * an enumerated type.
77.148 + * @since 1.5
77.149 + */
77.150 + public boolean isEnumConstant() {
77.151 + return (getModifiers() & Modifier.ENUM) != 0;
77.152 + }
77.153 +
77.154 + /**
77.155 + * Returns {@code true} if this field is a synthetic
77.156 + * field; returns {@code false} otherwise.
77.157 + *
77.158 + * @return true if and only if this field is a synthetic
77.159 + * field as defined by the Java Language Specification.
77.160 + * @since 1.5
77.161 + */
77.162 + public boolean isSynthetic() {
77.163 + return Modifier.isSynthetic(getModifiers());
77.164 + }
77.165 +
77.166 + /**
77.167 + * Returns a {@code Class} object that identifies the
77.168 + * declared type for the field represented by this
77.169 + * {@code Field} object.
77.170 + *
77.171 + * @return a {@code Class} object identifying the declared
77.172 + * type of the field represented by this object
77.173 + */
77.174 + public Class<?> getType() {
77.175 + return type;
77.176 + }
77.177 +
77.178 + /**
77.179 + * Returns a {@code Type} object that represents the declared type for
77.180 + * the field represented by this {@code Field} object.
77.181 + *
77.182 + * <p>If the {@code Type} is a parameterized type, the
77.183 + * {@code Type} object returned must accurately reflect the
77.184 + * actual type parameters used in the source code.
77.185 + *
77.186 + * <p>If the type of the underlying field is a type variable or a
77.187 + * parameterized type, it is created. Otherwise, it is resolved.
77.188 + *
77.189 + * @return a {@code Type} object that represents the declared type for
77.190 + * the field represented by this {@code Field} object
77.191 + * @throws GenericSignatureFormatError if the generic field
77.192 + * signature does not conform to the format specified in
77.193 + * <cite>The Java™ Virtual Machine Specification</cite>
77.194 + * @throws TypeNotPresentException if the generic type
77.195 + * signature of the underlying field refers to a non-existent
77.196 + * type declaration
77.197 + * @throws MalformedParameterizedTypeException if the generic
77.198 + * signature of the underlying field refers to a parameterized type
77.199 + * that cannot be instantiated for any reason
77.200 + * @since 1.5
77.201 + */
77.202 + public Type getGenericType() {
77.203 + throw new UnsupportedOperationException();
77.204 + }
77.205 +
77.206 +
77.207 + /**
77.208 + * Compares this {@code Field} against the specified object. Returns
77.209 + * true if the objects are the same. Two {@code Field} objects are the same if
77.210 + * they were declared by the same class and have the same name
77.211 + * and type.
77.212 + */
77.213 + public boolean equals(Object obj) {
77.214 + if (obj != null && obj instanceof Field) {
77.215 + Field other = (Field)obj;
77.216 + return (getDeclaringClass() == other.getDeclaringClass())
77.217 + && (getName() == other.getName())
77.218 + && (getType() == other.getType());
77.219 + }
77.220 + return false;
77.221 + }
77.222 +
77.223 + /**
77.224 + * Returns a hashcode for this {@code Field}. This is computed as the
77.225 + * exclusive-or of the hashcodes for the underlying field's
77.226 + * declaring class name and its name.
77.227 + */
77.228 + public int hashCode() {
77.229 + return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
77.230 + }
77.231 +
77.232 + /**
77.233 + * Returns a string describing this {@code Field}. The format is
77.234 + * the access modifiers for the field, if any, followed
77.235 + * by the field type, followed by a space, followed by
77.236 + * the fully-qualified name of the class declaring the field,
77.237 + * followed by a period, followed by the name of the field.
77.238 + * For example:
77.239 + * <pre>
77.240 + * public static final int java.lang.Thread.MIN_PRIORITY
77.241 + * private int java.io.FileDescriptor.fd
77.242 + * </pre>
77.243 + *
77.244 + * <p>The modifiers are placed in canonical order as specified by
77.245 + * "The Java Language Specification". This is {@code public},
77.246 + * {@code protected} or {@code private} first, and then other
77.247 + * modifiers in the following order: {@code static}, {@code final},
77.248 + * {@code transient}, {@code volatile}.
77.249 + */
77.250 + public String toString() {
77.251 + int mod = getModifiers();
77.252 + return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
77.253 + + getTypeName(getType()) + " "
77.254 + + getTypeName(getDeclaringClass()) + "."
77.255 + + getName());
77.256 + }
77.257 +
77.258 + /**
77.259 + * Returns a string describing this {@code Field}, including
77.260 + * its generic type. The format is the access modifiers for the
77.261 + * field, if any, followed by the generic field type, followed by
77.262 + * a space, followed by the fully-qualified name of the class
77.263 + * declaring the field, followed by a period, followed by the name
77.264 + * of the field.
77.265 + *
77.266 + * <p>The modifiers are placed in canonical order as specified by
77.267 + * "The Java Language Specification". This is {@code public},
77.268 + * {@code protected} or {@code private} first, and then other
77.269 + * modifiers in the following order: {@code static}, {@code final},
77.270 + * {@code transient}, {@code volatile}.
77.271 + *
77.272 + * @return a string describing this {@code Field}, including
77.273 + * its generic type
77.274 + *
77.275 + * @since 1.5
77.276 + */
77.277 + public String toGenericString() {
77.278 + int mod = getModifiers();
77.279 + Type fieldType = getGenericType();
77.280 + return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
77.281 + + ((fieldType instanceof Class) ?
77.282 + getTypeName((Class)fieldType): fieldType.toString())+ " "
77.283 + + getTypeName(getDeclaringClass()) + "."
77.284 + + getName());
77.285 + }
77.286 +
77.287 + /**
77.288 + * Returns the value of the field represented by this {@code Field}, on
77.289 + * the specified object. The value is automatically wrapped in an
77.290 + * object if it has a primitive type.
77.291 + *
77.292 + * <p>The underlying field's value is obtained as follows:
77.293 + *
77.294 + * <p>If the underlying field is a static field, the {@code obj} argument
77.295 + * is ignored; it may be null.
77.296 + *
77.297 + * <p>Otherwise, the underlying field is an instance field. If the
77.298 + * specified {@code obj} argument is null, the method throws a
77.299 + * {@code NullPointerException}. If the specified object is not an
77.300 + * instance of the class or interface declaring the underlying
77.301 + * field, the method throws an {@code IllegalArgumentException}.
77.302 + *
77.303 + * <p>If this {@code Field} object is enforcing Java language access control, and
77.304 + * the underlying field is inaccessible, the method throws an
77.305 + * {@code IllegalAccessException}.
77.306 + * If the underlying field is static, the class that declared the
77.307 + * field is initialized if it has not already been initialized.
77.308 + *
77.309 + * <p>Otherwise, the value is retrieved from the underlying instance
77.310 + * or static field. If the field has a primitive type, the value
77.311 + * is wrapped in an object before being returned, otherwise it is
77.312 + * returned as is.
77.313 + *
77.314 + * <p>If the field is hidden in the type of {@code obj},
77.315 + * the field's value is obtained according to the preceding rules.
77.316 + *
77.317 + * @param obj object from which the represented field's value is
77.318 + * to be extracted
77.319 + * @return the value of the represented field in object
77.320 + * {@code obj}; primitive values are wrapped in an appropriate
77.321 + * object before being returned
77.322 + *
77.323 + * @exception IllegalAccessException if this {@code Field} object
77.324 + * is enforcing Java language access control and the underlying
77.325 + * field is inaccessible.
77.326 + * @exception IllegalArgumentException if the specified object is not an
77.327 + * instance of the class or interface declaring the underlying
77.328 + * field (or a subclass or implementor thereof).
77.329 + * @exception NullPointerException if the specified object is null
77.330 + * and the field is an instance field.
77.331 + * @exception ExceptionInInitializerError if the initialization provoked
77.332 + * by this method fails.
77.333 + */
77.334 + public Object get(Object obj)
77.335 + throws IllegalArgumentException, IllegalAccessException
77.336 + {
77.337 + return getFieldAccessor(obj).get(obj);
77.338 + }
77.339 +
77.340 + /**
77.341 + * Gets the value of a static or instance {@code boolean} field.
77.342 + *
77.343 + * @param obj the object to extract the {@code boolean} value
77.344 + * from
77.345 + * @return the value of the {@code boolean} field
77.346 + *
77.347 + * @exception IllegalAccessException if this {@code Field} object
77.348 + * is enforcing Java language access control and the underlying
77.349 + * field is inaccessible.
77.350 + * @exception IllegalArgumentException if the specified object is not
77.351 + * an instance of the class or interface declaring the
77.352 + * underlying field (or a subclass or implementor
77.353 + * thereof), or if the field value cannot be
77.354 + * converted to the type {@code boolean} by a
77.355 + * widening conversion.
77.356 + * @exception NullPointerException if the specified object is null
77.357 + * and the field is an instance field.
77.358 + * @exception ExceptionInInitializerError if the initialization provoked
77.359 + * by this method fails.
77.360 + * @see Field#get
77.361 + */
77.362 + public boolean getBoolean(Object obj)
77.363 + throws IllegalArgumentException, IllegalAccessException
77.364 + {
77.365 + return getFieldAccessor(obj).getBoolean(obj);
77.366 + }
77.367 +
77.368 + /**
77.369 + * Gets the value of a static or instance {@code byte} field.
77.370 + *
77.371 + * @param obj the object to extract the {@code byte} value
77.372 + * from
77.373 + * @return the value of the {@code byte} field
77.374 + *
77.375 + * @exception IllegalAccessException if this {@code Field} object
77.376 + * is enforcing Java language access control and the underlying
77.377 + * field is inaccessible.
77.378 + * @exception IllegalArgumentException if the specified object is not
77.379 + * an instance of the class or interface declaring the
77.380 + * underlying field (or a subclass or implementor
77.381 + * thereof), or if the field value cannot be
77.382 + * converted to the type {@code byte} by a
77.383 + * widening conversion.
77.384 + * @exception NullPointerException if the specified object is null
77.385 + * and the field is an instance field.
77.386 + * @exception ExceptionInInitializerError if the initialization provoked
77.387 + * by this method fails.
77.388 + * @see Field#get
77.389 + */
77.390 + public byte getByte(Object obj)
77.391 + throws IllegalArgumentException, IllegalAccessException
77.392 + {
77.393 + return getFieldAccessor(obj).getByte(obj);
77.394 + }
77.395 +
77.396 + /**
77.397 + * Gets the value of a static or instance field of type
77.398 + * {@code char} or of another primitive type convertible to
77.399 + * type {@code char} via a widening conversion.
77.400 + *
77.401 + * @param obj the object to extract the {@code char} value
77.402 + * from
77.403 + * @return the value of the field converted to type {@code char}
77.404 + *
77.405 + * @exception IllegalAccessException if this {@code Field} object
77.406 + * is enforcing Java language access control and the underlying
77.407 + * field is inaccessible.
77.408 + * @exception IllegalArgumentException if the specified object is not
77.409 + * an instance of the class or interface declaring the
77.410 + * underlying field (or a subclass or implementor
77.411 + * thereof), or if the field value cannot be
77.412 + * converted to the type {@code char} by a
77.413 + * widening conversion.
77.414 + * @exception NullPointerException if the specified object is null
77.415 + * and the field is an instance field.
77.416 + * @exception ExceptionInInitializerError if the initialization provoked
77.417 + * by this method fails.
77.418 + * @see Field#get
77.419 + */
77.420 + public char getChar(Object obj)
77.421 + throws IllegalArgumentException, IllegalAccessException
77.422 + {
77.423 + return getFieldAccessor(obj).getChar(obj);
77.424 + }
77.425 +
77.426 + /**
77.427 + * Gets the value of a static or instance field of type
77.428 + * {@code short} or of another primitive type convertible to
77.429 + * type {@code short} via a widening conversion.
77.430 + *
77.431 + * @param obj the object to extract the {@code short} value
77.432 + * from
77.433 + * @return the value of the field converted to type {@code short}
77.434 + *
77.435 + * @exception IllegalAccessException if this {@code Field} object
77.436 + * is enforcing Java language access control and the underlying
77.437 + * field is inaccessible.
77.438 + * @exception IllegalArgumentException if the specified object is not
77.439 + * an instance of the class or interface declaring the
77.440 + * underlying field (or a subclass or implementor
77.441 + * thereof), or if the field value cannot be
77.442 + * converted to the type {@code short} by a
77.443 + * widening conversion.
77.444 + * @exception NullPointerException if the specified object is null
77.445 + * and the field is an instance field.
77.446 + * @exception ExceptionInInitializerError if the initialization provoked
77.447 + * by this method fails.
77.448 + * @see Field#get
77.449 + */
77.450 + public short getShort(Object obj)
77.451 + throws IllegalArgumentException, IllegalAccessException
77.452 + {
77.453 + return getFieldAccessor(obj).getShort(obj);
77.454 + }
77.455 +
77.456 + /**
77.457 + * Gets the value of a static or instance field of type
77.458 + * {@code int} or of another primitive type convertible to
77.459 + * type {@code int} via a widening conversion.
77.460 + *
77.461 + * @param obj the object to extract the {@code int} value
77.462 + * from
77.463 + * @return the value of the field converted to type {@code int}
77.464 + *
77.465 + * @exception IllegalAccessException if this {@code Field} object
77.466 + * is enforcing Java language access control and the underlying
77.467 + * field is inaccessible.
77.468 + * @exception IllegalArgumentException if the specified object is not
77.469 + * an instance of the class or interface declaring the
77.470 + * underlying field (or a subclass or implementor
77.471 + * thereof), or if the field value cannot be
77.472 + * converted to the type {@code int} by a
77.473 + * widening conversion.
77.474 + * @exception NullPointerException if the specified object is null
77.475 + * and the field is an instance field.
77.476 + * @exception ExceptionInInitializerError if the initialization provoked
77.477 + * by this method fails.
77.478 + * @see Field#get
77.479 + */
77.480 + public int getInt(Object obj)
77.481 + throws IllegalArgumentException, IllegalAccessException
77.482 + {
77.483 + return getFieldAccessor(obj).getInt(obj);
77.484 + }
77.485 +
77.486 + /**
77.487 + * Gets the value of a static or instance field of type
77.488 + * {@code long} or of another primitive type convertible to
77.489 + * type {@code long} via a widening conversion.
77.490 + *
77.491 + * @param obj the object to extract the {@code long} value
77.492 + * from
77.493 + * @return the value of the field converted to type {@code long}
77.494 + *
77.495 + * @exception IllegalAccessException if this {@code Field} object
77.496 + * is enforcing Java language access control and the underlying
77.497 + * field is inaccessible.
77.498 + * @exception IllegalArgumentException if the specified object is not
77.499 + * an instance of the class or interface declaring the
77.500 + * underlying field (or a subclass or implementor
77.501 + * thereof), or if the field value cannot be
77.502 + * converted to the type {@code long} by a
77.503 + * widening conversion.
77.504 + * @exception NullPointerException if the specified object is null
77.505 + * and the field is an instance field.
77.506 + * @exception ExceptionInInitializerError if the initialization provoked
77.507 + * by this method fails.
77.508 + * @see Field#get
77.509 + */
77.510 + public long getLong(Object obj)
77.511 + throws IllegalArgumentException, IllegalAccessException
77.512 + {
77.513 + return getFieldAccessor(obj).getLong(obj);
77.514 + }
77.515 +
77.516 + /**
77.517 + * Gets the value of a static or instance field of type
77.518 + * {@code float} or of another primitive type convertible to
77.519 + * type {@code float} via a widening conversion.
77.520 + *
77.521 + * @param obj the object to extract the {@code float} value
77.522 + * from
77.523 + * @return the value of the field converted to type {@code float}
77.524 + *
77.525 + * @exception IllegalAccessException if this {@code Field} object
77.526 + * is enforcing Java language access control and the underlying
77.527 + * field is inaccessible.
77.528 + * @exception IllegalArgumentException if the specified object is not
77.529 + * an instance of the class or interface declaring the
77.530 + * underlying field (or a subclass or implementor
77.531 + * thereof), or if the field value cannot be
77.532 + * converted to the type {@code float} by a
77.533 + * widening conversion.
77.534 + * @exception NullPointerException if the specified object is null
77.535 + * and the field is an instance field.
77.536 + * @exception ExceptionInInitializerError if the initialization provoked
77.537 + * by this method fails.
77.538 + * @see Field#get
77.539 + */
77.540 + public float getFloat(Object obj)
77.541 + throws IllegalArgumentException, IllegalAccessException
77.542 + {
77.543 + return getFieldAccessor(obj).getFloat(obj);
77.544 + }
77.545 +
77.546 + /**
77.547 + * Gets the value of a static or instance field of type
77.548 + * {@code double} or of another primitive type convertible to
77.549 + * type {@code double} via a widening conversion.
77.550 + *
77.551 + * @param obj the object to extract the {@code double} value
77.552 + * from
77.553 + * @return the value of the field converted to type {@code double}
77.554 + *
77.555 + * @exception IllegalAccessException if this {@code Field} object
77.556 + * is enforcing Java language access control and the underlying
77.557 + * field is inaccessible.
77.558 + * @exception IllegalArgumentException if the specified object is not
77.559 + * an instance of the class or interface declaring the
77.560 + * underlying field (or a subclass or implementor
77.561 + * thereof), or if the field value cannot be
77.562 + * converted to the type {@code double} by a
77.563 + * widening conversion.
77.564 + * @exception NullPointerException if the specified object is null
77.565 + * and the field is an instance field.
77.566 + * @exception ExceptionInInitializerError if the initialization provoked
77.567 + * by this method fails.
77.568 + * @see Field#get
77.569 + */
77.570 + public double getDouble(Object obj)
77.571 + throws IllegalArgumentException, IllegalAccessException
77.572 + {
77.573 + return getFieldAccessor(obj).getDouble(obj);
77.574 + }
77.575 +
77.576 + /**
77.577 + * Sets the field represented by this {@code Field} object on the
77.578 + * specified object argument to the specified new value. The new
77.579 + * value is automatically unwrapped if the underlying field has a
77.580 + * primitive type.
77.581 + *
77.582 + * <p>The operation proceeds as follows:
77.583 + *
77.584 + * <p>If the underlying field is static, the {@code obj} argument is
77.585 + * ignored; it may be null.
77.586 + *
77.587 + * <p>Otherwise the underlying field is an instance field. If the
77.588 + * specified object argument is null, the method throws a
77.589 + * {@code NullPointerException}. If the specified object argument is not
77.590 + * an instance of the class or interface declaring the underlying
77.591 + * field, the method throws an {@code IllegalArgumentException}.
77.592 + *
77.593 + * <p>If this {@code Field} object is enforcing Java language access control, and
77.594 + * the underlying field is inaccessible, the method throws an
77.595 + * {@code IllegalAccessException}.
77.596 + *
77.597 + * <p>If the underlying field is final, the method throws an
77.598 + * {@code IllegalAccessException} unless {@code setAccessible(true)}
77.599 + * has succeeded for this {@code Field} object
77.600 + * and the field is non-static. Setting a final field in this way
77.601 + * is meaningful only during deserialization or reconstruction of
77.602 + * instances of classes with blank final fields, before they are
77.603 + * made available for access by other parts of a program. Use in
77.604 + * any other context may have unpredictable effects, including cases
77.605 + * in which other parts of a program continue to use the original
77.606 + * value of this field.
77.607 + *
77.608 + * <p>If the underlying field is of a primitive type, an unwrapping
77.609 + * conversion is attempted to convert the new value to a value of
77.610 + * a primitive type. If this attempt fails, the method throws an
77.611 + * {@code IllegalArgumentException}.
77.612 + *
77.613 + * <p>If, after possible unwrapping, the new value cannot be
77.614 + * converted to the type of the underlying field by an identity or
77.615 + * widening conversion, the method throws an
77.616 + * {@code IllegalArgumentException}.
77.617 + *
77.618 + * <p>If the underlying field is static, the class that declared the
77.619 + * field is initialized if it has not already been initialized.
77.620 + *
77.621 + * <p>The field is set to the possibly unwrapped and widened new value.
77.622 + *
77.623 + * <p>If the field is hidden in the type of {@code obj},
77.624 + * the field's value is set according to the preceding rules.
77.625 + *
77.626 + * @param obj the object whose field should be modified
77.627 + * @param value the new value for the field of {@code obj}
77.628 + * being modified
77.629 + *
77.630 + * @exception IllegalAccessException if this {@code Field} object
77.631 + * is enforcing Java language access control and the underlying
77.632 + * field is either inaccessible or final.
77.633 + * @exception IllegalArgumentException if the specified object is not an
77.634 + * instance of the class or interface declaring the underlying
77.635 + * field (or a subclass or implementor thereof),
77.636 + * or if an unwrapping conversion fails.
77.637 + * @exception NullPointerException if the specified object is null
77.638 + * and the field is an instance field.
77.639 + * @exception ExceptionInInitializerError if the initialization provoked
77.640 + * by this method fails.
77.641 + */
77.642 + public void set(Object obj, Object value)
77.643 + throws IllegalArgumentException, IllegalAccessException
77.644 + {
77.645 + getFieldAccessor(obj).set(obj, value);
77.646 + }
77.647 +
77.648 + /**
77.649 + * Sets the value of a field as a {@code boolean} on the specified object.
77.650 + * This method is equivalent to
77.651 + * {@code set(obj, zObj)},
77.652 + * where {@code zObj} is a {@code Boolean} object and
77.653 + * {@code zObj.booleanValue() == z}.
77.654 + *
77.655 + * @param obj the object whose field should be modified
77.656 + * @param z the new value for the field of {@code obj}
77.657 + * being modified
77.658 + *
77.659 + * @exception IllegalAccessException if this {@code Field} object
77.660 + * is enforcing Java language access control and the underlying
77.661 + * field is either inaccessible or final.
77.662 + * @exception IllegalArgumentException if the specified object is not an
77.663 + * instance of the class or interface declaring the underlying
77.664 + * field (or a subclass or implementor thereof),
77.665 + * or if an unwrapping conversion fails.
77.666 + * @exception NullPointerException if the specified object is null
77.667 + * and the field is an instance field.
77.668 + * @exception ExceptionInInitializerError if the initialization provoked
77.669 + * by this method fails.
77.670 + * @see Field#set
77.671 + */
77.672 + public void setBoolean(Object obj, boolean z)
77.673 + throws IllegalArgumentException, IllegalAccessException
77.674 + {
77.675 + getFieldAccessor(obj).setBoolean(obj, z);
77.676 + }
77.677 +
77.678 + /**
77.679 + * Sets the value of a field as a {@code byte} on the specified object.
77.680 + * This method is equivalent to
77.681 + * {@code set(obj, bObj)},
77.682 + * where {@code bObj} is a {@code Byte} object and
77.683 + * {@code bObj.byteValue() == b}.
77.684 + *
77.685 + * @param obj the object whose field should be modified
77.686 + * @param b the new value for the field of {@code obj}
77.687 + * being modified
77.688 + *
77.689 + * @exception IllegalAccessException if this {@code Field} object
77.690 + * is enforcing Java language access control and the underlying
77.691 + * field is either inaccessible or final.
77.692 + * @exception IllegalArgumentException if the specified object is not an
77.693 + * instance of the class or interface declaring the underlying
77.694 + * field (or a subclass or implementor thereof),
77.695 + * or if an unwrapping conversion fails.
77.696 + * @exception NullPointerException if the specified object is null
77.697 + * and the field is an instance field.
77.698 + * @exception ExceptionInInitializerError if the initialization provoked
77.699 + * by this method fails.
77.700 + * @see Field#set
77.701 + */
77.702 + public void setByte(Object obj, byte b)
77.703 + throws IllegalArgumentException, IllegalAccessException
77.704 + {
77.705 + getFieldAccessor(obj).setByte(obj, b);
77.706 + }
77.707 +
77.708 + /**
77.709 + * Sets the value of a field as a {@code char} on the specified object.
77.710 + * This method is equivalent to
77.711 + * {@code set(obj, cObj)},
77.712 + * where {@code cObj} is a {@code Character} object and
77.713 + * {@code cObj.charValue() == c}.
77.714 + *
77.715 + * @param obj the object whose field should be modified
77.716 + * @param c the new value for the field of {@code obj}
77.717 + * being modified
77.718 + *
77.719 + * @exception IllegalAccessException if this {@code Field} object
77.720 + * is enforcing Java language access control and the underlying
77.721 + * field is either inaccessible or final.
77.722 + * @exception IllegalArgumentException if the specified object is not an
77.723 + * instance of the class or interface declaring the underlying
77.724 + * field (or a subclass or implementor thereof),
77.725 + * or if an unwrapping conversion fails.
77.726 + * @exception NullPointerException if the specified object is null
77.727 + * and the field is an instance field.
77.728 + * @exception ExceptionInInitializerError if the initialization provoked
77.729 + * by this method fails.
77.730 + * @see Field#set
77.731 + */
77.732 + public void setChar(Object obj, char c)
77.733 + throws IllegalArgumentException, IllegalAccessException
77.734 + {
77.735 + getFieldAccessor(obj).setChar(obj, c);
77.736 + }
77.737 +
77.738 + /**
77.739 + * Sets the value of a field as a {@code short} on the specified object.
77.740 + * This method is equivalent to
77.741 + * {@code set(obj, sObj)},
77.742 + * where {@code sObj} is a {@code Short} object and
77.743 + * {@code sObj.shortValue() == s}.
77.744 + *
77.745 + * @param obj the object whose field should be modified
77.746 + * @param s the new value for the field of {@code obj}
77.747 + * being modified
77.748 + *
77.749 + * @exception IllegalAccessException if this {@code Field} object
77.750 + * is enforcing Java language access control and the underlying
77.751 + * field is either inaccessible or final.
77.752 + * @exception IllegalArgumentException if the specified object is not an
77.753 + * instance of the class or interface declaring the underlying
77.754 + * field (or a subclass or implementor thereof),
77.755 + * or if an unwrapping conversion fails.
77.756 + * @exception NullPointerException if the specified object is null
77.757 + * and the field is an instance field.
77.758 + * @exception ExceptionInInitializerError if the initialization provoked
77.759 + * by this method fails.
77.760 + * @see Field#set
77.761 + */
77.762 + public void setShort(Object obj, short s)
77.763 + throws IllegalArgumentException, IllegalAccessException
77.764 + {
77.765 + getFieldAccessor(obj).setShort(obj, s);
77.766 + }
77.767 +
77.768 + /**
77.769 + * Sets the value of a field as an {@code int} on the specified object.
77.770 + * This method is equivalent to
77.771 + * {@code set(obj, iObj)},
77.772 + * where {@code iObj} is a {@code Integer} object and
77.773 + * {@code iObj.intValue() == i}.
77.774 + *
77.775 + * @param obj the object whose field should be modified
77.776 + * @param i the new value for the field of {@code obj}
77.777 + * being modified
77.778 + *
77.779 + * @exception IllegalAccessException if this {@code Field} object
77.780 + * is enforcing Java language access control and the underlying
77.781 + * field is either inaccessible or final.
77.782 + * @exception IllegalArgumentException if the specified object is not an
77.783 + * instance of the class or interface declaring the underlying
77.784 + * field (or a subclass or implementor thereof),
77.785 + * or if an unwrapping conversion fails.
77.786 + * @exception NullPointerException if the specified object is null
77.787 + * and the field is an instance field.
77.788 + * @exception ExceptionInInitializerError if the initialization provoked
77.789 + * by this method fails.
77.790 + * @see Field#set
77.791 + */
77.792 + public void setInt(Object obj, int i)
77.793 + throws IllegalArgumentException, IllegalAccessException
77.794 + {
77.795 + getFieldAccessor(obj).setInt(obj, i);
77.796 + }
77.797 +
77.798 + /**
77.799 + * Sets the value of a field as a {@code long} on the specified object.
77.800 + * This method is equivalent to
77.801 + * {@code set(obj, lObj)},
77.802 + * where {@code lObj} is a {@code Long} object and
77.803 + * {@code lObj.longValue() == l}.
77.804 + *
77.805 + * @param obj the object whose field should be modified
77.806 + * @param l the new value for the field of {@code obj}
77.807 + * being modified
77.808 + *
77.809 + * @exception IllegalAccessException if this {@code Field} object
77.810 + * is enforcing Java language access control and the underlying
77.811 + * field is either inaccessible or final.
77.812 + * @exception IllegalArgumentException if the specified object is not an
77.813 + * instance of the class or interface declaring the underlying
77.814 + * field (or a subclass or implementor thereof),
77.815 + * or if an unwrapping conversion fails.
77.816 + * @exception NullPointerException if the specified object is null
77.817 + * and the field is an instance field.
77.818 + * @exception ExceptionInInitializerError if the initialization provoked
77.819 + * by this method fails.
77.820 + * @see Field#set
77.821 + */
77.822 + public void setLong(Object obj, long l)
77.823 + throws IllegalArgumentException, IllegalAccessException
77.824 + {
77.825 + getFieldAccessor(obj).setLong(obj, l);
77.826 + }
77.827 +
77.828 + /**
77.829 + * Sets the value of a field as a {@code float} on the specified object.
77.830 + * This method is equivalent to
77.831 + * {@code set(obj, fObj)},
77.832 + * where {@code fObj} is a {@code Float} object and
77.833 + * {@code fObj.floatValue() == f}.
77.834 + *
77.835 + * @param obj the object whose field should be modified
77.836 + * @param f the new value for the field of {@code obj}
77.837 + * being modified
77.838 + *
77.839 + * @exception IllegalAccessException if this {@code Field} object
77.840 + * is enforcing Java language access control and the underlying
77.841 + * field is either inaccessible or final.
77.842 + * @exception IllegalArgumentException if the specified object is not an
77.843 + * instance of the class or interface declaring the underlying
77.844 + * field (or a subclass or implementor thereof),
77.845 + * or if an unwrapping conversion fails.
77.846 + * @exception NullPointerException if the specified object is null
77.847 + * and the field is an instance field.
77.848 + * @exception ExceptionInInitializerError if the initialization provoked
77.849 + * by this method fails.
77.850 + * @see Field#set
77.851 + */
77.852 + public void setFloat(Object obj, float f)
77.853 + throws IllegalArgumentException, IllegalAccessException
77.854 + {
77.855 + getFieldAccessor(obj).setFloat(obj, f);
77.856 + }
77.857 +
77.858 + /**
77.859 + * Sets the value of a field as a {@code double} on the specified object.
77.860 + * This method is equivalent to
77.861 + * {@code set(obj, dObj)},
77.862 + * where {@code dObj} is a {@code Double} object and
77.863 + * {@code dObj.doubleValue() == d}.
77.864 + *
77.865 + * @param obj the object whose field should be modified
77.866 + * @param d the new value for the field of {@code obj}
77.867 + * being modified
77.868 + *
77.869 + * @exception IllegalAccessException if this {@code Field} object
77.870 + * is enforcing Java language access control and the underlying
77.871 + * field is either inaccessible or final.
77.872 + * @exception IllegalArgumentException if the specified object is not an
77.873 + * instance of the class or interface declaring the underlying
77.874 + * field (or a subclass or implementor thereof),
77.875 + * or if an unwrapping conversion fails.
77.876 + * @exception NullPointerException if the specified object is null
77.877 + * and the field is an instance field.
77.878 + * @exception ExceptionInInitializerError if the initialization provoked
77.879 + * by this method fails.
77.880 + * @see Field#set
77.881 + */
77.882 + public void setDouble(Object obj, double d)
77.883 + throws IllegalArgumentException, IllegalAccessException
77.884 + {
77.885 + getFieldAccessor(obj).setDouble(obj, d);
77.886 + }
77.887 +
77.888 + // Convenience routine which performs security checks
77.889 + private FieldAccessor getFieldAccessor(Object obj)
77.890 + throws IllegalAccessException
77.891 + {
77.892 + throw new SecurityException();
77.893 + }
77.894 +
77.895 + private static abstract class FieldAccessor {
77.896 + abstract void setShort(Object obj, short s);
77.897 + abstract void setInt(Object obj, int i);
77.898 + abstract void setChar(Object obj, char c);
77.899 + abstract void setByte(Object obj, byte b);
77.900 + abstract void setBoolean(Object obj, boolean z);
77.901 + abstract void set(Object obj, Object value);
77.902 + abstract double getDouble(Object obj);
77.903 + abstract void setLong(Object obj, long l);
77.904 + abstract void setFloat(Object obj, float f);
77.905 + abstract void setDouble(Object obj, double d);
77.906 + abstract long getLong(Object obj);
77.907 + abstract int getInt(Object obj);
77.908 + abstract short getShort(Object obj);
77.909 + abstract char getChar(Object obj);
77.910 + abstract byte getByte(Object obj);
77.911 + abstract boolean getBoolean(Object obj);
77.912 + abstract Object get(Object obj);
77.913 + abstract float getFloat(Object obj);
77.914 + }
77.915 +
77.916 + /*
77.917 + * Utility routine to paper over array type names
77.918 + */
77.919 + static String getTypeName(Class<?> type) {
77.920 + if (type.isArray()) {
77.921 + try {
77.922 + Class<?> cl = type;
77.923 + int dimensions = 0;
77.924 + while (cl.isArray()) {
77.925 + dimensions++;
77.926 + cl = cl.getComponentType();
77.927 + }
77.928 + StringBuffer sb = new StringBuffer();
77.929 + sb.append(cl.getName());
77.930 + for (int i = 0; i < dimensions; i++) {
77.931 + sb.append("[]");
77.932 + }
77.933 + return sb.toString();
77.934 + } catch (Throwable e) { /*FALLTHRU*/ }
77.935 + }
77.936 + return type.getName();
77.937 + }
77.938 +
77.939 + /**
77.940 + * @throws NullPointerException {@inheritDoc}
77.941 + * @since 1.5
77.942 + */
77.943 + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
77.944 + if (annotationClass == null)
77.945 + throw new NullPointerException();
77.946 +
77.947 + throw new UnsupportedOperationException();
77.948 + }
77.949 +
77.950 + /**
77.951 + * @since 1.5
77.952 + */
77.953 + public Annotation[] getDeclaredAnnotations() {
77.954 + throw new UnsupportedOperationException();
77.955 + }
77.956 +}
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
78.2 +++ b/emul/mini/src/main/java/java/lang/reflect/GenericDeclaration.java Wed Jan 23 20:39:23 2013 +0100
78.3 @@ -0,0 +1,49 @@
78.4 +/*
78.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
78.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
78.7 + *
78.8 + * This code is free software; you can redistribute it and/or modify it
78.9 + * under the terms of the GNU General Public License version 2 only, as
78.10 + * published by the Free Software Foundation. Oracle designates this
78.11 + * particular file as subject to the "Classpath" exception as provided
78.12 + * by Oracle in the LICENSE file that accompanied this code.
78.13 + *
78.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
78.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78.17 + * version 2 for more details (a copy is included in the LICENSE file that
78.18 + * accompanied this code).
78.19 + *
78.20 + * You should have received a copy of the GNU General Public License version
78.21 + * 2 along with this work; if not, write to the Free Software Foundation,
78.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
78.23 + *
78.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
78.25 + * or visit www.oracle.com if you need additional information or have any
78.26 + * questions.
78.27 + */
78.28 +
78.29 +package java.lang.reflect;
78.30 +
78.31 +/**
78.32 + * A common interface for all entities that declare type variables.
78.33 + *
78.34 + * @since 1.5
78.35 + */
78.36 +public interface GenericDeclaration {
78.37 + /**
78.38 + * Returns an array of {@code TypeVariable} objects that
78.39 + * represent the type variables declared by the generic
78.40 + * declaration represented by this {@code GenericDeclaration}
78.41 + * object, in declaration order. Returns an array of length 0 if
78.42 + * the underlying generic declaration declares no type variables.
78.43 + *
78.44 + * @return an array of {@code TypeVariable} objects that represent
78.45 + * the type variables declared by this generic declaration
78.46 + * @throws GenericSignatureFormatError if the generic
78.47 + * signature of this generic declaration does not conform to
78.48 + * the format specified in
78.49 + * <cite>The Java™ Virtual Machine Specification</cite>
78.50 + */
78.51 + public TypeVariable<?>[] getTypeParameters();
78.52 +}
79.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
79.2 +++ b/emul/mini/src/main/java/java/lang/reflect/InvocationTargetException.java Wed Jan 23 20:39:23 2013 +0100
79.3 @@ -0,0 +1,111 @@
79.4 +/*
79.5 + * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
79.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
79.7 + *
79.8 + * This code is free software; you can redistribute it and/or modify it
79.9 + * under the terms of the GNU General Public License version 2 only, as
79.10 + * published by the Free Software Foundation. Oracle designates this
79.11 + * particular file as subject to the "Classpath" exception as provided
79.12 + * by Oracle in the LICENSE file that accompanied this code.
79.13 + *
79.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
79.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
79.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
79.17 + * version 2 for more details (a copy is included in the LICENSE file that
79.18 + * accompanied this code).
79.19 + *
79.20 + * You should have received a copy of the GNU General Public License version
79.21 + * 2 along with this work; if not, write to the Free Software Foundation,
79.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
79.23 + *
79.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
79.25 + * or visit www.oracle.com if you need additional information or have any
79.26 + * questions.
79.27 + */
79.28 +
79.29 +package java.lang.reflect;
79.30 +
79.31 +/**
79.32 + * InvocationTargetException is a checked exception that wraps
79.33 + * an exception thrown by an invoked method or constructor.
79.34 + *
79.35 + * <p>As of release 1.4, this exception has been retrofitted to conform to
79.36 + * the general purpose exception-chaining mechanism. The "target exception"
79.37 + * that is provided at construction time and accessed via the
79.38 + * {@link #getTargetException()} method is now known as the <i>cause</i>,
79.39 + * and may be accessed via the {@link Throwable#getCause()} method,
79.40 + * as well as the aforementioned "legacy method."
79.41 + *
79.42 + * @see Method
79.43 + * @see Constructor
79.44 + */
79.45 +public class InvocationTargetException extends ReflectiveOperationException {
79.46 + /**
79.47 + * Use serialVersionUID from JDK 1.1.X for interoperability
79.48 + */
79.49 + private static final long serialVersionUID = 4085088731926701167L;
79.50 +
79.51 + /**
79.52 + * This field holds the target if the
79.53 + * InvocationTargetException(Throwable target) constructor was
79.54 + * used to instantiate the object
79.55 + *
79.56 + * @serial
79.57 + *
79.58 + */
79.59 + private Throwable target;
79.60 +
79.61 + /**
79.62 + * Constructs an {@code InvocationTargetException} with
79.63 + * {@code null} as the target exception.
79.64 + */
79.65 + protected InvocationTargetException() {
79.66 + super((Throwable)null); // Disallow initCause
79.67 + }
79.68 +
79.69 + /**
79.70 + * Constructs a InvocationTargetException with a target exception.
79.71 + *
79.72 + * @param target the target exception
79.73 + */
79.74 + public InvocationTargetException(Throwable target) {
79.75 + super((Throwable)null); // Disallow initCause
79.76 + this.target = target;
79.77 + }
79.78 +
79.79 + /**
79.80 + * Constructs a InvocationTargetException with a target exception
79.81 + * and a detail message.
79.82 + *
79.83 + * @param target the target exception
79.84 + * @param s the detail message
79.85 + */
79.86 + public InvocationTargetException(Throwable target, String s) {
79.87 + super(s, null); // Disallow initCause
79.88 + this.target = target;
79.89 + }
79.90 +
79.91 + /**
79.92 + * Get the thrown target exception.
79.93 + *
79.94 + * <p>This method predates the general-purpose exception chaining facility.
79.95 + * The {@link Throwable#getCause()} method is now the preferred means of
79.96 + * obtaining this information.
79.97 + *
79.98 + * @return the thrown target exception (cause of this exception).
79.99 + */
79.100 + public Throwable getTargetException() {
79.101 + return target;
79.102 + }
79.103 +
79.104 + /**
79.105 + * Returns the cause of this exception (the thrown target exception,
79.106 + * which may be {@code null}).
79.107 + *
79.108 + * @return the cause of this exception.
79.109 + * @since 1.4
79.110 + */
79.111 + public Throwable getCause() {
79.112 + return target;
79.113 + }
79.114 +}
80.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
80.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Member.java Wed Jan 23 20:39:23 2013 +0100
80.3 @@ -0,0 +1,93 @@
80.4 +/*
80.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
80.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
80.7 + *
80.8 + * This code is free software; you can redistribute it and/or modify it
80.9 + * under the terms of the GNU General Public License version 2 only, as
80.10 + * published by the Free Software Foundation. Oracle designates this
80.11 + * particular file as subject to the "Classpath" exception as provided
80.12 + * by Oracle in the LICENSE file that accompanied this code.
80.13 + *
80.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
80.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
80.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
80.17 + * version 2 for more details (a copy is included in the LICENSE file that
80.18 + * accompanied this code).
80.19 + *
80.20 + * You should have received a copy of the GNU General Public License version
80.21 + * 2 along with this work; if not, write to the Free Software Foundation,
80.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
80.23 + *
80.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
80.25 + * or visit www.oracle.com if you need additional information or have any
80.26 + * questions.
80.27 + */
80.28 +
80.29 +package java.lang.reflect;
80.30 +
80.31 +/**
80.32 + * Member is an interface that reflects identifying information about
80.33 + * a single member (a field or a method) or a constructor.
80.34 + *
80.35 + * @see java.lang.Class
80.36 + * @see Field
80.37 + * @see Method
80.38 + * @see Constructor
80.39 + *
80.40 + * @author Nakul Saraiya
80.41 + */
80.42 +public
80.43 +interface Member {
80.44 +
80.45 + /**
80.46 + * Identifies the set of all public members of a class or interface,
80.47 + * including inherited members.
80.48 + * @see java.lang.SecurityManager#checkMemberAccess
80.49 + */
80.50 + public static final int PUBLIC = 0;
80.51 +
80.52 + /**
80.53 + * Identifies the set of declared members of a class or interface.
80.54 + * Inherited members are not included.
80.55 + * @see java.lang.SecurityManager#checkMemberAccess
80.56 + */
80.57 + public static final int DECLARED = 1;
80.58 +
80.59 + /**
80.60 + * Returns the Class object representing the class or interface
80.61 + * that declares the member or constructor represented by this Member.
80.62 + *
80.63 + * @return an object representing the declaring class of the
80.64 + * underlying member
80.65 + */
80.66 + public Class<?> getDeclaringClass();
80.67 +
80.68 + /**
80.69 + * Returns the simple name of the underlying member or constructor
80.70 + * represented by this Member.
80.71 + *
80.72 + * @return the simple name of the underlying member
80.73 + */
80.74 + public String getName();
80.75 +
80.76 + /**
80.77 + * Returns the Java language modifiers for the member or
80.78 + * constructor represented by this Member, as an integer. The
80.79 + * Modifier class should be used to decode the modifiers in
80.80 + * the integer.
80.81 + *
80.82 + * @return the Java language modifiers for the underlying member
80.83 + * @see Modifier
80.84 + */
80.85 + public int getModifiers();
80.86 +
80.87 + /**
80.88 + * Returns {@code true} if this member was introduced by
80.89 + * the compiler; returns {@code false} otherwise.
80.90 + *
80.91 + * @return true if and only if this member was introduced by
80.92 + * the compiler.
80.93 + * @since 1.5
80.94 + */
80.95 + public boolean isSynthetic();
80.96 +}
81.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
81.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Method.java Wed Jan 23 20:39:23 2013 +0100
81.3 @@ -0,0 +1,720 @@
81.4 +/*
81.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
81.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
81.7 + *
81.8 + * This code is free software; you can redistribute it and/or modify it
81.9 + * under the terms of the GNU General Public License version 2 only, as
81.10 + * published by the Free Software Foundation. Oracle designates this
81.11 + * particular file as subject to the "Classpath" exception as provided
81.12 + * by Oracle in the LICENSE file that accompanied this code.
81.13 + *
81.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
81.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
81.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
81.17 + * version 2 for more details (a copy is included in the LICENSE file that
81.18 + * accompanied this code).
81.19 + *
81.20 + * You should have received a copy of the GNU General Public License version
81.21 + * 2 along with this work; if not, write to the Free Software Foundation,
81.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
81.23 + *
81.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
81.25 + * or visit www.oracle.com if you need additional information or have any
81.26 + * questions.
81.27 + */
81.28 +
81.29 +package java.lang.reflect;
81.30 +
81.31 +import java.lang.annotation.Annotation;
81.32 +import java.util.Enumeration;
81.33 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
81.34 +import org.apidesign.bck2brwsr.emul.AnnotationImpl;
81.35 +import org.apidesign.bck2brwsr.emul.MethodImpl;
81.36 +
81.37 +/**
81.38 + * A {@code Method} provides information about, and access to, a single method
81.39 + * on a class or interface. The reflected method may be a class method
81.40 + * or an instance method (including an abstract method).
81.41 + *
81.42 + * <p>A {@code Method} permits widening conversions to occur when matching the
81.43 + * actual parameters to invoke with the underlying method's formal
81.44 + * parameters, but it throws an {@code IllegalArgumentException} if a
81.45 + * narrowing conversion would occur.
81.46 + *
81.47 + * @see Member
81.48 + * @see java.lang.Class
81.49 + * @see java.lang.Class#getMethods()
81.50 + * @see java.lang.Class#getMethod(String, Class[])
81.51 + * @see java.lang.Class#getDeclaredMethods()
81.52 + * @see java.lang.Class#getDeclaredMethod(String, Class[])
81.53 + *
81.54 + * @author Kenneth Russell
81.55 + * @author Nakul Saraiya
81.56 + */
81.57 +public final
81.58 + class Method extends AccessibleObject implements GenericDeclaration,
81.59 + Member {
81.60 + private final Class<?> clazz;
81.61 + private final String name;
81.62 + private final Object data;
81.63 + private final String sig;
81.64 +
81.65 + // Generics infrastructure
81.66 +
81.67 + private String getGenericSignature() {return null;}
81.68 +
81.69 + /**
81.70 + * Package-private constructor used by ReflectAccess to enable
81.71 + * instantiation of these objects in Java code from the java.lang
81.72 + * package via sun.reflect.LangReflectAccess.
81.73 + */
81.74 + Method(Class<?> declaringClass, String name, Object data, String sig)
81.75 + {
81.76 + this.clazz = declaringClass;
81.77 + this.name = name;
81.78 + this.data = data;
81.79 + this.sig = sig;
81.80 + }
81.81 +
81.82 + /**
81.83 + * Package-private routine (exposed to java.lang.Class via
81.84 + * ReflectAccess) which returns a copy of this Method. The copy's
81.85 + * "root" field points to this Method.
81.86 + */
81.87 + Method copy() {
81.88 + return this;
81.89 + }
81.90 +
81.91 + /**
81.92 + * Returns the {@code Class} object representing the class or interface
81.93 + * that declares the method represented by this {@code Method} object.
81.94 + */
81.95 + public Class<?> getDeclaringClass() {
81.96 + return clazz;
81.97 + }
81.98 +
81.99 + /**
81.100 + * Returns the name of the method represented by this {@code Method}
81.101 + * object, as a {@code String}.
81.102 + */
81.103 + public String getName() {
81.104 + return name;
81.105 + }
81.106 +
81.107 + /**
81.108 + * Returns the Java language modifiers for the method represented
81.109 + * by this {@code Method} object, as an integer. The {@code Modifier} class should
81.110 + * be used to decode the modifiers.
81.111 + *
81.112 + * @see Modifier
81.113 + */
81.114 + public int getModifiers() {
81.115 + return getAccess(data);
81.116 + }
81.117 +
81.118 + @JavaScriptBody(args = "self", body = "return self.access;")
81.119 + private static native int getAccess(Object self);
81.120 +
81.121 + /**
81.122 + * Returns an array of {@code TypeVariable} objects that represent the
81.123 + * type variables declared by the generic declaration represented by this
81.124 + * {@code GenericDeclaration} object, in declaration order. Returns an
81.125 + * array of length 0 if the underlying generic declaration declares no type
81.126 + * variables.
81.127 + *
81.128 + * @return an array of {@code TypeVariable} objects that represent
81.129 + * the type variables declared by this generic declaration
81.130 + * @throws GenericSignatureFormatError if the generic
81.131 + * signature of this generic declaration does not conform to
81.132 + * the format specified in
81.133 + * <cite>The Java™ Virtual Machine Specification</cite>
81.134 + * @since 1.5
81.135 + */
81.136 + public TypeVariable<Method>[] getTypeParameters() {
81.137 + throw new UnsupportedOperationException();
81.138 + }
81.139 +
81.140 + /**
81.141 + * Returns a {@code Class} object that represents the formal return type
81.142 + * of the method represented by this {@code Method} object.
81.143 + *
81.144 + * @return the return type for the method this object represents
81.145 + */
81.146 + public Class<?> getReturnType() {
81.147 + return MethodImpl.signatureParser(sig).nextElement();
81.148 + }
81.149 +
81.150 + /**
81.151 + * Returns a {@code Type} object that represents the formal return
81.152 + * type of the method represented by this {@code Method} object.
81.153 + *
81.154 + * <p>If the return type is a parameterized type,
81.155 + * the {@code Type} object returned must accurately reflect
81.156 + * the actual type parameters used in the source code.
81.157 + *
81.158 + * <p>If the return type is a type variable or a parameterized type, it
81.159 + * is created. Otherwise, it is resolved.
81.160 + *
81.161 + * @return a {@code Type} object that represents the formal return
81.162 + * type of the underlying method
81.163 + * @throws GenericSignatureFormatError
81.164 + * if the generic method signature does not conform to the format
81.165 + * specified in
81.166 + * <cite>The Java™ Virtual Machine Specification</cite>
81.167 + * @throws TypeNotPresentException if the underlying method's
81.168 + * return type refers to a non-existent type declaration
81.169 + * @throws MalformedParameterizedTypeException if the
81.170 + * underlying method's return typed refers to a parameterized
81.171 + * type that cannot be instantiated for any reason
81.172 + * @since 1.5
81.173 + */
81.174 + public Type getGenericReturnType() {
81.175 + throw new UnsupportedOperationException();
81.176 + }
81.177 +
81.178 +
81.179 + /**
81.180 + * Returns an array of {@code Class} objects that represent the formal
81.181 + * parameter types, in declaration order, of the method
81.182 + * represented by this {@code Method} object. Returns an array of length
81.183 + * 0 if the underlying method takes no parameters.
81.184 + *
81.185 + * @return the parameter types for the method this object
81.186 + * represents
81.187 + */
81.188 + public Class<?>[] getParameterTypes() {
81.189 + Class[] arr = new Class[MethodImpl.signatureElements(sig) - 1];
81.190 + Enumeration<Class> en = MethodImpl.signatureParser(sig);
81.191 + en.nextElement(); // return type
81.192 + for (int i = 0; i < arr.length; i++) {
81.193 + arr[i] = en.nextElement();
81.194 + }
81.195 + return arr;
81.196 + }
81.197 +
81.198 + /**
81.199 + * Returns an array of {@code Type} objects that represent the formal
81.200 + * parameter types, in declaration order, of the method represented by
81.201 + * this {@code Method} object. Returns an array of length 0 if the
81.202 + * underlying method takes no parameters.
81.203 + *
81.204 + * <p>If a formal parameter type is a parameterized type,
81.205 + * the {@code Type} object returned for it must accurately reflect
81.206 + * the actual type parameters used in the source code.
81.207 + *
81.208 + * <p>If a formal parameter type is a type variable or a parameterized
81.209 + * type, it is created. Otherwise, it is resolved.
81.210 + *
81.211 + * @return an array of Types that represent the formal
81.212 + * parameter types of the underlying method, in declaration order
81.213 + * @throws GenericSignatureFormatError
81.214 + * if the generic method signature does not conform to the format
81.215 + * specified in
81.216 + * <cite>The Java™ Virtual Machine Specification</cite>
81.217 + * @throws TypeNotPresentException if any of the parameter
81.218 + * types of the underlying method refers to a non-existent type
81.219 + * declaration
81.220 + * @throws MalformedParameterizedTypeException if any of
81.221 + * the underlying method's parameter types refer to a parameterized
81.222 + * type that cannot be instantiated for any reason
81.223 + * @since 1.5
81.224 + */
81.225 + public Type[] getGenericParameterTypes() {
81.226 + throw new UnsupportedOperationException();
81.227 + }
81.228 +
81.229 +
81.230 + /**
81.231 + * Returns an array of {@code Class} objects that represent
81.232 + * the types of the exceptions declared to be thrown
81.233 + * by the underlying method
81.234 + * represented by this {@code Method} object. Returns an array of length
81.235 + * 0 if the method declares no exceptions in its {@code throws} clause.
81.236 + *
81.237 + * @return the exception types declared as being thrown by the
81.238 + * method this object represents
81.239 + */
81.240 + public Class<?>[] getExceptionTypes() {
81.241 + throw new UnsupportedOperationException();
81.242 + //return (Class<?>[]) exceptionTypes.clone();
81.243 + }
81.244 +
81.245 + /**
81.246 + * Returns an array of {@code Type} objects that represent the
81.247 + * exceptions declared to be thrown by this {@code Method} object.
81.248 + * Returns an array of length 0 if the underlying method declares
81.249 + * no exceptions in its {@code throws} clause.
81.250 + *
81.251 + * <p>If an exception type is a type variable or a parameterized
81.252 + * type, it is created. Otherwise, it is resolved.
81.253 + *
81.254 + * @return an array of Types that represent the exception types
81.255 + * thrown by the underlying method
81.256 + * @throws GenericSignatureFormatError
81.257 + * if the generic method signature does not conform to the format
81.258 + * specified in
81.259 + * <cite>The Java™ Virtual Machine Specification</cite>
81.260 + * @throws TypeNotPresentException if the underlying method's
81.261 + * {@code throws} clause refers to a non-existent type declaration
81.262 + * @throws MalformedParameterizedTypeException if
81.263 + * the underlying method's {@code throws} clause refers to a
81.264 + * parameterized type that cannot be instantiated for any reason
81.265 + * @since 1.5
81.266 + */
81.267 + public Type[] getGenericExceptionTypes() {
81.268 + throw new UnsupportedOperationException();
81.269 + }
81.270 +
81.271 + /**
81.272 + * Compares this {@code Method} against the specified object. Returns
81.273 + * true if the objects are the same. Two {@code Methods} are the same if
81.274 + * they were declared by the same class and have the same name
81.275 + * and formal parameter types and return type.
81.276 + */
81.277 + public boolean equals(Object obj) {
81.278 + if (obj != null && obj instanceof Method) {
81.279 + Method other = (Method)obj;
81.280 + return data == other.data;
81.281 + }
81.282 + return false;
81.283 + }
81.284 +
81.285 + /**
81.286 + * Returns a hashcode for this {@code Method}. The hashcode is computed
81.287 + * as the exclusive-or of the hashcodes for the underlying
81.288 + * method's declaring class name and the method's name.
81.289 + */
81.290 + public int hashCode() {
81.291 + return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
81.292 + }
81.293 +
81.294 + /**
81.295 + * Returns a string describing this {@code Method}. The string is
81.296 + * formatted as the method access modifiers, if any, followed by
81.297 + * the method return type, followed by a space, followed by the
81.298 + * class declaring the method, followed by a period, followed by
81.299 + * the method name, followed by a parenthesized, comma-separated
81.300 + * list of the method's formal parameter types. If the method
81.301 + * throws checked exceptions, the parameter list is followed by a
81.302 + * space, followed by the word throws followed by a
81.303 + * comma-separated list of the thrown exception types.
81.304 + * For example:
81.305 + * <pre>
81.306 + * public boolean java.lang.Object.equals(java.lang.Object)
81.307 + * </pre>
81.308 + *
81.309 + * <p>The access modifiers are placed in canonical order as
81.310 + * specified by "The Java Language Specification". This is
81.311 + * {@code public}, {@code protected} or {@code private} first,
81.312 + * and then other modifiers in the following order:
81.313 + * {@code abstract}, {@code static}, {@code final},
81.314 + * {@code synchronized}, {@code native}, {@code strictfp}.
81.315 + */
81.316 + public String toString() {
81.317 + try {
81.318 + StringBuilder sb = new StringBuilder();
81.319 + int mod = getModifiers() & Modifier.methodModifiers();
81.320 + if (mod != 0) {
81.321 + sb.append(Modifier.toString(mod)).append(' ');
81.322 + }
81.323 + sb.append(Field.getTypeName(getReturnType())).append(' ');
81.324 + sb.append(Field.getTypeName(getDeclaringClass())).append('.');
81.325 + sb.append(getName()).append('(');
81.326 + Class<?>[] params = getParameterTypes(); // avoid clone
81.327 + for (int j = 0; j < params.length; j++) {
81.328 + sb.append(Field.getTypeName(params[j]));
81.329 + if (j < (params.length - 1))
81.330 + sb.append(',');
81.331 + }
81.332 + sb.append(')');
81.333 + /*
81.334 + Class<?>[] exceptions = exceptionTypes; // avoid clone
81.335 + if (exceptions.length > 0) {
81.336 + sb.append(" throws ");
81.337 + for (int k = 0; k < exceptions.length; k++) {
81.338 + sb.append(exceptions[k].getName());
81.339 + if (k < (exceptions.length - 1))
81.340 + sb.append(',');
81.341 + }
81.342 + }
81.343 + */
81.344 + return sb.toString();
81.345 + } catch (Exception e) {
81.346 + return "<" + e + ">";
81.347 + }
81.348 + }
81.349 +
81.350 + /**
81.351 + * Returns a string describing this {@code Method}, including
81.352 + * type parameters. The string is formatted as the method access
81.353 + * modifiers, if any, followed by an angle-bracketed
81.354 + * comma-separated list of the method's type parameters, if any,
81.355 + * followed by the method's generic return type, followed by a
81.356 + * space, followed by the class declaring the method, followed by
81.357 + * a period, followed by the method name, followed by a
81.358 + * parenthesized, comma-separated list of the method's generic
81.359 + * formal parameter types.
81.360 + *
81.361 + * If this method was declared to take a variable number of
81.362 + * arguments, instead of denoting the last parameter as
81.363 + * "<tt><i>Type</i>[]</tt>", it is denoted as
81.364 + * "<tt><i>Type</i>...</tt>".
81.365 + *
81.366 + * A space is used to separate access modifiers from one another
81.367 + * and from the type parameters or return type. If there are no
81.368 + * type parameters, the type parameter list is elided; if the type
81.369 + * parameter list is present, a space separates the list from the
81.370 + * class name. If the method is declared to throw exceptions, the
81.371 + * parameter list is followed by a space, followed by the word
81.372 + * throws followed by a comma-separated list of the generic thrown
81.373 + * exception types. If there are no type parameters, the type
81.374 + * parameter list is elided.
81.375 + *
81.376 + * <p>The access modifiers are placed in canonical order as
81.377 + * specified by "The Java Language Specification". This is
81.378 + * {@code public}, {@code protected} or {@code private} first,
81.379 + * and then other modifiers in the following order:
81.380 + * {@code abstract}, {@code static}, {@code final},
81.381 + * {@code synchronized}, {@code native}, {@code strictfp}.
81.382 + *
81.383 + * @return a string describing this {@code Method},
81.384 + * include type parameters
81.385 + *
81.386 + * @since 1.5
81.387 + */
81.388 + public String toGenericString() {
81.389 + try {
81.390 + StringBuilder sb = new StringBuilder();
81.391 + int mod = getModifiers() & Modifier.methodModifiers();
81.392 + if (mod != 0) {
81.393 + sb.append(Modifier.toString(mod)).append(' ');
81.394 + }
81.395 + TypeVariable<?>[] typeparms = getTypeParameters();
81.396 + if (typeparms.length > 0) {
81.397 + boolean first = true;
81.398 + sb.append('<');
81.399 + for(TypeVariable<?> typeparm: typeparms) {
81.400 + if (!first)
81.401 + sb.append(',');
81.402 + // Class objects can't occur here; no need to test
81.403 + // and call Class.getName().
81.404 + sb.append(typeparm.toString());
81.405 + first = false;
81.406 + }
81.407 + sb.append("> ");
81.408 + }
81.409 +
81.410 + Type genRetType = getGenericReturnType();
81.411 + sb.append( ((genRetType instanceof Class<?>)?
81.412 + Field.getTypeName((Class<?>)genRetType):genRetType.toString()))
81.413 + .append(' ');
81.414 +
81.415 + sb.append(Field.getTypeName(getDeclaringClass())).append('.');
81.416 + sb.append(getName()).append('(');
81.417 + Type[] params = getGenericParameterTypes();
81.418 + for (int j = 0; j < params.length; j++) {
81.419 + String param = (params[j] instanceof Class)?
81.420 + Field.getTypeName((Class)params[j]):
81.421 + (params[j].toString());
81.422 + if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
81.423 + param = param.replaceFirst("\\[\\]$", "...");
81.424 + sb.append(param);
81.425 + if (j < (params.length - 1))
81.426 + sb.append(',');
81.427 + }
81.428 + sb.append(')');
81.429 + Type[] exceptions = getGenericExceptionTypes();
81.430 + if (exceptions.length > 0) {
81.431 + sb.append(" throws ");
81.432 + for (int k = 0; k < exceptions.length; k++) {
81.433 + sb.append((exceptions[k] instanceof Class)?
81.434 + ((Class)exceptions[k]).getName():
81.435 + exceptions[k].toString());
81.436 + if (k < (exceptions.length - 1))
81.437 + sb.append(',');
81.438 + }
81.439 + }
81.440 + return sb.toString();
81.441 + } catch (Exception e) {
81.442 + return "<" + e + ">";
81.443 + }
81.444 + }
81.445 +
81.446 + /**
81.447 + * Invokes the underlying method represented by this {@code Method}
81.448 + * object, on the specified object with the specified parameters.
81.449 + * Individual parameters are automatically unwrapped to match
81.450 + * primitive formal parameters, and both primitive and reference
81.451 + * parameters are subject to method invocation conversions as
81.452 + * necessary.
81.453 + *
81.454 + * <p>If the underlying method is static, then the specified {@code obj}
81.455 + * argument is ignored. It may be null.
81.456 + *
81.457 + * <p>If the number of formal parameters required by the underlying method is
81.458 + * 0, the supplied {@code args} array may be of length 0 or null.
81.459 + *
81.460 + * <p>If the underlying method is an instance method, it is invoked
81.461 + * using dynamic method lookup as documented in The Java Language
81.462 + * Specification, Second Edition, section 15.12.4.4; in particular,
81.463 + * overriding based on the runtime type of the target object will occur.
81.464 + *
81.465 + * <p>If the underlying method is static, the class that declared
81.466 + * the method is initialized if it has not already been initialized.
81.467 + *
81.468 + * <p>If the method completes normally, the value it returns is
81.469 + * returned to the caller of invoke; if the value has a primitive
81.470 + * type, it is first appropriately wrapped in an object. However,
81.471 + * if the value has the type of an array of a primitive type, the
81.472 + * elements of the array are <i>not</i> wrapped in objects; in
81.473 + * other words, an array of primitive type is returned. If the
81.474 + * underlying method return type is void, the invocation returns
81.475 + * null.
81.476 + *
81.477 + * @param obj the object the underlying method is invoked from
81.478 + * @param args the arguments used for the method call
81.479 + * @return the result of dispatching the method represented by
81.480 + * this object on {@code obj} with parameters
81.481 + * {@code args}
81.482 + *
81.483 + * @exception IllegalAccessException if this {@code Method} object
81.484 + * is enforcing Java language access control and the underlying
81.485 + * method is inaccessible.
81.486 + * @exception IllegalArgumentException if the method is an
81.487 + * instance method and the specified object argument
81.488 + * is not an instance of the class or interface
81.489 + * declaring the underlying method (or of a subclass
81.490 + * or implementor thereof); if the number of actual
81.491 + * and formal parameters differ; if an unwrapping
81.492 + * conversion for primitive arguments fails; or if,
81.493 + * after possible unwrapping, a parameter value
81.494 + * cannot be converted to the corresponding formal
81.495 + * parameter type by a method invocation conversion.
81.496 + * @exception InvocationTargetException if the underlying method
81.497 + * throws an exception.
81.498 + * @exception NullPointerException if the specified object is null
81.499 + * and the method is an instance method.
81.500 + * @exception ExceptionInInitializerError if the initialization
81.501 + * provoked by this method fails.
81.502 + */
81.503 + public Object invoke(Object obj, Object... args)
81.504 + throws IllegalAccessException, IllegalArgumentException,
81.505 + InvocationTargetException
81.506 + {
81.507 + final boolean isStatic = (getModifiers() & Modifier.STATIC) == 0;
81.508 + if (isStatic && obj == null) {
81.509 + throw new NullPointerException();
81.510 + }
81.511 + Class[] types = getParameterTypes();
81.512 + if (types.length != args.length) {
81.513 + throw new IllegalArgumentException("Types len " + types.length + " args: " + args.length);
81.514 + } else {
81.515 + args = args.clone();
81.516 + for (int i = 0; i < types.length; i++) {
81.517 + Class c = types[i];
81.518 + if (c.isPrimitive()) {
81.519 + args[i] = toPrimitive(c, args[i]);
81.520 + }
81.521 + }
81.522 + }
81.523 + Object res = invoke0(isStatic, this, obj, args);
81.524 + if (getReturnType().isPrimitive()) {
81.525 + res = fromPrimitive(getReturnType(), res);
81.526 + }
81.527 + return res;
81.528 + }
81.529 +
81.530 + @JavaScriptBody(args = { "st", "method", "self", "args" }, body =
81.531 + "var p;\n"
81.532 + + "if (st) {\n"
81.533 + + " p = new Array(1);\n"
81.534 + + " p[0] = self;\n"
81.535 + + " p = p.concat(args);\n"
81.536 + + "} else {\n"
81.537 + + " p = args;\n"
81.538 + + "}\n"
81.539 + + "return method.fld_data.apply(self, p);\n"
81.540 + )
81.541 + private static native Object invoke0(boolean isStatic, Method m, Object self, Object[] args);
81.542 +
81.543 + static Object fromPrimitive(Class<?> type, Object o) {
81.544 + if (type == Integer.TYPE) {
81.545 + return fromRaw(Integer.class, "valueOf__Ljava_lang_Integer_2I", o);
81.546 + }
81.547 + if (type == Long.TYPE) {
81.548 + return fromRaw(Long.class, "valueOf__Ljava_lang_Long_2J", o);
81.549 + }
81.550 + if (type == Double.TYPE) {
81.551 + return fromRaw(Double.class, "valueOf__Ljava_lang_Double_2D", o);
81.552 + }
81.553 + if (type == Float.TYPE) {
81.554 + return fromRaw(Float.class, "valueOf__Ljava_lang_Float_2F", o);
81.555 + }
81.556 + if (type == Byte.TYPE) {
81.557 + return fromRaw(Byte.class, "valueOf__Ljava_lang_Byte_2B", o);
81.558 + }
81.559 + if (type == Boolean.TYPE) {
81.560 + return fromRaw(Boolean.class, "valueOf__Ljava_lang_Boolean_2Z", o);
81.561 + }
81.562 + if (type == Short.TYPE) {
81.563 + return fromRaw(Short.class, "valueOf__Ljava_lang_Short_2S", o);
81.564 + }
81.565 + if (type == Character.TYPE) {
81.566 + return fromRaw(Character.class, "valueOf__Ljava_lang_Character_2C", o);
81.567 + }
81.568 + if (type.getName().equals("void")) {
81.569 + return null;
81.570 + }
81.571 + throw new IllegalStateException("Can't convert " + o);
81.572 + }
81.573 +
81.574 + @JavaScriptBody(args = { "cls", "m", "o" },
81.575 + body = "return cls.cnstr(false)[m](o);"
81.576 + )
81.577 + private static native Integer fromRaw(Class<?> cls, String m, Object o);
81.578 +
81.579 + private static Object toPrimitive(Class<?> type, Object o) {
81.580 + if (type == Integer.TYPE) {
81.581 + return toRaw("intValue__I", o);
81.582 + }
81.583 + if (type == Long.TYPE) {
81.584 + return toRaw("longValue__J", o);
81.585 + }
81.586 + if (type == Double.TYPE) {
81.587 + return toRaw("doubleValue__D", o);
81.588 + }
81.589 + if (type == Float.TYPE) {
81.590 + return toRaw("floatValue__F", o);
81.591 + }
81.592 + if (type == Byte.TYPE) {
81.593 + return toRaw("byteValue__B", o);
81.594 + }
81.595 + if (type == Boolean.TYPE) {
81.596 + return toRaw("booleanValue__Z", o);
81.597 + }
81.598 + if (type == Short.TYPE) {
81.599 + return toRaw("shortValue__S", o);
81.600 + }
81.601 + if (type == Character.TYPE) {
81.602 + return toRaw("charValue__C", o);
81.603 + }
81.604 + if (type.getName().equals("void")) {
81.605 + return o;
81.606 + }
81.607 + throw new IllegalStateException("Can't convert " + o);
81.608 + }
81.609 +
81.610 + @JavaScriptBody(args = { "m", "o" },
81.611 + body = "return o[m](o);"
81.612 + )
81.613 + private static native Object toRaw(String m, Object o);
81.614 +
81.615 + /**
81.616 + * Returns {@code true} if this method is a bridge
81.617 + * method; returns {@code false} otherwise.
81.618 + *
81.619 + * @return true if and only if this method is a bridge
81.620 + * method as defined by the Java Language Specification.
81.621 + * @since 1.5
81.622 + */
81.623 + public boolean isBridge() {
81.624 + return (getModifiers() & Modifier.BRIDGE) != 0;
81.625 + }
81.626 +
81.627 + /**
81.628 + * Returns {@code true} if this method was declared to take
81.629 + * a variable number of arguments; returns {@code false}
81.630 + * otherwise.
81.631 + *
81.632 + * @return {@code true} if an only if this method was declared to
81.633 + * take a variable number of arguments.
81.634 + * @since 1.5
81.635 + */
81.636 + public boolean isVarArgs() {
81.637 + return (getModifiers() & Modifier.VARARGS) != 0;
81.638 + }
81.639 +
81.640 + /**
81.641 + * Returns {@code true} if this method is a synthetic
81.642 + * method; returns {@code false} otherwise.
81.643 + *
81.644 + * @return true if and only if this method is a synthetic
81.645 + * method as defined by the Java Language Specification.
81.646 + * @since 1.5
81.647 + */
81.648 + public boolean isSynthetic() {
81.649 + return Modifier.isSynthetic(getModifiers());
81.650 + }
81.651 +
81.652 + @JavaScriptBody(args = { "ac" },
81.653 + body =
81.654 + "if (this.fld_data.anno) {"
81.655 + + " return this.fld_data.anno['L' + ac.jvmName + ';'];"
81.656 + + "} else return null;"
81.657 + )
81.658 + private Object getAnnotationData(Class<?> annotationClass) {
81.659 + throw new UnsupportedOperationException();
81.660 + }
81.661 +
81.662 + /**
81.663 + * @throws NullPointerException {@inheritDoc}
81.664 + * @since 1.5
81.665 + */
81.666 + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
81.667 + Object data = getAnnotationData(annotationClass);
81.668 + return data == null ? null : AnnotationImpl.create(annotationClass, data);
81.669 + }
81.670 +
81.671 + /**
81.672 + * @since 1.5
81.673 + */
81.674 + public Annotation[] getDeclaredAnnotations() {
81.675 + throw new UnsupportedOperationException();
81.676 + }
81.677 +
81.678 + /**
81.679 + * Returns the default value for the annotation member represented by
81.680 + * this {@code Method} instance. If the member is of a primitive type,
81.681 + * an instance of the corresponding wrapper type is returned. Returns
81.682 + * null if no default is associated with the member, or if the method
81.683 + * instance does not represent a declared member of an annotation type.
81.684 + *
81.685 + * @return the default value for the annotation member represented
81.686 + * by this {@code Method} instance.
81.687 + * @throws TypeNotPresentException if the annotation is of type
81.688 + * {@link Class} and no definition can be found for the
81.689 + * default class value.
81.690 + * @since 1.5
81.691 + */
81.692 + public Object getDefaultValue() {
81.693 + throw new UnsupportedOperationException();
81.694 + }
81.695 +
81.696 + /**
81.697 + * Returns an array of arrays that represent the annotations on the formal
81.698 + * parameters, in declaration order, of the method represented by
81.699 + * this {@code Method} object. (Returns an array of length zero if the
81.700 + * underlying method is parameterless. If the method has one or more
81.701 + * parameters, a nested array of length zero is returned for each parameter
81.702 + * with no annotations.) The annotation objects contained in the returned
81.703 + * arrays are serializable. The caller of this method is free to modify
81.704 + * the returned arrays; it will have no effect on the arrays returned to
81.705 + * other callers.
81.706 + *
81.707 + * @return an array of arrays that represent the annotations on the formal
81.708 + * parameters, in declaration order, of the method represented by this
81.709 + * Method object
81.710 + * @since 1.5
81.711 + */
81.712 + public Annotation[][] getParameterAnnotations() {
81.713 + throw new UnsupportedOperationException();
81.714 + }
81.715 +
81.716 + static {
81.717 + MethodImpl.INSTANCE = new MethodImpl() {
81.718 + protected Method create(Class<?> declaringClass, String name, Object data, String sig) {
81.719 + return new Method(declaringClass, name, data, sig);
81.720 + }
81.721 + };
81.722 + }
81.723 +}
82.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
82.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Modifier.java Wed Jan 23 20:39:23 2013 +0100
82.3 @@ -0,0 +1,437 @@
82.4 +/*
82.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
82.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
82.7 + *
82.8 + * This code is free software; you can redistribute it and/or modify it
82.9 + * under the terms of the GNU General Public License version 2 only, as
82.10 + * published by the Free Software Foundation. Oracle designates this
82.11 + * particular file as subject to the "Classpath" exception as provided
82.12 + * by Oracle in the LICENSE file that accompanied this code.
82.13 + *
82.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
82.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
82.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
82.17 + * version 2 for more details (a copy is included in the LICENSE file that
82.18 + * accompanied this code).
82.19 + *
82.20 + * You should have received a copy of the GNU General Public License version
82.21 + * 2 along with this work; if not, write to the Free Software Foundation,
82.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
82.23 + *
82.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
82.25 + * or visit www.oracle.com if you need additional information or have any
82.26 + * questions.
82.27 + */
82.28 +
82.29 +package java.lang.reflect;
82.30 +
82.31 +/**
82.32 + * The Modifier class provides {@code static} methods and
82.33 + * constants to decode class and member access modifiers. The sets of
82.34 + * modifiers are represented as integers with distinct bit positions
82.35 + * representing different modifiers. The values for the constants
82.36 + * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
82.37 + * <cite>The Java™ Virtual Machine Specification</cite>.
82.38 + *
82.39 + * @see Class#getModifiers()
82.40 + * @see Member#getModifiers()
82.41 + *
82.42 + * @author Nakul Saraiya
82.43 + * @author Kenneth Russell
82.44 + */
82.45 +public
82.46 +class Modifier {
82.47 +
82.48 + /**
82.49 + * Return {@code true} if the integer argument includes the
82.50 + * {@code public} modifier, {@code false} otherwise.
82.51 + *
82.52 + * @param mod a set of modifiers
82.53 + * @return {@code true} if {@code mod} includes the
82.54 + * {@code public} modifier; {@code false} otherwise.
82.55 + */
82.56 + public static boolean isPublic(int mod) {
82.57 + return (mod & PUBLIC) != 0;
82.58 + }
82.59 +
82.60 + /**
82.61 + * Return {@code true} if the integer argument includes the
82.62 + * {@code private} modifier, {@code false} otherwise.
82.63 + *
82.64 + * @param mod a set of modifiers
82.65 + * @return {@code true} if {@code mod} includes the
82.66 + * {@code private} modifier; {@code false} otherwise.
82.67 + */
82.68 + public static boolean isPrivate(int mod) {
82.69 + return (mod & PRIVATE) != 0;
82.70 + }
82.71 +
82.72 + /**
82.73 + * Return {@code true} if the integer argument includes the
82.74 + * {@code protected} modifier, {@code false} otherwise.
82.75 + *
82.76 + * @param mod a set of modifiers
82.77 + * @return {@code true} if {@code mod} includes the
82.78 + * {@code protected} modifier; {@code false} otherwise.
82.79 + */
82.80 + public static boolean isProtected(int mod) {
82.81 + return (mod & PROTECTED) != 0;
82.82 + }
82.83 +
82.84 + /**
82.85 + * Return {@code true} if the integer argument includes the
82.86 + * {@code static} modifier, {@code false} otherwise.
82.87 + *
82.88 + * @param mod a set of modifiers
82.89 + * @return {@code true} if {@code mod} includes the
82.90 + * {@code static} modifier; {@code false} otherwise.
82.91 + */
82.92 + public static boolean isStatic(int mod) {
82.93 + return (mod & STATIC) != 0;
82.94 + }
82.95 +
82.96 + /**
82.97 + * Return {@code true} if the integer argument includes the
82.98 + * {@code final} modifier, {@code false} otherwise.
82.99 + *
82.100 + * @param mod a set of modifiers
82.101 + * @return {@code true} if {@code mod} includes the
82.102 + * {@code final} modifier; {@code false} otherwise.
82.103 + */
82.104 + public static boolean isFinal(int mod) {
82.105 + return (mod & FINAL) != 0;
82.106 + }
82.107 +
82.108 + /**
82.109 + * Return {@code true} if the integer argument includes the
82.110 + * {@code synchronized} modifier, {@code false} otherwise.
82.111 + *
82.112 + * @param mod a set of modifiers
82.113 + * @return {@code true} if {@code mod} includes the
82.114 + * {@code synchronized} modifier; {@code false} otherwise.
82.115 + */
82.116 + public static boolean isSynchronized(int mod) {
82.117 + return (mod & SYNCHRONIZED) != 0;
82.118 + }
82.119 +
82.120 + /**
82.121 + * Return {@code true} if the integer argument includes the
82.122 + * {@code volatile} modifier, {@code false} otherwise.
82.123 + *
82.124 + * @param mod a set of modifiers
82.125 + * @return {@code true} if {@code mod} includes the
82.126 + * {@code volatile} modifier; {@code false} otherwise.
82.127 + */
82.128 + public static boolean isVolatile(int mod) {
82.129 + return (mod & VOLATILE) != 0;
82.130 + }
82.131 +
82.132 + /**
82.133 + * Return {@code true} if the integer argument includes the
82.134 + * {@code transient} modifier, {@code false} otherwise.
82.135 + *
82.136 + * @param mod a set of modifiers
82.137 + * @return {@code true} if {@code mod} includes the
82.138 + * {@code transient} modifier; {@code false} otherwise.
82.139 + */
82.140 + public static boolean isTransient(int mod) {
82.141 + return (mod & TRANSIENT) != 0;
82.142 + }
82.143 +
82.144 + /**
82.145 + * Return {@code true} if the integer argument includes the
82.146 + * {@code native} modifier, {@code false} otherwise.
82.147 + *
82.148 + * @param mod a set of modifiers
82.149 + * @return {@code true} if {@code mod} includes the
82.150 + * {@code native} modifier; {@code false} otherwise.
82.151 + */
82.152 + public static boolean isNative(int mod) {
82.153 + return (mod & NATIVE) != 0;
82.154 + }
82.155 +
82.156 + /**
82.157 + * Return {@code true} if the integer argument includes the
82.158 + * {@code interface} modifier, {@code false} otherwise.
82.159 + *
82.160 + * @param mod a set of modifiers
82.161 + * @return {@code true} if {@code mod} includes the
82.162 + * {@code interface} modifier; {@code false} otherwise.
82.163 + */
82.164 + public static boolean isInterface(int mod) {
82.165 + return (mod & INTERFACE) != 0;
82.166 + }
82.167 +
82.168 + /**
82.169 + * Return {@code true} if the integer argument includes the
82.170 + * {@code abstract} modifier, {@code false} otherwise.
82.171 + *
82.172 + * @param mod a set of modifiers
82.173 + * @return {@code true} if {@code mod} includes the
82.174 + * {@code abstract} modifier; {@code false} otherwise.
82.175 + */
82.176 + public static boolean isAbstract(int mod) {
82.177 + return (mod & ABSTRACT) != 0;
82.178 + }
82.179 +
82.180 + /**
82.181 + * Return {@code true} if the integer argument includes the
82.182 + * {@code strictfp} modifier, {@code false} otherwise.
82.183 + *
82.184 + * @param mod a set of modifiers
82.185 + * @return {@code true} if {@code mod} includes the
82.186 + * {@code strictfp} modifier; {@code false} otherwise.
82.187 + */
82.188 + public static boolean isStrict(int mod) {
82.189 + return (mod & STRICT) != 0;
82.190 + }
82.191 +
82.192 + /**
82.193 + * Return a string describing the access modifier flags in
82.194 + * the specified modifier. For example:
82.195 + * <blockquote><pre>
82.196 + * public final synchronized strictfp
82.197 + * </pre></blockquote>
82.198 + * The modifier names are returned in an order consistent with the
82.199 + * suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of
82.200 + * <cite>The Java™ Language Specification</cite>.
82.201 + * The full modifier ordering used by this method is:
82.202 + * <blockquote> {@code
82.203 + * public protected private abstract static final transient
82.204 + * volatile synchronized native strictfp
82.205 + * interface } </blockquote>
82.206 + * The {@code interface} modifier discussed in this class is
82.207 + * not a true modifier in the Java language and it appears after
82.208 + * all other modifiers listed by this method. This method may
82.209 + * return a string of modifiers that are not valid modifiers of a
82.210 + * Java entity; in other words, no checking is done on the
82.211 + * possible validity of the combination of modifiers represented
82.212 + * by the input.
82.213 + *
82.214 + * Note that to perform such checking for a known kind of entity,
82.215 + * such as a constructor or method, first AND the argument of
82.216 + * {@code toString} with the appropriate mask from a method like
82.217 + * {@link #constructorModifiers} or {@link #methodModifiers}.
82.218 + *
82.219 + * @param mod a set of modifiers
82.220 + * @return a string representation of the set of modifiers
82.221 + * represented by {@code mod}
82.222 + */
82.223 + public static String toString(int mod) {
82.224 + StringBuffer sb = new StringBuffer();
82.225 + int len;
82.226 +
82.227 + if ((mod & PUBLIC) != 0) sb.append("public ");
82.228 + if ((mod & PROTECTED) != 0) sb.append("protected ");
82.229 + if ((mod & PRIVATE) != 0) sb.append("private ");
82.230 +
82.231 + /* Canonical order */
82.232 + if ((mod & ABSTRACT) != 0) sb.append("abstract ");
82.233 + if ((mod & STATIC) != 0) sb.append("static ");
82.234 + if ((mod & FINAL) != 0) sb.append("final ");
82.235 + if ((mod & TRANSIENT) != 0) sb.append("transient ");
82.236 + if ((mod & VOLATILE) != 0) sb.append("volatile ");
82.237 + if ((mod & SYNCHRONIZED) != 0) sb.append("synchronized ");
82.238 + if ((mod & NATIVE) != 0) sb.append("native ");
82.239 + if ((mod & STRICT) != 0) sb.append("strictfp ");
82.240 + if ((mod & INTERFACE) != 0) sb.append("interface ");
82.241 +
82.242 + if ((len = sb.length()) > 0) /* trim trailing space */
82.243 + return sb.toString().substring(0, len-1);
82.244 + return "";
82.245 + }
82.246 +
82.247 + /*
82.248 + * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
82.249 + * <cite>The Java™ Virtual Machine Specification</cite>
82.250 + */
82.251 +
82.252 + /**
82.253 + * The {@code int} value representing the {@code public}
82.254 + * modifier.
82.255 + */
82.256 + public static final int PUBLIC = 0x00000001;
82.257 +
82.258 + /**
82.259 + * The {@code int} value representing the {@code private}
82.260 + * modifier.
82.261 + */
82.262 + public static final int PRIVATE = 0x00000002;
82.263 +
82.264 + /**
82.265 + * The {@code int} value representing the {@code protected}
82.266 + * modifier.
82.267 + */
82.268 + public static final int PROTECTED = 0x00000004;
82.269 +
82.270 + /**
82.271 + * The {@code int} value representing the {@code static}
82.272 + * modifier.
82.273 + */
82.274 + public static final int STATIC = 0x00000008;
82.275 +
82.276 + /**
82.277 + * The {@code int} value representing the {@code final}
82.278 + * modifier.
82.279 + */
82.280 + public static final int FINAL = 0x00000010;
82.281 +
82.282 + /**
82.283 + * The {@code int} value representing the {@code synchronized}
82.284 + * modifier.
82.285 + */
82.286 + public static final int SYNCHRONIZED = 0x00000020;
82.287 +
82.288 + /**
82.289 + * The {@code int} value representing the {@code volatile}
82.290 + * modifier.
82.291 + */
82.292 + public static final int VOLATILE = 0x00000040;
82.293 +
82.294 + /**
82.295 + * The {@code int} value representing the {@code transient}
82.296 + * modifier.
82.297 + */
82.298 + public static final int TRANSIENT = 0x00000080;
82.299 +
82.300 + /**
82.301 + * The {@code int} value representing the {@code native}
82.302 + * modifier.
82.303 + */
82.304 + public static final int NATIVE = 0x00000100;
82.305 +
82.306 + /**
82.307 + * The {@code int} value representing the {@code interface}
82.308 + * modifier.
82.309 + */
82.310 + public static final int INTERFACE = 0x00000200;
82.311 +
82.312 + /**
82.313 + * The {@code int} value representing the {@code abstract}
82.314 + * modifier.
82.315 + */
82.316 + public static final int ABSTRACT = 0x00000400;
82.317 +
82.318 + /**
82.319 + * The {@code int} value representing the {@code strictfp}
82.320 + * modifier.
82.321 + */
82.322 + public static final int STRICT = 0x00000800;
82.323 +
82.324 + // Bits not (yet) exposed in the public API either because they
82.325 + // have different meanings for fields and methods and there is no
82.326 + // way to distinguish between the two in this class, or because
82.327 + // they are not Java programming language keywords
82.328 + static final int BRIDGE = 0x00000040;
82.329 + static final int VARARGS = 0x00000080;
82.330 + static final int SYNTHETIC = 0x00001000;
82.331 + static final int ANNOTATION= 0x00002000;
82.332 + static final int ENUM = 0x00004000;
82.333 + static boolean isSynthetic(int mod) {
82.334 + return (mod & SYNTHETIC) != 0;
82.335 + }
82.336 +
82.337 + /**
82.338 + * See JLSv3 section 8.1.1.
82.339 + */
82.340 + private static final int CLASS_MODIFIERS =
82.341 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
82.342 + Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
82.343 + Modifier.STRICT;
82.344 +
82.345 + /**
82.346 + * See JLSv3 section 9.1.1.
82.347 + */
82.348 + private static final int INTERFACE_MODIFIERS =
82.349 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
82.350 + Modifier.ABSTRACT | Modifier.STATIC | Modifier.STRICT;
82.351 +
82.352 +
82.353 + /**
82.354 + * See JLSv3 section 8.8.3.
82.355 + */
82.356 + private static final int CONSTRUCTOR_MODIFIERS =
82.357 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE;
82.358 +
82.359 + /**
82.360 + * See JLSv3 section 8.4.3.
82.361 + */
82.362 + private static final int METHOD_MODIFIERS =
82.363 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
82.364 + Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
82.365 + Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT;
82.366 +
82.367 + /**
82.368 + * See JLSv3 section 8.3.1.
82.369 + */
82.370 + private static final int FIELD_MODIFIERS =
82.371 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
82.372 + Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT |
82.373 + Modifier.VOLATILE;
82.374 +
82.375 + /**
82.376 + * Return an {@code int} value OR-ing together the source language
82.377 + * modifiers that can be applied to a class.
82.378 + * @return an {@code int} value OR-ing together the source language
82.379 + * modifiers that can be applied to a class.
82.380 + *
82.381 + * @jls 8.1.1 Class Modifiers
82.382 + * @since 1.7
82.383 + */
82.384 + public static int classModifiers() {
82.385 + return CLASS_MODIFIERS;
82.386 + }
82.387 +
82.388 + /**
82.389 + * Return an {@code int} value OR-ing together the source language
82.390 + * modifiers that can be applied to an interface.
82.391 + * @return an {@code int} value OR-ing together the source language
82.392 + * modifiers that can be applied to an inteface.
82.393 + *
82.394 + * @jls 9.1.1 Interface Modifiers
82.395 + * @since 1.7
82.396 + */
82.397 + public static int interfaceModifiers() {
82.398 + return INTERFACE_MODIFIERS;
82.399 + }
82.400 +
82.401 + /**
82.402 + * Return an {@code int} value OR-ing together the source language
82.403 + * modifiers that can be applied to a constructor.
82.404 + * @return an {@code int} value OR-ing together the source language
82.405 + * modifiers that can be applied to a constructor.
82.406 + *
82.407 + * @jls 8.8.3 Constructor Modifiers
82.408 + * @since 1.7
82.409 + */
82.410 + public static int constructorModifiers() {
82.411 + return CONSTRUCTOR_MODIFIERS;
82.412 + }
82.413 +
82.414 + /**
82.415 + * Return an {@code int} value OR-ing together the source language
82.416 + * modifiers that can be applied to a method.
82.417 + * @return an {@code int} value OR-ing together the source language
82.418 + * modifiers that can be applied to a method.
82.419 + *
82.420 + * @jls 8.4.3 Method Modifiers
82.421 + * @since 1.7
82.422 + */
82.423 + public static int methodModifiers() {
82.424 + return METHOD_MODIFIERS;
82.425 + }
82.426 +
82.427 +
82.428 + /**
82.429 + * Return an {@code int} value OR-ing together the source language
82.430 + * modifiers that can be applied to a field.
82.431 + * @return an {@code int} value OR-ing together the source language
82.432 + * modifiers that can be applied to a field.
82.433 + *
82.434 + * @jls 8.3.1 Field Modifiers
82.435 + * @since 1.7
82.436 + */
82.437 + public static int fieldModifiers() {
82.438 + return FIELD_MODIFIERS;
82.439 + }
82.440 +}
83.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
83.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Type.java Wed Jan 23 20:39:23 2013 +0100
83.3 @@ -0,0 +1,37 @@
83.4 +/*
83.5 + * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
83.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83.7 + *
83.8 + * This code is free software; you can redistribute it and/or modify it
83.9 + * under the terms of the GNU General Public License version 2 only, as
83.10 + * published by the Free Software Foundation. Oracle designates this
83.11 + * particular file as subject to the "Classpath" exception as provided
83.12 + * by Oracle in the LICENSE file that accompanied this code.
83.13 + *
83.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
83.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
83.17 + * version 2 for more details (a copy is included in the LICENSE file that
83.18 + * accompanied this code).
83.19 + *
83.20 + * You should have received a copy of the GNU General Public License version
83.21 + * 2 along with this work; if not, write to the Free Software Foundation,
83.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83.23 + *
83.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
83.25 + * or visit www.oracle.com if you need additional information or have any
83.26 + * questions.
83.27 + */
83.28 +
83.29 +package java.lang.reflect;
83.30 +
83.31 +/**
83.32 + * Type is the common superinterface for all types in the Java
83.33 + * programming language. These include raw types, parameterized types,
83.34 + * array types, type variables and primitive types.
83.35 + *
83.36 + * @since 1.5
83.37 + */
83.38 +
83.39 +public interface Type {
83.40 +}
84.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
84.2 +++ b/emul/mini/src/main/java/java/lang/reflect/TypeVariable.java Wed Jan 23 20:39:23 2013 +0100
84.3 @@ -0,0 +1,89 @@
84.4 +/*
84.5 + * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
84.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
84.7 + *
84.8 + * This code is free software; you can redistribute it and/or modify it
84.9 + * under the terms of the GNU General Public License version 2 only, as
84.10 + * published by the Free Software Foundation. Oracle designates this
84.11 + * particular file as subject to the "Classpath" exception as provided
84.12 + * by Oracle in the LICENSE file that accompanied this code.
84.13 + *
84.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
84.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
84.17 + * version 2 for more details (a copy is included in the LICENSE file that
84.18 + * accompanied this code).
84.19 + *
84.20 + * You should have received a copy of the GNU General Public License version
84.21 + * 2 along with this work; if not, write to the Free Software Foundation,
84.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
84.23 + *
84.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
84.25 + * or visit www.oracle.com if you need additional information or have any
84.26 + * questions.
84.27 + */
84.28 +
84.29 +package java.lang.reflect;
84.30 +
84.31 +/**
84.32 + * TypeVariable is the common superinterface for type variables of kinds.
84.33 + * A type variable is created the first time it is needed by a reflective
84.34 + * method, as specified in this package. If a type variable t is referenced
84.35 + * by a type (i.e, class, interface or annotation type) T, and T is declared
84.36 + * by the nth enclosing class of T (see JLS 8.1.2), then the creation of t
84.37 + * requires the resolution (see JVMS 5) of the ith enclosing class of T,
84.38 + * for i = 0 to n, inclusive. Creating a type variable must not cause the
84.39 + * creation of its bounds. Repeated creation of a type variable has no effect.
84.40 + *
84.41 + * <p>Multiple objects may be instantiated at run-time to
84.42 + * represent a given type variable. Even though a type variable is
84.43 + * created only once, this does not imply any requirement to cache
84.44 + * instances representing the type variable. However, all instances
84.45 + * representing a type variable must be equal() to each other.
84.46 + * As a consequence, users of type variables must not rely on the identity
84.47 + * of instances of classes implementing this interface.
84.48 + *
84.49 + * @param <D> the type of generic declaration that declared the
84.50 + * underlying type variable.
84.51 + *
84.52 + * @since 1.5
84.53 + */
84.54 +public interface TypeVariable<D extends GenericDeclaration> extends Type {
84.55 + /**
84.56 + * Returns an array of {@code Type} objects representing the
84.57 + * upper bound(s) of this type variable. Note that if no upper bound is
84.58 + * explicitly declared, the upper bound is {@code Object}.
84.59 + *
84.60 + * <p>For each upper bound B: <ul> <li>if B is a parameterized
84.61 + * type or a type variable, it is created, (see {@link
84.62 + * java.lang.reflect.ParameterizedType ParameterizedType} for the
84.63 + * details of the creation process for parameterized types).
84.64 + * <li>Otherwise, B is resolved. </ul>
84.65 + *
84.66 + * @throws TypeNotPresentException if any of the
84.67 + * bounds refers to a non-existent type declaration
84.68 + * @throws MalformedParameterizedTypeException if any of the
84.69 + * bounds refer to a parameterized type that cannot be instantiated
84.70 + * for any reason
84.71 + * @return an array of {@code Type}s representing the upper
84.72 + * bound(s) of this type variable
84.73 + */
84.74 + Type[] getBounds();
84.75 +
84.76 + /**
84.77 + * Returns the {@code GenericDeclaration} object representing the
84.78 + * generic declaration declared this type variable.
84.79 + *
84.80 + * @return the generic declaration declared for this type variable.
84.81 + *
84.82 + * @since 1.5
84.83 + */
84.84 + D getGenericDeclaration();
84.85 +
84.86 + /**
84.87 + * Returns the name of this type variable, as it occurs in the source code.
84.88 + *
84.89 + * @return the name of this type variable, as it appears in the source code
84.90 + */
84.91 + String getName();
84.92 +}
85.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
85.2 +++ b/emul/mini/src/main/java/java/lang/reflect/package-info.java Wed Jan 23 20:39:23 2013 +0100
85.3 @@ -0,0 +1,49 @@
85.4 +/*
85.5 + * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
85.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
85.7 + *
85.8 + * This code is free software; you can redistribute it and/or modify it
85.9 + * under the terms of the GNU General Public License version 2 only, as
85.10 + * published by the Free Software Foundation. Oracle designates this
85.11 + * particular file as subject to the "Classpath" exception as provided
85.12 + * by Oracle in the LICENSE file that accompanied this code.
85.13 + *
85.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
85.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
85.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
85.17 + * version 2 for more details (a copy is included in the LICENSE file that
85.18 + * accompanied this code).
85.19 + *
85.20 + * You should have received a copy of the GNU General Public License version
85.21 + * 2 along with this work; if not, write to the Free Software Foundation,
85.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
85.23 + *
85.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
85.25 + * or visit www.oracle.com if you need additional information or have any
85.26 + * questions.
85.27 + */
85.28 +
85.29 +/**
85.30 + * Provides classes and interfaces for obtaining reflective
85.31 + * information about classes and objects. Reflection allows
85.32 + * programmatic access to information about the fields, methods and
85.33 + * constructors of loaded classes, and the use of reflected fields,
85.34 + * methods, and constructors to operate on their underlying
85.35 + * counterparts, within security restrictions.
85.36 + *
85.37 + * <p>{@code AccessibleObject} allows suppression of access checks if
85.38 + * the necessary {@code ReflectPermission} is available.
85.39 + *
85.40 + * <p>{@code Array} provides static methods to dynamically create and
85.41 + * access arrays.
85.42 + *
85.43 + * <p>Classes in this package, along with {@code java.lang.Class}
85.44 + * accommodate applications such as debuggers, interpreters, object
85.45 + * inspectors, class browsers, and services such as Object
85.46 + * Serialization and JavaBeans that need access to either the public
85.47 + * members of a target object (based on its runtime class) or the
85.48 + * members declared by a given class.
85.49 + *
85.50 + * @since JDK1.1
85.51 + */
85.52 +package java.lang.reflect;
86.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
86.2 +++ b/emul/mini/src/main/java/java/net/MalformedURLException.java Wed Jan 23 20:39:23 2013 +0100
86.3 @@ -0,0 +1,56 @@
86.4 +/*
86.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
86.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
86.7 + *
86.8 + * This code is free software; you can redistribute it and/or modify it
86.9 + * under the terms of the GNU General Public License version 2 only, as
86.10 + * published by the Free Software Foundation. Oracle designates this
86.11 + * particular file as subject to the "Classpath" exception as provided
86.12 + * by Oracle in the LICENSE file that accompanied this code.
86.13 + *
86.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
86.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
86.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
86.17 + * version 2 for more details (a copy is included in the LICENSE file that
86.18 + * accompanied this code).
86.19 + *
86.20 + * You should have received a copy of the GNU General Public License version
86.21 + * 2 along with this work; if not, write to the Free Software Foundation,
86.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
86.23 + *
86.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86.25 + * or visit www.oracle.com if you need additional information or have any
86.26 + * questions.
86.27 + */
86.28 +
86.29 +package java.net;
86.30 +
86.31 +import java.io.IOException;
86.32 +
86.33 +/**
86.34 + * Thrown to indicate that a malformed URL has occurred. Either no
86.35 + * legal protocol could be found in a specification string or the
86.36 + * string could not be parsed.
86.37 + *
86.38 + * @author Arthur van Hoff
86.39 + * @since JDK1.0
86.40 + */
86.41 +public class MalformedURLException extends IOException {
86.42 + private static final long serialVersionUID = -182787522200415866L;
86.43 +
86.44 + /**
86.45 + * Constructs a <code>MalformedURLException</code> with no detail message.
86.46 + */
86.47 + public MalformedURLException() {
86.48 + }
86.49 +
86.50 + /**
86.51 + * Constructs a <code>MalformedURLException</code> with the
86.52 + * specified detail message.
86.53 + *
86.54 + * @param msg the detail message.
86.55 + */
86.56 + public MalformedURLException(String msg) {
86.57 + super(msg);
86.58 + }
86.59 +}
87.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
87.2 +++ b/emul/mini/src/main/java/java/net/URL.java Wed Jan 23 20:39:23 2013 +0100
87.3 @@ -0,0 +1,1037 @@
87.4 +/*
87.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
87.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
87.7 + *
87.8 + * This code is free software; you can redistribute it and/or modify it
87.9 + * under the terms of the GNU General Public License version 2 only, as
87.10 + * published by the Free Software Foundation. Oracle designates this
87.11 + * particular file as subject to the "Classpath" exception as provided
87.12 + * by Oracle in the LICENSE file that accompanied this code.
87.13 + *
87.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
87.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
87.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
87.17 + * version 2 for more details (a copy is included in the LICENSE file that
87.18 + * accompanied this code).
87.19 + *
87.20 + * You should have received a copy of the GNU General Public License version
87.21 + * 2 along with this work; if not, write to the Free Software Foundation,
87.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
87.23 + *
87.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
87.25 + * or visit www.oracle.com if you need additional information or have any
87.26 + * questions.
87.27 + */
87.28 +
87.29 +package java.net;
87.30 +
87.31 +import java.io.IOException;
87.32 +import java.io.InputStream;
87.33 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
87.34 +
87.35 +/**
87.36 + * Class <code>URL</code> represents a Uniform Resource
87.37 + * Locator, a pointer to a "resource" on the World
87.38 + * Wide Web. A resource can be something as simple as a file or a
87.39 + * directory, or it can be a reference to a more complicated object,
87.40 + * such as a query to a database or to a search engine. More
87.41 + * information on the types of URLs and their formats can be found at:
87.42 + * <blockquote>
87.43 + * <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
87.44 + * <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
87.45 + * </blockquote>
87.46 + * <p>
87.47 + * In general, a URL can be broken into several parts. The previous
87.48 + * example of a URL indicates that the protocol to use is
87.49 + * <code>http</code> (HyperText Transfer Protocol) and that the
87.50 + * information resides on a host machine named
87.51 + * <code>www.socs.uts.edu.au</code>. The information on that host
87.52 + * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
87.53 + * meaning of this name on the host machine is both protocol
87.54 + * dependent and host dependent. The information normally resides in
87.55 + * a file, but it could be generated on the fly. This component of
87.56 + * the URL is called the <i>path</i> component.
87.57 + * <p>
87.58 + * A URL can optionally specify a "port", which is the
87.59 + * port number to which the TCP connection is made on the remote host
87.60 + * machine. If the port is not specified, the default port for
87.61 + * the protocol is used instead. For example, the default port for
87.62 + * <code>http</code> is <code>80</code>. An alternative port could be
87.63 + * specified as:
87.64 + * <blockquote><pre>
87.65 + * http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
87.66 + * </pre></blockquote>
87.67 + * <p>
87.68 + * The syntax of <code>URL</code> is defined by <a
87.69 + * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC 2396: Uniform
87.70 + * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
87.71 + * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC 2732: Format for
87.72 + * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
87.73 + * also supports scope_ids. The syntax and usage of scope_ids is described
87.74 + * <a href="Inet6Address.html#scoped">here</a>.
87.75 + * <p>
87.76 + * A URL may have appended to it a "fragment", also known
87.77 + * as a "ref" or a "reference". The fragment is indicated by the sharp
87.78 + * sign character "#" followed by more characters. For example,
87.79 + * <blockquote><pre>
87.80 + * http://java.sun.com/index.html#chapter1
87.81 + * </pre></blockquote>
87.82 + * <p>
87.83 + * This fragment is not technically part of the URL. Rather, it
87.84 + * indicates that after the specified resource is retrieved, the
87.85 + * application is specifically interested in that part of the
87.86 + * document that has the tag <code>chapter1</code> attached to it. The
87.87 + * meaning of a tag is resource specific.
87.88 + * <p>
87.89 + * An application can also specify a "relative URL",
87.90 + * which contains only enough information to reach the resource
87.91 + * relative to another URL. Relative URLs are frequently used within
87.92 + * HTML pages. For example, if the contents of the URL:
87.93 + * <blockquote><pre>
87.94 + * http://java.sun.com/index.html
87.95 + * </pre></blockquote>
87.96 + * contained within it the relative URL:
87.97 + * <blockquote><pre>
87.98 + * FAQ.html
87.99 + * </pre></blockquote>
87.100 + * it would be a shorthand for:
87.101 + * <blockquote><pre>
87.102 + * http://java.sun.com/FAQ.html
87.103 + * </pre></blockquote>
87.104 + * <p>
87.105 + * The relative URL need not specify all the components of a URL. If
87.106 + * the protocol, host name, or port number is missing, the value is
87.107 + * inherited from the fully specified URL. The file component must be
87.108 + * specified. The optional fragment is not inherited.
87.109 + * <p>
87.110 + * The URL class does not itself encode or decode any URL components
87.111 + * according to the escaping mechanism defined in RFC2396. It is the
87.112 + * responsibility of the caller to encode any fields, which need to be
87.113 + * escaped prior to calling URL, and also to decode any escaped fields,
87.114 + * that are returned from URL. Furthermore, because URL has no knowledge
87.115 + * of URL escaping, it does not recognise equivalence between the encoded
87.116 + * or decoded form of the same URL. For example, the two URLs:<br>
87.117 + * <pre> http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
87.118 + * would be considered not equal to each other.
87.119 + * <p>
87.120 + * Note, the {@link java.net.URI} class does perform escaping of its
87.121 + * component fields in certain circumstances. The recommended way
87.122 + * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
87.123 + * and to convert between these two classes using {@link #toURI()} and
87.124 + * {@link URI#toURL()}.
87.125 + * <p>
87.126 + * The {@link URLEncoder} and {@link URLDecoder} classes can also be
87.127 + * used, but only for HTML form encoding, which is not the same
87.128 + * as the encoding scheme defined in RFC2396.
87.129 + *
87.130 + * @author James Gosling
87.131 + * @since JDK1.0
87.132 + */
87.133 +public final class URL implements java.io.Serializable {
87.134 +
87.135 + static final long serialVersionUID = -7627629688361524110L;
87.136 +
87.137 + /**
87.138 + * The property which specifies the package prefix list to be scanned
87.139 + * for protocol handlers. The value of this property (if any) should
87.140 + * be a vertical bar delimited list of package names to search through
87.141 + * for a protocol handler to load. The policy of this class is that
87.142 + * all protocol handlers will be in a class called <protocolname>.Handler,
87.143 + * and each package in the list is examined in turn for a matching
87.144 + * handler. If none are found (or the property is not specified), the
87.145 + * default package prefix, sun.net.www.protocol, is used. The search
87.146 + * proceeds from the first package in the list to the last and stops
87.147 + * when a match is found.
87.148 + */
87.149 + private static final String protocolPathProp = "java.protocol.handler.pkgs";
87.150 +
87.151 + /**
87.152 + * The protocol to use (ftp, http, nntp, ... etc.) .
87.153 + * @serial
87.154 + */
87.155 + private String protocol;
87.156 +
87.157 + /**
87.158 + * The host name to connect to.
87.159 + * @serial
87.160 + */
87.161 + private String host;
87.162 +
87.163 + /**
87.164 + * The protocol port to connect to.
87.165 + * @serial
87.166 + */
87.167 + private int port = -1;
87.168 +
87.169 + /**
87.170 + * The specified file name on that host. <code>file</code> is
87.171 + * defined as <code>path[?query]</code>
87.172 + * @serial
87.173 + */
87.174 + private String file;
87.175 +
87.176 + /**
87.177 + * The query part of this URL.
87.178 + */
87.179 + private transient String query;
87.180 +
87.181 + /**
87.182 + * The authority part of this URL.
87.183 + * @serial
87.184 + */
87.185 + private String authority;
87.186 +
87.187 + /**
87.188 + * The path part of this URL.
87.189 + */
87.190 + private transient String path;
87.191 +
87.192 + /**
87.193 + * The userinfo part of this URL.
87.194 + */
87.195 + private transient String userInfo;
87.196 +
87.197 + /**
87.198 + * # reference.
87.199 + * @serial
87.200 + */
87.201 + private String ref;
87.202 +
87.203 + /**
87.204 + * The host's IP address, used in equals and hashCode.
87.205 + * Computed on demand. An uninitialized or unknown hostAddress is null.
87.206 + */
87.207 + transient Object hostAddress;
87.208 +
87.209 + /**
87.210 + * The URLStreamHandler for this URL.
87.211 + */
87.212 + transient URLStreamHandler handler;
87.213 +
87.214 + /* Our hash code.
87.215 + * @serial
87.216 + */
87.217 + private int hashCode = -1;
87.218 +
87.219 + /**
87.220 + * Creates a <code>URL</code> object from the specified
87.221 + * <code>protocol</code>, <code>host</code>, <code>port</code>
87.222 + * number, and <code>file</code>.<p>
87.223 + *
87.224 + * <code>host</code> can be expressed as a host name or a literal
87.225 + * IP address. If IPv6 literal address is used, it should be
87.226 + * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
87.227 + * specified by <a
87.228 + * href="http://www.ietf.org/rfc/rfc2732.txt">RFC 2732</a>;
87.229 + * However, the literal IPv6 address format defined in <a
87.230 + * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC 2373: IP
87.231 + * Version 6 Addressing Architecture</i></a> is also accepted.<p>
87.232 + *
87.233 + * Specifying a <code>port</code> number of <code>-1</code>
87.234 + * indicates that the URL should use the default port for the
87.235 + * protocol.<p>
87.236 + *
87.237 + * If this is the first URL object being created with the specified
87.238 + * protocol, a <i>stream protocol handler</i> object, an instance of
87.239 + * class <code>URLStreamHandler</code>, is created for that protocol:
87.240 + * <ol>
87.241 + * <li>If the application has previously set up an instance of
87.242 + * <code>URLStreamHandlerFactory</code> as the stream handler factory,
87.243 + * then the <code>createURLStreamHandler</code> method of that instance
87.244 + * is called with the protocol string as an argument to create the
87.245 + * stream protocol handler.
87.246 + * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
87.247 + * or if the factory's <code>createURLStreamHandler</code> method
87.248 + * returns <code>null</code>, then the constructor finds the
87.249 + * value of the system property:
87.250 + * <blockquote><pre>
87.251 + * java.protocol.handler.pkgs
87.252 + * </pre></blockquote>
87.253 + * If the value of that system property is not <code>null</code>,
87.254 + * it is interpreted as a list of packages separated by a vertical
87.255 + * slash character '<code>|</code>'. The constructor tries to load
87.256 + * the class named:
87.257 + * <blockquote><pre>
87.258 + * <<i>package</i>>.<<i>protocol</i>>.Handler
87.259 + * </pre></blockquote>
87.260 + * where <<i>package</i>> is replaced by the name of the package
87.261 + * and <<i>protocol</i>> is replaced by the name of the protocol.
87.262 + * If this class does not exist, or if the class exists but it is not
87.263 + * a subclass of <code>URLStreamHandler</code>, then the next package
87.264 + * in the list is tried.
87.265 + * <li>If the previous step fails to find a protocol handler, then the
87.266 + * constructor tries to load from a system default package.
87.267 + * <blockquote><pre>
87.268 + * <<i>system default package</i>>.<<i>protocol</i>>.Handler
87.269 + * </pre></blockquote>
87.270 + * If this class does not exist, or if the class exists but it is not a
87.271 + * subclass of <code>URLStreamHandler</code>, then a
87.272 + * <code>MalformedURLException</code> is thrown.
87.273 + * </ol>
87.274 + *
87.275 + * <p>Protocol handlers for the following protocols are guaranteed
87.276 + * to exist on the search path :-
87.277 + * <blockquote><pre>
87.278 + * http, https, ftp, file, and jar
87.279 + * </pre></blockquote>
87.280 + * Protocol handlers for additional protocols may also be
87.281 + * available.
87.282 + *
87.283 + * <p>No validation of the inputs is performed by this constructor.
87.284 + *
87.285 + * @param protocol the name of the protocol to use.
87.286 + * @param host the name of the host.
87.287 + * @param port the port number on the host.
87.288 + * @param file the file on the host
87.289 + * @exception MalformedURLException if an unknown protocol is specified.
87.290 + * @see java.lang.System#getProperty(java.lang.String)
87.291 + * @see java.net.URL#setURLStreamHandlerFactory(
87.292 + * java.net.URLStreamHandlerFactory)
87.293 + * @see java.net.URLStreamHandler
87.294 + * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
87.295 + * java.lang.String)
87.296 + */
87.297 + public URL(String protocol, String host, int port, String file)
87.298 + throws MalformedURLException
87.299 + {
87.300 + this(protocol, host, port, file, null);
87.301 + }
87.302 +
87.303 + /**
87.304 + * Creates a URL from the specified <code>protocol</code>
87.305 + * name, <code>host</code> name, and <code>file</code> name. The
87.306 + * default port for the specified protocol is used.
87.307 + * <p>
87.308 + * This method is equivalent to calling the four-argument
87.309 + * constructor with the arguments being <code>protocol</code>,
87.310 + * <code>host</code>, <code>-1</code>, and <code>file</code>.
87.311 + *
87.312 + * No validation of the inputs is performed by this constructor.
87.313 + *
87.314 + * @param protocol the name of the protocol to use.
87.315 + * @param host the name of the host.
87.316 + * @param file the file on the host.
87.317 + * @exception MalformedURLException if an unknown protocol is specified.
87.318 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
87.319 + * int, java.lang.String)
87.320 + */
87.321 + public URL(String protocol, String host, String file)
87.322 + throws MalformedURLException {
87.323 + this(protocol, host, -1, file);
87.324 + }
87.325 +
87.326 + /**
87.327 + * Creates a <code>URL</code> object from the specified
87.328 + * <code>protocol</code>, <code>host</code>, <code>port</code>
87.329 + * number, <code>file</code>, and <code>handler</code>. Specifying
87.330 + * a <code>port</code> number of <code>-1</code> indicates that
87.331 + * the URL should use the default port for the protocol. Specifying
87.332 + * a <code>handler</code> of <code>null</code> indicates that the URL
87.333 + * should use a default stream handler for the protocol, as outlined
87.334 + * for:
87.335 + * java.net.URL#URL(java.lang.String, java.lang.String, int,
87.336 + * java.lang.String)
87.337 + *
87.338 + * <p>If the handler is not null and there is a security manager,
87.339 + * the security manager's <code>checkPermission</code>
87.340 + * method is called with a
87.341 + * <code>NetPermission("specifyStreamHandler")</code> permission.
87.342 + * This may result in a SecurityException.
87.343 + *
87.344 + * No validation of the inputs is performed by this constructor.
87.345 + *
87.346 + * @param protocol the name of the protocol to use.
87.347 + * @param host the name of the host.
87.348 + * @param port the port number on the host.
87.349 + * @param file the file on the host
87.350 + * @param handler the stream handler for the URL.
87.351 + * @exception MalformedURLException if an unknown protocol is specified.
87.352 + * @exception SecurityException
87.353 + * if a security manager exists and its
87.354 + * <code>checkPermission</code> method doesn't allow
87.355 + * specifying a stream handler explicitly.
87.356 + * @see java.lang.System#getProperty(java.lang.String)
87.357 + * @see java.net.URL#setURLStreamHandlerFactory(
87.358 + * java.net.URLStreamHandlerFactory)
87.359 + * @see java.net.URLStreamHandler
87.360 + * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
87.361 + * java.lang.String)
87.362 + * @see SecurityManager#checkPermission
87.363 + * @see java.net.NetPermission
87.364 + */
87.365 + public URL(String protocol, String host, int port, String file,
87.366 + URLStreamHandler handler) throws MalformedURLException {
87.367 + if (handler != null) {
87.368 + throw new SecurityException();
87.369 + }
87.370 +
87.371 + protocol = protocol.toLowerCase();
87.372 + this.protocol = protocol;
87.373 + if (host != null) {
87.374 +
87.375 + /**
87.376 + * if host is a literal IPv6 address,
87.377 + * we will make it conform to RFC 2732
87.378 + */
87.379 + if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
87.380 + host = "["+host+"]";
87.381 + }
87.382 + this.host = host;
87.383 +
87.384 + if (port < -1) {
87.385 + throw new MalformedURLException("Invalid port number :" +
87.386 + port);
87.387 + }
87.388 + this.port = port;
87.389 + authority = (port == -1) ? host : host + ":" + port;
87.390 + }
87.391 +
87.392 + Parts parts = new Parts(file);
87.393 + path = parts.getPath();
87.394 + query = parts.getQuery();
87.395 +
87.396 + if (query != null) {
87.397 + this.file = path + "?" + query;
87.398 + } else {
87.399 + this.file = path;
87.400 + }
87.401 + ref = parts.getRef();
87.402 +
87.403 + // Note: we don't do validation of the URL here. Too risky to change
87.404 + // right now, but worth considering for future reference. -br
87.405 + if (handler == null &&
87.406 + (handler = getURLStreamHandler(protocol)) == null) {
87.407 + throw new MalformedURLException("unknown protocol: " + protocol);
87.408 + }
87.409 + this.handler = handler;
87.410 + }
87.411 +
87.412 + /**
87.413 + * Creates a <code>URL</code> object from the <code>String</code>
87.414 + * representation.
87.415 + * <p>
87.416 + * This constructor is equivalent to a call to the two-argument
87.417 + * constructor with a <code>null</code> first argument.
87.418 + *
87.419 + * @param spec the <code>String</code> to parse as a URL.
87.420 + * @exception MalformedURLException if no protocol is specified, or an
87.421 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
87.422 + * @see java.net.URL#URL(java.net.URL, java.lang.String)
87.423 + */
87.424 + public URL(String spec) throws MalformedURLException {
87.425 + this(null, spec);
87.426 + }
87.427 +
87.428 + /**
87.429 + * Creates a URL by parsing the given spec within a specified context.
87.430 + *
87.431 + * The new URL is created from the given context URL and the spec
87.432 + * argument as described in
87.433 + * RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
87.434 + * <blockquote><pre>
87.435 + * <scheme>://<authority><path>?<query>#<fragment>
87.436 + * </pre></blockquote>
87.437 + * The reference is parsed into the scheme, authority, path, query and
87.438 + * fragment parts. If the path component is empty and the scheme,
87.439 + * authority, and query components are undefined, then the new URL is a
87.440 + * reference to the current document. Otherwise, the fragment and query
87.441 + * parts present in the spec are used in the new URL.
87.442 + * <p>
87.443 + * If the scheme component is defined in the given spec and does not match
87.444 + * the scheme of the context, then the new URL is created as an absolute
87.445 + * URL based on the spec alone. Otherwise the scheme component is inherited
87.446 + * from the context URL.
87.447 + * <p>
87.448 + * If the authority component is present in the spec then the spec is
87.449 + * treated as absolute and the spec authority and path will replace the
87.450 + * context authority and path. If the authority component is absent in the
87.451 + * spec then the authority of the new URL will be inherited from the
87.452 + * context.
87.453 + * <p>
87.454 + * If the spec's path component begins with a slash character
87.455 + * "/" then the
87.456 + * path is treated as absolute and the spec path replaces the context path.
87.457 + * <p>
87.458 + * Otherwise, the path is treated as a relative path and is appended to the
87.459 + * context path, as described in RFC2396. Also, in this case,
87.460 + * the path is canonicalized through the removal of directory
87.461 + * changes made by occurences of ".." and ".".
87.462 + * <p>
87.463 + * For a more detailed description of URL parsing, refer to RFC2396.
87.464 + *
87.465 + * @param context the context in which to parse the specification.
87.466 + * @param spec the <code>String</code> to parse as a URL.
87.467 + * @exception MalformedURLException if no protocol is specified, or an
87.468 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
87.469 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
87.470 + * int, java.lang.String)
87.471 + * @see java.net.URLStreamHandler
87.472 + * @see java.net.URLStreamHandler#parseURL(java.net.URL,
87.473 + * java.lang.String, int, int)
87.474 + */
87.475 + public URL(URL context, String spec) throws MalformedURLException {
87.476 + this(context, spec, null);
87.477 + }
87.478 +
87.479 + /**
87.480 + * Creates a URL by parsing the given spec with the specified handler
87.481 + * within a specified context. If the handler is null, the parsing
87.482 + * occurs as with the two argument constructor.
87.483 + *
87.484 + * @param context the context in which to parse the specification.
87.485 + * @param spec the <code>String</code> to parse as a URL.
87.486 + * @param handler the stream handler for the URL.
87.487 + * @exception MalformedURLException if no protocol is specified, or an
87.488 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
87.489 + * @exception SecurityException
87.490 + * if a security manager exists and its
87.491 + * <code>checkPermission</code> method doesn't allow
87.492 + * specifying a stream handler.
87.493 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
87.494 + * int, java.lang.String)
87.495 + * @see java.net.URLStreamHandler
87.496 + * @see java.net.URLStreamHandler#parseURL(java.net.URL,
87.497 + * java.lang.String, int, int)
87.498 + */
87.499 + public URL(URL context, String spec, URLStreamHandler handler)
87.500 + throws MalformedURLException
87.501 + {
87.502 + String original = spec;
87.503 + int i, limit, c;
87.504 + int start = 0;
87.505 + String newProtocol = null;
87.506 + boolean aRef=false;
87.507 + boolean isRelative = false;
87.508 +
87.509 + // Check for permission to specify a handler
87.510 + if (handler != null) {
87.511 + throw new SecurityException();
87.512 + }
87.513 +
87.514 + try {
87.515 + limit = spec.length();
87.516 + while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
87.517 + limit--; //eliminate trailing whitespace
87.518 + }
87.519 + while ((start < limit) && (spec.charAt(start) <= ' ')) {
87.520 + start++; // eliminate leading whitespace
87.521 + }
87.522 +
87.523 + if (spec.regionMatches(true, start, "url:", 0, 4)) {
87.524 + start += 4;
87.525 + }
87.526 + if (start < spec.length() && spec.charAt(start) == '#') {
87.527 + /* we're assuming this is a ref relative to the context URL.
87.528 + * This means protocols cannot start w/ '#', but we must parse
87.529 + * ref URL's like: "hello:there" w/ a ':' in them.
87.530 + */
87.531 + aRef=true;
87.532 + }
87.533 + for (i = start ; !aRef && (i < limit) &&
87.534 + ((c = spec.charAt(i)) != '/') ; i++) {
87.535 + if (c == ':') {
87.536 +
87.537 + String s = spec.substring(start, i).toLowerCase();
87.538 + if (isValidProtocol(s)) {
87.539 + newProtocol = s;
87.540 + start = i + 1;
87.541 + }
87.542 + break;
87.543 + }
87.544 + }
87.545 +
87.546 + // Only use our context if the protocols match.
87.547 + protocol = newProtocol;
87.548 + if ((context != null) && ((newProtocol == null) ||
87.549 + newProtocol.equalsIgnoreCase(context.protocol))) {
87.550 + // inherit the protocol handler from the context
87.551 + // if not specified to the constructor
87.552 + if (handler == null) {
87.553 + handler = context.handler;
87.554 + }
87.555 +
87.556 + // If the context is a hierarchical URL scheme and the spec
87.557 + // contains a matching scheme then maintain backwards
87.558 + // compatibility and treat it as if the spec didn't contain
87.559 + // the scheme; see 5.2.3 of RFC2396
87.560 + if (context.path != null && context.path.startsWith("/"))
87.561 + newProtocol = null;
87.562 +
87.563 + if (newProtocol == null) {
87.564 + protocol = context.protocol;
87.565 + authority = context.authority;
87.566 + userInfo = context.userInfo;
87.567 + host = context.host;
87.568 + port = context.port;
87.569 + file = context.file;
87.570 + path = context.path;
87.571 + isRelative = true;
87.572 + }
87.573 + }
87.574 +
87.575 + if (protocol == null) {
87.576 + throw new MalformedURLException("no protocol: "+original);
87.577 + }
87.578 +
87.579 + // Get the protocol handler if not specified or the protocol
87.580 + // of the context could not be used
87.581 + if (handler == null &&
87.582 + (handler = getURLStreamHandler(protocol)) == null) {
87.583 + throw new MalformedURLException("unknown protocol: "+protocol);
87.584 + }
87.585 + this.handler = handler;
87.586 +
87.587 + i = spec.indexOf('#', start);
87.588 + if (i >= 0) {
87.589 +//thrw(protocol + " hnd: " + handler.getClass().getName() + " i: " + i);
87.590 + ref = spec.substring(i + 1, limit);
87.591 + limit = i;
87.592 + }
87.593 +
87.594 + /*
87.595 + * Handle special case inheritance of query and fragment
87.596 + * implied by RFC2396 section 5.2.2.
87.597 + */
87.598 + if (isRelative && start == limit) {
87.599 + query = context.query;
87.600 + if (ref == null) {
87.601 + ref = context.ref;
87.602 + }
87.603 + }
87.604 +
87.605 + handler.parseURL(this, spec, start, limit);
87.606 +
87.607 + } catch(MalformedURLException e) {
87.608 + throw e;
87.609 + } catch(Exception e) {
87.610 + MalformedURLException exception = new MalformedURLException(e.getMessage());
87.611 + exception.initCause(e);
87.612 + throw exception;
87.613 + }
87.614 + }
87.615 +
87.616 + /*
87.617 + * Returns true if specified string is a valid protocol name.
87.618 + */
87.619 + private boolean isValidProtocol(String protocol) {
87.620 + int len = protocol.length();
87.621 + if (len < 1)
87.622 + return false;
87.623 + char c = protocol.charAt(0);
87.624 + if (!Character.isLetter(c))
87.625 + return false;
87.626 + for (int i = 1; i < len; i++) {
87.627 + c = protocol.charAt(i);
87.628 + if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
87.629 + c != '-') {
87.630 + return false;
87.631 + }
87.632 + }
87.633 + return true;
87.634 + }
87.635 +
87.636 + /**
87.637 + * Sets the fields of the URL. This is not a public method so that
87.638 + * only URLStreamHandlers can modify URL fields. URLs are
87.639 + * otherwise constant.
87.640 + *
87.641 + * @param protocol the name of the protocol to use
87.642 + * @param host the name of the host
87.643 + @param port the port number on the host
87.644 + * @param file the file on the host
87.645 + * @param ref the internal reference in the URL
87.646 + */
87.647 + protected void set(String protocol, String host,
87.648 + int port, String file, String ref) {
87.649 + synchronized (this) {
87.650 + this.protocol = protocol;
87.651 + this.host = host;
87.652 + authority = port == -1 ? host : host + ":" + port;
87.653 + this.port = port;
87.654 + this.file = file;
87.655 + this.ref = ref;
87.656 + /* This is very important. We must recompute this after the
87.657 + * URL has been changed. */
87.658 + hashCode = -1;
87.659 + hostAddress = null;
87.660 + int q = file.lastIndexOf('?');
87.661 + if (q != -1) {
87.662 + query = file.substring(q+1);
87.663 + path = file.substring(0, q);
87.664 + } else
87.665 + path = file;
87.666 + }
87.667 + }
87.668 +
87.669 + /**
87.670 + * Sets the specified 8 fields of the URL. This is not a public method so
87.671 + * that only URLStreamHandlers can modify URL fields. URLs are otherwise
87.672 + * constant.
87.673 + *
87.674 + * @param protocol the name of the protocol to use
87.675 + * @param host the name of the host
87.676 + * @param port the port number on the host
87.677 + * @param authority the authority part for the url
87.678 + * @param userInfo the username and password
87.679 + * @param path the file on the host
87.680 + * @param ref the internal reference in the URL
87.681 + * @param query the query part of this URL
87.682 + * @since 1.3
87.683 + */
87.684 + protected void set(String protocol, String host, int port,
87.685 + String authority, String userInfo, String path,
87.686 + String query, String ref) {
87.687 + synchronized (this) {
87.688 + this.protocol = protocol;
87.689 + this.host = host;
87.690 + this.port = port;
87.691 + this.file = query == null ? path : path + "?" + query;
87.692 + this.userInfo = userInfo;
87.693 + this.path = path;
87.694 + this.ref = ref;
87.695 + /* This is very important. We must recompute this after the
87.696 + * URL has been changed. */
87.697 + hashCode = -1;
87.698 + hostAddress = null;
87.699 + this.query = query;
87.700 + this.authority = authority;
87.701 + }
87.702 + }
87.703 +
87.704 + /**
87.705 + * Gets the query part of this <code>URL</code>.
87.706 + *
87.707 + * @return the query part of this <code>URL</code>,
87.708 + * or <CODE>null</CODE> if one does not exist
87.709 + * @since 1.3
87.710 + */
87.711 + public String getQuery() {
87.712 + return query;
87.713 + }
87.714 +
87.715 + /**
87.716 + * Gets the path part of this <code>URL</code>.
87.717 + *
87.718 + * @return the path part of this <code>URL</code>, or an
87.719 + * empty string if one does not exist
87.720 + * @since 1.3
87.721 + */
87.722 + public String getPath() {
87.723 + return path;
87.724 + }
87.725 +
87.726 + /**
87.727 + * Gets the userInfo part of this <code>URL</code>.
87.728 + *
87.729 + * @return the userInfo part of this <code>URL</code>, or
87.730 + * <CODE>null</CODE> if one does not exist
87.731 + * @since 1.3
87.732 + */
87.733 + public String getUserInfo() {
87.734 + return userInfo;
87.735 + }
87.736 +
87.737 + /**
87.738 + * Gets the authority part of this <code>URL</code>.
87.739 + *
87.740 + * @return the authority part of this <code>URL</code>
87.741 + * @since 1.3
87.742 + */
87.743 + public String getAuthority() {
87.744 + return authority;
87.745 + }
87.746 +
87.747 + /**
87.748 + * Gets the port number of this <code>URL</code>.
87.749 + *
87.750 + * @return the port number, or -1 if the port is not set
87.751 + */
87.752 + public int getPort() {
87.753 + return port;
87.754 + }
87.755 +
87.756 + /**
87.757 + * Gets the default port number of the protocol associated
87.758 + * with this <code>URL</code>. If the URL scheme or the URLStreamHandler
87.759 + * for the URL do not define a default port number,
87.760 + * then -1 is returned.
87.761 + *
87.762 + * @return the port number
87.763 + * @since 1.4
87.764 + */
87.765 + public int getDefaultPort() {
87.766 + return handler.getDefaultPort();
87.767 + }
87.768 +
87.769 + /**
87.770 + * Gets the protocol name of this <code>URL</code>.
87.771 + *
87.772 + * @return the protocol of this <code>URL</code>.
87.773 + */
87.774 + public String getProtocol() {
87.775 + return protocol;
87.776 + }
87.777 +
87.778 + /**
87.779 + * Gets the host name of this <code>URL</code>, if applicable.
87.780 + * The format of the host conforms to RFC 2732, i.e. for a
87.781 + * literal IPv6 address, this method will return the IPv6 address
87.782 + * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
87.783 + *
87.784 + * @return the host name of this <code>URL</code>.
87.785 + */
87.786 + public String getHost() {
87.787 + return host;
87.788 + }
87.789 +
87.790 + /**
87.791 + * Gets the file name of this <code>URL</code>.
87.792 + * The returned file portion will be
87.793 + * the same as <CODE>getPath()</CODE>, plus the concatenation of
87.794 + * the value of <CODE>getQuery()</CODE>, if any. If there is
87.795 + * no query portion, this method and <CODE>getPath()</CODE> will
87.796 + * return identical results.
87.797 + *
87.798 + * @return the file name of this <code>URL</code>,
87.799 + * or an empty string if one does not exist
87.800 + */
87.801 + public String getFile() {
87.802 + return file;
87.803 + }
87.804 +
87.805 + /**
87.806 + * Gets the anchor (also known as the "reference") of this
87.807 + * <code>URL</code>.
87.808 + *
87.809 + * @return the anchor (also known as the "reference") of this
87.810 + * <code>URL</code>, or <CODE>null</CODE> if one does not exist
87.811 + */
87.812 + public String getRef() {
87.813 + return ref;
87.814 + }
87.815 +
87.816 + /**
87.817 + * Compares this URL for equality with another object.<p>
87.818 + *
87.819 + * If the given object is not a URL then this method immediately returns
87.820 + * <code>false</code>.<p>
87.821 + *
87.822 + * Two URL objects are equal if they have the same protocol, reference
87.823 + * equivalent hosts, have the same port number on the host, and the same
87.824 + * file and fragment of the file.<p>
87.825 + *
87.826 + * Two hosts are considered equivalent if both host names can be resolved
87.827 + * into the same IP addresses; else if either host name can't be
87.828 + * resolved, the host names must be equal without regard to case; or both
87.829 + * host names equal to null.<p>
87.830 + *
87.831 + * Since hosts comparison requires name resolution, this operation is a
87.832 + * blocking operation. <p>
87.833 + *
87.834 + * Note: The defined behavior for <code>equals</code> is known to
87.835 + * be inconsistent with virtual hosting in HTTP.
87.836 + *
87.837 + * @param obj the URL to compare against.
87.838 + * @return <code>true</code> if the objects are the same;
87.839 + * <code>false</code> otherwise.
87.840 + */
87.841 + public boolean equals(Object obj) {
87.842 + if (!(obj instanceof URL))
87.843 + return false;
87.844 + URL u2 = (URL)obj;
87.845 +
87.846 + return handler.equals(this, u2);
87.847 + }
87.848 +
87.849 + /**
87.850 + * Creates an integer suitable for hash table indexing.<p>
87.851 + *
87.852 + * The hash code is based upon all the URL components relevant for URL
87.853 + * comparison. As such, this operation is a blocking operation.<p>
87.854 + *
87.855 + * @return a hash code for this <code>URL</code>.
87.856 + */
87.857 + public synchronized int hashCode() {
87.858 + if (hashCode != -1)
87.859 + return hashCode;
87.860 +
87.861 + hashCode = handler.hashCode(this);
87.862 + return hashCode;
87.863 + }
87.864 +
87.865 + /**
87.866 + * Compares two URLs, excluding the fragment component.<p>
87.867 + *
87.868 + * Returns <code>true</code> if this <code>URL</code> and the
87.869 + * <code>other</code> argument are equal without taking the
87.870 + * fragment component into consideration.
87.871 + *
87.872 + * @param other the <code>URL</code> to compare against.
87.873 + * @return <code>true</code> if they reference the same remote object;
87.874 + * <code>false</code> otherwise.
87.875 + */
87.876 + public boolean sameFile(URL other) {
87.877 + return handler.sameFile(this, other);
87.878 + }
87.879 +
87.880 + /**
87.881 + * Constructs a string representation of this <code>URL</code>. The
87.882 + * string is created by calling the <code>toExternalForm</code>
87.883 + * method of the stream protocol handler for this object.
87.884 + *
87.885 + * @return a string representation of this object.
87.886 + * @see java.net.URL#URL(java.lang.String, java.lang.String, int,
87.887 + * java.lang.String)
87.888 + * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
87.889 + */
87.890 + public String toString() {
87.891 + return toExternalForm();
87.892 + }
87.893 +
87.894 + /**
87.895 + * Constructs a string representation of this <code>URL</code>. The
87.896 + * string is created by calling the <code>toExternalForm</code>
87.897 + * method of the stream protocol handler for this object.
87.898 + *
87.899 + * @return a string representation of this object.
87.900 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
87.901 + * int, java.lang.String)
87.902 + * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
87.903 + */
87.904 + public String toExternalForm() {
87.905 + return handler.toExternalForm(this);
87.906 + }
87.907 +
87.908 + /**
87.909 + * Returns a {@link java.net.URLConnection URLConnection} instance that
87.910 + * represents a connection to the remote object referred to by the
87.911 + * {@code URL}.
87.912 + *
87.913 + * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
87.914 + * created every time when invoking the
87.915 + * {@linkplain java.net.URLStreamHandler#openConnection(URL)
87.916 + * URLStreamHandler.openConnection(URL)} method of the protocol handler for
87.917 + * this URL.</P>
87.918 + *
87.919 + * <P>It should be noted that a URLConnection instance does not establish
87.920 + * the actual network connection on creation. This will happen only when
87.921 + * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
87.922 + *
87.923 + * <P>If for the URL's protocol (such as HTTP or JAR), there
87.924 + * exists a public, specialized URLConnection subclass belonging
87.925 + * to one of the following packages or one of their subpackages:
87.926 + * java.lang, java.io, java.util, java.net, the connection
87.927 + * returned will be of that subclass. For example, for HTTP an
87.928 + * HttpURLConnection will be returned, and for JAR a
87.929 + * JarURLConnection will be returned.</P>
87.930 + *
87.931 + * @return a {@link java.net.URLConnection URLConnection} linking
87.932 + * to the URL.
87.933 + * @exception IOException if an I/O exception occurs.
87.934 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
87.935 + * int, java.lang.String)
87.936 + */
87.937 +// public URLConnection openConnection() throws java.io.IOException {
87.938 +// return handler.openConnection(this);
87.939 +// }
87.940 +
87.941 +
87.942 + /**
87.943 + * Opens a connection to this <code>URL</code> and returns an
87.944 + * <code>InputStream</code> for reading from that connection. This
87.945 + * method is a shorthand for:
87.946 + * <blockquote><pre>
87.947 + * openConnection().getInputStream()
87.948 + * </pre></blockquote>
87.949 + *
87.950 + * @return an input stream for reading from the URL connection.
87.951 + * @exception IOException if an I/O exception occurs.
87.952 + * @see java.net.URL#openConnection()
87.953 + * @see java.net.URLConnection#getInputStream()
87.954 + */
87.955 + public final InputStream openStream() throws java.io.IOException {
87.956 + throw new IOException();
87.957 +// return openConnection().getInputStream();
87.958 + }
87.959 +
87.960 + /**
87.961 + * Gets the contents of this URL. This method is a shorthand for:
87.962 + * <blockquote><pre>
87.963 + * openConnection().getContent()
87.964 + * </pre></blockquote>
87.965 + *
87.966 + * @return the contents of this URL.
87.967 + * @exception IOException if an I/O exception occurs.
87.968 + * @see java.net.URLConnection#getContent()
87.969 + */
87.970 + public final Object getContent() throws java.io.IOException {
87.971 + return loadText(toExternalForm());
87.972 + }
87.973 +
87.974 + @JavaScriptBody(args = "url", body = ""
87.975 + + "var request = new XMLHttpRequest();\n"
87.976 + + "request.open('GET', url, false);\n"
87.977 + + "request.send();\n"
87.978 + + "return request.responseText;\n"
87.979 + )
87.980 + private static native String loadText(String url) throws IOException;
87.981 +
87.982 + /**
87.983 + * Gets the contents of this URL. This method is a shorthand for:
87.984 + * <blockquote><pre>
87.985 + * openConnection().getContent(Class[])
87.986 + * </pre></blockquote>
87.987 + *
87.988 + * @param classes an array of Java types
87.989 + * @return the content object of this URL that is the first match of
87.990 + * the types specified in the classes array.
87.991 + * null if none of the requested types are supported.
87.992 + * @exception IOException if an I/O exception occurs.
87.993 + * @see java.net.URLConnection#getContent(Class[])
87.994 + * @since 1.3
87.995 + */
87.996 + public final Object getContent(Class[] classes)
87.997 + throws java.io.IOException {
87.998 + for (Class<?> c : classes) {
87.999 + if (c == String.class) {
87.1000 + return getContent();
87.1001 + }
87.1002 + }
87.1003 + return null;
87.1004 + }
87.1005 +
87.1006 + static URLStreamHandler getURLStreamHandler(String protocol) {
87.1007 + URLStreamHandler universal = new URLStreamHandler() {};
87.1008 + return universal;
87.1009 + }
87.1010 +
87.1011 +}
87.1012 +
87.1013 +class Parts {
87.1014 + String path, query, ref;
87.1015 +
87.1016 + Parts(String file) {
87.1017 + int ind = file.indexOf('#');
87.1018 + ref = ind < 0 ? null: file.substring(ind + 1);
87.1019 + file = ind < 0 ? file: file.substring(0, ind);
87.1020 + int q = file.lastIndexOf('?');
87.1021 + if (q != -1) {
87.1022 + query = file.substring(q+1);
87.1023 + path = file.substring(0, q);
87.1024 + } else {
87.1025 + path = file;
87.1026 + }
87.1027 + }
87.1028 +
87.1029 + String getPath() {
87.1030 + return path;
87.1031 + }
87.1032 +
87.1033 + String getQuery() {
87.1034 + return query;
87.1035 + }
87.1036 +
87.1037 + String getRef() {
87.1038 + return ref;
87.1039 + }
87.1040 +}
88.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
88.2 +++ b/emul/mini/src/main/java/java/net/URLStreamHandler.java Wed Jan 23 20:39:23 2013 +0100
88.3 @@ -0,0 +1,568 @@
88.4 +/*
88.5 + * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
88.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
88.7 + *
88.8 + * This code is free software; you can redistribute it and/or modify it
88.9 + * under the terms of the GNU General Public License version 2 only, as
88.10 + * published by the Free Software Foundation. Oracle designates this
88.11 + * particular file as subject to the "Classpath" exception as provided
88.12 + * by Oracle in the LICENSE file that accompanied this code.
88.13 + *
88.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
88.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
88.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
88.17 + * version 2 for more details (a copy is included in the LICENSE file that
88.18 + * accompanied this code).
88.19 + *
88.20 + * You should have received a copy of the GNU General Public License version
88.21 + * 2 along with this work; if not, write to the Free Software Foundation,
88.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
88.23 + *
88.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
88.25 + * or visit www.oracle.com if you need additional information or have any
88.26 + * questions.
88.27 + */
88.28 +
88.29 +package java.net;
88.30 +
88.31 +
88.32 +/**
88.33 + * The abstract class <code>URLStreamHandler</code> is the common
88.34 + * superclass for all stream protocol handlers. A stream protocol
88.35 + * handler knows how to make a connection for a particular protocol
88.36 + * type, such as <code>http</code>, <code>ftp</code>, or
88.37 + * <code>gopher</code>.
88.38 + * <p>
88.39 + * In most cases, an instance of a <code>URLStreamHandler</code>
88.40 + * subclass is not created directly by an application. Rather, the
88.41 + * first time a protocol name is encountered when constructing a
88.42 + * <code>URL</code>, the appropriate stream protocol handler is
88.43 + * automatically loaded.
88.44 + *
88.45 + * @author James Gosling
88.46 + * @see java.net.URL#URL(java.lang.String, java.lang.String, int, java.lang.String)
88.47 + * @since JDK1.0
88.48 + */
88.49 +public abstract class URLStreamHandler {
88.50 + /**
88.51 + * Opens a connection to the object referenced by the
88.52 + * <code>URL</code> argument.
88.53 + * This method should be overridden by a subclass.
88.54 + *
88.55 + * <p>If for the handler's protocol (such as HTTP or JAR), there
88.56 + * exists a public, specialized URLConnection subclass belonging
88.57 + * to one of the following packages or one of their subpackages:
88.58 + * java.lang, java.io, java.util, java.net, the connection
88.59 + * returned will be of that subclass. For example, for HTTP an
88.60 + * HttpURLConnection will be returned, and for JAR a
88.61 + * JarURLConnection will be returned.
88.62 + *
88.63 + * @param u the URL that this connects to.
88.64 + * @return a <code>URLConnection</code> object for the <code>URL</code>.
88.65 + * @exception IOException if an I/O error occurs while opening the
88.66 + * connection.
88.67 + */
88.68 +// abstract protected URLConnection openConnection(URL u) throws IOException;
88.69 +
88.70 + /**
88.71 + * Same as openConnection(URL), except that the connection will be
88.72 + * made through the specified proxy; Protocol handlers that do not
88.73 + * support proxying will ignore the proxy parameter and make a
88.74 + * normal connection.
88.75 + *
88.76 + * Calling this method preempts the system's default ProxySelector
88.77 + * settings.
88.78 + *
88.79 + * @param u the URL that this connects to.
88.80 + * @param p the proxy through which the connection will be made.
88.81 + * If direct connection is desired, Proxy.NO_PROXY
88.82 + * should be specified.
88.83 + * @return a <code>URLConnection</code> object for the <code>URL</code>.
88.84 + * @exception IOException if an I/O error occurs while opening the
88.85 + * connection.
88.86 + * @exception IllegalArgumentException if either u or p is null,
88.87 + * or p has the wrong type.
88.88 + * @exception UnsupportedOperationException if the subclass that
88.89 + * implements the protocol doesn't support this method.
88.90 + * @since 1.5
88.91 + */
88.92 +// protected URLConnection openConnection(URL u, Proxy p) throws IOException {
88.93 +// throw new UnsupportedOperationException("Method not implemented.");
88.94 +// }
88.95 +
88.96 + /**
88.97 + * Parses the string representation of a <code>URL</code> into a
88.98 + * <code>URL</code> object.
88.99 + * <p>
88.100 + * If there is any inherited context, then it has already been
88.101 + * copied into the <code>URL</code> argument.
88.102 + * <p>
88.103 + * The <code>parseURL</code> method of <code>URLStreamHandler</code>
88.104 + * parses the string representation as if it were an
88.105 + * <code>http</code> specification. Most URL protocol families have a
88.106 + * similar parsing. A stream protocol handler for a protocol that has
88.107 + * a different syntax must override this routine.
88.108 + *
88.109 + * @param u the <code>URL</code> to receive the result of parsing
88.110 + * the spec.
88.111 + * @param spec the <code>String</code> representing the URL that
88.112 + * must be parsed.
88.113 + * @param start the character index at which to begin parsing. This is
88.114 + * just past the '<code>:</code>' (if there is one) that
88.115 + * specifies the determination of the protocol name.
88.116 + * @param limit the character position to stop parsing at. This is the
88.117 + * end of the string or the position of the
88.118 + * "<code>#</code>" character, if present. All information
88.119 + * after the sharp sign indicates an anchor.
88.120 + */
88.121 + protected void parseURL(URL u, String spec, int start, int limit) {
88.122 + // These fields may receive context content if this was relative URL
88.123 + String protocol = u.getProtocol();
88.124 + String authority = u.getAuthority();
88.125 + String userInfo = u.getUserInfo();
88.126 + String host = u.getHost();
88.127 + int port = u.getPort();
88.128 + String path = u.getPath();
88.129 + String query = u.getQuery();
88.130 +
88.131 + // This field has already been parsed
88.132 + String ref = u.getRef();
88.133 +
88.134 + boolean isRelPath = false;
88.135 + boolean queryOnly = false;
88.136 +
88.137 +// FIX: should not assume query if opaque
88.138 + // Strip off the query part
88.139 + if (start < limit) {
88.140 + int queryStart = spec.indexOf('?');
88.141 + queryOnly = queryStart == start;
88.142 + if ((queryStart != -1) && (queryStart < limit)) {
88.143 + query = spec.substring(queryStart+1, limit);
88.144 + if (limit > queryStart)
88.145 + limit = queryStart;
88.146 + spec = spec.substring(0, queryStart);
88.147 + }
88.148 + }
88.149 +
88.150 + int i = 0;
88.151 + // Parse the authority part if any
88.152 + boolean isUNCName = (start <= limit - 4) &&
88.153 + (spec.charAt(start) == '/') &&
88.154 + (spec.charAt(start + 1) == '/') &&
88.155 + (spec.charAt(start + 2) == '/') &&
88.156 + (spec.charAt(start + 3) == '/');
88.157 + if (!isUNCName && (start <= limit - 2) && (spec.charAt(start) == '/') &&
88.158 + (spec.charAt(start + 1) == '/')) {
88.159 + start += 2;
88.160 + i = spec.indexOf('/', start);
88.161 + if (i < 0) {
88.162 + i = spec.indexOf('?', start);
88.163 + if (i < 0)
88.164 + i = limit;
88.165 + }
88.166 +
88.167 + host = authority = spec.substring(start, i);
88.168 +
88.169 + int ind = authority.indexOf('@');
88.170 + if (ind != -1) {
88.171 + userInfo = authority.substring(0, ind);
88.172 + host = authority.substring(ind+1);
88.173 + } else {
88.174 + userInfo = null;
88.175 + }
88.176 + if (host != null) {
88.177 + // If the host is surrounded by [ and ] then its an IPv6
88.178 + // literal address as specified in RFC2732
88.179 + if (host.length()>0 && (host.charAt(0) == '[')) {
88.180 + if ((ind = host.indexOf(']')) > 2) {
88.181 +
88.182 + String nhost = host ;
88.183 + host = nhost.substring(0,ind+1);
88.184 +// if (!IPAddressUtil.
88.185 +// isIPv6LiteralAddress(host.substring(1, ind))) {
88.186 +// throw new IllegalArgumentException(
88.187 +// "Invalid host: "+ host);
88.188 +// }
88.189 +
88.190 + port = -1 ;
88.191 + if (nhost.length() > ind+1) {
88.192 + if (nhost.charAt(ind+1) == ':') {
88.193 + ++ind ;
88.194 + // port can be null according to RFC2396
88.195 + if (nhost.length() > (ind + 1)) {
88.196 + port = Integer.parseInt(nhost.substring(ind+1));
88.197 + }
88.198 + } else {
88.199 + throw new IllegalArgumentException(
88.200 + "Invalid authority field: " + authority);
88.201 + }
88.202 + }
88.203 + } else {
88.204 + throw new IllegalArgumentException(
88.205 + "Invalid authority field: " + authority);
88.206 + }
88.207 + } else {
88.208 + ind = host.indexOf(':');
88.209 + port = -1;
88.210 + if (ind >= 0) {
88.211 + // port can be null according to RFC2396
88.212 + if (host.length() > (ind + 1)) {
88.213 + port = Integer.parseInt(host.substring(ind + 1));
88.214 + }
88.215 + host = host.substring(0, ind);
88.216 + }
88.217 + }
88.218 + } else {
88.219 + host = "";
88.220 + }
88.221 + if (port < -1)
88.222 + throw new IllegalArgumentException("Invalid port number :" +
88.223 + port);
88.224 + start = i;
88.225 + // If the authority is defined then the path is defined by the
88.226 + // spec only; See RFC 2396 Section 5.2.4.
88.227 + if (authority != null && authority.length() > 0)
88.228 + path = "";
88.229 + }
88.230 +
88.231 + if (host == null) {
88.232 + host = "";
88.233 + }
88.234 +
88.235 + // Parse the file path if any
88.236 + if (start < limit) {
88.237 + if (spec.charAt(start) == '/') {
88.238 + path = spec.substring(start, limit);
88.239 + } else if (path != null && path.length() > 0) {
88.240 + isRelPath = true;
88.241 + int ind = path.lastIndexOf('/');
88.242 + String seperator = "";
88.243 + if (ind == -1 && authority != null)
88.244 + seperator = "/";
88.245 + path = path.substring(0, ind + 1) + seperator +
88.246 + spec.substring(start, limit);
88.247 +
88.248 + } else {
88.249 + String seperator = (authority != null) ? "/" : "";
88.250 + path = seperator + spec.substring(start, limit);
88.251 + }
88.252 + } else if (queryOnly && path != null) {
88.253 + int ind = path.lastIndexOf('/');
88.254 + if (ind < 0)
88.255 + ind = 0;
88.256 + path = path.substring(0, ind) + "/";
88.257 + }
88.258 + if (path == null)
88.259 + path = "";
88.260 +
88.261 + if (isRelPath) {
88.262 + // Remove embedded /./
88.263 + while ((i = path.indexOf("/./")) >= 0) {
88.264 + path = path.substring(0, i) + path.substring(i + 2);
88.265 + }
88.266 + // Remove embedded /../ if possible
88.267 + i = 0;
88.268 + while ((i = path.indexOf("/../", i)) >= 0) {
88.269 + /*
88.270 + * A "/../" will cancel the previous segment and itself,
88.271 + * unless that segment is a "/../" itself
88.272 + * i.e. "/a/b/../c" becomes "/a/c"
88.273 + * but "/../../a" should stay unchanged
88.274 + */
88.275 + if (i > 0 && (limit = path.lastIndexOf('/', i - 1)) >= 0 &&
88.276 + (path.indexOf("/../", limit) != 0)) {
88.277 + path = path.substring(0, limit) + path.substring(i + 3);
88.278 + i = 0;
88.279 + } else {
88.280 + i = i + 3;
88.281 + }
88.282 + }
88.283 + // Remove trailing .. if possible
88.284 + while (path.endsWith("/..")) {
88.285 + i = path.indexOf("/..");
88.286 + if ((limit = path.lastIndexOf('/', i - 1)) >= 0) {
88.287 + path = path.substring(0, limit+1);
88.288 + } else {
88.289 + break;
88.290 + }
88.291 + }
88.292 + // Remove starting .
88.293 + if (path.startsWith("./") && path.length() > 2)
88.294 + path = path.substring(2);
88.295 +
88.296 + // Remove trailing .
88.297 + if (path.endsWith("/."))
88.298 + path = path.substring(0, path.length() -1);
88.299 + }
88.300 +
88.301 + setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
88.302 + }
88.303 +
88.304 + /**
88.305 + * Returns the default port for a URL parsed by this handler. This method
88.306 + * is meant to be overidden by handlers with default port numbers.
88.307 + * @return the default port for a <code>URL</code> parsed by this handler.
88.308 + * @since 1.3
88.309 + */
88.310 + protected int getDefaultPort() {
88.311 + return -1;
88.312 + }
88.313 +
88.314 + /**
88.315 + * Provides the default equals calculation. May be overidden by handlers
88.316 + * for other protocols that have different requirements for equals().
88.317 + * This method requires that none of its arguments is null. This is
88.318 + * guaranteed by the fact that it is only called by java.net.URL class.
88.319 + * @param u1 a URL object
88.320 + * @param u2 a URL object
88.321 + * @return <tt>true</tt> if the two urls are
88.322 + * considered equal, ie. they refer to the same
88.323 + * fragment in the same file.
88.324 + * @since 1.3
88.325 + */
88.326 + protected boolean equals(URL u1, URL u2) {
88.327 + String ref1 = u1.getRef();
88.328 + String ref2 = u2.getRef();
88.329 + return (ref1 == ref2 || (ref1 != null && ref1.equals(ref2))) &&
88.330 + sameFile(u1, u2);
88.331 + }
88.332 +
88.333 + /**
88.334 + * Provides the default hash calculation. May be overidden by handlers for
88.335 + * other protocols that have different requirements for hashCode
88.336 + * calculation.
88.337 + * @param u a URL object
88.338 + * @return an <tt>int</tt> suitable for hash table indexing
88.339 + * @since 1.3
88.340 + */
88.341 + protected int hashCode(URL u) {
88.342 + int h = 0;
88.343 +
88.344 + // Generate the protocol part.
88.345 + String protocol = u.getProtocol();
88.346 + if (protocol != null)
88.347 + h += protocol.hashCode();
88.348 +
88.349 + // Generate the host part.
88.350 + Object addr = getHostAddress(u);
88.351 + if (addr != null) {
88.352 + h += addr.hashCode();
88.353 + } else {
88.354 + String host = u.getHost();
88.355 + if (host != null)
88.356 + h += host.toLowerCase().hashCode();
88.357 + }
88.358 +
88.359 + // Generate the file part.
88.360 + String file = u.getFile();
88.361 + if (file != null)
88.362 + h += file.hashCode();
88.363 +
88.364 + // Generate the port part.
88.365 + if (u.getPort() == -1)
88.366 + h += getDefaultPort();
88.367 + else
88.368 + h += u.getPort();
88.369 +
88.370 + // Generate the ref part.
88.371 + String ref = u.getRef();
88.372 + if (ref != null)
88.373 + h += ref.hashCode();
88.374 +
88.375 + return h;
88.376 + }
88.377 +
88.378 + /**
88.379 + * Compare two urls to see whether they refer to the same file,
88.380 + * i.e., having the same protocol, host, port, and path.
88.381 + * This method requires that none of its arguments is null. This is
88.382 + * guaranteed by the fact that it is only called indirectly
88.383 + * by java.net.URL class.
88.384 + * @param u1 a URL object
88.385 + * @param u2 a URL object
88.386 + * @return true if u1 and u2 refer to the same file
88.387 + * @since 1.3
88.388 + */
88.389 + protected boolean sameFile(URL u1, URL u2) {
88.390 + // Compare the protocols.
88.391 + if (!((u1.getProtocol() == u2.getProtocol()) ||
88.392 + (u1.getProtocol() != null &&
88.393 + u1.getProtocol().equalsIgnoreCase(u2.getProtocol()))))
88.394 + return false;
88.395 +
88.396 + // Compare the files.
88.397 + if (!(u1.getFile() == u2.getFile() ||
88.398 + (u1.getFile() != null && u1.getFile().equals(u2.getFile()))))
88.399 + return false;
88.400 +
88.401 + // Compare the ports.
88.402 + int port1, port2;
88.403 + port1 = (u1.getPort() != -1) ? u1.getPort() : u1.handler.getDefaultPort();
88.404 + port2 = (u2.getPort() != -1) ? u2.getPort() : u2.handler.getDefaultPort();
88.405 + if (port1 != port2)
88.406 + return false;
88.407 +
88.408 + // Compare the hosts.
88.409 + if (!hostsEqual(u1, u2))
88.410 + return false;
88.411 +
88.412 + return true;
88.413 + }
88.414 +
88.415 + /**
88.416 + * Get the IP address of our host. An empty host field or a DNS failure
88.417 + * will result in a null return.
88.418 + *
88.419 + * @param u a URL object
88.420 + * @return an <code>InetAddress</code> representing the host
88.421 + * IP address.
88.422 + * @since 1.3
88.423 + */
88.424 + private synchronized Object getHostAddress(URL u) {
88.425 + return u.hostAddress;
88.426 + }
88.427 +
88.428 + /**
88.429 + * Compares the host components of two URLs.
88.430 + * @param u1 the URL of the first host to compare
88.431 + * @param u2 the URL of the second host to compare
88.432 + * @return <tt>true</tt> if and only if they
88.433 + * are equal, <tt>false</tt> otherwise.
88.434 + * @since 1.3
88.435 + */
88.436 + protected boolean hostsEqual(URL u1, URL u2) {
88.437 + Object a1 = getHostAddress(u1);
88.438 + Object a2 = getHostAddress(u2);
88.439 + // if we have internet address for both, compare them
88.440 + if (a1 != null && a2 != null) {
88.441 + return a1.equals(a2);
88.442 + // else, if both have host names, compare them
88.443 + } else if (u1.getHost() != null && u2.getHost() != null)
88.444 + return u1.getHost().equalsIgnoreCase(u2.getHost());
88.445 + else
88.446 + return u1.getHost() == null && u2.getHost() == null;
88.447 + }
88.448 +
88.449 + /**
88.450 + * Converts a <code>URL</code> of a specific protocol to a
88.451 + * <code>String</code>.
88.452 + *
88.453 + * @param u the URL.
88.454 + * @return a string representation of the <code>URL</code> argument.
88.455 + */
88.456 + protected String toExternalForm(URL u) {
88.457 +
88.458 + // pre-compute length of StringBuffer
88.459 + int len = u.getProtocol().length() + 1;
88.460 + if (u.getAuthority() != null && u.getAuthority().length() > 0)
88.461 + len += 2 + u.getAuthority().length();
88.462 + if (u.getPath() != null) {
88.463 + len += u.getPath().length();
88.464 + }
88.465 + if (u.getQuery() != null) {
88.466 + len += 1 + u.getQuery().length();
88.467 + }
88.468 + if (u.getRef() != null)
88.469 + len += 1 + u.getRef().length();
88.470 +
88.471 + StringBuffer result = new StringBuffer(len);
88.472 + result.append(u.getProtocol());
88.473 + result.append(":");
88.474 + if (u.getAuthority() != null && u.getAuthority().length() > 0) {
88.475 + result.append("//");
88.476 + result.append(u.getAuthority());
88.477 + }
88.478 + if (u.getPath() != null) {
88.479 + result.append(u.getPath());
88.480 + }
88.481 + if (u.getQuery() != null) {
88.482 + result.append('?');
88.483 + result.append(u.getQuery());
88.484 + }
88.485 + if (u.getRef() != null) {
88.486 + result.append("#");
88.487 + result.append(u.getRef());
88.488 + }
88.489 + return result.toString();
88.490 + }
88.491 +
88.492 + /**
88.493 + * Sets the fields of the <code>URL</code> argument to the indicated values.
88.494 + * Only classes derived from URLStreamHandler are supposed to be able
88.495 + * to call the set method on a URL.
88.496 + *
88.497 + * @param u the URL to modify.
88.498 + * @param protocol the protocol name.
88.499 + * @param host the remote host value for the URL.
88.500 + * @param port the port on the remote machine.
88.501 + * @param authority the authority part for the URL.
88.502 + * @param userInfo the userInfo part of the URL.
88.503 + * @param path the path component of the URL.
88.504 + * @param query the query part for the URL.
88.505 + * @param ref the reference.
88.506 + * @exception SecurityException if the protocol handler of the URL is
88.507 + * different from this one
88.508 + * @see java.net.URL#set(java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
88.509 + * @since 1.3
88.510 + */
88.511 + protected void setURL(URL u, String protocol, String host, int port,
88.512 + String authority, String userInfo, String path,
88.513 + String query, String ref) {
88.514 + if (this != u.handler) {
88.515 + throw new SecurityException("handler for url different from " +
88.516 + "this handler");
88.517 + }
88.518 + // ensure that no one can reset the protocol on a given URL.
88.519 + u.set(u.getProtocol(), host, port, authority, userInfo, path, query, ref);
88.520 + }
88.521 +
88.522 + /**
88.523 + * Sets the fields of the <code>URL</code> argument to the indicated values.
88.524 + * Only classes derived from URLStreamHandler are supposed to be able
88.525 + * to call the set method on a URL.
88.526 + *
88.527 + * @param u the URL to modify.
88.528 + * @param protocol the protocol name. This value is ignored since 1.2.
88.529 + * @param host the remote host value for the URL.
88.530 + * @param port the port on the remote machine.
88.531 + * @param file the file.
88.532 + * @param ref the reference.
88.533 + * @exception SecurityException if the protocol handler of the URL is
88.534 + * different from this one
88.535 + * @deprecated Use setURL(URL, String, String, int, String, String, String,
88.536 + * String);
88.537 + */
88.538 + @Deprecated
88.539 + protected void setURL(URL u, String protocol, String host, int port,
88.540 + String file, String ref) {
88.541 + /*
88.542 + * Only old URL handlers call this, so assume that the host
88.543 + * field might contain "user:passwd@host". Fix as necessary.
88.544 + */
88.545 + String authority = null;
88.546 + String userInfo = null;
88.547 + if (host != null && host.length() != 0) {
88.548 + authority = (port == -1) ? host : host + ":" + port;
88.549 + int at = host.lastIndexOf('@');
88.550 + if (at != -1) {
88.551 + userInfo = host.substring(0, at);
88.552 + host = host.substring(at+1);
88.553 + }
88.554 + }
88.555 +
88.556 + /*
88.557 + * Assume file might contain query part. Fix as necessary.
88.558 + */
88.559 + String path = null;
88.560 + String query = null;
88.561 + if (file != null) {
88.562 + int q = file.lastIndexOf('?');
88.563 + if (q != -1) {
88.564 + query = file.substring(q+1);
88.565 + path = file.substring(0, q);
88.566 + } else
88.567 + path = file;
88.568 + }
88.569 + setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
88.570 + }
88.571 +}
89.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
89.2 +++ b/emul/mini/src/main/java/java/util/Comparator.java Wed Jan 23 20:39:23 2013 +0100
89.3 @@ -0,0 +1,168 @@
89.4 +/*
89.5 + * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
89.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
89.7 + *
89.8 + * This code is free software; you can redistribute it and/or modify it
89.9 + * under the terms of the GNU General Public License version 2 only, as
89.10 + * published by the Free Software Foundation. Oracle designates this
89.11 + * particular file as subject to the "Classpath" exception as provided
89.12 + * by Oracle in the LICENSE file that accompanied this code.
89.13 + *
89.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
89.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
89.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
89.17 + * version 2 for more details (a copy is included in the LICENSE file that
89.18 + * accompanied this code).
89.19 + *
89.20 + * You should have received a copy of the GNU General Public License version
89.21 + * 2 along with this work; if not, write to the Free Software Foundation,
89.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
89.23 + *
89.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
89.25 + * or visit www.oracle.com if you need additional information or have any
89.26 + * questions.
89.27 + */
89.28 +
89.29 +package java.util;
89.30 +
89.31 +/**
89.32 + * A comparison function, which imposes a <i>total ordering</i> on some
89.33 + * collection of objects. Comparators can be passed to a sort method (such
89.34 + * as {@link Collections#sort(List,Comparator) Collections.sort} or {@link
89.35 + * Arrays#sort(Object[],Comparator) Arrays.sort}) to allow precise control
89.36 + * over the sort order. Comparators can also be used to control the order of
89.37 + * certain data structures (such as {@link SortedSet sorted sets} or {@link
89.38 + * SortedMap sorted maps}), or to provide an ordering for collections of
89.39 + * objects that don't have a {@link Comparable natural ordering}.<p>
89.40 + *
89.41 + * The ordering imposed by a comparator <tt>c</tt> on a set of elements
89.42 + * <tt>S</tt> is said to be <i>consistent with equals</i> if and only if
89.43 + * <tt>c.compare(e1, e2)==0</tt> has the same boolean value as
89.44 + * <tt>e1.equals(e2)</tt> for every <tt>e1</tt> and <tt>e2</tt> in
89.45 + * <tt>S</tt>.<p>
89.46 + *
89.47 + * Caution should be exercised when using a comparator capable of imposing an
89.48 + * ordering inconsistent with equals to order a sorted set (or sorted map).
89.49 + * Suppose a sorted set (or sorted map) with an explicit comparator <tt>c</tt>
89.50 + * is used with elements (or keys) drawn from a set <tt>S</tt>. If the
89.51 + * ordering imposed by <tt>c</tt> on <tt>S</tt> is inconsistent with equals,
89.52 + * the sorted set (or sorted map) will behave "strangely." In particular the
89.53 + * sorted set (or sorted map) will violate the general contract for set (or
89.54 + * map), which is defined in terms of <tt>equals</tt>.<p>
89.55 + *
89.56 + * For example, suppose one adds two elements {@code a} and {@code b} such that
89.57 + * {@code (a.equals(b) && c.compare(a, b) != 0)}
89.58 + * to an empty {@code TreeSet} with comparator {@code c}.
89.59 + * The second {@code add} operation will return
89.60 + * true (and the size of the tree set will increase) because {@code a} and
89.61 + * {@code b} are not equivalent from the tree set's perspective, even though
89.62 + * this is contrary to the specification of the
89.63 + * {@link Set#add Set.add} method.<p>
89.64 + *
89.65 + * Note: It is generally a good idea for comparators to also implement
89.66 + * <tt>java.io.Serializable</tt>, as they may be used as ordering methods in
89.67 + * serializable data structures (like {@link TreeSet}, {@link TreeMap}). In
89.68 + * order for the data structure to serialize successfully, the comparator (if
89.69 + * provided) must implement <tt>Serializable</tt>.<p>
89.70 + *
89.71 + * For the mathematically inclined, the <i>relation</i> that defines the
89.72 + * <i>imposed ordering</i> that a given comparator <tt>c</tt> imposes on a
89.73 + * given set of objects <tt>S</tt> is:<pre>
89.74 + * {(x, y) such that c.compare(x, y) <= 0}.
89.75 + * </pre> The <i>quotient</i> for this total order is:<pre>
89.76 + * {(x, y) such that c.compare(x, y) == 0}.
89.77 + * </pre>
89.78 + *
89.79 + * It follows immediately from the contract for <tt>compare</tt> that the
89.80 + * quotient is an <i>equivalence relation</i> on <tt>S</tt>, and that the
89.81 + * imposed ordering is a <i>total order</i> on <tt>S</tt>. When we say that
89.82 + * the ordering imposed by <tt>c</tt> on <tt>S</tt> is <i>consistent with
89.83 + * equals</i>, we mean that the quotient for the ordering is the equivalence
89.84 + * relation defined by the objects' {@link Object#equals(Object)
89.85 + * equals(Object)} method(s):<pre>
89.86 + * {(x, y) such that x.equals(y)}. </pre>
89.87 + *
89.88 + * <p>Unlike {@code Comparable}, a comparator may optionally permit
89.89 + * comparison of null arguments, while maintaining the requirements for
89.90 + * an equivalence relation.
89.91 + *
89.92 + * <p>This interface is a member of the
89.93 + * <a href="{@docRoot}/../technotes/guides/collections/index.html">
89.94 + * Java Collections Framework</a>.
89.95 + *
89.96 + * @param <T> the type of objects that may be compared by this comparator
89.97 + *
89.98 + * @author Josh Bloch
89.99 + * @author Neal Gafter
89.100 + * @see Comparable
89.101 + * @see java.io.Serializable
89.102 + * @since 1.2
89.103 + */
89.104 +
89.105 +public interface Comparator<T> {
89.106 + /**
89.107 + * Compares its two arguments for order. Returns a negative integer,
89.108 + * zero, or a positive integer as the first argument is less than, equal
89.109 + * to, or greater than the second.<p>
89.110 + *
89.111 + * In the foregoing description, the notation
89.112 + * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
89.113 + * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
89.114 + * <tt>0</tt>, or <tt>1</tt> according to whether the value of
89.115 + * <i>expression</i> is negative, zero or positive.<p>
89.116 + *
89.117 + * The implementor must ensure that <tt>sgn(compare(x, y)) ==
89.118 + * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
89.119 + * implies that <tt>compare(x, y)</tt> must throw an exception if and only
89.120 + * if <tt>compare(y, x)</tt> throws an exception.)<p>
89.121 + *
89.122 + * The implementor must also ensure that the relation is transitive:
89.123 + * <tt>((compare(x, y)>0) && (compare(y, z)>0))</tt> implies
89.124 + * <tt>compare(x, z)>0</tt>.<p>
89.125 + *
89.126 + * Finally, the implementor must ensure that <tt>compare(x, y)==0</tt>
89.127 + * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
89.128 + * <tt>z</tt>.<p>
89.129 + *
89.130 + * It is generally the case, but <i>not</i> strictly required that
89.131 + * <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking,
89.132 + * any comparator that violates this condition should clearly indicate
89.133 + * this fact. The recommended language is "Note: this comparator
89.134 + * imposes orderings that are inconsistent with equals."
89.135 + *
89.136 + * @param o1 the first object to be compared.
89.137 + * @param o2 the second object to be compared.
89.138 + * @return a negative integer, zero, or a positive integer as the
89.139 + * first argument is less than, equal to, or greater than the
89.140 + * second.
89.141 + * @throws NullPointerException if an argument is null and this
89.142 + * comparator does not permit null arguments
89.143 + * @throws ClassCastException if the arguments' types prevent them from
89.144 + * being compared by this comparator.
89.145 + */
89.146 + int compare(T o1, T o2);
89.147 +
89.148 + /**
89.149 + * Indicates whether some other object is "equal to" this
89.150 + * comparator. This method must obey the general contract of
89.151 + * {@link Object#equals(Object)}. Additionally, this method can return
89.152 + * <tt>true</tt> <i>only</i> if the specified object is also a comparator
89.153 + * and it imposes the same ordering as this comparator. Thus,
89.154 + * <code>comp1.equals(comp2)</code> implies that <tt>sgn(comp1.compare(o1,
89.155 + * o2))==sgn(comp2.compare(o1, o2))</tt> for every object reference
89.156 + * <tt>o1</tt> and <tt>o2</tt>.<p>
89.157 + *
89.158 + * Note that it is <i>always</i> safe <i>not</i> to override
89.159 + * <tt>Object.equals(Object)</tt>. However, overriding this method may,
89.160 + * in some cases, improve performance by allowing programs to determine
89.161 + * that two distinct comparators impose the same order.
89.162 + *
89.163 + * @param obj the reference object with which to compare.
89.164 + * @return <code>true</code> only if the specified object is also
89.165 + * a comparator and it imposes the same ordering as this
89.166 + * comparator.
89.167 + * @see Object#equals(Object)
89.168 + * @see Object#hashCode()
89.169 + */
89.170 + boolean equals(Object obj);
89.171 +}
90.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
90.2 +++ b/emul/mini/src/main/java/java/util/Enumeration.java Wed Jan 23 20:39:23 2013 +0100
90.3 @@ -0,0 +1,79 @@
90.4 +/*
90.5 + * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
90.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90.7 + *
90.8 + * This code is free software; you can redistribute it and/or modify it
90.9 + * under the terms of the GNU General Public License version 2 only, as
90.10 + * published by the Free Software Foundation. Oracle designates this
90.11 + * particular file as subject to the "Classpath" exception as provided
90.12 + * by Oracle in the LICENSE file that accompanied this code.
90.13 + *
90.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
90.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
90.17 + * version 2 for more details (a copy is included in the LICENSE file that
90.18 + * accompanied this code).
90.19 + *
90.20 + * You should have received a copy of the GNU General Public License version
90.21 + * 2 along with this work; if not, write to the Free Software Foundation,
90.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90.23 + *
90.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
90.25 + * or visit www.oracle.com if you need additional information or have any
90.26 + * questions.
90.27 + */
90.28 +
90.29 +package java.util;
90.30 +
90.31 +/**
90.32 + * An object that implements the Enumeration interface generates a
90.33 + * series of elements, one at a time. Successive calls to the
90.34 + * <code>nextElement</code> method return successive elements of the
90.35 + * series.
90.36 + * <p>
90.37 + * For example, to print all elements of a <tt>Vector<E></tt> <i>v</i>:
90.38 + * <pre>
90.39 + * for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
90.40 + * System.out.println(e.nextElement());</pre>
90.41 + * <p>
90.42 + * Methods are provided to enumerate through the elements of a
90.43 + * vector, the keys of a hashtable, and the values in a hashtable.
90.44 + * Enumerations are also used to specify the input streams to a
90.45 + * <code>SequenceInputStream</code>.
90.46 + * <p>
90.47 + * NOTE: The functionality of this interface is duplicated by the Iterator
90.48 + * interface. In addition, Iterator adds an optional remove operation, and
90.49 + * has shorter method names. New implementations should consider using
90.50 + * Iterator in preference to Enumeration.
90.51 + *
90.52 + * @see java.util.Iterator
90.53 + * @see java.io.SequenceInputStream
90.54 + * @see java.util.Enumeration#nextElement()
90.55 + * @see java.util.Hashtable
90.56 + * @see java.util.Hashtable#elements()
90.57 + * @see java.util.Hashtable#keys()
90.58 + * @see java.util.Vector
90.59 + * @see java.util.Vector#elements()
90.60 + *
90.61 + * @author Lee Boynton
90.62 + * @since JDK1.0
90.63 + */
90.64 +public interface Enumeration<E> {
90.65 + /**
90.66 + * Tests if this enumeration contains more elements.
90.67 + *
90.68 + * @return <code>true</code> if and only if this enumeration object
90.69 + * contains at least one more element to provide;
90.70 + * <code>false</code> otherwise.
90.71 + */
90.72 + boolean hasMoreElements();
90.73 +
90.74 + /**
90.75 + * Returns the next element of this enumeration if this enumeration
90.76 + * object has at least one more element to provide.
90.77 + *
90.78 + * @return the next element of this enumeration.
90.79 + * @exception NoSuchElementException if no more elements exist.
90.80 + */
90.81 + E nextElement();
90.82 +}
91.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
91.2 +++ b/emul/mini/src/main/java/java/util/NoSuchElementException.java Wed Jan 23 20:39:23 2013 +0100
91.3 @@ -0,0 +1,60 @@
91.4 +/*
91.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
91.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
91.7 + *
91.8 + * This code is free software; you can redistribute it and/or modify it
91.9 + * under the terms of the GNU General Public License version 2 only, as
91.10 + * published by the Free Software Foundation. Oracle designates this
91.11 + * particular file as subject to the "Classpath" exception as provided
91.12 + * by Oracle in the LICENSE file that accompanied this code.
91.13 + *
91.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
91.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
91.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
91.17 + * version 2 for more details (a copy is included in the LICENSE file that
91.18 + * accompanied this code).
91.19 + *
91.20 + * You should have received a copy of the GNU General Public License version
91.21 + * 2 along with this work; if not, write to the Free Software Foundation,
91.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
91.23 + *
91.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
91.25 + * or visit www.oracle.com if you need additional information or have any
91.26 + * questions.
91.27 + */
91.28 +
91.29 +package java.util;
91.30 +
91.31 +/**
91.32 + * Thrown by the <code>nextElement</code> method of an
91.33 + * <code>Enumeration</code> to indicate that there are no more
91.34 + * elements in the enumeration.
91.35 + *
91.36 + * @author unascribed
91.37 + * @see java.util.Enumeration
91.38 + * @see java.util.Enumeration#nextElement()
91.39 + * @since JDK1.0
91.40 + */
91.41 +public
91.42 +class NoSuchElementException extends RuntimeException {
91.43 + private static final long serialVersionUID = 6769829250639411880L;
91.44 +
91.45 + /**
91.46 + * Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
91.47 + * as its error message string.
91.48 + */
91.49 + public NoSuchElementException() {
91.50 + super();
91.51 + }
91.52 +
91.53 + /**
91.54 + * Constructs a <code>NoSuchElementException</code>, saving a reference
91.55 + * to the error message string <tt>s</tt> for later retrieval by the
91.56 + * <tt>getMessage</tt> method.
91.57 + *
91.58 + * @param s the detail message.
91.59 + */
91.60 + public NoSuchElementException(String s) {
91.61 + super(s);
91.62 + }
91.63 +}
92.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
92.2 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/AnnotationImpl.java Wed Jan 23 20:39:23 2013 +0100
92.3 @@ -0,0 +1,81 @@
92.4 +/**
92.5 + * Back 2 Browser Bytecode Translator
92.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
92.7 + *
92.8 + * This program is free software: you can redistribute it and/or modify
92.9 + * it under the terms of the GNU General Public License as published by
92.10 + * the Free Software Foundation, version 2 of the License.
92.11 + *
92.12 + * This program is distributed in the hope that it will be useful,
92.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
92.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
92.15 + * GNU General Public License for more details.
92.16 + *
92.17 + * You should have received a copy of the GNU General Public License
92.18 + * along with this program. Look for COPYING file in the top folder.
92.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
92.20 + */
92.21 +package org.apidesign.bck2brwsr.emul;
92.22 +
92.23 +import java.lang.annotation.Annotation;
92.24 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
92.25 +
92.26 +/**
92.27 + *
92.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
92.29 + */
92.30 +public final class AnnotationImpl implements Annotation {
92.31 + public Class<? extends Annotation> annotationType() {
92.32 + return getClass();
92.33 + }
92.34 +
92.35 + @JavaScriptBody(args = { "a", "n", "values" }, body = ""
92.36 + + "function f(v, p) {\n"
92.37 + + " var val = v;\n"
92.38 + + " var prop = p;\n"
92.39 + + " return function() {\n"
92.40 + + " return val[prop];\n"
92.41 + + " };\n"
92.42 + + "}\n"
92.43 + + "var props = Object.getOwnPropertyNames(values);\n"
92.44 + + "for (var i = 0; i < props.length; i++) {\n"
92.45 + + " var p = props[i];\n"
92.46 + + " a[p] = new f(values, p);\n"
92.47 + + "}\n"
92.48 + + "a['$instOf_' + n] = true;\n"
92.49 + + "return a;"
92.50 + )
92.51 + private static <T extends Annotation> T create(AnnotationImpl a, String n, Object values) {
92.52 + return null;
92.53 + }
92.54 + public static <T extends Annotation> T create(Class<T> annoClass, Object values) {
92.55 + return create(new AnnotationImpl(), annoClass.getName().replace('.', '_'), values);
92.56 + }
92.57 +
92.58 + public static Annotation[] create(Object anno) {
92.59 + String[] names = findNames(anno);
92.60 + Annotation[] ret = new Annotation[names.length];
92.61 + for (int i = 0; i < names.length; i++) {
92.62 + String n = names[i].substring(1, names[i].length() - 1).replace('/', '_');
92.63 + ret[i] = create(new AnnotationImpl(), n, findData(anno, names[i]));
92.64 + }
92.65 + return ret;
92.66 + }
92.67 + @JavaScriptBody(args = "anno", body =
92.68 + "var arr = new Array();"
92.69 + + "var props = Object.getOwnPropertyNames(anno);\n"
92.70 + + "for (var i = 0; i < props.length; i++) {\n"
92.71 + + " var p = props[i];\n"
92.72 + + " arr.push(p);"
92.73 + + "}"
92.74 + + "return arr;"
92.75 + )
92.76 + private static String[] findNames(Object anno) {
92.77 + throw new UnsupportedOperationException();
92.78 + }
92.79 +
92.80 + @JavaScriptBody(args={ "anno", "p"}, body="return anno[p];")
92.81 + private static Object findData(Object anno, String p) {
92.82 + throw new UnsupportedOperationException();
92.83 + }
92.84 +}
93.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
93.2 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/MethodImpl.java Wed Jan 23 20:39:23 2013 +0100
93.3 @@ -0,0 +1,164 @@
93.4 +/*
93.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
93.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
93.7 + *
93.8 + * This code is free software; you can redistribute it and/or modify it
93.9 + * under the terms of the GNU General Public License version 2 only, as
93.10 + * published by the Free Software Foundation. Oracle designates this
93.11 + * particular file as subject to the "Classpath" exception as provided
93.12 + * by Oracle in the LICENSE file that accompanied this code.
93.13 + *
93.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
93.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
93.17 + * version 2 for more details (a copy is included in the LICENSE file that
93.18 + * accompanied this code).
93.19 + *
93.20 + * You should have received a copy of the GNU General Public License version
93.21 + * 2 along with this work; if not, write to the Free Software Foundation,
93.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
93.23 + *
93.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
93.25 + * or visit www.oracle.com if you need additional information or have any
93.26 + * questions.
93.27 + */
93.28 +package org.apidesign.bck2brwsr.emul;
93.29 +
93.30 +import java.lang.reflect.Method;
93.31 +import java.util.Enumeration;
93.32 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
93.33 +
93.34 +/** Utilities to work on methods.
93.35 + *
93.36 + * @author Jaroslav Tulach <jtulach@netbeans.org>
93.37 + */
93.38 +public abstract class MethodImpl {
93.39 + public static MethodImpl INSTANCE;
93.40 + static {
93.41 + try {
93.42 + Class.forName(Method.class.getName());
93.43 + } catch (ClassNotFoundException ex) {
93.44 + throw new IllegalStateException(ex);
93.45 + }
93.46 + }
93.47 +
93.48 + protected abstract Method create(Class<?> declaringClass, String name, Object data, String sig);
93.49 +
93.50 +
93.51 + //
93.52 + // bck2brwsr implementation
93.53 + //
93.54 +
93.55 + @JavaScriptBody(args = {"clazz", "prefix"},
93.56 + body = ""
93.57 + + "var c = clazz.cnstr.prototype;"
93.58 + + "var arr = new Array();\n"
93.59 + + "for (m in c) {\n"
93.60 + + " if (m.indexOf(prefix) === 0) {\n"
93.61 + + " arr.push(m);\n"
93.62 + + " arr.push(c[m]);\n"
93.63 + + " }"
93.64 + + "}\n"
93.65 + + "return arr;")
93.66 + private static native Object[] findMethodData(
93.67 + Class<?> clazz, String prefix);
93.68 +
93.69 + public static Method findMethod(
93.70 + Class<?> clazz, String name, Class<?>... parameterTypes) {
93.71 + Object[] data = findMethodData(clazz, name + "__");
93.72 + BIG: for (int i = 0; i < data.length; i += 2) {
93.73 + String sig = ((String) data[0]).substring(name.length() + 2);
93.74 + Method tmp = INSTANCE.create(clazz, name, data[1], sig);
93.75 + Class<?>[] tmpParms = tmp.getParameterTypes();
93.76 + if (parameterTypes.length != tmpParms.length) {
93.77 + continue;
93.78 + }
93.79 + for (int j = 0; j < tmpParms.length; j++) {
93.80 + if (!parameterTypes[j].equals(tmpParms[j])) {
93.81 + continue BIG;
93.82 + }
93.83 + }
93.84 + return tmp;
93.85 + }
93.86 + return null;
93.87 + }
93.88 +
93.89 + public static Method[] findMethods(Class<?> clazz, int mask) {
93.90 + Object[] namesAndData = findMethodData(clazz, "");
93.91 + int cnt = 0;
93.92 + for (int i = 0; i < namesAndData.length; i += 2) {
93.93 + String sig = (String) namesAndData[i];
93.94 + Object data = namesAndData[i + 1];
93.95 + int middle = sig.indexOf("__");
93.96 + if (middle == -1) {
93.97 + continue;
93.98 + }
93.99 + String name = sig.substring(0, middle);
93.100 + sig = sig.substring(middle + 2);
93.101 + final Method m = INSTANCE.create(clazz, name, data, sig);
93.102 + if ((m.getModifiers() & mask) == 0) {
93.103 + continue;
93.104 + }
93.105 + namesAndData[cnt++] = m;
93.106 + }
93.107 + Method[] arr = new Method[cnt];
93.108 + for (int i = 0; i < cnt; i++) {
93.109 + arr[i] = (Method) namesAndData[i];
93.110 + }
93.111 + return arr;
93.112 + }
93.113 +
93.114 + public static int signatureElements(String sig) {
93.115 + Enumeration<Class> en = signatureParser(sig);
93.116 + int cnt = 0;
93.117 + while (en.hasMoreElements()) {
93.118 + en.nextElement();
93.119 + cnt++;
93.120 + }
93.121 + return cnt;
93.122 + }
93.123 +
93.124 + public static Enumeration<Class> signatureParser(final String sig) {
93.125 + class E implements Enumeration<Class> {
93.126 + int pos;
93.127 +
93.128 + public boolean hasMoreElements() {
93.129 + return pos < sig.length();
93.130 + }
93.131 +
93.132 + public Class nextElement() {
93.133 + switch (sig.charAt(pos++)) {
93.134 + case 'I':
93.135 + return Integer.TYPE;
93.136 + case 'J':
93.137 + return Long.TYPE;
93.138 + case 'D':
93.139 + return Double.TYPE;
93.140 + case 'F':
93.141 + return Float.TYPE;
93.142 + case 'B':
93.143 + return Byte.TYPE;
93.144 + case 'Z':
93.145 + return Boolean.TYPE;
93.146 + case 'S':
93.147 + return Short.TYPE;
93.148 + case 'V':
93.149 + return Void.TYPE;
93.150 + case 'C':
93.151 + return Character.TYPE;
93.152 + case 'L':
93.153 + try {
93.154 + int up = sig.indexOf("_2");
93.155 + String type = sig.substring(1, up);
93.156 + pos = up + 2;
93.157 + return Class.forName(type);
93.158 + } catch (ClassNotFoundException ex) {
93.159 + // should not happen
93.160 + }
93.161 + }
93.162 + throw new UnsupportedOperationException(sig + " at " + pos);
93.163 + }
93.164 + }
93.165 + return new E();
93.166 + }
93.167 +}
94.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
94.2 +++ b/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_Number.js Wed Jan 23 20:39:23 2013 +0100
94.3 @@ -0,0 +1,9 @@
94.4 +// empty line needed here
94.5 +Number.prototype.add32 = function(x) { return (this + x) | 0; };
94.6 +Number.prototype.sub32 = function(x) { return (this - x) | 0; };
94.7 +Number.prototype.mul32 = function(x) {
94.8 + return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0;
94.9 +};
94.10 +
94.11 +Number.prototype.toInt8 = function() { return (this << 24) >> 24; };
94.12 +Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
94.13 \ No newline at end of file
95.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
95.2 +++ b/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js Wed Jan 23 20:39:23 2013 +0100
95.3 @@ -0,0 +1,26 @@
95.4 +// initialize methods on arrays and String constants
95.5 +vm.java_lang_reflect_Array(false);
95.6 +vm.java_lang_String(false);
95.7 +
95.8 +Array.prototype.at = function(indx, value) {
95.9 + if (indx < 0 || indx > this.length) {
95.10 + var e = vm.java_lang_ArrayIndexOutOfBoundsException(true);
95.11 + e.constructor.cons__VLjava_lang_String_2.call(e, indx.toString());
95.12 + throw e;
95.13 + }
95.14 + if (arguments.length === 2) {
95.15 + this[indx] = value;
95.16 + }
95.17 + return this[indx];
95.18 +};
95.19 +Array.prototype.getClass__Ljava_lang_Class_2 = function() {
95.20 + return vm.java_lang_Class(false).defineArray__Ljava_lang_Class_2Ljava_lang_String_2(this.jvmName);
95.21 +};
95.22 +Array.prototype.clone__Ljava_lang_Object_2 = function() {
95.23 + var s = this.length;
95.24 + var ret = new Array(s);
95.25 + for (var i = 0; i < s; i++) {
95.26 + ret[i] = this[i];
95.27 + }
95.28 + return ret;
95.29 +};
96.1 --- a/emul/pom.xml Wed Jan 23 20:16:48 2013 +0100
96.2 +++ b/emul/pom.xml Wed Jan 23 20:39:23 2013 +0100
96.3 @@ -1,42 +1,17 @@
96.4 -<?xml version="1.0"?>
96.5 -<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
96.6 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
96.7 +<?xml version="1.0" encoding="UTF-8"?>
96.8 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
96.9 <modelVersion>4.0.0</modelVersion>
96.10 <parent>
96.11 - <groupId>org.apidesign</groupId>
96.12 <artifactId>bck2brwsr</artifactId>
96.13 + <groupId>org.apidesign.</groupId>
96.14 <version>0.3-SNAPSHOT</version>
96.15 </parent>
96.16 <groupId>org.apidesign.bck2brwsr</groupId>
96.17 - <artifactId>emul</artifactId>
96.18 + <artifactId>emul.pom</artifactId>
96.19 <version>0.3-SNAPSHOT</version>
96.20 - <name>Java API Emulation</name>
96.21 - <url>http://maven.apache.org</url>
96.22 - <properties>
96.23 - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
96.24 - </properties>
96.25 - <dependencies>
96.26 - <dependency>
96.27 - <groupId>org.apidesign.bck2brwsr</groupId>
96.28 - <artifactId>core</artifactId>
96.29 - <version>0.3-SNAPSHOT</version>
96.30 - <type>jar</type>
96.31 - </dependency>
96.32 - </dependencies>
96.33 - <build>
96.34 - <plugins>
96.35 - <plugin>
96.36 - <groupId>org.apache.maven.plugins</groupId>
96.37 - <artifactId>maven-compiler-plugin</artifactId>
96.38 - <version>2.5.1</version>
96.39 - <configuration>
96.40 - <compilerArguments>
96.41 - <bootclasspath>non-existing</bootclasspath>
96.42 - </compilerArguments>
96.43 - <source>1.7</source>
96.44 - <target>1.7</target>
96.45 - </configuration>
96.46 - </plugin>
96.47 - </plugins>
96.48 - </build>
96.49 + <packaging>pom</packaging>
96.50 + <name>Emulation of Core Libraries</name>
96.51 + <modules>
96.52 + <module>mini</module>
96.53 + </modules>
96.54 </project>
97.1 --- a/emul/src/main/java/java/io/ByteArrayInputStream.java Wed Jan 23 20:16:48 2013 +0100
97.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
97.3 @@ -1,283 +0,0 @@
97.4 -/*
97.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
97.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
97.7 - *
97.8 - * This code is free software; you can redistribute it and/or modify it
97.9 - * under the terms of the GNU General Public License version 2 only, as
97.10 - * published by the Free Software Foundation. Oracle designates this
97.11 - * particular file as subject to the "Classpath" exception as provided
97.12 - * by Oracle in the LICENSE file that accompanied this code.
97.13 - *
97.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
97.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
97.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
97.17 - * version 2 for more details (a copy is included in the LICENSE file that
97.18 - * accompanied this code).
97.19 - *
97.20 - * You should have received a copy of the GNU General Public License version
97.21 - * 2 along with this work; if not, write to the Free Software Foundation,
97.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
97.23 - *
97.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
97.25 - * or visit www.oracle.com if you need additional information or have any
97.26 - * questions.
97.27 - */
97.28 -
97.29 -package java.io;
97.30 -
97.31 -/**
97.32 - * A <code>ByteArrayInputStream</code> contains
97.33 - * an internal buffer that contains bytes that
97.34 - * may be read from the stream. An internal
97.35 - * counter keeps track of the next byte to
97.36 - * be supplied by the <code>read</code> method.
97.37 - * <p>
97.38 - * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
97.39 - * this class can be called after the stream has been closed without
97.40 - * generating an <tt>IOException</tt>.
97.41 - *
97.42 - * @author Arthur van Hoff
97.43 - * @see java.io.StringBufferInputStream
97.44 - * @since JDK1.0
97.45 - */
97.46 -public
97.47 -class ByteArrayInputStream extends InputStream {
97.48 -
97.49 - /**
97.50 - * An array of bytes that was provided
97.51 - * by the creator of the stream. Elements <code>buf[0]</code>
97.52 - * through <code>buf[count-1]</code> are the
97.53 - * only bytes that can ever be read from the
97.54 - * stream; element <code>buf[pos]</code> is
97.55 - * the next byte to be read.
97.56 - */
97.57 - protected byte buf[];
97.58 -
97.59 - /**
97.60 - * The index of the next character to read from the input stream buffer.
97.61 - * This value should always be nonnegative
97.62 - * and not larger than the value of <code>count</code>.
97.63 - * The next byte to be read from the input stream buffer
97.64 - * will be <code>buf[pos]</code>.
97.65 - */
97.66 - protected int pos;
97.67 -
97.68 - /**
97.69 - * The currently marked position in the stream.
97.70 - * ByteArrayInputStream objects are marked at position zero by
97.71 - * default when constructed. They may be marked at another
97.72 - * position within the buffer by the <code>mark()</code> method.
97.73 - * The current buffer position is set to this point by the
97.74 - * <code>reset()</code> method.
97.75 - * <p>
97.76 - * If no mark has been set, then the value of mark is the offset
97.77 - * passed to the constructor (or 0 if the offset was not supplied).
97.78 - *
97.79 - * @since JDK1.1
97.80 - */
97.81 - protected int mark = 0;
97.82 -
97.83 - /**
97.84 - * The index one greater than the last valid character in the input
97.85 - * stream buffer.
97.86 - * This value should always be nonnegative
97.87 - * and not larger than the length of <code>buf</code>.
97.88 - * It is one greater than the position of
97.89 - * the last byte within <code>buf</code> that
97.90 - * can ever be read from the input stream buffer.
97.91 - */
97.92 - protected int count;
97.93 -
97.94 - /**
97.95 - * Creates a <code>ByteArrayInputStream</code>
97.96 - * so that it uses <code>buf</code> as its
97.97 - * buffer array.
97.98 - * The buffer array is not copied.
97.99 - * The initial value of <code>pos</code>
97.100 - * is <code>0</code> and the initial value
97.101 - * of <code>count</code> is the length of
97.102 - * <code>buf</code>.
97.103 - *
97.104 - * @param buf the input buffer.
97.105 - */
97.106 - public ByteArrayInputStream(byte buf[]) {
97.107 - this.buf = buf;
97.108 - this.pos = 0;
97.109 - this.count = buf.length;
97.110 - }
97.111 -
97.112 - /**
97.113 - * Creates <code>ByteArrayInputStream</code>
97.114 - * that uses <code>buf</code> as its
97.115 - * buffer array. The initial value of <code>pos</code>
97.116 - * is <code>offset</code> and the initial value
97.117 - * of <code>count</code> is the minimum of <code>offset+length</code>
97.118 - * and <code>buf.length</code>.
97.119 - * The buffer array is not copied. The buffer's mark is
97.120 - * set to the specified offset.
97.121 - *
97.122 - * @param buf the input buffer.
97.123 - * @param offset the offset in the buffer of the first byte to read.
97.124 - * @param length the maximum number of bytes to read from the buffer.
97.125 - */
97.126 - public ByteArrayInputStream(byte buf[], int offset, int length) {
97.127 - this.buf = buf;
97.128 - this.pos = offset;
97.129 - this.count = Math.min(offset + length, buf.length);
97.130 - this.mark = offset;
97.131 - }
97.132 -
97.133 - /**
97.134 - * Reads the next byte of data from this input stream. The value
97.135 - * byte is returned as an <code>int</code> in the range
97.136 - * <code>0</code> to <code>255</code>. If no byte is available
97.137 - * because the end of the stream has been reached, the value
97.138 - * <code>-1</code> is returned.
97.139 - * <p>
97.140 - * This <code>read</code> method
97.141 - * cannot block.
97.142 - *
97.143 - * @return the next byte of data, or <code>-1</code> if the end of the
97.144 - * stream has been reached.
97.145 - */
97.146 - public synchronized int read() {
97.147 - return (pos < count) ? (buf[pos++] & 0xff) : -1;
97.148 - }
97.149 -
97.150 - /**
97.151 - * Reads up to <code>len</code> bytes of data into an array of bytes
97.152 - * from this input stream.
97.153 - * If <code>pos</code> equals <code>count</code>,
97.154 - * then <code>-1</code> is returned to indicate
97.155 - * end of file. Otherwise, the number <code>k</code>
97.156 - * of bytes read is equal to the smaller of
97.157 - * <code>len</code> and <code>count-pos</code>.
97.158 - * If <code>k</code> is positive, then bytes
97.159 - * <code>buf[pos]</code> through <code>buf[pos+k-1]</code>
97.160 - * are copied into <code>b[off]</code> through
97.161 - * <code>b[off+k-1]</code> in the manner performed
97.162 - * by <code>System.arraycopy</code>. The
97.163 - * value <code>k</code> is added into <code>pos</code>
97.164 - * and <code>k</code> is returned.
97.165 - * <p>
97.166 - * This <code>read</code> method cannot block.
97.167 - *
97.168 - * @param b the buffer into which the data is read.
97.169 - * @param off the start offset in the destination array <code>b</code>
97.170 - * @param len the maximum number of bytes read.
97.171 - * @return the total number of bytes read into the buffer, or
97.172 - * <code>-1</code> if there is no more data because the end of
97.173 - * the stream has been reached.
97.174 - * @exception NullPointerException If <code>b</code> is <code>null</code>.
97.175 - * @exception IndexOutOfBoundsException If <code>off</code> is negative,
97.176 - * <code>len</code> is negative, or <code>len</code> is greater than
97.177 - * <code>b.length - off</code>
97.178 - */
97.179 - public synchronized int read(byte b[], int off, int len) {
97.180 - if (b == null) {
97.181 - throw new NullPointerException();
97.182 - } else if (off < 0 || len < 0 || len > b.length - off) {
97.183 - throw new IndexOutOfBoundsException();
97.184 - }
97.185 -
97.186 - if (pos >= count) {
97.187 - return -1;
97.188 - }
97.189 -
97.190 - int avail = count - pos;
97.191 - if (len > avail) {
97.192 - len = avail;
97.193 - }
97.194 - if (len <= 0) {
97.195 - return 0;
97.196 - }
97.197 - PushbackInputStream.arraycopy(buf, pos, b, off, len);
97.198 - pos += len;
97.199 - return len;
97.200 - }
97.201 -
97.202 - /**
97.203 - * Skips <code>n</code> bytes of input from this input stream. Fewer
97.204 - * bytes might be skipped if the end of the input stream is reached.
97.205 - * The actual number <code>k</code>
97.206 - * of bytes to be skipped is equal to the smaller
97.207 - * of <code>n</code> and <code>count-pos</code>.
97.208 - * The value <code>k</code> is added into <code>pos</code>
97.209 - * and <code>k</code> is returned.
97.210 - *
97.211 - * @param n the number of bytes to be skipped.
97.212 - * @return the actual number of bytes skipped.
97.213 - */
97.214 - public synchronized long skip(long n) {
97.215 - long k = count - pos;
97.216 - if (n < k) {
97.217 - k = n < 0 ? 0 : n;
97.218 - }
97.219 -
97.220 - pos += k;
97.221 - return k;
97.222 - }
97.223 -
97.224 - /**
97.225 - * Returns the number of remaining bytes that can be read (or skipped over)
97.226 - * from this input stream.
97.227 - * <p>
97.228 - * The value returned is <code>count - pos</code>,
97.229 - * which is the number of bytes remaining to be read from the input buffer.
97.230 - *
97.231 - * @return the number of remaining bytes that can be read (or skipped
97.232 - * over) from this input stream without blocking.
97.233 - */
97.234 - public synchronized int available() {
97.235 - return count - pos;
97.236 - }
97.237 -
97.238 - /**
97.239 - * Tests if this <code>InputStream</code> supports mark/reset. The
97.240 - * <code>markSupported</code> method of <code>ByteArrayInputStream</code>
97.241 - * always returns <code>true</code>.
97.242 - *
97.243 - * @since JDK1.1
97.244 - */
97.245 - public boolean markSupported() {
97.246 - return true;
97.247 - }
97.248 -
97.249 - /**
97.250 - * Set the current marked position in the stream.
97.251 - * ByteArrayInputStream objects are marked at position zero by
97.252 - * default when constructed. They may be marked at another
97.253 - * position within the buffer by this method.
97.254 - * <p>
97.255 - * If no mark has been set, then the value of the mark is the
97.256 - * offset passed to the constructor (or 0 if the offset was not
97.257 - * supplied).
97.258 - *
97.259 - * <p> Note: The <code>readAheadLimit</code> for this class
97.260 - * has no meaning.
97.261 - *
97.262 - * @since JDK1.1
97.263 - */
97.264 - public void mark(int readAheadLimit) {
97.265 - mark = pos;
97.266 - }
97.267 -
97.268 - /**
97.269 - * Resets the buffer to the marked position. The marked position
97.270 - * is 0 unless another position was marked or an offset was specified
97.271 - * in the constructor.
97.272 - */
97.273 - public synchronized void reset() {
97.274 - pos = mark;
97.275 - }
97.276 -
97.277 - /**
97.278 - * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
97.279 - * this class can be called after the stream has been closed without
97.280 - * generating an <tt>IOException</tt>.
97.281 - * <p>
97.282 - */
97.283 - public void close() throws IOException {
97.284 - }
97.285 -
97.286 -}
98.1 --- a/emul/src/main/java/java/io/Closeable.java Wed Jan 23 20:16:48 2013 +0100
98.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
98.3 @@ -1,48 +0,0 @@
98.4 -/*
98.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
98.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
98.7 - *
98.8 - * This code is free software; you can redistribute it and/or modify it
98.9 - * under the terms of the GNU General Public License version 2 only, as
98.10 - * published by the Free Software Foundation. Oracle designates this
98.11 - * particular file as subject to the "Classpath" exception as provided
98.12 - * by Oracle in the LICENSE file that accompanied this code.
98.13 - *
98.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
98.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
98.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
98.17 - * version 2 for more details (a copy is included in the LICENSE file that
98.18 - * accompanied this code).
98.19 - *
98.20 - * You should have received a copy of the GNU General Public License version
98.21 - * 2 along with this work; if not, write to the Free Software Foundation,
98.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
98.23 - *
98.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
98.25 - * or visit www.oracle.com if you need additional information or have any
98.26 - * questions.
98.27 - */
98.28 -
98.29 -package java.io;
98.30 -
98.31 -import java.io.IOException;
98.32 -
98.33 -/**
98.34 - * A {@code Closeable} is a source or destination of data that can be closed.
98.35 - * The close method is invoked to release resources that the object is
98.36 - * holding (such as open files).
98.37 - *
98.38 - * @since 1.5
98.39 - */
98.40 -
98.41 -public interface Closeable extends AutoCloseable {
98.42 -
98.43 - /**
98.44 - * Closes this stream and releases any system resources associated
98.45 - * with it. If the stream is already closed then invoking this
98.46 - * method has no effect.
98.47 - *
98.48 - * @throws IOException if an I/O error occurs
98.49 - */
98.50 - public void close() throws IOException;
98.51 -}
99.1 --- a/emul/src/main/java/java/io/DataInput.java Wed Jan 23 20:16:48 2013 +0100
99.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
99.3 @@ -1,635 +0,0 @@
99.4 -/*
99.5 - * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
99.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
99.7 - *
99.8 - * This code is free software; you can redistribute it and/or modify it
99.9 - * under the terms of the GNU General Public License version 2 only, as
99.10 - * published by the Free Software Foundation. Oracle designates this
99.11 - * particular file as subject to the "Classpath" exception as provided
99.12 - * by Oracle in the LICENSE file that accompanied this code.
99.13 - *
99.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
99.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
99.17 - * version 2 for more details (a copy is included in the LICENSE file that
99.18 - * accompanied this code).
99.19 - *
99.20 - * You should have received a copy of the GNU General Public License version
99.21 - * 2 along with this work; if not, write to the Free Software Foundation,
99.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
99.23 - *
99.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
99.25 - * or visit www.oracle.com if you need additional information or have any
99.26 - * questions.
99.27 - */
99.28 -
99.29 -package java.io;
99.30 -
99.31 -/**
99.32 - * The <code>DataInput</code> interface provides
99.33 - * for reading bytes from a binary stream and
99.34 - * reconstructing from them data in any of
99.35 - * the Java primitive types. There is also
99.36 - * a
99.37 - * facility for reconstructing a <code>String</code>
99.38 - * from data in
99.39 - * <a href="#modified-utf-8">modified UTF-8</a>
99.40 - * format.
99.41 - * <p>
99.42 - * It is generally true of all the reading
99.43 - * routines in this interface that if end of
99.44 - * file is reached before the desired number
99.45 - * of bytes has been read, an <code>EOFException</code>
99.46 - * (which is a kind of <code>IOException</code>)
99.47 - * is thrown. If any byte cannot be read for
99.48 - * any reason other than end of file, an <code>IOException</code>
99.49 - * other than <code>EOFException</code> is
99.50 - * thrown. In particular, an <code>IOException</code>
99.51 - * may be thrown if the input stream has been
99.52 - * closed.
99.53 - *
99.54 - * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
99.55 - * <p>
99.56 - * Implementations of the DataInput and DataOutput interfaces represent
99.57 - * Unicode strings in a format that is a slight modification of UTF-8.
99.58 - * (For information regarding the standard UTF-8 format, see section
99.59 - * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
99.60 - * 4.0</i>).
99.61 - * Note that in the following tables, the most significant bit appears in the
99.62 - * far left-hand column.
99.63 - * <p>
99.64 - * All characters in the range <code>'\u0001'</code> to
99.65 - * <code>'\u007F'</code> are represented by a single byte:
99.66 - *
99.67 - * <blockquote>
99.68 - * <table border="1" cellspacing="0" cellpadding="8" width="50%"
99.69 - * summary="Bit values and bytes">
99.70 - * <tr>
99.71 - * <td></td>
99.72 - * <th id="bit">Bit Values</th>
99.73 - * </tr>
99.74 - * <tr>
99.75 - * <th id="byte1">Byte 1</th>
99.76 - * <td>
99.77 - * <table border="1" cellspacing="0" width="100%">
99.78 - * <tr>
99.79 - * <td width="12%"><center>0</center>
99.80 - * <td colspan="7"><center>bits 6-0</center>
99.81 - * </tr>
99.82 - * </table>
99.83 - * </td>
99.84 - * </tr>
99.85 - * </table>
99.86 - * </blockquote>
99.87 - *
99.88 - * <p>
99.89 - * The null character <code>'\u0000'</code> and characters in the
99.90 - * range <code>'\u0080'</code> to <code>'\u07FF'</code> are
99.91 - * represented by a pair of bytes:
99.92 - *
99.93 - * <blockquote>
99.94 - * <table border="1" cellspacing="0" cellpadding="8" width="50%"
99.95 - * summary="Bit values and bytes">
99.96 - * <tr>
99.97 - * <td></td>
99.98 - * <th id="bit">Bit Values</th>
99.99 - * </tr>
99.100 - * <tr>
99.101 - * <th id="byte1">Byte 1</th>
99.102 - * <td>
99.103 - * <table border="1" cellspacing="0" width="100%">
99.104 - * <tr>
99.105 - * <td width="12%"><center>1</center>
99.106 - * <td width="13%"><center>1</center>
99.107 - * <td width="12%"><center>0</center>
99.108 - * <td colspan="5"><center>bits 10-6</center>
99.109 - * </tr>
99.110 - * </table>
99.111 - * </td>
99.112 - * </tr>
99.113 - * <tr>
99.114 - * <th id="byte2">Byte 2</th>
99.115 - * <td>
99.116 - * <table border="1" cellspacing="0" width="100%">
99.117 - * <tr>
99.118 - * <td width="12%"><center>1</center>
99.119 - * <td width="13%"><center>0</center>
99.120 - * <td colspan="6"><center>bits 5-0</center>
99.121 - * </tr>
99.122 - * </table>
99.123 - * </td>
99.124 - * </tr>
99.125 - * </table>
99.126 - * </blockquote>
99.127 - *
99.128 - * <br>
99.129 - * <code>char</code> values in the range <code>'\u0800'</code> to
99.130 - * <code>'\uFFFF'</code> are represented by three bytes:
99.131 - *
99.132 - * <blockquote>
99.133 - * <table border="1" cellspacing="0" cellpadding="8" width="50%"
99.134 - * summary="Bit values and bytes">
99.135 - * <tr>
99.136 - * <td></td>
99.137 - * <th id="bit">Bit Values</th>
99.138 - * </tr>
99.139 - * <tr>
99.140 - * <th id="byte1">Byte 1</th>
99.141 - * <td>
99.142 - * <table border="1" cellspacing="0" width="100%">
99.143 - * <tr>
99.144 - * <td width="12%"><center>1</center>
99.145 - * <td width="13%"><center>1</center>
99.146 - * <td width="12%"><center>1</center>
99.147 - * <td width="13%"><center>0</center>
99.148 - * <td colspan="4"><center>bits 15-12</center>
99.149 - * </tr>
99.150 - * </table>
99.151 - * </td>
99.152 - * </tr>
99.153 - * <tr>
99.154 - * <th id="byte2">Byte 2</th>
99.155 - * <td>
99.156 - * <table border="1" cellspacing="0" width="100%">
99.157 - * <tr>
99.158 - * <td width="12%"><center>1</center>
99.159 - * <td width="13%"><center>0</center>
99.160 - * <td colspan="6"><center>bits 11-6</center>
99.161 - * </tr>
99.162 - * </table>
99.163 - * </td>
99.164 - * </tr>
99.165 - * <tr>
99.166 - * <th id="byte3">Byte 3</th>
99.167 - * <td>
99.168 - * <table border="1" cellspacing="0" width="100%">
99.169 - * <tr>
99.170 - * <td width="12%"><center>1</center>
99.171 - * <td width="13%"><center>0</center>
99.172 - * <td colspan="6"><center>bits 5-0</center>
99.173 - * </tr>
99.174 - * </table>
99.175 - * </td>
99.176 - * </tr>
99.177 - * </table>
99.178 - * </blockquote>
99.179 - *
99.180 - * <p>
99.181 - * The differences between this format and the
99.182 - * standard UTF-8 format are the following:
99.183 - * <ul>
99.184 - * <li>The null byte <code>'\u0000'</code> is encoded in 2-byte format
99.185 - * rather than 1-byte, so that the encoded strings never have
99.186 - * embedded nulls.
99.187 - * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
99.188 - * <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
99.189 - * are represented in the form of surrogate pairs.
99.190 - * </ul>
99.191 - * @author Frank Yellin
99.192 - * @see java.io.DataInputStream
99.193 - * @see java.io.DataOutput
99.194 - * @since JDK1.0
99.195 - */
99.196 -public
99.197 -interface DataInput {
99.198 - /**
99.199 - * Reads some bytes from an input
99.200 - * stream and stores them into the buffer
99.201 - * array <code>b</code>. The number of bytes
99.202 - * read is equal
99.203 - * to the length of <code>b</code>.
99.204 - * <p>
99.205 - * This method blocks until one of the
99.206 - * following conditions occurs:<p>
99.207 - * <ul>
99.208 - * <li><code>b.length</code>
99.209 - * bytes of input data are available, in which
99.210 - * case a normal return is made.
99.211 - *
99.212 - * <li>End of
99.213 - * file is detected, in which case an <code>EOFException</code>
99.214 - * is thrown.
99.215 - *
99.216 - * <li>An I/O error occurs, in
99.217 - * which case an <code>IOException</code> other
99.218 - * than <code>EOFException</code> is thrown.
99.219 - * </ul>
99.220 - * <p>
99.221 - * If <code>b</code> is <code>null</code>,
99.222 - * a <code>NullPointerException</code> is thrown.
99.223 - * If <code>b.length</code> is zero, then
99.224 - * no bytes are read. Otherwise, the first
99.225 - * byte read is stored into element <code>b[0]</code>,
99.226 - * the next one into <code>b[1]</code>, and
99.227 - * so on.
99.228 - * If an exception is thrown from
99.229 - * this method, then it may be that some but
99.230 - * not all bytes of <code>b</code> have been
99.231 - * updated with data from the input stream.
99.232 - *
99.233 - * @param b the buffer into which the data is read.
99.234 - * @exception EOFException if this stream reaches the end before reading
99.235 - * all the bytes.
99.236 - * @exception IOException if an I/O error occurs.
99.237 - */
99.238 - void readFully(byte b[]) throws IOException;
99.239 -
99.240 - /**
99.241 - *
99.242 - * Reads <code>len</code>
99.243 - * bytes from
99.244 - * an input stream.
99.245 - * <p>
99.246 - * This method
99.247 - * blocks until one of the following conditions
99.248 - * occurs:<p>
99.249 - * <ul>
99.250 - * <li><code>len</code> bytes
99.251 - * of input data are available, in which case
99.252 - * a normal return is made.
99.253 - *
99.254 - * <li>End of file
99.255 - * is detected, in which case an <code>EOFException</code>
99.256 - * is thrown.
99.257 - *
99.258 - * <li>An I/O error occurs, in
99.259 - * which case an <code>IOException</code> other
99.260 - * than <code>EOFException</code> is thrown.
99.261 - * </ul>
99.262 - * <p>
99.263 - * If <code>b</code> is <code>null</code>,
99.264 - * a <code>NullPointerException</code> is thrown.
99.265 - * If <code>off</code> is negative, or <code>len</code>
99.266 - * is negative, or <code>off+len</code> is
99.267 - * greater than the length of the array <code>b</code>,
99.268 - * then an <code>IndexOutOfBoundsException</code>
99.269 - * is thrown.
99.270 - * If <code>len</code> is zero,
99.271 - * then no bytes are read. Otherwise, the first
99.272 - * byte read is stored into element <code>b[off]</code>,
99.273 - * the next one into <code>b[off+1]</code>,
99.274 - * and so on. The number of bytes read is,
99.275 - * at most, equal to <code>len</code>.
99.276 - *
99.277 - * @param b the buffer into which the data is read.
99.278 - * @param off an int specifying the offset into the data.
99.279 - * @param len an int specifying the number of bytes to read.
99.280 - * @exception EOFException if this stream reaches the end before reading
99.281 - * all the bytes.
99.282 - * @exception IOException if an I/O error occurs.
99.283 - */
99.284 - void readFully(byte b[], int off, int len) throws IOException;
99.285 -
99.286 - /**
99.287 - * Makes an attempt to skip over
99.288 - * <code>n</code> bytes
99.289 - * of data from the input
99.290 - * stream, discarding the skipped bytes. However,
99.291 - * it may skip
99.292 - * over some smaller number of
99.293 - * bytes, possibly zero. This may result from
99.294 - * any of a
99.295 - * number of conditions; reaching
99.296 - * end of file before <code>n</code> bytes
99.297 - * have been skipped is
99.298 - * only one possibility.
99.299 - * This method never throws an <code>EOFException</code>.
99.300 - * The actual
99.301 - * number of bytes skipped is returned.
99.302 - *
99.303 - * @param n the number of bytes to be skipped.
99.304 - * @return the number of bytes actually skipped.
99.305 - * @exception IOException if an I/O error occurs.
99.306 - */
99.307 - int skipBytes(int n) throws IOException;
99.308 -
99.309 - /**
99.310 - * Reads one input byte and returns
99.311 - * <code>true</code> if that byte is nonzero,
99.312 - * <code>false</code> if that byte is zero.
99.313 - * This method is suitable for reading
99.314 - * the byte written by the <code>writeBoolean</code>
99.315 - * method of interface <code>DataOutput</code>.
99.316 - *
99.317 - * @return the <code>boolean</code> value read.
99.318 - * @exception EOFException if this stream reaches the end before reading
99.319 - * all the bytes.
99.320 - * @exception IOException if an I/O error occurs.
99.321 - */
99.322 - boolean readBoolean() throws IOException;
99.323 -
99.324 - /**
99.325 - * Reads and returns one input byte.
99.326 - * The byte is treated as a signed value in
99.327 - * the range <code>-128</code> through <code>127</code>,
99.328 - * inclusive.
99.329 - * This method is suitable for
99.330 - * reading the byte written by the <code>writeByte</code>
99.331 - * method of interface <code>DataOutput</code>.
99.332 - *
99.333 - * @return the 8-bit value read.
99.334 - * @exception EOFException if this stream reaches the end before reading
99.335 - * all the bytes.
99.336 - * @exception IOException if an I/O error occurs.
99.337 - */
99.338 - byte readByte() throws IOException;
99.339 -
99.340 - /**
99.341 - * Reads one input byte, zero-extends
99.342 - * it to type <code>int</code>, and returns
99.343 - * the result, which is therefore in the range
99.344 - * <code>0</code>
99.345 - * through <code>255</code>.
99.346 - * This method is suitable for reading
99.347 - * the byte written by the <code>writeByte</code>
99.348 - * method of interface <code>DataOutput</code>
99.349 - * if the argument to <code>writeByte</code>
99.350 - * was intended to be a value in the range
99.351 - * <code>0</code> through <code>255</code>.
99.352 - *
99.353 - * @return the unsigned 8-bit value read.
99.354 - * @exception EOFException if this stream reaches the end before reading
99.355 - * all the bytes.
99.356 - * @exception IOException if an I/O error occurs.
99.357 - */
99.358 - int readUnsignedByte() throws IOException;
99.359 -
99.360 - /**
99.361 - * Reads two input bytes and returns
99.362 - * a <code>short</code> value. Let <code>a</code>
99.363 - * be the first byte read and <code>b</code>
99.364 - * be the second byte. The value
99.365 - * returned
99.366 - * is:
99.367 - * <p><pre><code>(short)((a << 8) | (b & 0xff))
99.368 - * </code></pre>
99.369 - * This method
99.370 - * is suitable for reading the bytes written
99.371 - * by the <code>writeShort</code> method of
99.372 - * interface <code>DataOutput</code>.
99.373 - *
99.374 - * @return the 16-bit value read.
99.375 - * @exception EOFException if this stream reaches the end before reading
99.376 - * all the bytes.
99.377 - * @exception IOException if an I/O error occurs.
99.378 - */
99.379 - short readShort() throws IOException;
99.380 -
99.381 - /**
99.382 - * Reads two input bytes and returns
99.383 - * an <code>int</code> value in the range <code>0</code>
99.384 - * through <code>65535</code>. Let <code>a</code>
99.385 - * be the first byte read and
99.386 - * <code>b</code>
99.387 - * be the second byte. The value returned is:
99.388 - * <p><pre><code>(((a & 0xff) << 8) | (b & 0xff))
99.389 - * </code></pre>
99.390 - * This method is suitable for reading the bytes
99.391 - * written by the <code>writeShort</code> method
99.392 - * of interface <code>DataOutput</code> if
99.393 - * the argument to <code>writeShort</code>
99.394 - * was intended to be a value in the range
99.395 - * <code>0</code> through <code>65535</code>.
99.396 - *
99.397 - * @return the unsigned 16-bit value read.
99.398 - * @exception EOFException if this stream reaches the end before reading
99.399 - * all the bytes.
99.400 - * @exception IOException if an I/O error occurs.
99.401 - */
99.402 - int readUnsignedShort() throws IOException;
99.403 -
99.404 - /**
99.405 - * Reads two input bytes and returns a <code>char</code> value.
99.406 - * Let <code>a</code>
99.407 - * be the first byte read and <code>b</code>
99.408 - * be the second byte. The value
99.409 - * returned is:
99.410 - * <p><pre><code>(char)((a << 8) | (b & 0xff))
99.411 - * </code></pre>
99.412 - * This method
99.413 - * is suitable for reading bytes written by
99.414 - * the <code>writeChar</code> method of interface
99.415 - * <code>DataOutput</code>.
99.416 - *
99.417 - * @return the <code>char</code> value read.
99.418 - * @exception EOFException if this stream reaches the end before reading
99.419 - * all the bytes.
99.420 - * @exception IOException if an I/O error occurs.
99.421 - */
99.422 - char readChar() throws IOException;
99.423 -
99.424 - /**
99.425 - * Reads four input bytes and returns an
99.426 - * <code>int</code> value. Let <code>a-d</code>
99.427 - * be the first through fourth bytes read. The value returned is:
99.428 - * <p><pre>
99.429 - * <code>
99.430 - * (((a & 0xff) << 24) | ((b & 0xff) << 16) |
99.431 - *  ((c & 0xff) << 8) | (d & 0xff))
99.432 - * </code></pre>
99.433 - * This method is suitable
99.434 - * for reading bytes written by the <code>writeInt</code>
99.435 - * method of interface <code>DataOutput</code>.
99.436 - *
99.437 - * @return the <code>int</code> value read.
99.438 - * @exception EOFException if this stream reaches the end before reading
99.439 - * all the bytes.
99.440 - * @exception IOException if an I/O error occurs.
99.441 - */
99.442 - int readInt() throws IOException;
99.443 -
99.444 - /**
99.445 - * Reads eight input bytes and returns
99.446 - * a <code>long</code> value. Let <code>a-h</code>
99.447 - * be the first through eighth bytes read.
99.448 - * The value returned is:
99.449 - * <p><pre> <code>
99.450 - * (((long)(a & 0xff) << 56) |
99.451 - * ((long)(b & 0xff) << 48) |
99.452 - * ((long)(c & 0xff) << 40) |
99.453 - * ((long)(d & 0xff) << 32) |
99.454 - * ((long)(e & 0xff) << 24) |
99.455 - * ((long)(f & 0xff) << 16) |
99.456 - * ((long)(g & 0xff) << 8) |
99.457 - * ((long)(h & 0xff)))
99.458 - * </code></pre>
99.459 - * <p>
99.460 - * This method is suitable
99.461 - * for reading bytes written by the <code>writeLong</code>
99.462 - * method of interface <code>DataOutput</code>.
99.463 - *
99.464 - * @return the <code>long</code> value read.
99.465 - * @exception EOFException if this stream reaches the end before reading
99.466 - * all the bytes.
99.467 - * @exception IOException if an I/O error occurs.
99.468 - */
99.469 - long readLong() throws IOException;
99.470 -
99.471 - /**
99.472 - * Reads four input bytes and returns
99.473 - * a <code>float</code> value. It does this
99.474 - * by first constructing an <code>int</code>
99.475 - * value in exactly the manner
99.476 - * of the <code>readInt</code>
99.477 - * method, then converting this <code>int</code>
99.478 - * value to a <code>float</code> in
99.479 - * exactly the manner of the method <code>Float.intBitsToFloat</code>.
99.480 - * This method is suitable for reading
99.481 - * bytes written by the <code>writeFloat</code>
99.482 - * method of interface <code>DataOutput</code>.
99.483 - *
99.484 - * @return the <code>float</code> value read.
99.485 - * @exception EOFException if this stream reaches the end before reading
99.486 - * all the bytes.
99.487 - * @exception IOException if an I/O error occurs.
99.488 - */
99.489 - float readFloat() throws IOException;
99.490 -
99.491 - /**
99.492 - * Reads eight input bytes and returns
99.493 - * a <code>double</code> value. It does this
99.494 - * by first constructing a <code>long</code>
99.495 - * value in exactly the manner
99.496 - * of the <code>readlong</code>
99.497 - * method, then converting this <code>long</code>
99.498 - * value to a <code>double</code> in exactly
99.499 - * the manner of the method <code>Double.longBitsToDouble</code>.
99.500 - * This method is suitable for reading
99.501 - * bytes written by the <code>writeDouble</code>
99.502 - * method of interface <code>DataOutput</code>.
99.503 - *
99.504 - * @return the <code>double</code> value read.
99.505 - * @exception EOFException if this stream reaches the end before reading
99.506 - * all the bytes.
99.507 - * @exception IOException if an I/O error occurs.
99.508 - */
99.509 - double readDouble() throws IOException;
99.510 -
99.511 - /**
99.512 - * Reads the next line of text from the input stream.
99.513 - * It reads successive bytes, converting
99.514 - * each byte separately into a character,
99.515 - * until it encounters a line terminator or
99.516 - * end of
99.517 - * file; the characters read are then
99.518 - * returned as a <code>String</code>. Note
99.519 - * that because this
99.520 - * method processes bytes,
99.521 - * it does not support input of the full Unicode
99.522 - * character set.
99.523 - * <p>
99.524 - * If end of file is encountered
99.525 - * before even one byte can be read, then <code>null</code>
99.526 - * is returned. Otherwise, each byte that is
99.527 - * read is converted to type <code>char</code>
99.528 - * by zero-extension. If the character <code>'\n'</code>
99.529 - * is encountered, it is discarded and reading
99.530 - * ceases. If the character <code>'\r'</code>
99.531 - * is encountered, it is discarded and, if
99.532 - * the following byte converts  to the
99.533 - * character <code>'\n'</code>, then that is
99.534 - * discarded also; reading then ceases. If
99.535 - * end of file is encountered before either
99.536 - * of the characters <code>'\n'</code> and
99.537 - * <code>'\r'</code> is encountered, reading
99.538 - * ceases. Once reading has ceased, a <code>String</code>
99.539 - * is returned that contains all the characters
99.540 - * read and not discarded, taken in order.
99.541 - * Note that every character in this string
99.542 - * will have a value less than <code>\u0100</code>,
99.543 - * that is, <code>(char)256</code>.
99.544 - *
99.545 - * @return the next line of text from the input stream,
99.546 - * or <CODE>null</CODE> if the end of file is
99.547 - * encountered before a byte can be read.
99.548 - * @exception IOException if an I/O error occurs.
99.549 - */
99.550 - String readLine() throws IOException;
99.551 -
99.552 - /**
99.553 - * Reads in a string that has been encoded using a
99.554 - * <a href="#modified-utf-8">modified UTF-8</a>
99.555 - * format.
99.556 - * The general contract of <code>readUTF</code>
99.557 - * is that it reads a representation of a Unicode
99.558 - * character string encoded in modified
99.559 - * UTF-8 format; this string of characters
99.560 - * is then returned as a <code>String</code>.
99.561 - * <p>
99.562 - * First, two bytes are read and used to
99.563 - * construct an unsigned 16-bit integer in
99.564 - * exactly the manner of the <code>readUnsignedShort</code>
99.565 - * method . This integer value is called the
99.566 - * <i>UTF length</i> and specifies the number
99.567 - * of additional bytes to be read. These bytes
99.568 - * are then converted to characters by considering
99.569 - * them in groups. The length of each group
99.570 - * is computed from the value of the first
99.571 - * byte of the group. The byte following a
99.572 - * group, if any, is the first byte of the
99.573 - * next group.
99.574 - * <p>
99.575 - * If the first byte of a group
99.576 - * matches the bit pattern <code>0xxxxxxx</code>
99.577 - * (where <code>x</code> means "may be <code>0</code>
99.578 - * or <code>1</code>"), then the group consists
99.579 - * of just that byte. The byte is zero-extended
99.580 - * to form a character.
99.581 - * <p>
99.582 - * If the first byte
99.583 - * of a group matches the bit pattern <code>110xxxxx</code>,
99.584 - * then the group consists of that byte <code>a</code>
99.585 - * and a second byte <code>b</code>. If there
99.586 - * is no byte <code>b</code> (because byte
99.587 - * <code>a</code> was the last of the bytes
99.588 - * to be read), or if byte <code>b</code> does
99.589 - * not match the bit pattern <code>10xxxxxx</code>,
99.590 - * then a <code>UTFDataFormatException</code>
99.591 - * is thrown. Otherwise, the group is converted
99.592 - * to the character:<p>
99.593 - * <pre><code>(char)(((a& 0x1F) << 6) | (b & 0x3F))
99.594 - * </code></pre>
99.595 - * If the first byte of a group
99.596 - * matches the bit pattern <code>1110xxxx</code>,
99.597 - * then the group consists of that byte <code>a</code>
99.598 - * and two more bytes <code>b</code> and <code>c</code>.
99.599 - * If there is no byte <code>c</code> (because
99.600 - * byte <code>a</code> was one of the last
99.601 - * two of the bytes to be read), or either
99.602 - * byte <code>b</code> or byte <code>c</code>
99.603 - * does not match the bit pattern <code>10xxxxxx</code>,
99.604 - * then a <code>UTFDataFormatException</code>
99.605 - * is thrown. Otherwise, the group is converted
99.606 - * to the character:<p>
99.607 - * <pre><code>
99.608 - * (char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F))
99.609 - * </code></pre>
99.610 - * If the first byte of a group matches the
99.611 - * pattern <code>1111xxxx</code> or the pattern
99.612 - * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
99.613 - * is thrown.
99.614 - * <p>
99.615 - * If end of file is encountered
99.616 - * at any time during this entire process,
99.617 - * then an <code>EOFException</code> is thrown.
99.618 - * <p>
99.619 - * After every group has been converted to
99.620 - * a character by this process, the characters
99.621 - * are gathered, in the same order in which
99.622 - * their corresponding groups were read from
99.623 - * the input stream, to form a <code>String</code>,
99.624 - * which is returned.
99.625 - * <p>
99.626 - * The <code>writeUTF</code>
99.627 - * method of interface <code>DataOutput</code>
99.628 - * may be used to write data that is suitable
99.629 - * for reading by this method.
99.630 - * @return a Unicode string.
99.631 - * @exception EOFException if this stream reaches the end
99.632 - * before reading all the bytes.
99.633 - * @exception IOException if an I/O error occurs.
99.634 - * @exception UTFDataFormatException if the bytes do not represent a
99.635 - * valid modified UTF-8 encoding of a string.
99.636 - */
99.637 - String readUTF() throws IOException;
99.638 -}
100.1 --- a/emul/src/main/java/java/io/DataInputStream.java Wed Jan 23 20:16:48 2013 +0100
100.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
100.3 @@ -1,704 +0,0 @@
100.4 -/*
100.5 - * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
100.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
100.7 - *
100.8 - * This code is free software; you can redistribute it and/or modify it
100.9 - * under the terms of the GNU General Public License version 2 only, as
100.10 - * published by the Free Software Foundation. Oracle designates this
100.11 - * particular file as subject to the "Classpath" exception as provided
100.12 - * by Oracle in the LICENSE file that accompanied this code.
100.13 - *
100.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
100.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
100.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
100.17 - * version 2 for more details (a copy is included in the LICENSE file that
100.18 - * accompanied this code).
100.19 - *
100.20 - * You should have received a copy of the GNU General Public License version
100.21 - * 2 along with this work; if not, write to the Free Software Foundation,
100.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
100.23 - *
100.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
100.25 - * or visit www.oracle.com if you need additional information or have any
100.26 - * questions.
100.27 - */
100.28 -
100.29 -package java.io;
100.30 -
100.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
100.32 -
100.33 -/**
100.34 - * A data input stream lets an application read primitive Java data
100.35 - * types from an underlying input stream in a machine-independent
100.36 - * way. An application uses a data output stream to write data that
100.37 - * can later be read by a data input stream.
100.38 - * <p>
100.39 - * DataInputStream is not necessarily safe for multithreaded access.
100.40 - * Thread safety is optional and is the responsibility of users of
100.41 - * methods in this class.
100.42 - *
100.43 - * @author Arthur van Hoff
100.44 - * @see java.io.DataOutputStream
100.45 - * @since JDK1.0
100.46 - */
100.47 -public
100.48 -class DataInputStream extends FilterInputStream implements DataInput {
100.49 -
100.50 - /**
100.51 - * Creates a DataInputStream that uses the specified
100.52 - * underlying InputStream.
100.53 - *
100.54 - * @param in the specified input stream
100.55 - */
100.56 - public DataInputStream(InputStream in) {
100.57 - super(in);
100.58 - }
100.59 -
100.60 - /**
100.61 - * working arrays initialized on demand by readUTF
100.62 - */
100.63 - private byte bytearr[] = new byte[80];
100.64 - private char chararr[] = new char[80];
100.65 -
100.66 - /**
100.67 - * Reads some number of bytes from the contained input stream and
100.68 - * stores them into the buffer array <code>b</code>. The number of
100.69 - * bytes actually read is returned as an integer. This method blocks
100.70 - * until input data is available, end of file is detected, or an
100.71 - * exception is thrown.
100.72 - *
100.73 - * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
100.74 - * thrown. If the length of <code>b</code> is zero, then no bytes are
100.75 - * read and <code>0</code> is returned; otherwise, there is an attempt
100.76 - * to read at least one byte. If no byte is available because the
100.77 - * stream is at end of file, the value <code>-1</code> is returned;
100.78 - * otherwise, at least one byte is read and stored into <code>b</code>.
100.79 - *
100.80 - * <p>The first byte read is stored into element <code>b[0]</code>, the
100.81 - * next one into <code>b[1]</code>, and so on. The number of bytes read
100.82 - * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
100.83 - * be the number of bytes actually read; these bytes will be stored in
100.84 - * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
100.85 - * elements <code>b[k]</code> through <code>b[b.length-1]</code>
100.86 - * unaffected.
100.87 - *
100.88 - * <p>The <code>read(b)</code> method has the same effect as:
100.89 - * <blockquote><pre>
100.90 - * read(b, 0, b.length)
100.91 - * </pre></blockquote>
100.92 - *
100.93 - * @param b the buffer into which the data is read.
100.94 - * @return the total number of bytes read into the buffer, or
100.95 - * <code>-1</code> if there is no more data because the end
100.96 - * of the stream has been reached.
100.97 - * @exception IOException if the first byte cannot be read for any reason
100.98 - * other than end of file, the stream has been closed and the underlying
100.99 - * input stream does not support reading after close, or another I/O
100.100 - * error occurs.
100.101 - * @see java.io.FilterInputStream#in
100.102 - * @see java.io.InputStream#read(byte[], int, int)
100.103 - */
100.104 - public final int read(byte b[]) throws IOException {
100.105 - return in.read(b, 0, b.length);
100.106 - }
100.107 -
100.108 - /**
100.109 - * Reads up to <code>len</code> bytes of data from the contained
100.110 - * input stream into an array of bytes. An attempt is made to read
100.111 - * as many as <code>len</code> bytes, but a smaller number may be read,
100.112 - * possibly zero. The number of bytes actually read is returned as an
100.113 - * integer.
100.114 - *
100.115 - * <p> This method blocks until input data is available, end of file is
100.116 - * detected, or an exception is thrown.
100.117 - *
100.118 - * <p> If <code>len</code> is zero, then no bytes are read and
100.119 - * <code>0</code> is returned; otherwise, there is an attempt to read at
100.120 - * least one byte. If no byte is available because the stream is at end of
100.121 - * file, the value <code>-1</code> is returned; otherwise, at least one
100.122 - * byte is read and stored into <code>b</code>.
100.123 - *
100.124 - * <p> The first byte read is stored into element <code>b[off]</code>, the
100.125 - * next one into <code>b[off+1]</code>, and so on. The number of bytes read
100.126 - * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
100.127 - * bytes actually read; these bytes will be stored in elements
100.128 - * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
100.129 - * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
100.130 - * <code>b[off+len-1]</code> unaffected.
100.131 - *
100.132 - * <p> In every case, elements <code>b[0]</code> through
100.133 - * <code>b[off]</code> and elements <code>b[off+len]</code> through
100.134 - * <code>b[b.length-1]</code> are unaffected.
100.135 - *
100.136 - * @param b the buffer into which the data is read.
100.137 - * @param off the start offset in the destination array <code>b</code>
100.138 - * @param len the maximum number of bytes read.
100.139 - * @return the total number of bytes read into the buffer, or
100.140 - * <code>-1</code> if there is no more data because the end
100.141 - * of the stream has been reached.
100.142 - * @exception NullPointerException If <code>b</code> is <code>null</code>.
100.143 - * @exception IndexOutOfBoundsException If <code>off</code> is negative,
100.144 - * <code>len</code> is negative, or <code>len</code> is greater than
100.145 - * <code>b.length - off</code>
100.146 - * @exception IOException if the first byte cannot be read for any reason
100.147 - * other than end of file, the stream has been closed and the underlying
100.148 - * input stream does not support reading after close, or another I/O
100.149 - * error occurs.
100.150 - * @see java.io.FilterInputStream#in
100.151 - * @see java.io.InputStream#read(byte[], int, int)
100.152 - */
100.153 - public final int read(byte b[], int off, int len) throws IOException {
100.154 - return in.read(b, off, len);
100.155 - }
100.156 -
100.157 - /**
100.158 - * See the general contract of the <code>readFully</code>
100.159 - * method of <code>DataInput</code>.
100.160 - * <p>
100.161 - * Bytes
100.162 - * for this operation are read from the contained
100.163 - * input stream.
100.164 - *
100.165 - * @param b the buffer into which the data is read.
100.166 - * @exception EOFException if this input stream reaches the end before
100.167 - * reading all the bytes.
100.168 - * @exception IOException the stream has been closed and the contained
100.169 - * input stream does not support reading after close, or
100.170 - * another I/O error occurs.
100.171 - * @see java.io.FilterInputStream#in
100.172 - */
100.173 - public final void readFully(byte b[]) throws IOException {
100.174 - readFully(b, 0, b.length);
100.175 - }
100.176 -
100.177 - /**
100.178 - * See the general contract of the <code>readFully</code>
100.179 - * method of <code>DataInput</code>.
100.180 - * <p>
100.181 - * Bytes
100.182 - * for this operation are read from the contained
100.183 - * input stream.
100.184 - *
100.185 - * @param b the buffer into which the data is read.
100.186 - * @param off the start offset of the data.
100.187 - * @param len the number of bytes to read.
100.188 - * @exception EOFException if this input stream reaches the end before
100.189 - * reading all the bytes.
100.190 - * @exception IOException the stream has been closed and the contained
100.191 - * input stream does not support reading after close, or
100.192 - * another I/O error occurs.
100.193 - * @see java.io.FilterInputStream#in
100.194 - */
100.195 - public final void readFully(byte b[], int off, int len) throws IOException {
100.196 - if (len < 0)
100.197 - throw new IndexOutOfBoundsException();
100.198 - int n = 0;
100.199 - while (n < len) {
100.200 - int count = in.read(b, off + n, len - n);
100.201 - if (count < 0)
100.202 - throw new EOFException();
100.203 - n += count;
100.204 - }
100.205 - }
100.206 -
100.207 - /**
100.208 - * See the general contract of the <code>skipBytes</code>
100.209 - * method of <code>DataInput</code>.
100.210 - * <p>
100.211 - * Bytes for this operation are read from the contained
100.212 - * input stream.
100.213 - *
100.214 - * @param n the number of bytes to be skipped.
100.215 - * @return the actual number of bytes skipped.
100.216 - * @exception IOException if the contained input stream does not support
100.217 - * seek, or the stream has been closed and
100.218 - * the contained input stream does not support
100.219 - * reading after close, or another I/O error occurs.
100.220 - */
100.221 - public final int skipBytes(int n) throws IOException {
100.222 - int total = 0;
100.223 - int cur = 0;
100.224 -
100.225 - while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
100.226 - total += cur;
100.227 - }
100.228 -
100.229 - return total;
100.230 - }
100.231 -
100.232 - /**
100.233 - * See the general contract of the <code>readBoolean</code>
100.234 - * method of <code>DataInput</code>.
100.235 - * <p>
100.236 - * Bytes for this operation are read from the contained
100.237 - * input stream.
100.238 - *
100.239 - * @return the <code>boolean</code> value read.
100.240 - * @exception EOFException if this input stream has reached the end.
100.241 - * @exception IOException the stream has been closed and the contained
100.242 - * input stream does not support reading after close, or
100.243 - * another I/O error occurs.
100.244 - * @see java.io.FilterInputStream#in
100.245 - */
100.246 - public final boolean readBoolean() throws IOException {
100.247 - int ch = in.read();
100.248 - if (ch < 0)
100.249 - throw new EOFException();
100.250 - return (ch != 0);
100.251 - }
100.252 -
100.253 - /**
100.254 - * See the general contract of the <code>readByte</code>
100.255 - * method of <code>DataInput</code>.
100.256 - * <p>
100.257 - * Bytes
100.258 - * for this operation are read from the contained
100.259 - * input stream.
100.260 - *
100.261 - * @return the next byte of this input stream as a signed 8-bit
100.262 - * <code>byte</code>.
100.263 - * @exception EOFException if this input stream has reached the end.
100.264 - * @exception IOException the stream has been closed and the contained
100.265 - * input stream does not support reading after close, or
100.266 - * another I/O error occurs.
100.267 - * @see java.io.FilterInputStream#in
100.268 - */
100.269 - public final byte readByte() throws IOException {
100.270 - int ch = in.read();
100.271 - if (ch < 0)
100.272 - throw new EOFException();
100.273 - return (byte)(ch);
100.274 - }
100.275 -
100.276 - /**
100.277 - * See the general contract of the <code>readUnsignedByte</code>
100.278 - * method of <code>DataInput</code>.
100.279 - * <p>
100.280 - * Bytes
100.281 - * for this operation are read from the contained
100.282 - * input stream.
100.283 - *
100.284 - * @return the next byte of this input stream, interpreted as an
100.285 - * unsigned 8-bit number.
100.286 - * @exception EOFException if this input stream has reached the end.
100.287 - * @exception IOException the stream has been closed and the contained
100.288 - * input stream does not support reading after close, or
100.289 - * another I/O error occurs.
100.290 - * @see java.io.FilterInputStream#in
100.291 - */
100.292 - public final int readUnsignedByte() throws IOException {
100.293 - int ch = in.read();
100.294 - if (ch < 0)
100.295 - throw new EOFException();
100.296 - return ch;
100.297 - }
100.298 -
100.299 - /**
100.300 - * See the general contract of the <code>readShort</code>
100.301 - * method of <code>DataInput</code>.
100.302 - * <p>
100.303 - * Bytes
100.304 - * for this operation are read from the contained
100.305 - * input stream.
100.306 - *
100.307 - * @return the next two bytes of this input stream, interpreted as a
100.308 - * signed 16-bit number.
100.309 - * @exception EOFException if this input stream reaches the end before
100.310 - * reading two bytes.
100.311 - * @exception IOException the stream has been closed and the contained
100.312 - * input stream does not support reading after close, or
100.313 - * another I/O error occurs.
100.314 - * @see java.io.FilterInputStream#in
100.315 - */
100.316 - public final short readShort() throws IOException {
100.317 - int ch1 = in.read();
100.318 - int ch2 = in.read();
100.319 - if ((ch1 | ch2) < 0)
100.320 - throw new EOFException();
100.321 - return (short)((ch1 << 8) + (ch2 << 0));
100.322 - }
100.323 -
100.324 - /**
100.325 - * See the general contract of the <code>readUnsignedShort</code>
100.326 - * method of <code>DataInput</code>.
100.327 - * <p>
100.328 - * Bytes
100.329 - * for this operation are read from the contained
100.330 - * input stream.
100.331 - *
100.332 - * @return the next two bytes of this input stream, interpreted as an
100.333 - * unsigned 16-bit integer.
100.334 - * @exception EOFException if this input stream reaches the end before
100.335 - * reading two bytes.
100.336 - * @exception IOException the stream has been closed and the contained
100.337 - * input stream does not support reading after close, or
100.338 - * another I/O error occurs.
100.339 - * @see java.io.FilterInputStream#in
100.340 - */
100.341 - public final int readUnsignedShort() throws IOException {
100.342 - int ch1 = in.read();
100.343 - int ch2 = in.read();
100.344 - if ((ch1 | ch2) < 0)
100.345 - throw new EOFException();
100.346 - return (ch1 << 8) + (ch2 << 0);
100.347 - }
100.348 -
100.349 - /**
100.350 - * See the general contract of the <code>readChar</code>
100.351 - * method of <code>DataInput</code>.
100.352 - * <p>
100.353 - * Bytes
100.354 - * for this operation are read from the contained
100.355 - * input stream.
100.356 - *
100.357 - * @return the next two bytes of this input stream, interpreted as a
100.358 - * <code>char</code>.
100.359 - * @exception EOFException if this input stream reaches the end before
100.360 - * reading two bytes.
100.361 - * @exception IOException the stream has been closed and the contained
100.362 - * input stream does not support reading after close, or
100.363 - * another I/O error occurs.
100.364 - * @see java.io.FilterInputStream#in
100.365 - */
100.366 - public final char readChar() throws IOException {
100.367 - int ch1 = in.read();
100.368 - int ch2 = in.read();
100.369 - if ((ch1 | ch2) < 0)
100.370 - throw new EOFException();
100.371 - return (char)((ch1 << 8) + (ch2 << 0));
100.372 - }
100.373 -
100.374 - /**
100.375 - * See the general contract of the <code>readInt</code>
100.376 - * method of <code>DataInput</code>.
100.377 - * <p>
100.378 - * Bytes
100.379 - * for this operation are read from the contained
100.380 - * input stream.
100.381 - *
100.382 - * @return the next four bytes of this input stream, interpreted as an
100.383 - * <code>int</code>.
100.384 - * @exception EOFException if this input stream reaches the end before
100.385 - * reading four bytes.
100.386 - * @exception IOException the stream has been closed and the contained
100.387 - * input stream does not support reading after close, or
100.388 - * another I/O error occurs.
100.389 - * @see java.io.FilterInputStream#in
100.390 - */
100.391 - public final int readInt() throws IOException {
100.392 - int ch1 = in.read();
100.393 - int ch2 = in.read();
100.394 - int ch3 = in.read();
100.395 - int ch4 = in.read();
100.396 - if ((ch1 | ch2 | ch3 | ch4) < 0)
100.397 - throw new EOFException();
100.398 - return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
100.399 - }
100.400 -
100.401 - private byte readBuffer[] = new byte[8];
100.402 -
100.403 - /**
100.404 - * See the general contract of the <code>readLong</code>
100.405 - * method of <code>DataInput</code>.
100.406 - * <p>
100.407 - * Bytes
100.408 - * for this operation are read from the contained
100.409 - * input stream.
100.410 - *
100.411 - * @return the next eight bytes of this input stream, interpreted as a
100.412 - * <code>long</code>.
100.413 - * @exception EOFException if this input stream reaches the end before
100.414 - * reading eight bytes.
100.415 - * @exception IOException the stream has been closed and the contained
100.416 - * input stream does not support reading after close, or
100.417 - * another I/O error occurs.
100.418 - * @see java.io.FilterInputStream#in
100.419 - */
100.420 - public final long readLong() throws IOException {
100.421 - readFully(readBuffer, 0, 8);
100.422 - return (((long)readBuffer[0] << 56) +
100.423 - ((long)(readBuffer[1] & 255) << 48) +
100.424 - ((long)(readBuffer[2] & 255) << 40) +
100.425 - ((long)(readBuffer[3] & 255) << 32) +
100.426 - ((long)(readBuffer[4] & 255) << 24) +
100.427 - ((readBuffer[5] & 255) << 16) +
100.428 - ((readBuffer[6] & 255) << 8) +
100.429 - ((readBuffer[7] & 255) << 0));
100.430 - }
100.431 -
100.432 - /**
100.433 - * See the general contract of the <code>readFloat</code>
100.434 - * method of <code>DataInput</code>.
100.435 - * <p>
100.436 - * Bytes
100.437 - * for this operation are read from the contained
100.438 - * input stream.
100.439 - *
100.440 - * @return the next four bytes of this input stream, interpreted as a
100.441 - * <code>float</code>.
100.442 - * @exception EOFException if this input stream reaches the end before
100.443 - * reading four bytes.
100.444 - * @exception IOException the stream has been closed and the contained
100.445 - * input stream does not support reading after close, or
100.446 - * another I/O error occurs.
100.447 - * @see java.io.DataInputStream#readInt()
100.448 - * @see java.lang.Float#intBitsToFloat(int)
100.449 - */
100.450 - public final float readFloat() throws IOException {
100.451 - return Float.intBitsToFloat(readInt());
100.452 - }
100.453 -
100.454 - /**
100.455 - * See the general contract of the <code>readDouble</code>
100.456 - * method of <code>DataInput</code>.
100.457 - * <p>
100.458 - * Bytes
100.459 - * for this operation are read from the contained
100.460 - * input stream.
100.461 - *
100.462 - * @return the next eight bytes of this input stream, interpreted as a
100.463 - * <code>double</code>.
100.464 - * @exception EOFException if this input stream reaches the end before
100.465 - * reading eight bytes.
100.466 - * @exception IOException the stream has been closed and the contained
100.467 - * input stream does not support reading after close, or
100.468 - * another I/O error occurs.
100.469 - * @see java.io.DataInputStream#readLong()
100.470 - * @see java.lang.Double#longBitsToDouble(long)
100.471 - */
100.472 - public final double readDouble() throws IOException {
100.473 - int hi = readInt();
100.474 - int low = readInt();
100.475 - return toDouble(hi, low);
100.476 - }
100.477 -
100.478 - @JavaScriptBody(args={ "hi", "low" },
100.479 - body=
100.480 - "if (low == 0) {\n"
100.481 - + " if (hi === 0x7ff00000) return Number.POSITIVE_INFINITY;\n"
100.482 - + " if (hi === 0xfff00000) return Number.NEGATIVE_INFINITY;\n"
100.483 - + "}\n"
100.484 - + "if (hi >= 0x7ff00000 && hi <= 0x7fffffff) return Number.NaN;\n"
100.485 - + "if (hi >= 0xfff00000 && hi <= 0xffffffff) return Number.NaN;\n"
100.486 - + "var s = (hi & 0x80000000) === 0 ? 1 : -1;\n"
100.487 - + "var e = (hi >> 20) & 0x7ff;\n"
100.488 - + "var to32 = low >> 0;\n"
100.489 - + "if (e === 0) {\n"
100.490 - + " if (to32 & 0x80000000) {\n"
100.491 - + " hi = hi << 1 + 1; low = low << 1;\n"
100.492 - + " } else {\n"
100.493 - + " hi = hi << 1; low = low << 1;\n"
100.494 - + " }\n"
100.495 - + "} else {\n"
100.496 - + " hi = (hi & 0xfffff) | 0x100000;\n"
100.497 - + "}\n"
100.498 - + "to32 = low >> 0;\n"
100.499 - + "var m = Math.pow(2.0, 32) * hi + to32;\n"
100.500 - + "var r = s * m * Math.pow(2.0, e - 1075);\n"
100.501 - + "//throw 'exp: ' + e + ' sign: ' + s + ' hi:' + hi + ' low: ' + low + ' m: ' + m + ' r: ' + r;\n"
100.502 - + "return r;\n"
100.503 - )
100.504 - private static double toDouble(int hi, int low) {
100.505 - long both = hi;
100.506 - both = (both << 32) & low;
100.507 - return Double.doubleToLongBits(both);
100.508 - }
100.509 -
100.510 - private char lineBuffer[];
100.511 -
100.512 - /**
100.513 - * See the general contract of the <code>readLine</code>
100.514 - * method of <code>DataInput</code>.
100.515 - * <p>
100.516 - * Bytes
100.517 - * for this operation are read from the contained
100.518 - * input stream.
100.519 - *
100.520 - * @deprecated This method does not properly convert bytes to characters.
100.521 - * As of JDK 1.1, the preferred way to read lines of text is via the
100.522 - * <code>BufferedReader.readLine()</code> method. Programs that use the
100.523 - * <code>DataInputStream</code> class to read lines can be converted to use
100.524 - * the <code>BufferedReader</code> class by replacing code of the form:
100.525 - * <blockquote><pre>
100.526 - * DataInputStream d = new DataInputStream(in);
100.527 - * </pre></blockquote>
100.528 - * with:
100.529 - * <blockquote><pre>
100.530 - * BufferedReader d
100.531 - * = new BufferedReader(new InputStreamReader(in));
100.532 - * </pre></blockquote>
100.533 - *
100.534 - * @return the next line of text from this input stream.
100.535 - * @exception IOException if an I/O error occurs.
100.536 - * @see java.io.BufferedReader#readLine()
100.537 - * @see java.io.FilterInputStream#in
100.538 - */
100.539 - @Deprecated
100.540 - public final String readLine() throws IOException {
100.541 - char buf[] = lineBuffer;
100.542 -
100.543 - if (buf == null) {
100.544 - buf = lineBuffer = new char[128];
100.545 - }
100.546 -
100.547 - int room = buf.length;
100.548 - int offset = 0;
100.549 - int c;
100.550 -
100.551 -loop: while (true) {
100.552 - switch (c = in.read()) {
100.553 - case -1:
100.554 - case '\n':
100.555 - break loop;
100.556 -
100.557 - case '\r':
100.558 - int c2 = in.read();
100.559 - if ((c2 != '\n') && (c2 != -1)) {
100.560 - if (!(in instanceof PushbackInputStream)) {
100.561 - this.in = new PushbackInputStream(in);
100.562 - }
100.563 - ((PushbackInputStream)in).unread(c2);
100.564 - }
100.565 - break loop;
100.566 -
100.567 - default:
100.568 - if (--room < 0) {
100.569 - buf = new char[offset + 128];
100.570 - room = buf.length - offset - 1;
100.571 - arraycopy(lineBuffer, 0, buf, 0, offset);
100.572 - lineBuffer = buf;
100.573 - }
100.574 - buf[offset++] = (char) c;
100.575 - break;
100.576 - }
100.577 - }
100.578 - if ((c == -1) && (offset == 0)) {
100.579 - return null;
100.580 - }
100.581 - return String.copyValueOf(buf, 0, offset);
100.582 - }
100.583 -
100.584 - /**
100.585 - * See the general contract of the <code>readUTF</code>
100.586 - * method of <code>DataInput</code>.
100.587 - * <p>
100.588 - * Bytes
100.589 - * for this operation are read from the contained
100.590 - * input stream.
100.591 - *
100.592 - * @return a Unicode string.
100.593 - * @exception EOFException if this input stream reaches the end before
100.594 - * reading all the bytes.
100.595 - * @exception IOException the stream has been closed and the contained
100.596 - * input stream does not support reading after close, or
100.597 - * another I/O error occurs.
100.598 - * @exception UTFDataFormatException if the bytes do not represent a valid
100.599 - * modified UTF-8 encoding of a string.
100.600 - * @see java.io.DataInputStream#readUTF(java.io.DataInput)
100.601 - */
100.602 - public final String readUTF() throws IOException {
100.603 - return readUTF(this);
100.604 - }
100.605 -
100.606 - /**
100.607 - * Reads from the
100.608 - * stream <code>in</code> a representation
100.609 - * of a Unicode character string encoded in
100.610 - * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
100.611 - * this string of characters is then returned as a <code>String</code>.
100.612 - * The details of the modified UTF-8 representation
100.613 - * are exactly the same as for the <code>readUTF</code>
100.614 - * method of <code>DataInput</code>.
100.615 - *
100.616 - * @param in a data input stream.
100.617 - * @return a Unicode string.
100.618 - * @exception EOFException if the input stream reaches the end
100.619 - * before all the bytes.
100.620 - * @exception IOException the stream has been closed and the contained
100.621 - * input stream does not support reading after close, or
100.622 - * another I/O error occurs.
100.623 - * @exception UTFDataFormatException if the bytes do not represent a
100.624 - * valid modified UTF-8 encoding of a Unicode string.
100.625 - * @see java.io.DataInputStream#readUnsignedShort()
100.626 - */
100.627 - public final static String readUTF(DataInput in) throws IOException {
100.628 - int utflen = in.readUnsignedShort();
100.629 - byte[] bytearr = null;
100.630 - char[] chararr = null;
100.631 - if (in instanceof DataInputStream) {
100.632 - DataInputStream dis = (DataInputStream)in;
100.633 - if (dis.bytearr.length < utflen){
100.634 - dis.bytearr = new byte[utflen*2];
100.635 - dis.chararr = new char[utflen*2];
100.636 - }
100.637 - chararr = dis.chararr;
100.638 - bytearr = dis.bytearr;
100.639 - } else {
100.640 - bytearr = new byte[utflen];
100.641 - chararr = new char[utflen];
100.642 - }
100.643 -
100.644 - int c, char2, char3;
100.645 - int count = 0;
100.646 - int chararr_count=0;
100.647 -
100.648 - in.readFully(bytearr, 0, utflen);
100.649 -
100.650 - while (count < utflen) {
100.651 - c = (int) bytearr[count] & 0xff;
100.652 - if (c > 127) break;
100.653 - count++;
100.654 - chararr[chararr_count++]=(char)c;
100.655 - }
100.656 -
100.657 - while (count < utflen) {
100.658 - c = (int) bytearr[count] & 0xff;
100.659 - switch (c >> 4) {
100.660 - case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
100.661 - /* 0xxxxxxx*/
100.662 - count++;
100.663 - chararr[chararr_count++]=(char)c;
100.664 - break;
100.665 - case 12: case 13:
100.666 - /* 110x xxxx 10xx xxxx*/
100.667 - count += 2;
100.668 - if (count > utflen)
100.669 - throw new UTFDataFormatException(
100.670 - "malformed input: partial character at end");
100.671 - char2 = (int) bytearr[count-1];
100.672 - if ((char2 & 0xC0) != 0x80)
100.673 - throw new UTFDataFormatException(
100.674 - "malformed input around byte " + count);
100.675 - chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
100.676 - (char2 & 0x3F));
100.677 - break;
100.678 - case 14:
100.679 - /* 1110 xxxx 10xx xxxx 10xx xxxx */
100.680 - count += 3;
100.681 - if (count > utflen)
100.682 - throw new UTFDataFormatException(
100.683 - "malformed input: partial character at end");
100.684 - char2 = (int) bytearr[count-2];
100.685 - char3 = (int) bytearr[count-1];
100.686 - if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
100.687 - throw new UTFDataFormatException(
100.688 - "malformed input around byte " + (count-1));
100.689 - chararr[chararr_count++]=(char)(((c & 0x0F) << 12) |
100.690 - ((char2 & 0x3F) << 6) |
100.691 - ((char3 & 0x3F) << 0));
100.692 - break;
100.693 - default:
100.694 - /* 10xx xxxx, 1111 xxxx */
100.695 - throw new UTFDataFormatException(
100.696 - "malformed input around byte " + count);
100.697 - }
100.698 - }
100.699 - // The number of chars produced may be less than utflen
100.700 - return new String(chararr, 0, chararr_count);
100.701 - }
100.702 - static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
100.703 - while (count-- > 0) {
100.704 - dst[dstBegin++] = value[srcBegin++];
100.705 - }
100.706 - }
100.707 -}
101.1 --- a/emul/src/main/java/java/io/EOFException.java Wed Jan 23 20:16:48 2013 +0100
101.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
101.3 @@ -1,65 +0,0 @@
101.4 -/*
101.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
101.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
101.7 - *
101.8 - * This code is free software; you can redistribute it and/or modify it
101.9 - * under the terms of the GNU General Public License version 2 only, as
101.10 - * published by the Free Software Foundation. Oracle designates this
101.11 - * particular file as subject to the "Classpath" exception as provided
101.12 - * by Oracle in the LICENSE file that accompanied this code.
101.13 - *
101.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
101.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
101.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
101.17 - * version 2 for more details (a copy is included in the LICENSE file that
101.18 - * accompanied this code).
101.19 - *
101.20 - * You should have received a copy of the GNU General Public License version
101.21 - * 2 along with this work; if not, write to the Free Software Foundation,
101.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
101.23 - *
101.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
101.25 - * or visit www.oracle.com if you need additional information or have any
101.26 - * questions.
101.27 - */
101.28 -
101.29 -package java.io;
101.30 -
101.31 -/**
101.32 - * Signals that an end of file or end of stream has been reached
101.33 - * unexpectedly during input.
101.34 - * <p>
101.35 - * This exception is mainly used by data input streams to signal end of
101.36 - * stream. Note that many other input operations return a special value on
101.37 - * end of stream rather than throwing an exception.
101.38 - * <p>
101.39 - *
101.40 - * @author Frank Yellin
101.41 - * @see java.io.DataInputStream
101.42 - * @see java.io.IOException
101.43 - * @since JDK1.0
101.44 - */
101.45 -public
101.46 -class EOFException extends IOException {
101.47 - private static final long serialVersionUID = 6433858223774886977L;
101.48 -
101.49 - /**
101.50 - * Constructs an <code>EOFException</code> with <code>null</code>
101.51 - * as its error detail message.
101.52 - */
101.53 - public EOFException() {
101.54 - super();
101.55 - }
101.56 -
101.57 - /**
101.58 - * Constructs an <code>EOFException</code> with the specified detail
101.59 - * message. The string <code>s</code> may later be retrieved by the
101.60 - * <code>{@link java.lang.Throwable#getMessage}</code> method of class
101.61 - * <code>java.lang.Throwable</code>.
101.62 - *
101.63 - * @param s the detail message.
101.64 - */
101.65 - public EOFException(String s) {
101.66 - super(s);
101.67 - }
101.68 -}
102.1 --- a/emul/src/main/java/java/io/FilterInputStream.java Wed Jan 23 20:16:48 2013 +0100
102.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
102.3 @@ -1,245 +0,0 @@
102.4 -/*
102.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
102.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
102.7 - *
102.8 - * This code is free software; you can redistribute it and/or modify it
102.9 - * under the terms of the GNU General Public License version 2 only, as
102.10 - * published by the Free Software Foundation. Oracle designates this
102.11 - * particular file as subject to the "Classpath" exception as provided
102.12 - * by Oracle in the LICENSE file that accompanied this code.
102.13 - *
102.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
102.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
102.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
102.17 - * version 2 for more details (a copy is included in the LICENSE file that
102.18 - * accompanied this code).
102.19 - *
102.20 - * You should have received a copy of the GNU General Public License version
102.21 - * 2 along with this work; if not, write to the Free Software Foundation,
102.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
102.23 - *
102.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
102.25 - * or visit www.oracle.com if you need additional information or have any
102.26 - * questions.
102.27 - */
102.28 -
102.29 -package java.io;
102.30 -
102.31 -/**
102.32 - * A <code>FilterInputStream</code> contains
102.33 - * some other input stream, which it uses as
102.34 - * its basic source of data, possibly transforming
102.35 - * the data along the way or providing additional
102.36 - * functionality. The class <code>FilterInputStream</code>
102.37 - * itself simply overrides all methods of
102.38 - * <code>InputStream</code> with versions that
102.39 - * pass all requests to the contained input
102.40 - * stream. Subclasses of <code>FilterInputStream</code>
102.41 - * may further override some of these methods
102.42 - * and may also provide additional methods
102.43 - * and fields.
102.44 - *
102.45 - * @author Jonathan Payne
102.46 - * @since JDK1.0
102.47 - */
102.48 -public
102.49 -class FilterInputStream extends InputStream {
102.50 - /**
102.51 - * The input stream to be filtered.
102.52 - */
102.53 - protected volatile InputStream in;
102.54 -
102.55 - /**
102.56 - * Creates a <code>FilterInputStream</code>
102.57 - * by assigning the argument <code>in</code>
102.58 - * to the field <code>this.in</code> so as
102.59 - * to remember it for later use.
102.60 - *
102.61 - * @param in the underlying input stream, or <code>null</code> if
102.62 - * this instance is to be created without an underlying stream.
102.63 - */
102.64 - protected FilterInputStream(InputStream in) {
102.65 - this.in = in;
102.66 - }
102.67 -
102.68 - /**
102.69 - * Reads the next byte of data from this input stream. The value
102.70 - * byte is returned as an <code>int</code> in the range
102.71 - * <code>0</code> to <code>255</code>. If no byte is available
102.72 - * because the end of the stream has been reached, the value
102.73 - * <code>-1</code> is returned. This method blocks until input data
102.74 - * is available, the end of the stream is detected, or an exception
102.75 - * is thrown.
102.76 - * <p>
102.77 - * This method
102.78 - * simply performs <code>in.read()</code> and returns the result.
102.79 - *
102.80 - * @return the next byte of data, or <code>-1</code> if the end of the
102.81 - * stream is reached.
102.82 - * @exception IOException if an I/O error occurs.
102.83 - * @see java.io.FilterInputStream#in
102.84 - */
102.85 - public int read() throws IOException {
102.86 - return in.read();
102.87 - }
102.88 -
102.89 - /**
102.90 - * Reads up to <code>byte.length</code> bytes of data from this
102.91 - * input stream into an array of bytes. This method blocks until some
102.92 - * input is available.
102.93 - * <p>
102.94 - * This method simply performs the call
102.95 - * <code>read(b, 0, b.length)</code> and returns
102.96 - * the result. It is important that it does
102.97 - * <i>not</i> do <code>in.read(b)</code> instead;
102.98 - * certain subclasses of <code>FilterInputStream</code>
102.99 - * depend on the implementation strategy actually
102.100 - * used.
102.101 - *
102.102 - * @param b the buffer into which the data is read.
102.103 - * @return the total number of bytes read into the buffer, or
102.104 - * <code>-1</code> if there is no more data because the end of
102.105 - * the stream has been reached.
102.106 - * @exception IOException if an I/O error occurs.
102.107 - * @see java.io.FilterInputStream#read(byte[], int, int)
102.108 - */
102.109 - public int read(byte b[]) throws IOException {
102.110 - return read(b, 0, b.length);
102.111 - }
102.112 -
102.113 - /**
102.114 - * Reads up to <code>len</code> bytes of data from this input stream
102.115 - * into an array of bytes. If <code>len</code> is not zero, the method
102.116 - * blocks until some input is available; otherwise, no
102.117 - * bytes are read and <code>0</code> is returned.
102.118 - * <p>
102.119 - * This method simply performs <code>in.read(b, off, len)</code>
102.120 - * and returns the result.
102.121 - *
102.122 - * @param b the buffer into which the data is read.
102.123 - * @param off the start offset in the destination array <code>b</code>
102.124 - * @param len the maximum number of bytes read.
102.125 - * @return the total number of bytes read into the buffer, or
102.126 - * <code>-1</code> if there is no more data because the end of
102.127 - * the stream has been reached.
102.128 - * @exception NullPointerException If <code>b</code> is <code>null</code>.
102.129 - * @exception IndexOutOfBoundsException If <code>off</code> is negative,
102.130 - * <code>len</code> is negative, or <code>len</code> is greater than
102.131 - * <code>b.length - off</code>
102.132 - * @exception IOException if an I/O error occurs.
102.133 - * @see java.io.FilterInputStream#in
102.134 - */
102.135 - public int read(byte b[], int off, int len) throws IOException {
102.136 - return in.read(b, off, len);
102.137 - }
102.138 -
102.139 - /**
102.140 - * Skips over and discards <code>n</code> bytes of data from the
102.141 - * input stream. The <code>skip</code> method may, for a variety of
102.142 - * reasons, end up skipping over some smaller number of bytes,
102.143 - * possibly <code>0</code>. The actual number of bytes skipped is
102.144 - * returned.
102.145 - * <p>
102.146 - * This method simply performs <code>in.skip(n)</code>.
102.147 - *
102.148 - * @param n the number of bytes to be skipped.
102.149 - * @return the actual number of bytes skipped.
102.150 - * @exception IOException if the stream does not support seek,
102.151 - * or if some other I/O error occurs.
102.152 - */
102.153 - public long skip(long n) throws IOException {
102.154 - return in.skip(n);
102.155 - }
102.156 -
102.157 - /**
102.158 - * Returns an estimate of the number of bytes that can be read (or
102.159 - * skipped over) from this input stream without blocking by the next
102.160 - * caller of a method for this input stream. The next caller might be
102.161 - * the same thread or another thread. A single read or skip of this
102.162 - * many bytes will not block, but may read or skip fewer bytes.
102.163 - * <p>
102.164 - * This method returns the result of {@link #in in}.available().
102.165 - *
102.166 - * @return an estimate of the number of bytes that can be read (or skipped
102.167 - * over) from this input stream without blocking.
102.168 - * @exception IOException if an I/O error occurs.
102.169 - */
102.170 - public int available() throws IOException {
102.171 - return in.available();
102.172 - }
102.173 -
102.174 - /**
102.175 - * Closes this input stream and releases any system resources
102.176 - * associated with the stream.
102.177 - * This
102.178 - * method simply performs <code>in.close()</code>.
102.179 - *
102.180 - * @exception IOException if an I/O error occurs.
102.181 - * @see java.io.FilterInputStream#in
102.182 - */
102.183 - public void close() throws IOException {
102.184 - in.close();
102.185 - }
102.186 -
102.187 - /**
102.188 - * Marks the current position in this input stream. A subsequent
102.189 - * call to the <code>reset</code> method repositions this stream at
102.190 - * the last marked position so that subsequent reads re-read the same bytes.
102.191 - * <p>
102.192 - * The <code>readlimit</code> argument tells this input stream to
102.193 - * allow that many bytes to be read before the mark position gets
102.194 - * invalidated.
102.195 - * <p>
102.196 - * This method simply performs <code>in.mark(readlimit)</code>.
102.197 - *
102.198 - * @param readlimit the maximum limit of bytes that can be read before
102.199 - * the mark position becomes invalid.
102.200 - * @see java.io.FilterInputStream#in
102.201 - * @see java.io.FilterInputStream#reset()
102.202 - */
102.203 - public synchronized void mark(int readlimit) {
102.204 - in.mark(readlimit);
102.205 - }
102.206 -
102.207 - /**
102.208 - * Repositions this stream to the position at the time the
102.209 - * <code>mark</code> method was last called on this input stream.
102.210 - * <p>
102.211 - * This method
102.212 - * simply performs <code>in.reset()</code>.
102.213 - * <p>
102.214 - * Stream marks are intended to be used in
102.215 - * situations where you need to read ahead a little to see what's in
102.216 - * the stream. Often this is most easily done by invoking some
102.217 - * general parser. If the stream is of the type handled by the
102.218 - * parse, it just chugs along happily. If the stream is not of
102.219 - * that type, the parser should toss an exception when it fails.
102.220 - * If this happens within readlimit bytes, it allows the outer
102.221 - * code to reset the stream and try another parser.
102.222 - *
102.223 - * @exception IOException if the stream has not been marked or if the
102.224 - * mark has been invalidated.
102.225 - * @see java.io.FilterInputStream#in
102.226 - * @see java.io.FilterInputStream#mark(int)
102.227 - */
102.228 - public synchronized void reset() throws IOException {
102.229 - in.reset();
102.230 - }
102.231 -
102.232 - /**
102.233 - * Tests if this input stream supports the <code>mark</code>
102.234 - * and <code>reset</code> methods.
102.235 - * This method
102.236 - * simply performs <code>in.markSupported()</code>.
102.237 - *
102.238 - * @return <code>true</code> if this stream type supports the
102.239 - * <code>mark</code> and <code>reset</code> method;
102.240 - * <code>false</code> otherwise.
102.241 - * @see java.io.FilterInputStream#in
102.242 - * @see java.io.InputStream#mark(int)
102.243 - * @see java.io.InputStream#reset()
102.244 - */
102.245 - public boolean markSupported() {
102.246 - return in.markSupported();
102.247 - }
102.248 -}
103.1 --- a/emul/src/main/java/java/io/IOException.java Wed Jan 23 20:16:48 2013 +0100
103.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
103.3 @@ -1,101 +0,0 @@
103.4 -/*
103.5 - * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
103.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
103.7 - *
103.8 - * This code is free software; you can redistribute it and/or modify it
103.9 - * under the terms of the GNU General Public License version 2 only, as
103.10 - * published by the Free Software Foundation. Oracle designates this
103.11 - * particular file as subject to the "Classpath" exception as provided
103.12 - * by Oracle in the LICENSE file that accompanied this code.
103.13 - *
103.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
103.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
103.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
103.17 - * version 2 for more details (a copy is included in the LICENSE file that
103.18 - * accompanied this code).
103.19 - *
103.20 - * You should have received a copy of the GNU General Public License version
103.21 - * 2 along with this work; if not, write to the Free Software Foundation,
103.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
103.23 - *
103.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
103.25 - * or visit www.oracle.com if you need additional information or have any
103.26 - * questions.
103.27 - */
103.28 -
103.29 -package java.io;
103.30 -
103.31 -/**
103.32 - * Signals that an I/O exception of some sort has occurred. This
103.33 - * class is the general class of exceptions produced by failed or
103.34 - * interrupted I/O operations.
103.35 - *
103.36 - * @author unascribed
103.37 - * @see java.io.InputStream
103.38 - * @see java.io.OutputStream
103.39 - * @since JDK1.0
103.40 - */
103.41 -public
103.42 -class IOException extends Exception {
103.43 - static final long serialVersionUID = 7818375828146090155L;
103.44 -
103.45 - /**
103.46 - * Constructs an {@code IOException} with {@code null}
103.47 - * as its error detail message.
103.48 - */
103.49 - public IOException() {
103.50 - super();
103.51 - }
103.52 -
103.53 - /**
103.54 - * Constructs an {@code IOException} with the specified detail message.
103.55 - *
103.56 - * @param message
103.57 - * The detail message (which is saved for later retrieval
103.58 - * by the {@link #getMessage()} method)
103.59 - */
103.60 - public IOException(String message) {
103.61 - super(message);
103.62 - }
103.63 -
103.64 - /**
103.65 - * Constructs an {@code IOException} with the specified detail message
103.66 - * and cause.
103.67 - *
103.68 - * <p> Note that the detail message associated with {@code cause} is
103.69 - * <i>not</i> automatically incorporated into this exception's detail
103.70 - * message.
103.71 - *
103.72 - * @param message
103.73 - * The detail message (which is saved for later retrieval
103.74 - * by the {@link #getMessage()} method)
103.75 - *
103.76 - * @param cause
103.77 - * The cause (which is saved for later retrieval by the
103.78 - * {@link #getCause()} method). (A null value is permitted,
103.79 - * and indicates that the cause is nonexistent or unknown.)
103.80 - *
103.81 - * @since 1.6
103.82 - */
103.83 - public IOException(String message, Throwable cause) {
103.84 - super(message, cause);
103.85 - }
103.86 -
103.87 - /**
103.88 - * Constructs an {@code IOException} with the specified cause and a
103.89 - * detail message of {@code (cause==null ? null : cause.toString())}
103.90 - * (which typically contains the class and detail message of {@code cause}).
103.91 - * This constructor is useful for IO exceptions that are little more
103.92 - * than wrappers for other throwables.
103.93 - *
103.94 - * @param cause
103.95 - * The cause (which is saved for later retrieval by the
103.96 - * {@link #getCause()} method). (A null value is permitted,
103.97 - * and indicates that the cause is nonexistent or unknown.)
103.98 - *
103.99 - * @since 1.6
103.100 - */
103.101 - public IOException(Throwable cause) {
103.102 - super(cause);
103.103 - }
103.104 -}
104.1 --- a/emul/src/main/java/java/io/InputStream.java Wed Jan 23 20:16:48 2013 +0100
104.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
104.3 @@ -1,370 +0,0 @@
104.4 -/*
104.5 - * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
104.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
104.7 - *
104.8 - * This code is free software; you can redistribute it and/or modify it
104.9 - * under the terms of the GNU General Public License version 2 only, as
104.10 - * published by the Free Software Foundation. Oracle designates this
104.11 - * particular file as subject to the "Classpath" exception as provided
104.12 - * by Oracle in the LICENSE file that accompanied this code.
104.13 - *
104.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
104.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
104.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
104.17 - * version 2 for more details (a copy is included in the LICENSE file that
104.18 - * accompanied this code).
104.19 - *
104.20 - * You should have received a copy of the GNU General Public License version
104.21 - * 2 along with this work; if not, write to the Free Software Foundation,
104.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
104.23 - *
104.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
104.25 - * or visit www.oracle.com if you need additional information or have any
104.26 - * questions.
104.27 - */
104.28 -
104.29 -package java.io;
104.30 -
104.31 -/**
104.32 - * This abstract class is the superclass of all classes representing
104.33 - * an input stream of bytes.
104.34 - *
104.35 - * <p> Applications that need to define a subclass of <code>InputStream</code>
104.36 - * must always provide a method that returns the next byte of input.
104.37 - *
104.38 - * @author Arthur van Hoff
104.39 - * @see java.io.BufferedInputStream
104.40 - * @see java.io.ByteArrayInputStream
104.41 - * @see java.io.DataInputStream
104.42 - * @see java.io.FilterInputStream
104.43 - * @see java.io.InputStream#read()
104.44 - * @see java.io.OutputStream
104.45 - * @see java.io.PushbackInputStream
104.46 - * @since JDK1.0
104.47 - */
104.48 -public abstract class InputStream implements Closeable {
104.49 -
104.50 - // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
104.51 - private static final int SKIP_BUFFER_SIZE = 2048;
104.52 - // skipBuffer is initialized in skip(long), if needed.
104.53 - private static byte[] skipBuffer;
104.54 -
104.55 - /**
104.56 - * Reads the next byte of data from the input stream. The value byte is
104.57 - * returned as an <code>int</code> in the range <code>0</code> to
104.58 - * <code>255</code>. If no byte is available because the end of the stream
104.59 - * has been reached, the value <code>-1</code> is returned. This method
104.60 - * blocks until input data is available, the end of the stream is detected,
104.61 - * or an exception is thrown.
104.62 - *
104.63 - * <p> A subclass must provide an implementation of this method.
104.64 - *
104.65 - * @return the next byte of data, or <code>-1</code> if the end of the
104.66 - * stream is reached.
104.67 - * @exception IOException if an I/O error occurs.
104.68 - */
104.69 - public abstract int read() throws IOException;
104.70 -
104.71 - /**
104.72 - * Reads some number of bytes from the input stream and stores them into
104.73 - * the buffer array <code>b</code>. The number of bytes actually read is
104.74 - * returned as an integer. This method blocks until input data is
104.75 - * available, end of file is detected, or an exception is thrown.
104.76 - *
104.77 - * <p> If the length of <code>b</code> is zero, then no bytes are read and
104.78 - * <code>0</code> is returned; otherwise, there is an attempt to read at
104.79 - * least one byte. If no byte is available because the stream is at the
104.80 - * end of the file, the value <code>-1</code> is returned; otherwise, at
104.81 - * least one byte is read and stored into <code>b</code>.
104.82 - *
104.83 - * <p> The first byte read is stored into element <code>b[0]</code>, the
104.84 - * next one into <code>b[1]</code>, and so on. The number of bytes read is,
104.85 - * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
104.86 - * number of bytes actually read; these bytes will be stored in elements
104.87 - * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
104.88 - * leaving elements <code>b[</code><i>k</i><code>]</code> through
104.89 - * <code>b[b.length-1]</code> unaffected.
104.90 - *
104.91 - * <p> The <code>read(b)</code> method for class <code>InputStream</code>
104.92 - * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
104.93 - *
104.94 - * @param b the buffer into which the data is read.
104.95 - * @return the total number of bytes read into the buffer, or
104.96 - * <code>-1</code> if there is no more data because the end of
104.97 - * the stream has been reached.
104.98 - * @exception IOException If the first byte cannot be read for any reason
104.99 - * other than the end of the file, if the input stream has been closed, or
104.100 - * if some other I/O error occurs.
104.101 - * @exception NullPointerException if <code>b</code> is <code>null</code>.
104.102 - * @see java.io.InputStream#read(byte[], int, int)
104.103 - */
104.104 - public int read(byte b[]) throws IOException {
104.105 - return read(b, 0, b.length);
104.106 - }
104.107 -
104.108 - /**
104.109 - * Reads up to <code>len</code> bytes of data from the input stream into
104.110 - * an array of bytes. An attempt is made to read as many as
104.111 - * <code>len</code> bytes, but a smaller number may be read.
104.112 - * The number of bytes actually read is returned as an integer.
104.113 - *
104.114 - * <p> This method blocks until input data is available, end of file is
104.115 - * detected, or an exception is thrown.
104.116 - *
104.117 - * <p> If <code>len</code> is zero, then no bytes are read and
104.118 - * <code>0</code> is returned; otherwise, there is an attempt to read at
104.119 - * least one byte. If no byte is available because the stream is at end of
104.120 - * file, the value <code>-1</code> is returned; otherwise, at least one
104.121 - * byte is read and stored into <code>b</code>.
104.122 - *
104.123 - * <p> The first byte read is stored into element <code>b[off]</code>, the
104.124 - * next one into <code>b[off+1]</code>, and so on. The number of bytes read
104.125 - * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
104.126 - * bytes actually read; these bytes will be stored in elements
104.127 - * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
104.128 - * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
104.129 - * <code>b[off+len-1]</code> unaffected.
104.130 - *
104.131 - * <p> In every case, elements <code>b[0]</code> through
104.132 - * <code>b[off]</code> and elements <code>b[off+len]</code> through
104.133 - * <code>b[b.length-1]</code> are unaffected.
104.134 - *
104.135 - * <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
104.136 - * for class <code>InputStream</code> simply calls the method
104.137 - * <code>read()</code> repeatedly. If the first such call results in an
104.138 - * <code>IOException</code>, that exception is returned from the call to
104.139 - * the <code>read(b,</code> <code>off,</code> <code>len)</code> method. If
104.140 - * any subsequent call to <code>read()</code> results in a
104.141 - * <code>IOException</code>, the exception is caught and treated as if it
104.142 - * were end of file; the bytes read up to that point are stored into
104.143 - * <code>b</code> and the number of bytes read before the exception
104.144 - * occurred is returned. The default implementation of this method blocks
104.145 - * until the requested amount of input data <code>len</code> has been read,
104.146 - * end of file is detected, or an exception is thrown. Subclasses are encouraged
104.147 - * to provide a more efficient implementation of this method.
104.148 - *
104.149 - * @param b the buffer into which the data is read.
104.150 - * @param off the start offset in array <code>b</code>
104.151 - * at which the data is written.
104.152 - * @param len the maximum number of bytes to read.
104.153 - * @return the total number of bytes read into the buffer, or
104.154 - * <code>-1</code> if there is no more data because the end of
104.155 - * the stream has been reached.
104.156 - * @exception IOException If the first byte cannot be read for any reason
104.157 - * other than end of file, or if the input stream has been closed, or if
104.158 - * some other I/O error occurs.
104.159 - * @exception NullPointerException If <code>b</code> is <code>null</code>.
104.160 - * @exception IndexOutOfBoundsException If <code>off</code> is negative,
104.161 - * <code>len</code> is negative, or <code>len</code> is greater than
104.162 - * <code>b.length - off</code>
104.163 - * @see java.io.InputStream#read()
104.164 - */
104.165 - public int read(byte b[], int off, int len) throws IOException {
104.166 - if (b == null) {
104.167 - throw new NullPointerException();
104.168 - } else if (off < 0 || len < 0 || len > b.length - off) {
104.169 - throw new IndexOutOfBoundsException();
104.170 - } else if (len == 0) {
104.171 - return 0;
104.172 - }
104.173 -
104.174 - int c = read();
104.175 - if (c == -1) {
104.176 - return -1;
104.177 - }
104.178 - b[off] = (byte)c;
104.179 -
104.180 - int i = 1;
104.181 - try {
104.182 - for (; i < len ; i++) {
104.183 - c = read();
104.184 - if (c == -1) {
104.185 - break;
104.186 - }
104.187 - b[off + i] = (byte)c;
104.188 - }
104.189 - } catch (IOException ee) {
104.190 - }
104.191 - return i;
104.192 - }
104.193 -
104.194 - /**
104.195 - * Skips over and discards <code>n</code> bytes of data from this input
104.196 - * stream. The <code>skip</code> method may, for a variety of reasons, end
104.197 - * up skipping over some smaller number of bytes, possibly <code>0</code>.
104.198 - * This may result from any of a number of conditions; reaching end of file
104.199 - * before <code>n</code> bytes have been skipped is only one possibility.
104.200 - * The actual number of bytes skipped is returned. If <code>n</code> is
104.201 - * negative, no bytes are skipped.
104.202 - *
104.203 - * <p> The <code>skip</code> method of this class creates a
104.204 - * byte array and then repeatedly reads into it until <code>n</code> bytes
104.205 - * have been read or the end of the stream has been reached. Subclasses are
104.206 - * encouraged to provide a more efficient implementation of this method.
104.207 - * For instance, the implementation may depend on the ability to seek.
104.208 - *
104.209 - * @param n the number of bytes to be skipped.
104.210 - * @return the actual number of bytes skipped.
104.211 - * @exception IOException if the stream does not support seek,
104.212 - * or if some other I/O error occurs.
104.213 - */
104.214 - public long skip(long n) throws IOException {
104.215 -
104.216 - long remaining = n;
104.217 - int nr;
104.218 - if (skipBuffer == null)
104.219 - skipBuffer = new byte[SKIP_BUFFER_SIZE];
104.220 -
104.221 - byte[] localSkipBuffer = skipBuffer;
104.222 -
104.223 - if (n <= 0) {
104.224 - return 0;
104.225 - }
104.226 -
104.227 - while (remaining > 0) {
104.228 - nr = read(localSkipBuffer, 0,
104.229 - (int) Math.min(SKIP_BUFFER_SIZE, remaining));
104.230 - if (nr < 0) {
104.231 - break;
104.232 - }
104.233 - remaining -= nr;
104.234 - }
104.235 -
104.236 - return n - remaining;
104.237 - }
104.238 -
104.239 - /**
104.240 - * Returns an estimate of the number of bytes that can be read (or
104.241 - * skipped over) from this input stream without blocking by the next
104.242 - * invocation of a method for this input stream. The next invocation
104.243 - * might be the same thread or another thread. A single read or skip of this
104.244 - * many bytes will not block, but may read or skip fewer bytes.
104.245 - *
104.246 - * <p> Note that while some implementations of {@code InputStream} will return
104.247 - * the total number of bytes in the stream, many will not. It is
104.248 - * never correct to use the return value of this method to allocate
104.249 - * a buffer intended to hold all data in this stream.
104.250 - *
104.251 - * <p> A subclass' implementation of this method may choose to throw an
104.252 - * {@link IOException} if this input stream has been closed by
104.253 - * invoking the {@link #close()} method.
104.254 - *
104.255 - * <p> The {@code available} method for class {@code InputStream} always
104.256 - * returns {@code 0}.
104.257 - *
104.258 - * <p> This method should be overridden by subclasses.
104.259 - *
104.260 - * @return an estimate of the number of bytes that can be read (or skipped
104.261 - * over) from this input stream without blocking or {@code 0} when
104.262 - * it reaches the end of the input stream.
104.263 - * @exception IOException if an I/O error occurs.
104.264 - */
104.265 - public int available() throws IOException {
104.266 - return 0;
104.267 - }
104.268 -
104.269 - /**
104.270 - * Closes this input stream and releases any system resources associated
104.271 - * with the stream.
104.272 - *
104.273 - * <p> The <code>close</code> method of <code>InputStream</code> does
104.274 - * nothing.
104.275 - *
104.276 - * @exception IOException if an I/O error occurs.
104.277 - */
104.278 - public void close() throws IOException {}
104.279 -
104.280 - /**
104.281 - * Marks the current position in this input stream. A subsequent call to
104.282 - * the <code>reset</code> method repositions this stream at the last marked
104.283 - * position so that subsequent reads re-read the same bytes.
104.284 - *
104.285 - * <p> The <code>readlimit</code> arguments tells this input stream to
104.286 - * allow that many bytes to be read before the mark position gets
104.287 - * invalidated.
104.288 - *
104.289 - * <p> The general contract of <code>mark</code> is that, if the method
104.290 - * <code>markSupported</code> returns <code>true</code>, the stream somehow
104.291 - * remembers all the bytes read after the call to <code>mark</code> and
104.292 - * stands ready to supply those same bytes again if and whenever the method
104.293 - * <code>reset</code> is called. However, the stream is not required to
104.294 - * remember any data at all if more than <code>readlimit</code> bytes are
104.295 - * read from the stream before <code>reset</code> is called.
104.296 - *
104.297 - * <p> Marking a closed stream should not have any effect on the stream.
104.298 - *
104.299 - * <p> The <code>mark</code> method of <code>InputStream</code> does
104.300 - * nothing.
104.301 - *
104.302 - * @param readlimit the maximum limit of bytes that can be read before
104.303 - * the mark position becomes invalid.
104.304 - * @see java.io.InputStream#reset()
104.305 - */
104.306 - public synchronized void mark(int readlimit) {}
104.307 -
104.308 - /**
104.309 - * Repositions this stream to the position at the time the
104.310 - * <code>mark</code> method was last called on this input stream.
104.311 - *
104.312 - * <p> The general contract of <code>reset</code> is:
104.313 - *
104.314 - * <p><ul>
104.315 - *
104.316 - * <li> If the method <code>markSupported</code> returns
104.317 - * <code>true</code>, then:
104.318 - *
104.319 - * <ul><li> If the method <code>mark</code> has not been called since
104.320 - * the stream was created, or the number of bytes read from the stream
104.321 - * since <code>mark</code> was last called is larger than the argument
104.322 - * to <code>mark</code> at that last call, then an
104.323 - * <code>IOException</code> might be thrown.
104.324 - *
104.325 - * <li> If such an <code>IOException</code> is not thrown, then the
104.326 - * stream is reset to a state such that all the bytes read since the
104.327 - * most recent call to <code>mark</code> (or since the start of the
104.328 - * file, if <code>mark</code> has not been called) will be resupplied
104.329 - * to subsequent callers of the <code>read</code> method, followed by
104.330 - * any bytes that otherwise would have been the next input data as of
104.331 - * the time of the call to <code>reset</code>. </ul>
104.332 - *
104.333 - * <li> If the method <code>markSupported</code> returns
104.334 - * <code>false</code>, then:
104.335 - *
104.336 - * <ul><li> The call to <code>reset</code> may throw an
104.337 - * <code>IOException</code>.
104.338 - *
104.339 - * <li> If an <code>IOException</code> is not thrown, then the stream
104.340 - * is reset to a fixed state that depends on the particular type of the
104.341 - * input stream and how it was created. The bytes that will be supplied
104.342 - * to subsequent callers of the <code>read</code> method depend on the
104.343 - * particular type of the input stream. </ul></ul>
104.344 - *
104.345 - * <p>The method <code>reset</code> for class <code>InputStream</code>
104.346 - * does nothing except throw an <code>IOException</code>.
104.347 - *
104.348 - * @exception IOException if this stream has not been marked or if the
104.349 - * mark has been invalidated.
104.350 - * @see java.io.InputStream#mark(int)
104.351 - * @see java.io.IOException
104.352 - */
104.353 - public synchronized void reset() throws IOException {
104.354 - throw new IOException("mark/reset not supported");
104.355 - }
104.356 -
104.357 - /**
104.358 - * Tests if this input stream supports the <code>mark</code> and
104.359 - * <code>reset</code> methods. Whether or not <code>mark</code> and
104.360 - * <code>reset</code> are supported is an invariant property of a
104.361 - * particular input stream instance. The <code>markSupported</code> method
104.362 - * of <code>InputStream</code> returns <code>false</code>.
104.363 - *
104.364 - * @return <code>true</code> if this stream instance supports the mark
104.365 - * and reset methods; <code>false</code> otherwise.
104.366 - * @see java.io.InputStream#mark(int)
104.367 - * @see java.io.InputStream#reset()
104.368 - */
104.369 - public boolean markSupported() {
104.370 - return false;
104.371 - }
104.372 -
104.373 -}
105.1 --- a/emul/src/main/java/java/io/PushbackInputStream.java Wed Jan 23 20:16:48 2013 +0100
105.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
105.3 @@ -1,388 +0,0 @@
105.4 -/*
105.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
105.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
105.7 - *
105.8 - * This code is free software; you can redistribute it and/or modify it
105.9 - * under the terms of the GNU General Public License version 2 only, as
105.10 - * published by the Free Software Foundation. Oracle designates this
105.11 - * particular file as subject to the "Classpath" exception as provided
105.12 - * by Oracle in the LICENSE file that accompanied this code.
105.13 - *
105.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
105.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
105.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
105.17 - * version 2 for more details (a copy is included in the LICENSE file that
105.18 - * accompanied this code).
105.19 - *
105.20 - * You should have received a copy of the GNU General Public License version
105.21 - * 2 along with this work; if not, write to the Free Software Foundation,
105.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
105.23 - *
105.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
105.25 - * or visit www.oracle.com if you need additional information or have any
105.26 - * questions.
105.27 - */
105.28 -
105.29 -package java.io;
105.30 -
105.31 -/**
105.32 - * A <code>PushbackInputStream</code> adds
105.33 - * functionality to another input stream, namely
105.34 - * the ability to "push back" or "unread"
105.35 - * one byte. This is useful in situations where
105.36 - * it is convenient for a fragment of code
105.37 - * to read an indefinite number of data bytes
105.38 - * that are delimited by a particular byte
105.39 - * value; after reading the terminating byte,
105.40 - * the code fragment can "unread" it, so that
105.41 - * the next read operation on the input stream
105.42 - * will reread the byte that was pushed back.
105.43 - * For example, bytes representing the characters
105.44 - * constituting an identifier might be terminated
105.45 - * by a byte representing an operator character;
105.46 - * a method whose job is to read just an identifier
105.47 - * can read until it sees the operator and
105.48 - * then push the operator back to be re-read.
105.49 - *
105.50 - * @author David Connelly
105.51 - * @author Jonathan Payne
105.52 - * @since JDK1.0
105.53 - */
105.54 -public
105.55 -class PushbackInputStream extends FilterInputStream {
105.56 - /**
105.57 - * The pushback buffer.
105.58 - * @since JDK1.1
105.59 - */
105.60 - protected byte[] buf;
105.61 -
105.62 - /**
105.63 - * The position within the pushback buffer from which the next byte will
105.64 - * be read. When the buffer is empty, <code>pos</code> is equal to
105.65 - * <code>buf.length</code>; when the buffer is full, <code>pos</code> is
105.66 - * equal to zero.
105.67 - *
105.68 - * @since JDK1.1
105.69 - */
105.70 - protected int pos;
105.71 -
105.72 - /**
105.73 - * Check to make sure that this stream has not been closed
105.74 - */
105.75 - private void ensureOpen() throws IOException {
105.76 - if (in == null)
105.77 - throw new IOException("Stream closed");
105.78 - }
105.79 -
105.80 - /**
105.81 - * Creates a <code>PushbackInputStream</code>
105.82 - * with a pushback buffer of the specified <code>size</code>,
105.83 - * and saves its argument, the input stream
105.84 - * <code>in</code>, for later use. Initially,
105.85 - * there is no pushed-back byte (the field
105.86 - * <code>pushBack</code> is initialized to
105.87 - * <code>-1</code>).
105.88 - *
105.89 - * @param in the input stream from which bytes will be read.
105.90 - * @param size the size of the pushback buffer.
105.91 - * @exception IllegalArgumentException if size is <= 0
105.92 - * @since JDK1.1
105.93 - */
105.94 - public PushbackInputStream(InputStream in, int size) {
105.95 - super(in);
105.96 - if (size <= 0) {
105.97 - throw new IllegalArgumentException("size <= 0");
105.98 - }
105.99 - this.buf = new byte[size];
105.100 - this.pos = size;
105.101 - }
105.102 -
105.103 - /**
105.104 - * Creates a <code>PushbackInputStream</code>
105.105 - * and saves its argument, the input stream
105.106 - * <code>in</code>, for later use. Initially,
105.107 - * there is no pushed-back byte (the field
105.108 - * <code>pushBack</code> is initialized to
105.109 - * <code>-1</code>).
105.110 - *
105.111 - * @param in the input stream from which bytes will be read.
105.112 - */
105.113 - public PushbackInputStream(InputStream in) {
105.114 - this(in, 1);
105.115 - }
105.116 -
105.117 - /**
105.118 - * Reads the next byte of data from this input stream. The value
105.119 - * byte is returned as an <code>int</code> in the range
105.120 - * <code>0</code> to <code>255</code>. If no byte is available
105.121 - * because the end of the stream has been reached, the value
105.122 - * <code>-1</code> is returned. This method blocks until input data
105.123 - * is available, the end of the stream is detected, or an exception
105.124 - * is thrown.
105.125 - *
105.126 - * <p> This method returns the most recently pushed-back byte, if there is
105.127 - * one, and otherwise calls the <code>read</code> method of its underlying
105.128 - * input stream and returns whatever value that method returns.
105.129 - *
105.130 - * @return the next byte of data, or <code>-1</code> if the end of the
105.131 - * stream has been reached.
105.132 - * @exception IOException if this input stream has been closed by
105.133 - * invoking its {@link #close()} method,
105.134 - * or an I/O error occurs.
105.135 - * @see java.io.InputStream#read()
105.136 - */
105.137 - public int read() throws IOException {
105.138 - ensureOpen();
105.139 - if (pos < buf.length) {
105.140 - return buf[pos++] & 0xff;
105.141 - }
105.142 - return super.read();
105.143 - }
105.144 -
105.145 - /**
105.146 - * Reads up to <code>len</code> bytes of data from this input stream into
105.147 - * an array of bytes. This method first reads any pushed-back bytes; after
105.148 - * that, if fewer than <code>len</code> bytes have been read then it
105.149 - * reads from the underlying input stream. If <code>len</code> is not zero, the method
105.150 - * blocks until at least 1 byte of input is available; otherwise, no
105.151 - * bytes are read and <code>0</code> is returned.
105.152 - *
105.153 - * @param b the buffer into which the data is read.
105.154 - * @param off the start offset in the destination array <code>b</code>
105.155 - * @param len the maximum number of bytes read.
105.156 - * @return the total number of bytes read into the buffer, or
105.157 - * <code>-1</code> if there is no more data because the end of
105.158 - * the stream has been reached.
105.159 - * @exception NullPointerException If <code>b</code> is <code>null</code>.
105.160 - * @exception IndexOutOfBoundsException If <code>off</code> is negative,
105.161 - * <code>len</code> is negative, or <code>len</code> is greater than
105.162 - * <code>b.length - off</code>
105.163 - * @exception IOException if this input stream has been closed by
105.164 - * invoking its {@link #close()} method,
105.165 - * or an I/O error occurs.
105.166 - * @see java.io.InputStream#read(byte[], int, int)
105.167 - */
105.168 - public int read(byte[] b, int off, int len) throws IOException {
105.169 - ensureOpen();
105.170 - if (b == null) {
105.171 - throw new NullPointerException();
105.172 - } else if (off < 0 || len < 0 || len > b.length - off) {
105.173 - throw new IndexOutOfBoundsException();
105.174 - } else if (len == 0) {
105.175 - return 0;
105.176 - }
105.177 -
105.178 - int avail = buf.length - pos;
105.179 - if (avail > 0) {
105.180 - if (len < avail) {
105.181 - avail = len;
105.182 - }
105.183 - arraycopy(buf, pos, b, off, avail);
105.184 - pos += avail;
105.185 - off += avail;
105.186 - len -= avail;
105.187 - }
105.188 - if (len > 0) {
105.189 - len = super.read(b, off, len);
105.190 - if (len == -1) {
105.191 - return avail == 0 ? -1 : avail;
105.192 - }
105.193 - return avail + len;
105.194 - }
105.195 - return avail;
105.196 - }
105.197 -
105.198 - /**
105.199 - * Pushes back a byte by copying it to the front of the pushback buffer.
105.200 - * After this method returns, the next byte to be read will have the value
105.201 - * <code>(byte)b</code>.
105.202 - *
105.203 - * @param b the <code>int</code> value whose low-order
105.204 - * byte is to be pushed back.
105.205 - * @exception IOException If there is not enough room in the pushback
105.206 - * buffer for the byte, or this input stream has been closed by
105.207 - * invoking its {@link #close()} method.
105.208 - */
105.209 - public void unread(int b) throws IOException {
105.210 - ensureOpen();
105.211 - if (pos == 0) {
105.212 - throw new IOException("Push back buffer is full");
105.213 - }
105.214 - buf[--pos] = (byte)b;
105.215 - }
105.216 -
105.217 - /**
105.218 - * Pushes back a portion of an array of bytes by copying it to the front
105.219 - * of the pushback buffer. After this method returns, the next byte to be
105.220 - * read will have the value <code>b[off]</code>, the byte after that will
105.221 - * have the value <code>b[off+1]</code>, and so forth.
105.222 - *
105.223 - * @param b the byte array to push back.
105.224 - * @param off the start offset of the data.
105.225 - * @param len the number of bytes to push back.
105.226 - * @exception IOException If there is not enough room in the pushback
105.227 - * buffer for the specified number of bytes,
105.228 - * or this input stream has been closed by
105.229 - * invoking its {@link #close()} method.
105.230 - * @since JDK1.1
105.231 - */
105.232 - public void unread(byte[] b, int off, int len) throws IOException {
105.233 - ensureOpen();
105.234 - if (len > pos) {
105.235 - throw new IOException("Push back buffer is full");
105.236 - }
105.237 - pos -= len;
105.238 - arraycopy(b, off, buf, pos, len);
105.239 - }
105.240 -
105.241 - /**
105.242 - * Pushes back an array of bytes by copying it to the front of the
105.243 - * pushback buffer. After this method returns, the next byte to be read
105.244 - * will have the value <code>b[0]</code>, the byte after that will have the
105.245 - * value <code>b[1]</code>, and so forth.
105.246 - *
105.247 - * @param b the byte array to push back
105.248 - * @exception IOException If there is not enough room in the pushback
105.249 - * buffer for the specified number of bytes,
105.250 - * or this input stream has been closed by
105.251 - * invoking its {@link #close()} method.
105.252 - * @since JDK1.1
105.253 - */
105.254 - public void unread(byte[] b) throws IOException {
105.255 - unread(b, 0, b.length);
105.256 - }
105.257 -
105.258 - /**
105.259 - * Returns an estimate of the number of bytes that can be read (or
105.260 - * skipped over) from this input stream without blocking by the next
105.261 - * invocation of a method for this input stream. The next invocation might be
105.262 - * the same thread or another thread. A single read or skip of this
105.263 - * many bytes will not block, but may read or skip fewer bytes.
105.264 - *
105.265 - * <p> The method returns the sum of the number of bytes that have been
105.266 - * pushed back and the value returned by {@link
105.267 - * java.io.FilterInputStream#available available}.
105.268 - *
105.269 - * @return the number of bytes that can be read (or skipped over) from
105.270 - * the input stream without blocking.
105.271 - * @exception IOException if this input stream has been closed by
105.272 - * invoking its {@link #close()} method,
105.273 - * or an I/O error occurs.
105.274 - * @see java.io.FilterInputStream#in
105.275 - * @see java.io.InputStream#available()
105.276 - */
105.277 - public int available() throws IOException {
105.278 - ensureOpen();
105.279 - int n = buf.length - pos;
105.280 - int avail = super.available();
105.281 - return n > (Integer.MAX_VALUE - avail)
105.282 - ? Integer.MAX_VALUE
105.283 - : n + avail;
105.284 - }
105.285 -
105.286 - /**
105.287 - * Skips over and discards <code>n</code> bytes of data from this
105.288 - * input stream. The <code>skip</code> method may, for a variety of
105.289 - * reasons, end up skipping over some smaller number of bytes,
105.290 - * possibly zero. If <code>n</code> is negative, no bytes are skipped.
105.291 - *
105.292 - * <p> The <code>skip</code> method of <code>PushbackInputStream</code>
105.293 - * first skips over the bytes in the pushback buffer, if any. It then
105.294 - * calls the <code>skip</code> method of the underlying input stream if
105.295 - * more bytes need to be skipped. The actual number of bytes skipped
105.296 - * is returned.
105.297 - *
105.298 - * @param n {@inheritDoc}
105.299 - * @return {@inheritDoc}
105.300 - * @exception IOException if the stream does not support seek,
105.301 - * or the stream has been closed by
105.302 - * invoking its {@link #close()} method,
105.303 - * or an I/O error occurs.
105.304 - * @see java.io.FilterInputStream#in
105.305 - * @see java.io.InputStream#skip(long n)
105.306 - * @since 1.2
105.307 - */
105.308 - public long skip(long n) throws IOException {
105.309 - ensureOpen();
105.310 - if (n <= 0) {
105.311 - return 0;
105.312 - }
105.313 -
105.314 - long pskip = buf.length - pos;
105.315 - if (pskip > 0) {
105.316 - if (n < pskip) {
105.317 - pskip = n;
105.318 - }
105.319 - pos += pskip;
105.320 - n -= pskip;
105.321 - }
105.322 - if (n > 0) {
105.323 - pskip += super.skip(n);
105.324 - }
105.325 - return pskip;
105.326 - }
105.327 -
105.328 - /**
105.329 - * Tests if this input stream supports the <code>mark</code> and
105.330 - * <code>reset</code> methods, which it does not.
105.331 - *
105.332 - * @return <code>false</code>, since this class does not support the
105.333 - * <code>mark</code> and <code>reset</code> methods.
105.334 - * @see java.io.InputStream#mark(int)
105.335 - * @see java.io.InputStream#reset()
105.336 - */
105.337 - public boolean markSupported() {
105.338 - return false;
105.339 - }
105.340 -
105.341 - /**
105.342 - * Marks the current position in this input stream.
105.343 - *
105.344 - * <p> The <code>mark</code> method of <code>PushbackInputStream</code>
105.345 - * does nothing.
105.346 - *
105.347 - * @param readlimit the maximum limit of bytes that can be read before
105.348 - * the mark position becomes invalid.
105.349 - * @see java.io.InputStream#reset()
105.350 - */
105.351 - public synchronized void mark(int readlimit) {
105.352 - }
105.353 -
105.354 - /**
105.355 - * Repositions this stream to the position at the time the
105.356 - * <code>mark</code> method was last called on this input stream.
105.357 - *
105.358 - * <p> The method <code>reset</code> for class
105.359 - * <code>PushbackInputStream</code> does nothing except throw an
105.360 - * <code>IOException</code>.
105.361 - *
105.362 - * @exception IOException if this method is invoked.
105.363 - * @see java.io.InputStream#mark(int)
105.364 - * @see java.io.IOException
105.365 - */
105.366 - public synchronized void reset() throws IOException {
105.367 - throw new IOException("mark/reset not supported");
105.368 - }
105.369 -
105.370 - /**
105.371 - * Closes this input stream and releases any system resources
105.372 - * associated with the stream.
105.373 - * Once the stream has been closed, further read(), unread(),
105.374 - * available(), reset(), or skip() invocations will throw an IOException.
105.375 - * Closing a previously closed stream has no effect.
105.376 - *
105.377 - * @exception IOException if an I/O error occurs.
105.378 - */
105.379 - public synchronized void close() throws IOException {
105.380 - if (in == null)
105.381 - return;
105.382 - in.close();
105.383 - in = null;
105.384 - buf = null;
105.385 - }
105.386 - static void arraycopy(byte[] value, int srcBegin, byte[] dst, int dstBegin, int count) {
105.387 - while (count-- > 0) {
105.388 - dst[dstBegin++] = value[srcBegin++];
105.389 - }
105.390 - }
105.391 -}
106.1 --- a/emul/src/main/java/java/io/Serializable.java Wed Jan 23 20:16:48 2013 +0100
106.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
106.3 @@ -1,170 +0,0 @@
106.4 -/*
106.5 - * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
106.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
106.7 - *
106.8 - * This code is free software; you can redistribute it and/or modify it
106.9 - * under the terms of the GNU General Public License version 2 only, as
106.10 - * published by the Free Software Foundation. Oracle designates this
106.11 - * particular file as subject to the "Classpath" exception as provided
106.12 - * by Oracle in the LICENSE file that accompanied this code.
106.13 - *
106.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
106.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
106.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
106.17 - * version 2 for more details (a copy is included in the LICENSE file that
106.18 - * accompanied this code).
106.19 - *
106.20 - * You should have received a copy of the GNU General Public License version
106.21 - * 2 along with this work; if not, write to the Free Software Foundation,
106.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
106.23 - *
106.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
106.25 - * or visit www.oracle.com if you need additional information or have any
106.26 - * questions.
106.27 - */
106.28 -
106.29 -package java.io;
106.30 -
106.31 -/**
106.32 - * Serializability of a class is enabled by the class implementing the
106.33 - * java.io.Serializable interface. Classes that do not implement this
106.34 - * interface will not have any of their state serialized or
106.35 - * deserialized. All subtypes of a serializable class are themselves
106.36 - * serializable. The serialization interface has no methods or fields
106.37 - * and serves only to identify the semantics of being serializable. <p>
106.38 - *
106.39 - * To allow subtypes of non-serializable classes to be serialized, the
106.40 - * subtype may assume responsibility for saving and restoring the
106.41 - * state of the supertype's public, protected, and (if accessible)
106.42 - * package fields. The subtype may assume this responsibility only if
106.43 - * the class it extends has an accessible no-arg constructor to
106.44 - * initialize the class's state. It is an error to declare a class
106.45 - * Serializable if this is not the case. The error will be detected at
106.46 - * runtime. <p>
106.47 - *
106.48 - * During deserialization, the fields of non-serializable classes will
106.49 - * be initialized using the public or protected no-arg constructor of
106.50 - * the class. A no-arg constructor must be accessible to the subclass
106.51 - * that is serializable. The fields of serializable subclasses will
106.52 - * be restored from the stream. <p>
106.53 - *
106.54 - * When traversing a graph, an object may be encountered that does not
106.55 - * support the Serializable interface. In this case the
106.56 - * NotSerializableException will be thrown and will identify the class
106.57 - * of the non-serializable object. <p>
106.58 - *
106.59 - * Classes that require special handling during the serialization and
106.60 - * deserialization process must implement special methods with these exact
106.61 - * signatures: <p>
106.62 - *
106.63 - * <PRE>
106.64 - * private void writeObject(java.io.ObjectOutputStream out)
106.65 - * throws IOException
106.66 - * private void readObject(java.io.ObjectInputStream in)
106.67 - * throws IOException, ClassNotFoundException;
106.68 - * private void readObjectNoData()
106.69 - * throws ObjectStreamException;
106.70 - * </PRE>
106.71 - *
106.72 - * <p>The writeObject method is responsible for writing the state of the
106.73 - * object for its particular class so that the corresponding
106.74 - * readObject method can restore it. The default mechanism for saving
106.75 - * the Object's fields can be invoked by calling
106.76 - * out.defaultWriteObject. The method does not need to concern
106.77 - * itself with the state belonging to its superclasses or subclasses.
106.78 - * State is saved by writing the individual fields to the
106.79 - * ObjectOutputStream using the writeObject method or by using the
106.80 - * methods for primitive data types supported by DataOutput.
106.81 - *
106.82 - * <p>The readObject method is responsible for reading from the stream and
106.83 - * restoring the classes fields. It may call in.defaultReadObject to invoke
106.84 - * the default mechanism for restoring the object's non-static and
106.85 - * non-transient fields. The defaultReadObject method uses information in
106.86 - * the stream to assign the fields of the object saved in the stream with the
106.87 - * correspondingly named fields in the current object. This handles the case
106.88 - * when the class has evolved to add new fields. The method does not need to
106.89 - * concern itself with the state belonging to its superclasses or subclasses.
106.90 - * State is saved by writing the individual fields to the
106.91 - * ObjectOutputStream using the writeObject method or by using the
106.92 - * methods for primitive data types supported by DataOutput.
106.93 - *
106.94 - * <p>The readObjectNoData method is responsible for initializing the state of
106.95 - * the object for its particular class in the event that the serialization
106.96 - * stream does not list the given class as a superclass of the object being
106.97 - * deserialized. This may occur in cases where the receiving party uses a
106.98 - * different version of the deserialized instance's class than the sending
106.99 - * party, and the receiver's version extends classes that are not extended by
106.100 - * the sender's version. This may also occur if the serialization stream has
106.101 - * been tampered; hence, readObjectNoData is useful for initializing
106.102 - * deserialized objects properly despite a "hostile" or incomplete source
106.103 - * stream.
106.104 - *
106.105 - * <p>Serializable classes that need to designate an alternative object to be
106.106 - * used when writing an object to the stream should implement this
106.107 - * special method with the exact signature: <p>
106.108 - *
106.109 - * <PRE>
106.110 - * ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
106.111 - * </PRE><p>
106.112 - *
106.113 - * This writeReplace method is invoked by serialization if the method
106.114 - * exists and it would be accessible from a method defined within the
106.115 - * class of the object being serialized. Thus, the method can have private,
106.116 - * protected and package-private access. Subclass access to this method
106.117 - * follows java accessibility rules. <p>
106.118 - *
106.119 - * Classes that need to designate a replacement when an instance of it
106.120 - * is read from the stream should implement this special method with the
106.121 - * exact signature.<p>
106.122 - *
106.123 - * <PRE>
106.124 - * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
106.125 - * </PRE><p>
106.126 - *
106.127 - * This readResolve method follows the same invocation rules and
106.128 - * accessibility rules as writeReplace.<p>
106.129 - *
106.130 - * The serialization runtime associates with each serializable class a version
106.131 - * number, called a serialVersionUID, which is used during deserialization to
106.132 - * verify that the sender and receiver of a serialized object have loaded
106.133 - * classes for that object that are compatible with respect to serialization.
106.134 - * If the receiver has loaded a class for the object that has a different
106.135 - * serialVersionUID than that of the corresponding sender's class, then
106.136 - * deserialization will result in an {@link InvalidClassException}. A
106.137 - * serializable class can declare its own serialVersionUID explicitly by
106.138 - * declaring a field named <code>"serialVersionUID"</code> that must be static,
106.139 - * final, and of type <code>long</code>:<p>
106.140 - *
106.141 - * <PRE>
106.142 - * ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
106.143 - * </PRE>
106.144 - *
106.145 - * If a serializable class does not explicitly declare a serialVersionUID, then
106.146 - * the serialization runtime will calculate a default serialVersionUID value
106.147 - * for that class based on various aspects of the class, as described in the
106.148 - * Java(TM) Object Serialization Specification. However, it is <em>strongly
106.149 - * recommended</em> that all serializable classes explicitly declare
106.150 - * serialVersionUID values, since the default serialVersionUID computation is
106.151 - * highly sensitive to class details that may vary depending on compiler
106.152 - * implementations, and can thus result in unexpected
106.153 - * <code>InvalidClassException</code>s during deserialization. Therefore, to
106.154 - * guarantee a consistent serialVersionUID value across different java compiler
106.155 - * implementations, a serializable class must declare an explicit
106.156 - * serialVersionUID value. It is also strongly advised that explicit
106.157 - * serialVersionUID declarations use the <code>private</code> modifier where
106.158 - * possible, since such declarations apply only to the immediately declaring
106.159 - * class--serialVersionUID fields are not useful as inherited members. Array
106.160 - * classes cannot declare an explicit serialVersionUID, so they always have
106.161 - * the default computed value, but the requirement for matching
106.162 - * serialVersionUID values is waived for array classes.
106.163 - *
106.164 - * @author unascribed
106.165 - * @see java.io.ObjectOutputStream
106.166 - * @see java.io.ObjectInputStream
106.167 - * @see java.io.ObjectOutput
106.168 - * @see java.io.ObjectInput
106.169 - * @see java.io.Externalizable
106.170 - * @since JDK1.1
106.171 - */
106.172 -public interface Serializable {
106.173 -}
107.1 --- a/emul/src/main/java/java/io/UTFDataFormatException.java Wed Jan 23 20:16:48 2013 +0100
107.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
107.3 @@ -1,69 +0,0 @@
107.4 -/*
107.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
107.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
107.7 - *
107.8 - * This code is free software; you can redistribute it and/or modify it
107.9 - * under the terms of the GNU General Public License version 2 only, as
107.10 - * published by the Free Software Foundation. Oracle designates this
107.11 - * particular file as subject to the "Classpath" exception as provided
107.12 - * by Oracle in the LICENSE file that accompanied this code.
107.13 - *
107.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
107.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
107.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
107.17 - * version 2 for more details (a copy is included in the LICENSE file that
107.18 - * accompanied this code).
107.19 - *
107.20 - * You should have received a copy of the GNU General Public License version
107.21 - * 2 along with this work; if not, write to the Free Software Foundation,
107.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
107.23 - *
107.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
107.25 - * or visit www.oracle.com if you need additional information or have any
107.26 - * questions.
107.27 - */
107.28 -
107.29 -package java.io;
107.30 -
107.31 -/**
107.32 - * Signals that a malformed string in
107.33 - * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
107.34 - * format has been read in a data
107.35 - * input stream or by any class that implements the data input
107.36 - * interface.
107.37 - * See the
107.38 - * <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
107.39 - * class description for the format in
107.40 - * which modified UTF-8 strings are read and written.
107.41 - *
107.42 - * @author Frank Yellin
107.43 - * @see java.io.DataInput
107.44 - * @see java.io.DataInputStream#readUTF(java.io.DataInput)
107.45 - * @see java.io.IOException
107.46 - * @since JDK1.0
107.47 - */
107.48 -public
107.49 -class UTFDataFormatException extends IOException {
107.50 - private static final long serialVersionUID = 420743449228280612L;
107.51 -
107.52 - /**
107.53 - * Constructs a <code>UTFDataFormatException</code> with
107.54 - * <code>null</code> as its error detail message.
107.55 - */
107.56 - public UTFDataFormatException() {
107.57 - super();
107.58 - }
107.59 -
107.60 - /**
107.61 - * Constructs a <code>UTFDataFormatException</code> with the
107.62 - * specified detail message. The string <code>s</code> can be
107.63 - * retrieved later by the
107.64 - * <code>{@link java.lang.Throwable#getMessage}</code>
107.65 - * method of class <code>java.lang.Throwable</code>.
107.66 - *
107.67 - * @param s the detail message.
107.68 - */
107.69 - public UTFDataFormatException(String s) {
107.70 - super(s);
107.71 - }
107.72 -}
108.1 --- a/emul/src/main/java/java/io/UnsupportedEncodingException.java Wed Jan 23 20:16:48 2013 +0100
108.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
108.3 @@ -1,52 +0,0 @@
108.4 -/*
108.5 - * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
108.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
108.7 - *
108.8 - * This code is free software; you can redistribute it and/or modify it
108.9 - * under the terms of the GNU General Public License version 2 only, as
108.10 - * published by the Free Software Foundation. Oracle designates this
108.11 - * particular file as subject to the "Classpath" exception as provided
108.12 - * by Oracle in the LICENSE file that accompanied this code.
108.13 - *
108.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
108.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
108.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
108.17 - * version 2 for more details (a copy is included in the LICENSE file that
108.18 - * accompanied this code).
108.19 - *
108.20 - * You should have received a copy of the GNU General Public License version
108.21 - * 2 along with this work; if not, write to the Free Software Foundation,
108.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
108.23 - *
108.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
108.25 - * or visit www.oracle.com if you need additional information or have any
108.26 - * questions.
108.27 - */
108.28 -package java.io;
108.29 -
108.30 -/**
108.31 - * The Character Encoding is not supported.
108.32 - *
108.33 - * @author Asmus Freytag
108.34 - * @since JDK1.1
108.35 - */
108.36 -public class UnsupportedEncodingException
108.37 - extends IOException
108.38 -{
108.39 - private static final long serialVersionUID = -4274276298326136670L;
108.40 -
108.41 - /**
108.42 - * Constructs an UnsupportedEncodingException without a detail message.
108.43 - */
108.44 - public UnsupportedEncodingException() {
108.45 - super();
108.46 - }
108.47 -
108.48 - /**
108.49 - * Constructs an UnsupportedEncodingException with a detail message.
108.50 - * @param s Describes the reason for the exception.
108.51 - */
108.52 - public UnsupportedEncodingException(String s) {
108.53 - super(s);
108.54 - }
108.55 -}
109.1 --- a/emul/src/main/java/java/lang/AbstractStringBuilder.java Wed Jan 23 20:16:48 2013 +0100
109.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
109.3 @@ -1,1424 +0,0 @@
109.4 -/*
109.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
109.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
109.7 - *
109.8 - * This code is free software; you can redistribute it and/or modify it
109.9 - * under the terms of the GNU General Public License version 2 only, as
109.10 - * published by the Free Software Foundation. Oracle designates this
109.11 - * particular file as subject to the "Classpath" exception as provided
109.12 - * by Oracle in the LICENSE file that accompanied this code.
109.13 - *
109.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
109.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
109.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
109.17 - * version 2 for more details (a copy is included in the LICENSE file that
109.18 - * accompanied this code).
109.19 - *
109.20 - * You should have received a copy of the GNU General Public License version
109.21 - * 2 along with this work; if not, write to the Free Software Foundation,
109.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
109.23 - *
109.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
109.25 - * or visit www.oracle.com if you need additional information or have any
109.26 - * questions.
109.27 - */
109.28 -
109.29 -package java.lang;
109.30 -
109.31 -/**
109.32 - * A mutable sequence of characters.
109.33 - * <p>
109.34 - * Implements a modifiable string. At any point in time it contains some
109.35 - * particular sequence of characters, but the length and content of the
109.36 - * sequence can be changed through certain method calls.
109.37 - *
109.38 - * @author Michael McCloskey
109.39 - * @author Martin Buchholz
109.40 - * @author Ulf Zibis
109.41 - * @since 1.5
109.42 - */
109.43 -abstract class AbstractStringBuilder implements Appendable, CharSequence {
109.44 - /**
109.45 - * The value is used for character storage.
109.46 - */
109.47 - char[] value;
109.48 -
109.49 - /**
109.50 - * The count is the number of characters used.
109.51 - */
109.52 - int count;
109.53 -
109.54 - /**
109.55 - * This no-arg constructor is necessary for serialization of subclasses.
109.56 - */
109.57 - AbstractStringBuilder() {
109.58 - }
109.59 -
109.60 - /**
109.61 - * Creates an AbstractStringBuilder of the specified capacity.
109.62 - */
109.63 - AbstractStringBuilder(int capacity) {
109.64 - value = new char[capacity];
109.65 - }
109.66 -
109.67 - /**
109.68 - * Returns the length (character count).
109.69 - *
109.70 - * @return the length of the sequence of characters currently
109.71 - * represented by this object
109.72 - */
109.73 - public int length() {
109.74 - return count;
109.75 - }
109.76 -
109.77 - /**
109.78 - * Returns the current capacity. The capacity is the amount of storage
109.79 - * available for newly inserted characters, beyond which an allocation
109.80 - * will occur.
109.81 - *
109.82 - * @return the current capacity
109.83 - */
109.84 - public int capacity() {
109.85 - return value.length;
109.86 - }
109.87 -
109.88 - /**
109.89 - * Ensures that the capacity is at least equal to the specified minimum.
109.90 - * If the current capacity is less than the argument, then a new internal
109.91 - * array is allocated with greater capacity. The new capacity is the
109.92 - * larger of:
109.93 - * <ul>
109.94 - * <li>The <code>minimumCapacity</code> argument.
109.95 - * <li>Twice the old capacity, plus <code>2</code>.
109.96 - * </ul>
109.97 - * If the <code>minimumCapacity</code> argument is nonpositive, this
109.98 - * method takes no action and simply returns.
109.99 - *
109.100 - * @param minimumCapacity the minimum desired capacity.
109.101 - */
109.102 - public void ensureCapacity(int minimumCapacity) {
109.103 - if (minimumCapacity > 0)
109.104 - ensureCapacityInternal(minimumCapacity);
109.105 - }
109.106 -
109.107 - /**
109.108 - * This method has the same contract as ensureCapacity, but is
109.109 - * never synchronized.
109.110 - */
109.111 - private void ensureCapacityInternal(int minimumCapacity) {
109.112 - // overflow-conscious code
109.113 - if (minimumCapacity - value.length > 0)
109.114 - expandCapacity(minimumCapacity);
109.115 - }
109.116 -
109.117 - /**
109.118 - * This implements the expansion semantics of ensureCapacity with no
109.119 - * size check or synchronization.
109.120 - */
109.121 - void expandCapacity(int minimumCapacity) {
109.122 - int newCapacity = value.length * 2 + 2;
109.123 - if (newCapacity - minimumCapacity < 0)
109.124 - newCapacity = minimumCapacity;
109.125 - if (newCapacity < 0) {
109.126 - if (minimumCapacity < 0) // overflow
109.127 - throw new OutOfMemoryError();
109.128 - newCapacity = Integer.MAX_VALUE;
109.129 - }
109.130 - value = copyOf(value, newCapacity);
109.131 - }
109.132 -
109.133 - /**
109.134 - * Attempts to reduce storage used for the character sequence.
109.135 - * If the buffer is larger than necessary to hold its current sequence of
109.136 - * characters, then it may be resized to become more space efficient.
109.137 - * Calling this method may, but is not required to, affect the value
109.138 - * returned by a subsequent call to the {@link #capacity()} method.
109.139 - */
109.140 - public void trimToSize() {
109.141 - if (count < value.length) {
109.142 - value = copyOf(value, count);
109.143 - }
109.144 - }
109.145 -
109.146 - /**
109.147 - * Sets the length of the character sequence.
109.148 - * The sequence is changed to a new character sequence
109.149 - * whose length is specified by the argument. For every nonnegative
109.150 - * index <i>k</i> less than <code>newLength</code>, the character at
109.151 - * index <i>k</i> in the new character sequence is the same as the
109.152 - * character at index <i>k</i> in the old sequence if <i>k</i> is less
109.153 - * than the length of the old character sequence; otherwise, it is the
109.154 - * null character <code>'\u0000'</code>.
109.155 - *
109.156 - * In other words, if the <code>newLength</code> argument is less than
109.157 - * the current length, the length is changed to the specified length.
109.158 - * <p>
109.159 - * If the <code>newLength</code> argument is greater than or equal
109.160 - * to the current length, sufficient null characters
109.161 - * (<code>'\u0000'</code>) are appended so that
109.162 - * length becomes the <code>newLength</code> argument.
109.163 - * <p>
109.164 - * The <code>newLength</code> argument must be greater than or equal
109.165 - * to <code>0</code>.
109.166 - *
109.167 - * @param newLength the new length
109.168 - * @throws IndexOutOfBoundsException if the
109.169 - * <code>newLength</code> argument is negative.
109.170 - */
109.171 - public void setLength(int newLength) {
109.172 - if (newLength < 0)
109.173 - throw new StringIndexOutOfBoundsException(newLength);
109.174 - ensureCapacityInternal(newLength);
109.175 -
109.176 - if (count < newLength) {
109.177 - for (; count < newLength; count++)
109.178 - value[count] = '\0';
109.179 - } else {
109.180 - count = newLength;
109.181 - }
109.182 - }
109.183 -
109.184 - /**
109.185 - * Returns the <code>char</code> value in this sequence at the specified index.
109.186 - * The first <code>char</code> value is at index <code>0</code>, the next at index
109.187 - * <code>1</code>, and so on, as in array indexing.
109.188 - * <p>
109.189 - * The index argument must be greater than or equal to
109.190 - * <code>0</code>, and less than the length of this sequence.
109.191 - *
109.192 - * <p>If the <code>char</code> value specified by the index is a
109.193 - * <a href="Character.html#unicode">surrogate</a>, the surrogate
109.194 - * value is returned.
109.195 - *
109.196 - * @param index the index of the desired <code>char</code> value.
109.197 - * @return the <code>char</code> value at the specified index.
109.198 - * @throws IndexOutOfBoundsException if <code>index</code> is
109.199 - * negative or greater than or equal to <code>length()</code>.
109.200 - */
109.201 - public char charAt(int index) {
109.202 - if ((index < 0) || (index >= count))
109.203 - throw new StringIndexOutOfBoundsException(index);
109.204 - return value[index];
109.205 - }
109.206 -
109.207 - /**
109.208 - * Returns the character (Unicode code point) at the specified
109.209 - * index. The index refers to <code>char</code> values
109.210 - * (Unicode code units) and ranges from <code>0</code> to
109.211 - * {@link #length()}<code> - 1</code>.
109.212 - *
109.213 - * <p> If the <code>char</code> value specified at the given index
109.214 - * is in the high-surrogate range, the following index is less
109.215 - * than the length of this sequence, and the
109.216 - * <code>char</code> value at the following index is in the
109.217 - * low-surrogate range, then the supplementary code point
109.218 - * corresponding to this surrogate pair is returned. Otherwise,
109.219 - * the <code>char</code> value at the given index is returned.
109.220 - *
109.221 - * @param index the index to the <code>char</code> values
109.222 - * @return the code point value of the character at the
109.223 - * <code>index</code>
109.224 - * @exception IndexOutOfBoundsException if the <code>index</code>
109.225 - * argument is negative or not less than the length of this
109.226 - * sequence.
109.227 - */
109.228 - public int codePointAt(int index) {
109.229 - if ((index < 0) || (index >= count)) {
109.230 - throw new StringIndexOutOfBoundsException(index);
109.231 - }
109.232 - return Character.codePointAt(value, index);
109.233 - }
109.234 -
109.235 - /**
109.236 - * Returns the character (Unicode code point) before the specified
109.237 - * index. The index refers to <code>char</code> values
109.238 - * (Unicode code units) and ranges from <code>1</code> to {@link
109.239 - * #length()}.
109.240 - *
109.241 - * <p> If the <code>char</code> value at <code>(index - 1)</code>
109.242 - * is in the low-surrogate range, <code>(index - 2)</code> is not
109.243 - * negative, and the <code>char</code> value at <code>(index -
109.244 - * 2)</code> is in the high-surrogate range, then the
109.245 - * supplementary code point value of the surrogate pair is
109.246 - * returned. If the <code>char</code> value at <code>index -
109.247 - * 1</code> is an unpaired low-surrogate or a high-surrogate, the
109.248 - * surrogate value is returned.
109.249 - *
109.250 - * @param index the index following the code point that should be returned
109.251 - * @return the Unicode code point value before the given index.
109.252 - * @exception IndexOutOfBoundsException if the <code>index</code>
109.253 - * argument is less than 1 or greater than the length
109.254 - * of this sequence.
109.255 - */
109.256 - public int codePointBefore(int index) {
109.257 - int i = index - 1;
109.258 - if ((i < 0) || (i >= count)) {
109.259 - throw new StringIndexOutOfBoundsException(index);
109.260 - }
109.261 - return Character.codePointBefore(value, index);
109.262 - }
109.263 -
109.264 - /**
109.265 - * Returns the number of Unicode code points in the specified text
109.266 - * range of this sequence. The text range begins at the specified
109.267 - * <code>beginIndex</code> and extends to the <code>char</code> at
109.268 - * index <code>endIndex - 1</code>. Thus the length (in
109.269 - * <code>char</code>s) of the text range is
109.270 - * <code>endIndex-beginIndex</code>. Unpaired surrogates within
109.271 - * this sequence count as one code point each.
109.272 - *
109.273 - * @param beginIndex the index to the first <code>char</code> of
109.274 - * the text range.
109.275 - * @param endIndex the index after the last <code>char</code> of
109.276 - * the text range.
109.277 - * @return the number of Unicode code points in the specified text
109.278 - * range
109.279 - * @exception IndexOutOfBoundsException if the
109.280 - * <code>beginIndex</code> is negative, or <code>endIndex</code>
109.281 - * is larger than the length of this sequence, or
109.282 - * <code>beginIndex</code> is larger than <code>endIndex</code>.
109.283 - */
109.284 - public int codePointCount(int beginIndex, int endIndex) {
109.285 - if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
109.286 - throw new IndexOutOfBoundsException();
109.287 - }
109.288 - return Character.codePointCountImpl(value, beginIndex, endIndex-beginIndex);
109.289 - }
109.290 -
109.291 - /**
109.292 - * Returns the index within this sequence that is offset from the
109.293 - * given <code>index</code> by <code>codePointOffset</code> code
109.294 - * points. Unpaired surrogates within the text range given by
109.295 - * <code>index</code> and <code>codePointOffset</code> count as
109.296 - * one code point each.
109.297 - *
109.298 - * @param index the index to be offset
109.299 - * @param codePointOffset the offset in code points
109.300 - * @return the index within this sequence
109.301 - * @exception IndexOutOfBoundsException if <code>index</code>
109.302 - * is negative or larger then the length of this sequence,
109.303 - * or if <code>codePointOffset</code> is positive and the subsequence
109.304 - * starting with <code>index</code> has fewer than
109.305 - * <code>codePointOffset</code> code points,
109.306 - * or if <code>codePointOffset</code> is negative and the subsequence
109.307 - * before <code>index</code> has fewer than the absolute value of
109.308 - * <code>codePointOffset</code> code points.
109.309 - */
109.310 - public int offsetByCodePoints(int index, int codePointOffset) {
109.311 - if (index < 0 || index > count) {
109.312 - throw new IndexOutOfBoundsException();
109.313 - }
109.314 - return Character.offsetByCodePointsImpl(value, 0, count,
109.315 - index, codePointOffset);
109.316 - }
109.317 -
109.318 - /**
109.319 - * Characters are copied from this sequence into the
109.320 - * destination character array <code>dst</code>. The first character to
109.321 - * be copied is at index <code>srcBegin</code>; the last character to
109.322 - * be copied is at index <code>srcEnd-1</code>. The total number of
109.323 - * characters to be copied is <code>srcEnd-srcBegin</code>. The
109.324 - * characters are copied into the subarray of <code>dst</code> starting
109.325 - * at index <code>dstBegin</code> and ending at index:
109.326 - * <p><blockquote><pre>
109.327 - * dstbegin + (srcEnd-srcBegin) - 1
109.328 - * </pre></blockquote>
109.329 - *
109.330 - * @param srcBegin start copying at this offset.
109.331 - * @param srcEnd stop copying at this offset.
109.332 - * @param dst the array to copy the data into.
109.333 - * @param dstBegin offset into <code>dst</code>.
109.334 - * @throws NullPointerException if <code>dst</code> is
109.335 - * <code>null</code>.
109.336 - * @throws IndexOutOfBoundsException if any of the following is true:
109.337 - * <ul>
109.338 - * <li><code>srcBegin</code> is negative
109.339 - * <li><code>dstBegin</code> is negative
109.340 - * <li>the <code>srcBegin</code> argument is greater than
109.341 - * the <code>srcEnd</code> argument.
109.342 - * <li><code>srcEnd</code> is greater than
109.343 - * <code>this.length()</code>.
109.344 - * <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
109.345 - * <code>dst.length</code>
109.346 - * </ul>
109.347 - */
109.348 - public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
109.349 - {
109.350 - if (srcBegin < 0)
109.351 - throw new StringIndexOutOfBoundsException(srcBegin);
109.352 - if ((srcEnd < 0) || (srcEnd > count))
109.353 - throw new StringIndexOutOfBoundsException(srcEnd);
109.354 - if (srcBegin > srcEnd)
109.355 - throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
109.356 - arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
109.357 - }
109.358 -
109.359 - /**
109.360 - * The character at the specified index is set to <code>ch</code>. This
109.361 - * sequence is altered to represent a new character sequence that is
109.362 - * identical to the old character sequence, except that it contains the
109.363 - * character <code>ch</code> at position <code>index</code>.
109.364 - * <p>
109.365 - * The index argument must be greater than or equal to
109.366 - * <code>0</code>, and less than the length of this sequence.
109.367 - *
109.368 - * @param index the index of the character to modify.
109.369 - * @param ch the new character.
109.370 - * @throws IndexOutOfBoundsException if <code>index</code> is
109.371 - * negative or greater than or equal to <code>length()</code>.
109.372 - */
109.373 - public void setCharAt(int index, char ch) {
109.374 - if ((index < 0) || (index >= count))
109.375 - throw new StringIndexOutOfBoundsException(index);
109.376 - value[index] = ch;
109.377 - }
109.378 -
109.379 - /**
109.380 - * Appends the string representation of the {@code Object} argument.
109.381 - * <p>
109.382 - * The overall effect is exactly as if the argument were converted
109.383 - * to a string by the method {@link String#valueOf(Object)},
109.384 - * and the characters of that string were then
109.385 - * {@link #append(String) appended} to this character sequence.
109.386 - *
109.387 - * @param obj an {@code Object}.
109.388 - * @return a reference to this object.
109.389 - */
109.390 - public AbstractStringBuilder append(Object obj) {
109.391 - return append(String.valueOf(obj));
109.392 - }
109.393 -
109.394 - /**
109.395 - * Appends the specified string to this character sequence.
109.396 - * <p>
109.397 - * The characters of the {@code String} argument are appended, in
109.398 - * order, increasing the length of this sequence by the length of the
109.399 - * argument. If {@code str} is {@code null}, then the four
109.400 - * characters {@code "null"} are appended.
109.401 - * <p>
109.402 - * Let <i>n</i> be the length of this character sequence just prior to
109.403 - * execution of the {@code append} method. Then the character at
109.404 - * index <i>k</i> in the new character sequence is equal to the character
109.405 - * at index <i>k</i> in the old character sequence, if <i>k</i> is less
109.406 - * than <i>n</i>; otherwise, it is equal to the character at index
109.407 - * <i>k-n</i> in the argument {@code str}.
109.408 - *
109.409 - * @param str a string.
109.410 - * @return a reference to this object.
109.411 - */
109.412 - public AbstractStringBuilder append(String str) {
109.413 - if (str == null) str = "null";
109.414 - int len = str.length();
109.415 - ensureCapacityInternal(count + len);
109.416 - str.getChars(0, len, value, count);
109.417 - count += len;
109.418 - return this;
109.419 - }
109.420 -
109.421 - // Documentation in subclasses because of synchro difference
109.422 - public AbstractStringBuilder append(StringBuffer sb) {
109.423 - if (sb == null)
109.424 - return append("null");
109.425 - int len = sb.length();
109.426 - ensureCapacityInternal(count + len);
109.427 - sb.getChars(0, len, value, count);
109.428 - count += len;
109.429 - return this;
109.430 - }
109.431 -
109.432 - // Documentation in subclasses because of synchro difference
109.433 - public AbstractStringBuilder append(CharSequence s) {
109.434 - if (s == null)
109.435 - s = "null";
109.436 - if (s instanceof String)
109.437 - return this.append((String)s);
109.438 - if (s instanceof StringBuffer)
109.439 - return this.append((StringBuffer)s);
109.440 - return this.append(s, 0, s.length());
109.441 - }
109.442 -
109.443 - /**
109.444 - * Appends a subsequence of the specified {@code CharSequence} to this
109.445 - * sequence.
109.446 - * <p>
109.447 - * Characters of the argument {@code s}, starting at
109.448 - * index {@code start}, are appended, in order, to the contents of
109.449 - * this sequence up to the (exclusive) index {@code end}. The length
109.450 - * of this sequence is increased by the value of {@code end - start}.
109.451 - * <p>
109.452 - * Let <i>n</i> be the length of this character sequence just prior to
109.453 - * execution of the {@code append} method. Then the character at
109.454 - * index <i>k</i> in this character sequence becomes equal to the
109.455 - * character at index <i>k</i> in this sequence, if <i>k</i> is less than
109.456 - * <i>n</i>; otherwise, it is equal to the character at index
109.457 - * <i>k+start-n</i> in the argument {@code s}.
109.458 - * <p>
109.459 - * If {@code s} is {@code null}, then this method appends
109.460 - * characters as if the s parameter was a sequence containing the four
109.461 - * characters {@code "null"}.
109.462 - *
109.463 - * @param s the sequence to append.
109.464 - * @param start the starting index of the subsequence to be appended.
109.465 - * @param end the end index of the subsequence to be appended.
109.466 - * @return a reference to this object.
109.467 - * @throws IndexOutOfBoundsException if
109.468 - * {@code start} is negative, or
109.469 - * {@code start} is greater than {@code end} or
109.470 - * {@code end} is greater than {@code s.length()}
109.471 - */
109.472 - public AbstractStringBuilder append(CharSequence s, int start, int end) {
109.473 - if (s == null)
109.474 - s = "null";
109.475 - if ((start < 0) || (start > end) || (end > s.length()))
109.476 - throw new IndexOutOfBoundsException(
109.477 - "start " + start + ", end " + end + ", s.length() "
109.478 - + s.length());
109.479 - int len = end - start;
109.480 - ensureCapacityInternal(count + len);
109.481 - for (int i = start, j = count; i < end; i++, j++)
109.482 - value[j] = s.charAt(i);
109.483 - count += len;
109.484 - return this;
109.485 - }
109.486 -
109.487 - /**
109.488 - * Appends the string representation of the {@code char} array
109.489 - * argument to this sequence.
109.490 - * <p>
109.491 - * The characters of the array argument are appended, in order, to
109.492 - * the contents of this sequence. The length of this sequence
109.493 - * increases by the length of the argument.
109.494 - * <p>
109.495 - * The overall effect is exactly as if the argument were converted
109.496 - * to a string by the method {@link String#valueOf(char[])},
109.497 - * and the characters of that string were then
109.498 - * {@link #append(String) appended} to this character sequence.
109.499 - *
109.500 - * @param str the characters to be appended.
109.501 - * @return a reference to this object.
109.502 - */
109.503 - public AbstractStringBuilder append(char[] str) {
109.504 - int len = str.length;
109.505 - ensureCapacityInternal(count + len);
109.506 - arraycopy(str, 0, value, count, len);
109.507 - count += len;
109.508 - return this;
109.509 - }
109.510 -
109.511 - /**
109.512 - * Appends the string representation of a subarray of the
109.513 - * {@code char} array argument to this sequence.
109.514 - * <p>
109.515 - * Characters of the {@code char} array {@code str}, starting at
109.516 - * index {@code offset}, are appended, in order, to the contents
109.517 - * of this sequence. The length of this sequence increases
109.518 - * by the value of {@code len}.
109.519 - * <p>
109.520 - * The overall effect is exactly as if the arguments were converted
109.521 - * to a string by the method {@link String#valueOf(char[],int,int)},
109.522 - * and the characters of that string were then
109.523 - * {@link #append(String) appended} to this character sequence.
109.524 - *
109.525 - * @param str the characters to be appended.
109.526 - * @param offset the index of the first {@code char} to append.
109.527 - * @param len the number of {@code char}s to append.
109.528 - * @return a reference to this object.
109.529 - * @throws IndexOutOfBoundsException
109.530 - * if {@code offset < 0} or {@code len < 0}
109.531 - * or {@code offset+len > str.length}
109.532 - */
109.533 - public AbstractStringBuilder append(char str[], int offset, int len) {
109.534 - if (len > 0) // let arraycopy report AIOOBE for len < 0
109.535 - ensureCapacityInternal(count + len);
109.536 - arraycopy(str, offset, value, count, len);
109.537 - count += len;
109.538 - return this;
109.539 - }
109.540 -
109.541 - /**
109.542 - * Appends the string representation of the {@code boolean}
109.543 - * argument to the sequence.
109.544 - * <p>
109.545 - * The overall effect is exactly as if the argument were converted
109.546 - * to a string by the method {@link String#valueOf(boolean)},
109.547 - * and the characters of that string were then
109.548 - * {@link #append(String) appended} to this character sequence.
109.549 - *
109.550 - * @param b a {@code boolean}.
109.551 - * @return a reference to this object.
109.552 - */
109.553 - public AbstractStringBuilder append(boolean b) {
109.554 - if (b) {
109.555 - ensureCapacityInternal(count + 4);
109.556 - value[count++] = 't';
109.557 - value[count++] = 'r';
109.558 - value[count++] = 'u';
109.559 - value[count++] = 'e';
109.560 - } else {
109.561 - ensureCapacityInternal(count + 5);
109.562 - value[count++] = 'f';
109.563 - value[count++] = 'a';
109.564 - value[count++] = 'l';
109.565 - value[count++] = 's';
109.566 - value[count++] = 'e';
109.567 - }
109.568 - return this;
109.569 - }
109.570 -
109.571 - /**
109.572 - * Appends the string representation of the {@code char}
109.573 - * argument to this sequence.
109.574 - * <p>
109.575 - * The argument is appended to the contents of this sequence.
109.576 - * The length of this sequence increases by {@code 1}.
109.577 - * <p>
109.578 - * The overall effect is exactly as if the argument were converted
109.579 - * to a string by the method {@link String#valueOf(char)},
109.580 - * and the character in that string were then
109.581 - * {@link #append(String) appended} to this character sequence.
109.582 - *
109.583 - * @param c a {@code char}.
109.584 - * @return a reference to this object.
109.585 - */
109.586 - public AbstractStringBuilder append(char c) {
109.587 - ensureCapacityInternal(count + 1);
109.588 - value[count++] = c;
109.589 - return this;
109.590 - }
109.591 -
109.592 - /**
109.593 - * Appends the string representation of the {@code int}
109.594 - * argument to this sequence.
109.595 - * <p>
109.596 - * The overall effect is exactly as if the argument were converted
109.597 - * to a string by the method {@link String#valueOf(int)},
109.598 - * and the characters of that string were then
109.599 - * {@link #append(String) appended} to this character sequence.
109.600 - *
109.601 - * @param i an {@code int}.
109.602 - * @return a reference to this object.
109.603 - */
109.604 - public AbstractStringBuilder append(int i) {
109.605 - return append(Integer.toString(i));
109.606 - }
109.607 -
109.608 - /**
109.609 - * Appends the string representation of the {@code long}
109.610 - * argument to this sequence.
109.611 - * <p>
109.612 - * The overall effect is exactly as if the argument were converted
109.613 - * to a string by the method {@link String#valueOf(long)},
109.614 - * and the characters of that string were then
109.615 - * {@link #append(String) appended} to this character sequence.
109.616 - *
109.617 - * @param l a {@code long}.
109.618 - * @return a reference to this object.
109.619 - */
109.620 - public AbstractStringBuilder append(long l) {
109.621 - if (l == Long.MIN_VALUE) {
109.622 - append("-9223372036854775808");
109.623 - return this;
109.624 - }
109.625 - int appendedLength = (l < 0) ? Long.stringSize(-l) + 1
109.626 - : Long.stringSize(l);
109.627 - int spaceNeeded = count + appendedLength;
109.628 - ensureCapacityInternal(spaceNeeded);
109.629 - Long.getChars(l, spaceNeeded, value);
109.630 - count = spaceNeeded;
109.631 - return this;
109.632 - }
109.633 -
109.634 - /**
109.635 - * Appends the string representation of the {@code float}
109.636 - * argument to this sequence.
109.637 - * <p>
109.638 - * The overall effect is exactly as if the argument were converted
109.639 - * to a string by the method {@link String#valueOf(float)},
109.640 - * and the characters of that string were then
109.641 - * {@link #append(String) appended} to this character sequence.
109.642 - *
109.643 - * @param f a {@code float}.
109.644 - * @return a reference to this object.
109.645 - */
109.646 - public AbstractStringBuilder append(float f) {
109.647 - return append(Float.toString(f));
109.648 - }
109.649 -
109.650 - /**
109.651 - * Appends the string representation of the {@code double}
109.652 - * argument to this sequence.
109.653 - * <p>
109.654 - * The overall effect is exactly as if the argument were converted
109.655 - * to a string by the method {@link String#valueOf(double)},
109.656 - * and the characters of that string were then
109.657 - * {@link #append(String) appended} to this character sequence.
109.658 - *
109.659 - * @param d a {@code double}.
109.660 - * @return a reference to this object.
109.661 - */
109.662 - public AbstractStringBuilder append(double d) {
109.663 - return append(Double.toString(d));
109.664 - }
109.665 -
109.666 - /**
109.667 - * Removes the characters in a substring of this sequence.
109.668 - * The substring begins at the specified {@code start} and extends to
109.669 - * the character at index {@code end - 1} or to the end of the
109.670 - * sequence if no such character exists. If
109.671 - * {@code start} is equal to {@code end}, no changes are made.
109.672 - *
109.673 - * @param start The beginning index, inclusive.
109.674 - * @param end The ending index, exclusive.
109.675 - * @return This object.
109.676 - * @throws StringIndexOutOfBoundsException if {@code start}
109.677 - * is negative, greater than {@code length()}, or
109.678 - * greater than {@code end}.
109.679 - */
109.680 - public AbstractStringBuilder delete(int start, int end) {
109.681 - if (start < 0)
109.682 - throw new StringIndexOutOfBoundsException(start);
109.683 - if (end > count)
109.684 - end = count;
109.685 - if (start > end)
109.686 - throw new StringIndexOutOfBoundsException();
109.687 - int len = end - start;
109.688 - if (len > 0) {
109.689 - arraycopy(value, start+len, value, start, count-end);
109.690 - count -= len;
109.691 - }
109.692 - return this;
109.693 - }
109.694 -
109.695 - /**
109.696 - * Appends the string representation of the {@code codePoint}
109.697 - * argument to this sequence.
109.698 - *
109.699 - * <p> The argument is appended to the contents of this sequence.
109.700 - * The length of this sequence increases by
109.701 - * {@link Character#charCount(int) Character.charCount(codePoint)}.
109.702 - *
109.703 - * <p> The overall effect is exactly as if the argument were
109.704 - * converted to a {@code char} array by the method
109.705 - * {@link Character#toChars(int)} and the character in that array
109.706 - * were then {@link #append(char[]) appended} to this character
109.707 - * sequence.
109.708 - *
109.709 - * @param codePoint a Unicode code point
109.710 - * @return a reference to this object.
109.711 - * @exception IllegalArgumentException if the specified
109.712 - * {@code codePoint} isn't a valid Unicode code point
109.713 - */
109.714 - public AbstractStringBuilder appendCodePoint(int codePoint) {
109.715 - final int count = this.count;
109.716 -
109.717 - if (Character.isBmpCodePoint(codePoint)) {
109.718 - ensureCapacityInternal(count + 1);
109.719 - value[count] = (char) codePoint;
109.720 - this.count = count + 1;
109.721 - } else if (Character.isValidCodePoint(codePoint)) {
109.722 - ensureCapacityInternal(count + 2);
109.723 - Character.toSurrogates(codePoint, value, count);
109.724 - this.count = count + 2;
109.725 - } else {
109.726 - throw new IllegalArgumentException();
109.727 - }
109.728 - return this;
109.729 - }
109.730 -
109.731 - /**
109.732 - * Removes the <code>char</code> at the specified position in this
109.733 - * sequence. This sequence is shortened by one <code>char</code>.
109.734 - *
109.735 - * <p>Note: If the character at the given index is a supplementary
109.736 - * character, this method does not remove the entire character. If
109.737 - * correct handling of supplementary characters is required,
109.738 - * determine the number of <code>char</code>s to remove by calling
109.739 - * <code>Character.charCount(thisSequence.codePointAt(index))</code>,
109.740 - * where <code>thisSequence</code> is this sequence.
109.741 - *
109.742 - * @param index Index of <code>char</code> to remove
109.743 - * @return This object.
109.744 - * @throws StringIndexOutOfBoundsException if the <code>index</code>
109.745 - * is negative or greater than or equal to
109.746 - * <code>length()</code>.
109.747 - */
109.748 - public AbstractStringBuilder deleteCharAt(int index) {
109.749 - if ((index < 0) || (index >= count))
109.750 - throw new StringIndexOutOfBoundsException(index);
109.751 - arraycopy(value, index+1, value, index, count-index-1);
109.752 - count--;
109.753 - return this;
109.754 - }
109.755 -
109.756 - /**
109.757 - * Replaces the characters in a substring of this sequence
109.758 - * with characters in the specified <code>String</code>. The substring
109.759 - * begins at the specified <code>start</code> and extends to the character
109.760 - * at index <code>end - 1</code> or to the end of the
109.761 - * sequence if no such character exists. First the
109.762 - * characters in the substring are removed and then the specified
109.763 - * <code>String</code> is inserted at <code>start</code>. (This
109.764 - * sequence will be lengthened to accommodate the
109.765 - * specified String if necessary.)
109.766 - *
109.767 - * @param start The beginning index, inclusive.
109.768 - * @param end The ending index, exclusive.
109.769 - * @param str String that will replace previous contents.
109.770 - * @return This object.
109.771 - * @throws StringIndexOutOfBoundsException if <code>start</code>
109.772 - * is negative, greater than <code>length()</code>, or
109.773 - * greater than <code>end</code>.
109.774 - */
109.775 - public AbstractStringBuilder replace(int start, int end, String str) {
109.776 - if (start < 0)
109.777 - throw new StringIndexOutOfBoundsException(start);
109.778 - if (start > count)
109.779 - throw new StringIndexOutOfBoundsException("start > length()");
109.780 - if (start > end)
109.781 - throw new StringIndexOutOfBoundsException("start > end");
109.782 -
109.783 - if (end > count)
109.784 - end = count;
109.785 - int len = str.length();
109.786 - int newCount = count + len - (end - start);
109.787 - ensureCapacityInternal(newCount);
109.788 -
109.789 - arraycopy(value, end, value, start + len, count - end);
109.790 - str.getChars(value, start);
109.791 - count = newCount;
109.792 - return this;
109.793 - }
109.794 -
109.795 - /**
109.796 - * Returns a new <code>String</code> that contains a subsequence of
109.797 - * characters currently contained in this character sequence. The
109.798 - * substring begins at the specified index and extends to the end of
109.799 - * this sequence.
109.800 - *
109.801 - * @param start The beginning index, inclusive.
109.802 - * @return The new string.
109.803 - * @throws StringIndexOutOfBoundsException if <code>start</code> is
109.804 - * less than zero, or greater than the length of this object.
109.805 - */
109.806 - public String substring(int start) {
109.807 - return substring(start, count);
109.808 - }
109.809 -
109.810 - /**
109.811 - * Returns a new character sequence that is a subsequence of this sequence.
109.812 - *
109.813 - * <p> An invocation of this method of the form
109.814 - *
109.815 - * <blockquote><pre>
109.816 - * sb.subSequence(begin, end)</pre></blockquote>
109.817 - *
109.818 - * behaves in exactly the same way as the invocation
109.819 - *
109.820 - * <blockquote><pre>
109.821 - * sb.substring(begin, end)</pre></blockquote>
109.822 - *
109.823 - * This method is provided so that this class can
109.824 - * implement the {@link CharSequence} interface. </p>
109.825 - *
109.826 - * @param start the start index, inclusive.
109.827 - * @param end the end index, exclusive.
109.828 - * @return the specified subsequence.
109.829 - *
109.830 - * @throws IndexOutOfBoundsException
109.831 - * if <tt>start</tt> or <tt>end</tt> are negative,
109.832 - * if <tt>end</tt> is greater than <tt>length()</tt>,
109.833 - * or if <tt>start</tt> is greater than <tt>end</tt>
109.834 - * @spec JSR-51
109.835 - */
109.836 - public CharSequence subSequence(int start, int end) {
109.837 - return substring(start, end);
109.838 - }
109.839 -
109.840 - /**
109.841 - * Returns a new <code>String</code> that contains a subsequence of
109.842 - * characters currently contained in this sequence. The
109.843 - * substring begins at the specified <code>start</code> and
109.844 - * extends to the character at index <code>end - 1</code>.
109.845 - *
109.846 - * @param start The beginning index, inclusive.
109.847 - * @param end The ending index, exclusive.
109.848 - * @return The new string.
109.849 - * @throws StringIndexOutOfBoundsException if <code>start</code>
109.850 - * or <code>end</code> are negative or greater than
109.851 - * <code>length()</code>, or <code>start</code> is
109.852 - * greater than <code>end</code>.
109.853 - */
109.854 - public String substring(int start, int end) {
109.855 - if (start < 0)
109.856 - throw new StringIndexOutOfBoundsException(start);
109.857 - if (end > count)
109.858 - throw new StringIndexOutOfBoundsException(end);
109.859 - if (start > end)
109.860 - throw new StringIndexOutOfBoundsException(end - start);
109.861 - return new String(value, start, end - start);
109.862 - }
109.863 -
109.864 - /**
109.865 - * Inserts the string representation of a subarray of the {@code str}
109.866 - * array argument into this sequence. The subarray begins at the
109.867 - * specified {@code offset} and extends {@code len} {@code char}s.
109.868 - * The characters of the subarray are inserted into this sequence at
109.869 - * the position indicated by {@code index}. The length of this
109.870 - * sequence increases by {@code len} {@code char}s.
109.871 - *
109.872 - * @param index position at which to insert subarray.
109.873 - * @param str A {@code char} array.
109.874 - * @param offset the index of the first {@code char} in subarray to
109.875 - * be inserted.
109.876 - * @param len the number of {@code char}s in the subarray to
109.877 - * be inserted.
109.878 - * @return This object
109.879 - * @throws StringIndexOutOfBoundsException if {@code index}
109.880 - * is negative or greater than {@code length()}, or
109.881 - * {@code offset} or {@code len} are negative, or
109.882 - * {@code (offset+len)} is greater than
109.883 - * {@code str.length}.
109.884 - */
109.885 - public AbstractStringBuilder insert(int index, char[] str, int offset,
109.886 - int len)
109.887 - {
109.888 - if ((index < 0) || (index > length()))
109.889 - throw new StringIndexOutOfBoundsException(index);
109.890 - if ((offset < 0) || (len < 0) || (offset > str.length - len))
109.891 - throw new StringIndexOutOfBoundsException(
109.892 - "offset " + offset + ", len " + len + ", str.length "
109.893 - + str.length);
109.894 - ensureCapacityInternal(count + len);
109.895 - arraycopy(value, index, value, index + len, count - index);
109.896 - arraycopy(str, offset, value, index, len);
109.897 - count += len;
109.898 - return this;
109.899 - }
109.900 -
109.901 - /**
109.902 - * Inserts the string representation of the {@code Object}
109.903 - * argument into this character sequence.
109.904 - * <p>
109.905 - * The overall effect is exactly as if the second argument were
109.906 - * converted to a string by the method {@link String#valueOf(Object)},
109.907 - * and the characters of that string were then
109.908 - * {@link #insert(int,String) inserted} into this character
109.909 - * sequence at the indicated offset.
109.910 - * <p>
109.911 - * The {@code offset} argument must be greater than or equal to
109.912 - * {@code 0}, and less than or equal to the {@linkplain #length() length}
109.913 - * of this sequence.
109.914 - *
109.915 - * @param offset the offset.
109.916 - * @param obj an {@code Object}.
109.917 - * @return a reference to this object.
109.918 - * @throws StringIndexOutOfBoundsException if the offset is invalid.
109.919 - */
109.920 - public AbstractStringBuilder insert(int offset, Object obj) {
109.921 - return insert(offset, String.valueOf(obj));
109.922 - }
109.923 -
109.924 - /**
109.925 - * Inserts the string into this character sequence.
109.926 - * <p>
109.927 - * The characters of the {@code String} argument are inserted, in
109.928 - * order, into this sequence at the indicated offset, moving up any
109.929 - * characters originally above that position and increasing the length
109.930 - * of this sequence by the length of the argument. If
109.931 - * {@code str} is {@code null}, then the four characters
109.932 - * {@code "null"} are inserted into this sequence.
109.933 - * <p>
109.934 - * The character at index <i>k</i> in the new character sequence is
109.935 - * equal to:
109.936 - * <ul>
109.937 - * <li>the character at index <i>k</i> in the old character sequence, if
109.938 - * <i>k</i> is less than {@code offset}
109.939 - * <li>the character at index <i>k</i>{@code -offset} in the
109.940 - * argument {@code str}, if <i>k</i> is not less than
109.941 - * {@code offset} but is less than {@code offset+str.length()}
109.942 - * <li>the character at index <i>k</i>{@code -str.length()} in the
109.943 - * old character sequence, if <i>k</i> is not less than
109.944 - * {@code offset+str.length()}
109.945 - * </ul><p>
109.946 - * The {@code offset} argument must be greater than or equal to
109.947 - * {@code 0}, and less than or equal to the {@linkplain #length() length}
109.948 - * of this sequence.
109.949 - *
109.950 - * @param offset the offset.
109.951 - * @param str a string.
109.952 - * @return a reference to this object.
109.953 - * @throws StringIndexOutOfBoundsException if the offset is invalid.
109.954 - */
109.955 - public AbstractStringBuilder insert(int offset, String str) {
109.956 - if ((offset < 0) || (offset > length()))
109.957 - throw new StringIndexOutOfBoundsException(offset);
109.958 - if (str == null)
109.959 - str = "null";
109.960 - int len = str.length();
109.961 - ensureCapacityInternal(count + len);
109.962 - arraycopy(value, offset, value, offset + len, count - offset);
109.963 - str.getChars(value, offset);
109.964 - count += len;
109.965 - return this;
109.966 - }
109.967 -
109.968 - /**
109.969 - * Inserts the string representation of the {@code char} array
109.970 - * argument into this sequence.
109.971 - * <p>
109.972 - * The characters of the array argument are inserted into the
109.973 - * contents of this sequence at the position indicated by
109.974 - * {@code offset}. The length of this sequence increases by
109.975 - * the length of the argument.
109.976 - * <p>
109.977 - * The overall effect is exactly as if the second argument were
109.978 - * converted to a string by the method {@link String#valueOf(char[])},
109.979 - * and the characters of that string were then
109.980 - * {@link #insert(int,String) inserted} into this character
109.981 - * sequence at the indicated offset.
109.982 - * <p>
109.983 - * The {@code offset} argument must be greater than or equal to
109.984 - * {@code 0}, and less than or equal to the {@linkplain #length() length}
109.985 - * of this sequence.
109.986 - *
109.987 - * @param offset the offset.
109.988 - * @param str a character array.
109.989 - * @return a reference to this object.
109.990 - * @throws StringIndexOutOfBoundsException if the offset is invalid.
109.991 - */
109.992 - public AbstractStringBuilder insert(int offset, char[] str) {
109.993 - if ((offset < 0) || (offset > length()))
109.994 - throw new StringIndexOutOfBoundsException(offset);
109.995 - int len = str.length;
109.996 - ensureCapacityInternal(count + len);
109.997 - arraycopy(value, offset, value, offset + len, count - offset);
109.998 - arraycopy(str, 0, value, offset, len);
109.999 - count += len;
109.1000 - return this;
109.1001 - }
109.1002 -
109.1003 - /**
109.1004 - * Inserts the specified {@code CharSequence} into this sequence.
109.1005 - * <p>
109.1006 - * The characters of the {@code CharSequence} argument are inserted,
109.1007 - * in order, into this sequence at the indicated offset, moving up
109.1008 - * any characters originally above that position and increasing the length
109.1009 - * of this sequence by the length of the argument s.
109.1010 - * <p>
109.1011 - * The result of this method is exactly the same as if it were an
109.1012 - * invocation of this object's
109.1013 - * {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length())
109.1014 - * method.
109.1015 - *
109.1016 - * <p>If {@code s} is {@code null}, then the four characters
109.1017 - * {@code "null"} are inserted into this sequence.
109.1018 - *
109.1019 - * @param dstOffset the offset.
109.1020 - * @param s the sequence to be inserted
109.1021 - * @return a reference to this object.
109.1022 - * @throws IndexOutOfBoundsException if the offset is invalid.
109.1023 - */
109.1024 - public AbstractStringBuilder insert(int dstOffset, CharSequence s) {
109.1025 - if (s == null)
109.1026 - s = "null";
109.1027 - if (s instanceof String)
109.1028 - return this.insert(dstOffset, (String)s);
109.1029 - return this.insert(dstOffset, s, 0, s.length());
109.1030 - }
109.1031 -
109.1032 - /**
109.1033 - * Inserts a subsequence of the specified {@code CharSequence} into
109.1034 - * this sequence.
109.1035 - * <p>
109.1036 - * The subsequence of the argument {@code s} specified by
109.1037 - * {@code start} and {@code end} are inserted,
109.1038 - * in order, into this sequence at the specified destination offset, moving
109.1039 - * up any characters originally above that position. The length of this
109.1040 - * sequence is increased by {@code end - start}.
109.1041 - * <p>
109.1042 - * The character at index <i>k</i> in this sequence becomes equal to:
109.1043 - * <ul>
109.1044 - * <li>the character at index <i>k</i> in this sequence, if
109.1045 - * <i>k</i> is less than {@code dstOffset}
109.1046 - * <li>the character at index <i>k</i>{@code +start-dstOffset} in
109.1047 - * the argument {@code s}, if <i>k</i> is greater than or equal to
109.1048 - * {@code dstOffset} but is less than {@code dstOffset+end-start}
109.1049 - * <li>the character at index <i>k</i>{@code -(end-start)} in this
109.1050 - * sequence, if <i>k</i> is greater than or equal to
109.1051 - * {@code dstOffset+end-start}
109.1052 - * </ul><p>
109.1053 - * The {@code dstOffset} argument must be greater than or equal to
109.1054 - * {@code 0}, and less than or equal to the {@linkplain #length() length}
109.1055 - * of this sequence.
109.1056 - * <p>The start argument must be nonnegative, and not greater than
109.1057 - * {@code end}.
109.1058 - * <p>The end argument must be greater than or equal to
109.1059 - * {@code start}, and less than or equal to the length of s.
109.1060 - *
109.1061 - * <p>If {@code s} is {@code null}, then this method inserts
109.1062 - * characters as if the s parameter was a sequence containing the four
109.1063 - * characters {@code "null"}.
109.1064 - *
109.1065 - * @param dstOffset the offset in this sequence.
109.1066 - * @param s the sequence to be inserted.
109.1067 - * @param start the starting index of the subsequence to be inserted.
109.1068 - * @param end the end index of the subsequence to be inserted.
109.1069 - * @return a reference to this object.
109.1070 - * @throws IndexOutOfBoundsException if {@code dstOffset}
109.1071 - * is negative or greater than {@code this.length()}, or
109.1072 - * {@code start} or {@code end} are negative, or
109.1073 - * {@code start} is greater than {@code end} or
109.1074 - * {@code end} is greater than {@code s.length()}
109.1075 - */
109.1076 - public AbstractStringBuilder insert(int dstOffset, CharSequence s,
109.1077 - int start, int end) {
109.1078 - if (s == null)
109.1079 - s = "null";
109.1080 - if ((dstOffset < 0) || (dstOffset > this.length()))
109.1081 - throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
109.1082 - if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
109.1083 - throw new IndexOutOfBoundsException(
109.1084 - "start " + start + ", end " + end + ", s.length() "
109.1085 - + s.length());
109.1086 - int len = end - start;
109.1087 - ensureCapacityInternal(count + len);
109.1088 - arraycopy(value, dstOffset, value, dstOffset + len,
109.1089 - count - dstOffset);
109.1090 - for (int i=start; i<end; i++)
109.1091 - value[dstOffset++] = s.charAt(i);
109.1092 - count += len;
109.1093 - return this;
109.1094 - }
109.1095 -
109.1096 - /**
109.1097 - * Inserts the string representation of the {@code boolean}
109.1098 - * argument into this sequence.
109.1099 - * <p>
109.1100 - * The overall effect is exactly as if the second argument were
109.1101 - * converted to a string by the method {@link String#valueOf(boolean)},
109.1102 - * and the characters of that string were then
109.1103 - * {@link #insert(int,String) inserted} into this character
109.1104 - * sequence at the indicated offset.
109.1105 - * <p>
109.1106 - * The {@code offset} argument must be greater than or equal to
109.1107 - * {@code 0}, and less than or equal to the {@linkplain #length() length}
109.1108 - * of this sequence.
109.1109 - *
109.1110 - * @param offset the offset.
109.1111 - * @param b a {@code boolean}.
109.1112 - * @return a reference to this object.
109.1113 - * @throws StringIndexOutOfBoundsException if the offset is invalid.
109.1114 - */
109.1115 - public AbstractStringBuilder insert(int offset, boolean b) {
109.1116 - return insert(offset, String.valueOf(b));
109.1117 - }
109.1118 -
109.1119 - /**
109.1120 - * Inserts the string representation of the {@code char}
109.1121 - * argument into this sequence.
109.1122 - * <p>
109.1123 - * The overall effect is exactly as if the second argument were
109.1124 - * converted to a string by the method {@link String#valueOf(char)},
109.1125 - * and the character in that string were then
109.1126 - * {@link #insert(int,String) inserted} into this character
109.1127 - * sequence at the indicated offset.
109.1128 - * <p>
109.1129 - * The {@code offset} argument must be greater than or equal to
109.1130 - * {@code 0}, and less than or equal to the {@linkplain #length() length}
109.1131 - * of this sequence.
109.1132 - *
109.1133 - * @param offset the offset.
109.1134 - * @param c a {@code char}.
109.1135 - * @return a reference to this object.
109.1136 - * @throws IndexOutOfBoundsException if the offset is invalid.
109.1137 - */
109.1138 - public AbstractStringBuilder insert(int offset, char c) {
109.1139 - ensureCapacityInternal(count + 1);
109.1140 - arraycopy(value, offset, value, offset + 1, count - offset);
109.1141 - value[offset] = c;
109.1142 - count += 1;
109.1143 - return this;
109.1144 - }
109.1145 -
109.1146 - /**
109.1147 - * Inserts the string representation of the second {@code int}
109.1148 - * argument into this sequence.
109.1149 - * <p>
109.1150 - * The overall effect is exactly as if the second argument were
109.1151 - * converted to a string by the method {@link String#valueOf(int)},
109.1152 - * and the characters of that string were then
109.1153 - * {@link #insert(int,String) inserted} into this character
109.1154 - * sequence at the indicated offset.
109.1155 - * <p>
109.1156 - * The {@code offset} argument must be greater than or equal to
109.1157 - * {@code 0}, and less than or equal to the {@linkplain #length() length}
109.1158 - * of this sequence.
109.1159 - *
109.1160 - * @param offset the offset.
109.1161 - * @param i an {@code int}.
109.1162 - * @return a reference to this object.
109.1163 - * @throws StringIndexOutOfBoundsException if the offset is invalid.
109.1164 - */
109.1165 - public AbstractStringBuilder insert(int offset, int i) {
109.1166 - return insert(offset, String.valueOf(i));
109.1167 - }
109.1168 -
109.1169 - /**
109.1170 - * Inserts the string representation of the {@code long}
109.1171 - * argument into this sequence.
109.1172 - * <p>
109.1173 - * The overall effect is exactly as if the second argument were
109.1174 - * converted to a string by the method {@link String#valueOf(long)},
109.1175 - * and the characters of that string were then
109.1176 - * {@link #insert(int,String) inserted} into this character
109.1177 - * sequence at the indicated offset.
109.1178 - * <p>
109.1179 - * The {@code offset} argument must be greater than or equal to
109.1180 - * {@code 0}, and less than or equal to the {@linkplain #length() length}
109.1181 - * of this sequence.
109.1182 - *
109.1183 - * @param offset the offset.
109.1184 - * @param l a {@code long}.
109.1185 - * @return a reference to this object.
109.1186 - * @throws StringIndexOutOfBoundsException if the offset is invalid.
109.1187 - */
109.1188 - public AbstractStringBuilder insert(int offset, long l) {
109.1189 - return insert(offset, String.valueOf(l));
109.1190 - }
109.1191 -
109.1192 - /**
109.1193 - * Inserts the string representation of the {@code float}
109.1194 - * argument into this sequence.
109.1195 - * <p>
109.1196 - * The overall effect is exactly as if the second argument were
109.1197 - * converted to a string by the method {@link String#valueOf(float)},
109.1198 - * and the characters of that string were then
109.1199 - * {@link #insert(int,String) inserted} into this character
109.1200 - * sequence at the indicated offset.
109.1201 - * <p>
109.1202 - * The {@code offset} argument must be greater than or equal to
109.1203 - * {@code 0}, and less than or equal to the {@linkplain #length() length}
109.1204 - * of this sequence.
109.1205 - *
109.1206 - * @param offset the offset.
109.1207 - * @param f a {@code float}.
109.1208 - * @return a reference to this object.
109.1209 - * @throws StringIndexOutOfBoundsException if the offset is invalid.
109.1210 - */
109.1211 - public AbstractStringBuilder insert(int offset, float f) {
109.1212 - return insert(offset, String.valueOf(f));
109.1213 - }
109.1214 -
109.1215 - /**
109.1216 - * Inserts the string representation of the {@code double}
109.1217 - * argument into this sequence.
109.1218 - * <p>
109.1219 - * The overall effect is exactly as if the second argument were
109.1220 - * converted to a string by the method {@link String#valueOf(double)},
109.1221 - * and the characters of that string were then
109.1222 - * {@link #insert(int,String) inserted} into this character
109.1223 - * sequence at the indicated offset.
109.1224 - * <p>
109.1225 - * The {@code offset} argument must be greater than or equal to
109.1226 - * {@code 0}, and less than or equal to the {@linkplain #length() length}
109.1227 - * of this sequence.
109.1228 - *
109.1229 - * @param offset the offset.
109.1230 - * @param d a {@code double}.
109.1231 - * @return a reference to this object.
109.1232 - * @throws StringIndexOutOfBoundsException if the offset is invalid.
109.1233 - */
109.1234 - public AbstractStringBuilder insert(int offset, double d) {
109.1235 - return insert(offset, String.valueOf(d));
109.1236 - }
109.1237 -
109.1238 - /**
109.1239 - * Returns the index within this string of the first occurrence of the
109.1240 - * specified substring. The integer returned is the smallest value
109.1241 - * <i>k</i> such that:
109.1242 - * <blockquote><pre>
109.1243 - * this.toString().startsWith(str, <i>k</i>)
109.1244 - * </pre></blockquote>
109.1245 - * is <code>true</code>.
109.1246 - *
109.1247 - * @param str any string.
109.1248 - * @return if the string argument occurs as a substring within this
109.1249 - * object, then the index of the first character of the first
109.1250 - * such substring is returned; if it does not occur as a
109.1251 - * substring, <code>-1</code> is returned.
109.1252 - * @throws java.lang.NullPointerException if <code>str</code> is
109.1253 - * <code>null</code>.
109.1254 - */
109.1255 - public int indexOf(String str) {
109.1256 - return indexOf(str, 0);
109.1257 - }
109.1258 -
109.1259 - /**
109.1260 - * Returns the index within this string of the first occurrence of the
109.1261 - * specified substring, starting at the specified index. The integer
109.1262 - * returned is the smallest value <tt>k</tt> for which:
109.1263 - * <blockquote><pre>
109.1264 - * k >= Math.min(fromIndex, str.length()) &&
109.1265 - * this.toString().startsWith(str, k)
109.1266 - * </pre></blockquote>
109.1267 - * If no such value of <i>k</i> exists, then -1 is returned.
109.1268 - *
109.1269 - * @param str the substring for which to search.
109.1270 - * @param fromIndex the index from which to start the search.
109.1271 - * @return the index within this string of the first occurrence of the
109.1272 - * specified substring, starting at the specified index.
109.1273 - * @throws java.lang.NullPointerException if <code>str</code> is
109.1274 - * <code>null</code>.
109.1275 - */
109.1276 - public int indexOf(String str, int fromIndex) {
109.1277 - return toString().indexOf(str, fromIndex);
109.1278 - }
109.1279 -
109.1280 - /**
109.1281 - * Returns the index within this string of the rightmost occurrence
109.1282 - * of the specified substring. The rightmost empty string "" is
109.1283 - * considered to occur at the index value <code>this.length()</code>.
109.1284 - * The returned index is the largest value <i>k</i> such that
109.1285 - * <blockquote><pre>
109.1286 - * this.toString().startsWith(str, k)
109.1287 - * </pre></blockquote>
109.1288 - * is true.
109.1289 - *
109.1290 - * @param str the substring to search for.
109.1291 - * @return if the string argument occurs one or more times as a substring
109.1292 - * within this object, then the index of the first character of
109.1293 - * the last such substring is returned. If it does not occur as
109.1294 - * a substring, <code>-1</code> is returned.
109.1295 - * @throws java.lang.NullPointerException if <code>str</code> is
109.1296 - * <code>null</code>.
109.1297 - */
109.1298 - public int lastIndexOf(String str) {
109.1299 - return lastIndexOf(str, count);
109.1300 - }
109.1301 -
109.1302 - /**
109.1303 - * Returns the index within this string of the last occurrence of the
109.1304 - * specified substring. The integer returned is the largest value <i>k</i>
109.1305 - * such that:
109.1306 - * <blockquote><pre>
109.1307 - * k <= Math.min(fromIndex, str.length()) &&
109.1308 - * this.toString().startsWith(str, k)
109.1309 - * </pre></blockquote>
109.1310 - * If no such value of <i>k</i> exists, then -1 is returned.
109.1311 - *
109.1312 - * @param str the substring to search for.
109.1313 - * @param fromIndex the index to start the search from.
109.1314 - * @return the index within this sequence of the last occurrence of the
109.1315 - * specified substring.
109.1316 - * @throws java.lang.NullPointerException if <code>str</code> is
109.1317 - * <code>null</code>.
109.1318 - */
109.1319 - public int lastIndexOf(String str, int fromIndex) {
109.1320 - return String.lastIndexOf(value, 0, count,
109.1321 - str.toCharArray(), 0, str.length(), fromIndex);
109.1322 - }
109.1323 -
109.1324 - /**
109.1325 - * Causes this character sequence to be replaced by the reverse of
109.1326 - * the sequence. If there are any surrogate pairs included in the
109.1327 - * sequence, these are treated as single characters for the
109.1328 - * reverse operation. Thus, the order of the high-low surrogates
109.1329 - * is never reversed.
109.1330 - *
109.1331 - * Let <i>n</i> be the character length of this character sequence
109.1332 - * (not the length in <code>char</code> values) just prior to
109.1333 - * execution of the <code>reverse</code> method. Then the
109.1334 - * character at index <i>k</i> in the new character sequence is
109.1335 - * equal to the character at index <i>n-k-1</i> in the old
109.1336 - * character sequence.
109.1337 - *
109.1338 - * <p>Note that the reverse operation may result in producing
109.1339 - * surrogate pairs that were unpaired low-surrogates and
109.1340 - * high-surrogates before the operation. For example, reversing
109.1341 - * "\uDC00\uD800" produces "\uD800\uDC00" which is
109.1342 - * a valid surrogate pair.
109.1343 - *
109.1344 - * @return a reference to this object.
109.1345 - */
109.1346 - public AbstractStringBuilder reverse() {
109.1347 - boolean hasSurrogate = false;
109.1348 - int n = count - 1;
109.1349 - for (int j = (n-1) >> 1; j >= 0; --j) {
109.1350 - char temp = value[j];
109.1351 - char temp2 = value[n - j];
109.1352 - if (!hasSurrogate) {
109.1353 - hasSurrogate = (temp >= Character.MIN_SURROGATE && temp <= Character.MAX_SURROGATE)
109.1354 - || (temp2 >= Character.MIN_SURROGATE && temp2 <= Character.MAX_SURROGATE);
109.1355 - }
109.1356 - value[j] = temp2;
109.1357 - value[n - j] = temp;
109.1358 - }
109.1359 - if (hasSurrogate) {
109.1360 - // Reverse back all valid surrogate pairs
109.1361 - for (int i = 0; i < count - 1; i++) {
109.1362 - char c2 = value[i];
109.1363 - if (Character.isLowSurrogate(c2)) {
109.1364 - char c1 = value[i + 1];
109.1365 - if (Character.isHighSurrogate(c1)) {
109.1366 - value[i++] = c1;
109.1367 - value[i] = c2;
109.1368 - }
109.1369 - }
109.1370 - }
109.1371 - }
109.1372 - return this;
109.1373 - }
109.1374 -
109.1375 - /**
109.1376 - * Returns a string representing the data in this sequence.
109.1377 - * A new <code>String</code> object is allocated and initialized to
109.1378 - * contain the character sequence currently represented by this
109.1379 - * object. This <code>String</code> is then returned. Subsequent
109.1380 - * changes to this sequence do not affect the contents of the
109.1381 - * <code>String</code>.
109.1382 - *
109.1383 - * @return a string representation of this sequence of characters.
109.1384 - */
109.1385 - public abstract String toString();
109.1386 -
109.1387 - /**
109.1388 - * Needed by <tt>String</tt> for the contentEquals method.
109.1389 - */
109.1390 - final char[] getValue() {
109.1391 - return value;
109.1392 - }
109.1393 -
109.1394 - static char[] copyOfRange(char[] original, int from, int to) {
109.1395 - int newLength = to - from;
109.1396 - if (newLength < 0) {
109.1397 - throw new IllegalArgumentException(from + " > " + to);
109.1398 - }
109.1399 - char[] copy = new char[newLength];
109.1400 - arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
109.1401 - return copy;
109.1402 - }
109.1403 -
109.1404 - static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
109.1405 - if (srcBegin < dstBegin) {
109.1406 - while (count-- > 0) {
109.1407 - dst[dstBegin + count] = value[srcBegin + count];
109.1408 - }
109.1409 - } else {
109.1410 - while (count-- > 0) {
109.1411 - dst[dstBegin++] = value[srcBegin++];
109.1412 - }
109.1413 - }
109.1414 - }
109.1415 -
109.1416 - // access system property
109.1417 - static String getProperty(String nm) {
109.1418 - return null;
109.1419 - }
109.1420 -
109.1421 - static char[] copyOf(char[] original, int newLength) {
109.1422 - char[] copy = new char[newLength];
109.1423 - arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
109.1424 - return copy;
109.1425 - }
109.1426 -
109.1427 -}
110.1 --- a/emul/src/main/java/java/lang/Appendable.java Wed Jan 23 20:16:48 2013 +0100
110.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
110.3 @@ -1,121 +0,0 @@
110.4 -/*
110.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
110.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
110.7 - *
110.8 - * This code is free software; you can redistribute it and/or modify it
110.9 - * under the terms of the GNU General Public License version 2 only, as
110.10 - * published by the Free Software Foundation. Oracle designates this
110.11 - * particular file as subject to the "Classpath" exception as provided
110.12 - * by Oracle in the LICENSE file that accompanied this code.
110.13 - *
110.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
110.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
110.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
110.17 - * version 2 for more details (a copy is included in the LICENSE file that
110.18 - * accompanied this code).
110.19 - *
110.20 - * You should have received a copy of the GNU General Public License version
110.21 - * 2 along with this work; if not, write to the Free Software Foundation,
110.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
110.23 - *
110.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
110.25 - * or visit www.oracle.com if you need additional information or have any
110.26 - * questions.
110.27 - */
110.28 -
110.29 -package java.lang;
110.30 -
110.31 -import java.io.IOException;
110.32 -
110.33 -/**
110.34 - * An object to which <tt>char</tt> sequences and values can be appended. The
110.35 - * <tt>Appendable</tt> interface must be implemented by any class whose
110.36 - * instances are intended to receive formatted output from a {@link
110.37 - * java.util.Formatter}.
110.38 - *
110.39 - * <p> The characters to be appended should be valid Unicode characters as
110.40 - * described in <a href="Character.html#unicode">Unicode Character
110.41 - * Representation</a>. Note that supplementary characters may be composed of
110.42 - * multiple 16-bit <tt>char</tt> values.
110.43 - *
110.44 - * <p> Appendables are not necessarily safe for multithreaded access. Thread
110.45 - * safety is the responsibility of classes that extend and implement this
110.46 - * interface.
110.47 - *
110.48 - * <p> Since this interface may be implemented by existing classes
110.49 - * with different styles of error handling there is no guarantee that
110.50 - * errors will be propagated to the invoker.
110.51 - *
110.52 - * @since 1.5
110.53 - */
110.54 -public interface Appendable {
110.55 -
110.56 - /**
110.57 - * Appends the specified character sequence to this <tt>Appendable</tt>.
110.58 - *
110.59 - * <p> Depending on which class implements the character sequence
110.60 - * <tt>csq</tt>, the entire sequence may not be appended. For
110.61 - * instance, if <tt>csq</tt> is a {@link java.nio.CharBuffer} then
110.62 - * the subsequence to append is defined by the buffer's position and limit.
110.63 - *
110.64 - * @param csq
110.65 - * The character sequence to append. If <tt>csq</tt> is
110.66 - * <tt>null</tt>, then the four characters <tt>"null"</tt> are
110.67 - * appended to this Appendable.
110.68 - *
110.69 - * @return A reference to this <tt>Appendable</tt>
110.70 - *
110.71 - * @throws IOException
110.72 - * If an I/O error occurs
110.73 - */
110.74 - Appendable append(CharSequence csq) throws IOException;
110.75 -
110.76 - /**
110.77 - * Appends a subsequence of the specified character sequence to this
110.78 - * <tt>Appendable</tt>.
110.79 - *
110.80 - * <p> An invocation of this method of the form <tt>out.append(csq, start,
110.81 - * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
110.82 - * exactly the same way as the invocation
110.83 - *
110.84 - * <pre>
110.85 - * out.append(csq.subSequence(start, end)) </pre>
110.86 - *
110.87 - * @param csq
110.88 - * The character sequence from which a subsequence will be
110.89 - * appended. If <tt>csq</tt> is <tt>null</tt>, then characters
110.90 - * will be appended as if <tt>csq</tt> contained the four
110.91 - * characters <tt>"null"</tt>.
110.92 - *
110.93 - * @param start
110.94 - * The index of the first character in the subsequence
110.95 - *
110.96 - * @param end
110.97 - * The index of the character following the last character in the
110.98 - * subsequence
110.99 - *
110.100 - * @return A reference to this <tt>Appendable</tt>
110.101 - *
110.102 - * @throws IndexOutOfBoundsException
110.103 - * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
110.104 - * is greater than <tt>end</tt>, or <tt>end</tt> is greater than
110.105 - * <tt>csq.length()</tt>
110.106 - *
110.107 - * @throws IOException
110.108 - * If an I/O error occurs
110.109 - */
110.110 - Appendable append(CharSequence csq, int start, int end) throws IOException;
110.111 -
110.112 - /**
110.113 - * Appends the specified character to this <tt>Appendable</tt>.
110.114 - *
110.115 - * @param c
110.116 - * The character to append
110.117 - *
110.118 - * @return A reference to this <tt>Appendable</tt>
110.119 - *
110.120 - * @throws IOException
110.121 - * If an I/O error occurs
110.122 - */
110.123 - Appendable append(char c) throws IOException;
110.124 -}
111.1 --- a/emul/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java Wed Jan 23 20:16:48 2013 +0100
111.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
111.3 @@ -1,67 +0,0 @@
111.4 -/*
111.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
111.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
111.7 - *
111.8 - * This code is free software; you can redistribute it and/or modify it
111.9 - * under the terms of the GNU General Public License version 2 only, as
111.10 - * published by the Free Software Foundation. Oracle designates this
111.11 - * particular file as subject to the "Classpath" exception as provided
111.12 - * by Oracle in the LICENSE file that accompanied this code.
111.13 - *
111.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
111.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
111.17 - * version 2 for more details (a copy is included in the LICENSE file that
111.18 - * accompanied this code).
111.19 - *
111.20 - * You should have received a copy of the GNU General Public License version
111.21 - * 2 along with this work; if not, write to the Free Software Foundation,
111.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
111.23 - *
111.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
111.25 - * or visit www.oracle.com if you need additional information or have any
111.26 - * questions.
111.27 - */
111.28 -
111.29 -package java.lang;
111.30 -
111.31 -/**
111.32 - * Thrown to indicate that an array has been accessed with an
111.33 - * illegal index. The index is either negative or greater than or
111.34 - * equal to the size of the array.
111.35 - *
111.36 - * @author unascribed
111.37 - * @since JDK1.0
111.38 - */
111.39 -public
111.40 -class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
111.41 - private static final long serialVersionUID = -5116101128118950844L;
111.42 -
111.43 - /**
111.44 - * Constructs an <code>ArrayIndexOutOfBoundsException</code> with no
111.45 - * detail message.
111.46 - */
111.47 - public ArrayIndexOutOfBoundsException() {
111.48 - super();
111.49 - }
111.50 -
111.51 - /**
111.52 - * Constructs a new <code>ArrayIndexOutOfBoundsException</code>
111.53 - * class with an argument indicating the illegal index.
111.54 - *
111.55 - * @param index the illegal index.
111.56 - */
111.57 - public ArrayIndexOutOfBoundsException(int index) {
111.58 - super("Array index out of range: " + index);
111.59 - }
111.60 -
111.61 - /**
111.62 - * Constructs an <code>ArrayIndexOutOfBoundsException</code> class
111.63 - * with the specified detail message.
111.64 - *
111.65 - * @param s the detail message.
111.66 - */
111.67 - public ArrayIndexOutOfBoundsException(String s) {
111.68 - super(s);
111.69 - }
111.70 -}
112.1 --- a/emul/src/main/java/java/lang/AssertionError.java Wed Jan 23 20:16:48 2013 +0100
112.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
112.3 @@ -1,167 +0,0 @@
112.4 -/*
112.5 - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
112.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
112.7 - *
112.8 - * This code is free software; you can redistribute it and/or modify it
112.9 - * under the terms of the GNU General Public License version 2 only, as
112.10 - * published by the Free Software Foundation. Oracle designates this
112.11 - * particular file as subject to the "Classpath" exception as provided
112.12 - * by Oracle in the LICENSE file that accompanied this code.
112.13 - *
112.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
112.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
112.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
112.17 - * version 2 for more details (a copy is included in the LICENSE file that
112.18 - * accompanied this code).
112.19 - *
112.20 - * You should have received a copy of the GNU General Public License version
112.21 - * 2 along with this work; if not, write to the Free Software Foundation,
112.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
112.23 - *
112.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
112.25 - * or visit www.oracle.com if you need additional information or have any
112.26 - * questions.
112.27 - */
112.28 -
112.29 -package java.lang;
112.30 -
112.31 -/**
112.32 - * Thrown to indicate that an assertion has failed.
112.33 - *
112.34 - * <p>The seven one-argument public constructors provided by this
112.35 - * class ensure that the assertion error returned by the invocation:
112.36 - * <pre>
112.37 - * new AssertionError(<i>expression</i>)
112.38 - * </pre>
112.39 - * has as its detail message the <i>string conversion</i> of
112.40 - * <i>expression</i> (as defined in section 15.18.1.1 of
112.41 - * <cite>The Java™ Language Specification</cite>),
112.42 - * regardless of the type of <i>expression</i>.
112.43 - *
112.44 - * @since 1.4
112.45 - */
112.46 -public class AssertionError extends Error {
112.47 - private static final long serialVersionUID = -5013299493970297370L;
112.48 -
112.49 - /**
112.50 - * Constructs an AssertionError with no detail message.
112.51 - */
112.52 - public AssertionError() {
112.53 - }
112.54 -
112.55 - /**
112.56 - * This internal constructor does no processing on its string argument,
112.57 - * even if it is a null reference. The public constructors will
112.58 - * never call this constructor with a null argument.
112.59 - */
112.60 - private AssertionError(String detailMessage) {
112.61 - super(detailMessage);
112.62 - }
112.63 -
112.64 - /**
112.65 - * Constructs an AssertionError with its detail message derived
112.66 - * from the specified object, which is converted to a string as
112.67 - * defined in section 15.18.1.1 of
112.68 - * <cite>The Java™ Language Specification</cite>.
112.69 - *<p>
112.70 - * If the specified object is an instance of {@code Throwable}, it
112.71 - * becomes the <i>cause</i> of the newly constructed assertion error.
112.72 - *
112.73 - * @param detailMessage value to be used in constructing detail message
112.74 - * @see Throwable#getCause()
112.75 - */
112.76 - public AssertionError(Object detailMessage) {
112.77 - this("" + detailMessage);
112.78 - if (detailMessage instanceof Throwable)
112.79 - initCause((Throwable) detailMessage);
112.80 - }
112.81 -
112.82 - /**
112.83 - * Constructs an AssertionError with its detail message derived
112.84 - * from the specified <code>boolean</code>, which is converted to
112.85 - * a string as defined in section 15.18.1.1 of
112.86 - * <cite>The Java™ Language Specification</cite>.
112.87 - *
112.88 - * @param detailMessage value to be used in constructing detail message
112.89 - */
112.90 - public AssertionError(boolean detailMessage) {
112.91 - this("" + detailMessage);
112.92 - }
112.93 -
112.94 - /**
112.95 - * Constructs an AssertionError with its detail message derived
112.96 - * from the specified <code>char</code>, which is converted to a
112.97 - * string as defined in section 15.18.1.1 of
112.98 - * <cite>The Java™ Language Specification</cite>.
112.99 - *
112.100 - * @param detailMessage value to be used in constructing detail message
112.101 - */
112.102 - public AssertionError(char detailMessage) {
112.103 - this("" + detailMessage);
112.104 - }
112.105 -
112.106 - /**
112.107 - * Constructs an AssertionError with its detail message derived
112.108 - * from the specified <code>int</code>, which is converted to a
112.109 - * string as defined in section 15.18.1.1 of
112.110 - * <cite>The Java™ Language Specification</cite>.
112.111 - *
112.112 - * @param detailMessage value to be used in constructing detail message
112.113 - */
112.114 - public AssertionError(int detailMessage) {
112.115 - this("" + detailMessage);
112.116 - }
112.117 -
112.118 - /**
112.119 - * Constructs an AssertionError with its detail message derived
112.120 - * from the specified <code>long</code>, which is converted to a
112.121 - * string as defined in section 15.18.1.1 of
112.122 - * <cite>The Java™ Language Specification</cite>.
112.123 - *
112.124 - * @param detailMessage value to be used in constructing detail message
112.125 - */
112.126 - public AssertionError(long detailMessage) {
112.127 - this("" + detailMessage);
112.128 - }
112.129 -
112.130 - /**
112.131 - * Constructs an AssertionError with its detail message derived
112.132 - * from the specified <code>float</code>, which is converted to a
112.133 - * string as defined in section 15.18.1.1 of
112.134 - * <cite>The Java™ Language Specification</cite>.
112.135 - *
112.136 - * @param detailMessage value to be used in constructing detail message
112.137 - */
112.138 - public AssertionError(float detailMessage) {
112.139 - this("" + detailMessage);
112.140 - }
112.141 -
112.142 - /**
112.143 - * Constructs an AssertionError with its detail message derived
112.144 - * from the specified <code>double</code>, which is converted to a
112.145 - * string as defined in section 15.18.1.1 of
112.146 - * <cite>The Java™ Language Specification</cite>.
112.147 - *
112.148 - * @param detailMessage value to be used in constructing detail message
112.149 - */
112.150 - public AssertionError(double detailMessage) {
112.151 - this("" + detailMessage);
112.152 - }
112.153 -
112.154 - /**
112.155 - * Constructs a new {@code AssertionError} with the specified
112.156 - * detail message and cause.
112.157 - *
112.158 - * <p>Note that the detail message associated with
112.159 - * {@code cause} is <i>not</i> automatically incorporated in
112.160 - * this error's detail message.
112.161 - *
112.162 - * @param message the detail message, may be {@code null}
112.163 - * @param cause the cause, may be {@code null}
112.164 - *
112.165 - * @since 1.7
112.166 - */
112.167 - public AssertionError(String message, Throwable cause) {
112.168 - super(message, cause);
112.169 - }
112.170 -}
113.1 --- a/emul/src/main/java/java/lang/AutoCloseable.java Wed Jan 23 20:16:48 2013 +0100
113.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
113.3 @@ -1,72 +0,0 @@
113.4 -/*
113.5 - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
113.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
113.7 - *
113.8 - * This code is free software; you can redistribute it and/or modify it
113.9 - * under the terms of the GNU General Public License version 2 only, as
113.10 - * published by the Free Software Foundation. Oracle designates this
113.11 - * particular file as subject to the "Classpath" exception as provided
113.12 - * by Oracle in the LICENSE file that accompanied this code.
113.13 - *
113.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
113.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
113.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
113.17 - * version 2 for more details (a copy is included in the LICENSE file that
113.18 - * accompanied this code).
113.19 - *
113.20 - * You should have received a copy of the GNU General Public License version
113.21 - * 2 along with this work; if not, write to the Free Software Foundation,
113.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
113.23 - *
113.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
113.25 - * or visit www.oracle.com if you need additional information or have any
113.26 - * questions.
113.27 - */
113.28 -
113.29 -package java.lang;
113.30 -
113.31 -/**
113.32 - * A resource that must be closed when it is no longer needed.
113.33 - *
113.34 - * @author Josh Bloch
113.35 - * @since 1.7
113.36 - */
113.37 -public interface AutoCloseable {
113.38 - /**
113.39 - * Closes this resource, relinquishing any underlying resources.
113.40 - * This method is invoked automatically on objects managed by the
113.41 - * {@code try}-with-resources statement.
113.42 - *
113.43 - * <p>While this interface method is declared to throw {@code
113.44 - * Exception}, implementers are <em>strongly</em> encouraged to
113.45 - * declare concrete implementations of the {@code close} method to
113.46 - * throw more specific exceptions, or to throw no exception at all
113.47 - * if the close operation cannot fail.
113.48 - *
113.49 - * <p><em>Implementers of this interface are also strongly advised
113.50 - * to not have the {@code close} method throw {@link
113.51 - * InterruptedException}.</em>
113.52 - *
113.53 - * This exception interacts with a thread's interrupted status,
113.54 - * and runtime misbehavior is likely to occur if an {@code
113.55 - * InterruptedException} is {@linkplain Throwable#addSuppressed
113.56 - * suppressed}.
113.57 - *
113.58 - * More generally, if it would cause problems for an
113.59 - * exception to be suppressed, the {@code AutoCloseable.close}
113.60 - * method should not throw it.
113.61 - *
113.62 - * <p>Note that unlike the {@link java.io.Closeable#close close}
113.63 - * method of {@link java.io.Closeable}, this {@code close} method
113.64 - * is <em>not</em> required to be idempotent. In other words,
113.65 - * calling this {@code close} method more than once may have some
113.66 - * visible side effect, unlike {@code Closeable.close} which is
113.67 - * required to have no effect if called more than once.
113.68 - *
113.69 - * However, implementers of this interface are strongly encouraged
113.70 - * to make their {@code close} methods idempotent.
113.71 - *
113.72 - * @throws Exception if this resource cannot be closed
113.73 - */
113.74 - void close() throws Exception;
113.75 -}
114.1 --- a/emul/src/main/java/java/lang/Boolean.java Wed Jan 23 20:16:48 2013 +0100
114.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
114.3 @@ -1,282 +0,0 @@
114.4 -/*
114.5 - * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
114.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
114.7 - *
114.8 - * This code is free software; you can redistribute it and/or modify it
114.9 - * under the terms of the GNU General Public License version 2 only, as
114.10 - * published by the Free Software Foundation. Oracle designates this
114.11 - * particular file as subject to the "Classpath" exception as provided
114.12 - * by Oracle in the LICENSE file that accompanied this code.
114.13 - *
114.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
114.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
114.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
114.17 - * version 2 for more details (a copy is included in the LICENSE file that
114.18 - * accompanied this code).
114.19 - *
114.20 - * You should have received a copy of the GNU General Public License version
114.21 - * 2 along with this work; if not, write to the Free Software Foundation,
114.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
114.23 - *
114.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
114.25 - * or visit www.oracle.com if you need additional information or have any
114.26 - * questions.
114.27 - */
114.28 -
114.29 -package java.lang;
114.30 -
114.31 -/**
114.32 - * The Boolean class wraps a value of the primitive type
114.33 - * {@code boolean} in an object. An object of type
114.34 - * {@code Boolean} contains a single field whose type is
114.35 - * {@code boolean}.
114.36 - * <p>
114.37 - * In addition, this class provides many methods for
114.38 - * converting a {@code boolean} to a {@code String} and a
114.39 - * {@code String} to a {@code boolean}, as well as other
114.40 - * constants and methods useful when dealing with a
114.41 - * {@code boolean}.
114.42 - *
114.43 - * @author Arthur van Hoff
114.44 - * @since JDK1.0
114.45 - */
114.46 -public final class Boolean implements java.io.Serializable,
114.47 - Comparable<Boolean>
114.48 -{
114.49 - /**
114.50 - * The {@code Boolean} object corresponding to the primitive
114.51 - * value {@code true}.
114.52 - */
114.53 - public static final Boolean TRUE = new Boolean(true);
114.54 -
114.55 - /**
114.56 - * The {@code Boolean} object corresponding to the primitive
114.57 - * value {@code false}.
114.58 - */
114.59 - public static final Boolean FALSE = new Boolean(false);
114.60 -
114.61 - /**
114.62 - * The Class object representing the primitive type boolean.
114.63 - *
114.64 - * @since JDK1.1
114.65 - */
114.66 - public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean");
114.67 -
114.68 - /**
114.69 - * The value of the Boolean.
114.70 - *
114.71 - * @serial
114.72 - */
114.73 - private final boolean value;
114.74 -
114.75 - /** use serialVersionUID from JDK 1.0.2 for interoperability */
114.76 - private static final long serialVersionUID = -3665804199014368530L;
114.77 -
114.78 - /**
114.79 - * Allocates a {@code Boolean} object representing the
114.80 - * {@code value} argument.
114.81 - *
114.82 - * <p><b>Note: It is rarely appropriate to use this constructor.
114.83 - * Unless a <i>new</i> instance is required, the static factory
114.84 - * {@link #valueOf(boolean)} is generally a better choice. It is
114.85 - * likely to yield significantly better space and time performance.</b>
114.86 - *
114.87 - * @param value the value of the {@code Boolean}.
114.88 - */
114.89 - public Boolean(boolean value) {
114.90 - this.value = value;
114.91 - }
114.92 -
114.93 - /**
114.94 - * Allocates a {@code Boolean} object representing the value
114.95 - * {@code true} if the string argument is not {@code null}
114.96 - * and is equal, ignoring case, to the string {@code "true"}.
114.97 - * Otherwise, allocate a {@code Boolean} object representing the
114.98 - * value {@code false}. Examples:<p>
114.99 - * {@code new Boolean("True")} produces a {@code Boolean} object
114.100 - * that represents {@code true}.<br>
114.101 - * {@code new Boolean("yes")} produces a {@code Boolean} object
114.102 - * that represents {@code false}.
114.103 - *
114.104 - * @param s the string to be converted to a {@code Boolean}.
114.105 - */
114.106 - public Boolean(String s) {
114.107 - this(toBoolean(s));
114.108 - }
114.109 -
114.110 - /**
114.111 - * Parses the string argument as a boolean. The {@code boolean}
114.112 - * returned represents the value {@code true} if the string argument
114.113 - * is not {@code null} and is equal, ignoring case, to the string
114.114 - * {@code "true"}. <p>
114.115 - * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
114.116 - * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
114.117 - *
114.118 - * @param s the {@code String} containing the boolean
114.119 - * representation to be parsed
114.120 - * @return the boolean represented by the string argument
114.121 - * @since 1.5
114.122 - */
114.123 - public static boolean parseBoolean(String s) {
114.124 - return toBoolean(s);
114.125 - }
114.126 -
114.127 - /**
114.128 - * Returns the value of this {@code Boolean} object as a boolean
114.129 - * primitive.
114.130 - *
114.131 - * @return the primitive {@code boolean} value of this object.
114.132 - */
114.133 - public boolean booleanValue() {
114.134 - return value;
114.135 - }
114.136 -
114.137 - /**
114.138 - * Returns a {@code Boolean} instance representing the specified
114.139 - * {@code boolean} value. If the specified {@code boolean} value
114.140 - * is {@code true}, this method returns {@code Boolean.TRUE};
114.141 - * if it is {@code false}, this method returns {@code Boolean.FALSE}.
114.142 - * If a new {@code Boolean} instance is not required, this method
114.143 - * should generally be used in preference to the constructor
114.144 - * {@link #Boolean(boolean)}, as this method is likely to yield
114.145 - * significantly better space and time performance.
114.146 - *
114.147 - * @param b a boolean value.
114.148 - * @return a {@code Boolean} instance representing {@code b}.
114.149 - * @since 1.4
114.150 - */
114.151 - public static Boolean valueOf(boolean b) {
114.152 - return (b ? TRUE : FALSE);
114.153 - }
114.154 -
114.155 - /**
114.156 - * Returns a {@code Boolean} with a value represented by the
114.157 - * specified string. The {@code Boolean} returned represents a
114.158 - * true value if the string argument is not {@code null}
114.159 - * and is equal, ignoring case, to the string {@code "true"}.
114.160 - *
114.161 - * @param s a string.
114.162 - * @return the {@code Boolean} value represented by the string.
114.163 - */
114.164 - public static Boolean valueOf(String s) {
114.165 - return toBoolean(s) ? TRUE : FALSE;
114.166 - }
114.167 -
114.168 - /**
114.169 - * Returns a {@code String} object representing the specified
114.170 - * boolean. If the specified boolean is {@code true}, then
114.171 - * the string {@code "true"} will be returned, otherwise the
114.172 - * string {@code "false"} will be returned.
114.173 - *
114.174 - * @param b the boolean to be converted
114.175 - * @return the string representation of the specified {@code boolean}
114.176 - * @since 1.4
114.177 - */
114.178 - public static String toString(boolean b) {
114.179 - return b ? "true" : "false";
114.180 - }
114.181 -
114.182 - /**
114.183 - * Returns a {@code String} object representing this Boolean's
114.184 - * value. If this object represents the value {@code true},
114.185 - * a string equal to {@code "true"} is returned. Otherwise, a
114.186 - * string equal to {@code "false"} is returned.
114.187 - *
114.188 - * @return a string representation of this object.
114.189 - */
114.190 - public String toString() {
114.191 - return value ? "true" : "false";
114.192 - }
114.193 -
114.194 - /**
114.195 - * Returns a hash code for this {@code Boolean} object.
114.196 - *
114.197 - * @return the integer {@code 1231} if this object represents
114.198 - * {@code true}; returns the integer {@code 1237} if this
114.199 - * object represents {@code false}.
114.200 - */
114.201 - public int hashCode() {
114.202 - return value ? 1231 : 1237;
114.203 - }
114.204 -
114.205 - /**
114.206 - * Returns {@code true} if and only if the argument is not
114.207 - * {@code null} and is a {@code Boolean} object that
114.208 - * represents the same {@code boolean} value as this object.
114.209 - *
114.210 - * @param obj the object to compare with.
114.211 - * @return {@code true} if the Boolean objects represent the
114.212 - * same value; {@code false} otherwise.
114.213 - */
114.214 - public boolean equals(Object obj) {
114.215 - if (obj instanceof Boolean) {
114.216 - return value == ((Boolean)obj).booleanValue();
114.217 - }
114.218 - return false;
114.219 - }
114.220 -
114.221 - /**
114.222 - * Returns {@code true} if and only if the system property
114.223 - * named by the argument exists and is equal to the string
114.224 - * {@code "true"}. (Beginning with version 1.0.2 of the
114.225 - * Java<small><sup>TM</sup></small> platform, the test of
114.226 - * this string is case insensitive.) A system property is accessible
114.227 - * through {@code getProperty}, a method defined by the
114.228 - * {@code System} class.
114.229 - * <p>
114.230 - * If there is no property with the specified name, or if the specified
114.231 - * name is empty or null, then {@code false} is returned.
114.232 - *
114.233 - * @param name the system property name.
114.234 - * @return the {@code boolean} value of the system property.
114.235 - * @see java.lang.System#getProperty(java.lang.String)
114.236 - * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
114.237 - */
114.238 - public static boolean getBoolean(String name) {
114.239 - boolean result = false;
114.240 - try {
114.241 - result = toBoolean(AbstractStringBuilder.getProperty(name));
114.242 - } catch (IllegalArgumentException e) {
114.243 - } catch (NullPointerException e) {
114.244 - }
114.245 - return result;
114.246 - }
114.247 -
114.248 - /**
114.249 - * Compares this {@code Boolean} instance with another.
114.250 - *
114.251 - * @param b the {@code Boolean} instance to be compared
114.252 - * @return zero if this object represents the same boolean value as the
114.253 - * argument; a positive value if this object represents true
114.254 - * and the argument represents false; and a negative value if
114.255 - * this object represents false and the argument represents true
114.256 - * @throws NullPointerException if the argument is {@code null}
114.257 - * @see Comparable
114.258 - * @since 1.5
114.259 - */
114.260 - public int compareTo(Boolean b) {
114.261 - return compare(this.value, b.value);
114.262 - }
114.263 -
114.264 - /**
114.265 - * Compares two {@code boolean} values.
114.266 - * The value returned is identical to what would be returned by:
114.267 - * <pre>
114.268 - * Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
114.269 - * </pre>
114.270 - *
114.271 - * @param x the first {@code boolean} to compare
114.272 - * @param y the second {@code boolean} to compare
114.273 - * @return the value {@code 0} if {@code x == y};
114.274 - * a value less than {@code 0} if {@code !x && y}; and
114.275 - * a value greater than {@code 0} if {@code x && !y}
114.276 - * @since 1.7
114.277 - */
114.278 - public static int compare(boolean x, boolean y) {
114.279 - return (x == y) ? 0 : (x ? 1 : -1);
114.280 - }
114.281 -
114.282 - private static boolean toBoolean(String name) {
114.283 - return ((name != null) && name.equalsIgnoreCase("true"));
114.284 - }
114.285 -}
115.1 --- a/emul/src/main/java/java/lang/Byte.java Wed Jan 23 20:16:48 2013 +0100
115.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
115.3 @@ -1,452 +0,0 @@
115.4 -/*
115.5 - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
115.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
115.7 - *
115.8 - * This code is free software; you can redistribute it and/or modify it
115.9 - * under the terms of the GNU General Public License version 2 only, as
115.10 - * published by the Free Software Foundation. Oracle designates this
115.11 - * particular file as subject to the "Classpath" exception as provided
115.12 - * by Oracle in the LICENSE file that accompanied this code.
115.13 - *
115.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
115.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
115.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
115.17 - * version 2 for more details (a copy is included in the LICENSE file that
115.18 - * accompanied this code).
115.19 - *
115.20 - * You should have received a copy of the GNU General Public License version
115.21 - * 2 along with this work; if not, write to the Free Software Foundation,
115.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
115.23 - *
115.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
115.25 - * or visit www.oracle.com if you need additional information or have any
115.26 - * questions.
115.27 - */
115.28 -
115.29 -package java.lang;
115.30 -
115.31 -/**
115.32 - *
115.33 - * The {@code Byte} class wraps a value of primitive type {@code byte}
115.34 - * in an object. An object of type {@code Byte} contains a single
115.35 - * field whose type is {@code byte}.
115.36 - *
115.37 - * <p>In addition, this class provides several methods for converting
115.38 - * a {@code byte} to a {@code String} and a {@code String} to a {@code
115.39 - * byte}, as well as other constants and methods useful when dealing
115.40 - * with a {@code byte}.
115.41 - *
115.42 - * @author Nakul Saraiya
115.43 - * @author Joseph D. Darcy
115.44 - * @see java.lang.Number
115.45 - * @since JDK1.1
115.46 - */
115.47 -public final class Byte extends Number implements Comparable<Byte> {
115.48 -
115.49 - /**
115.50 - * A constant holding the minimum value a {@code byte} can
115.51 - * have, -2<sup>7</sup>.
115.52 - */
115.53 - public static final byte MIN_VALUE = -128;
115.54 -
115.55 - /**
115.56 - * A constant holding the maximum value a {@code byte} can
115.57 - * have, 2<sup>7</sup>-1.
115.58 - */
115.59 - public static final byte MAX_VALUE = 127;
115.60 -
115.61 - /**
115.62 - * The {@code Class} instance representing the primitive type
115.63 - * {@code byte}.
115.64 - */
115.65 - public static final Class<Byte> TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
115.66 -
115.67 - /**
115.68 - * Returns a new {@code String} object representing the
115.69 - * specified {@code byte}. The radix is assumed to be 10.
115.70 - *
115.71 - * @param b the {@code byte} to be converted
115.72 - * @return the string representation of the specified {@code byte}
115.73 - * @see java.lang.Integer#toString(int)
115.74 - */
115.75 - public static String toString(byte b) {
115.76 - return Integer.toString((int)b, 10);
115.77 - }
115.78 -
115.79 - private static class ByteCache {
115.80 - private ByteCache(){}
115.81 -
115.82 - static final Byte cache[] = new Byte[-(-128) + 127 + 1];
115.83 -
115.84 - static {
115.85 - for(int i = 0; i < cache.length; i++)
115.86 - cache[i] = new Byte((byte)(i - 128));
115.87 - }
115.88 - }
115.89 -
115.90 - /**
115.91 - * Returns a {@code Byte} instance representing the specified
115.92 - * {@code byte} value.
115.93 - * If a new {@code Byte} instance is not required, this method
115.94 - * should generally be used in preference to the constructor
115.95 - * {@link #Byte(byte)}, as this method is likely to yield
115.96 - * significantly better space and time performance since
115.97 - * all byte values are cached.
115.98 - *
115.99 - * @param b a byte value.
115.100 - * @return a {@code Byte} instance representing {@code b}.
115.101 - * @since 1.5
115.102 - */
115.103 - public static Byte valueOf(byte b) {
115.104 - final int offset = 128;
115.105 - return ByteCache.cache[(int)b + offset];
115.106 - }
115.107 -
115.108 - /**
115.109 - * Parses the string argument as a signed {@code byte} in the
115.110 - * radix specified by the second argument. The characters in the
115.111 - * string must all be digits, of the specified radix (as
115.112 - * determined by whether {@link java.lang.Character#digit(char,
115.113 - * int)} returns a nonnegative value) except that the first
115.114 - * character may be an ASCII minus sign {@code '-'}
115.115 - * (<code>'\u002D'</code>) to indicate a negative value or an
115.116 - * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
115.117 - * indicate a positive value. The resulting {@code byte} value is
115.118 - * returned.
115.119 - *
115.120 - * <p>An exception of type {@code NumberFormatException} is
115.121 - * thrown if any of the following situations occurs:
115.122 - * <ul>
115.123 - * <li> The first argument is {@code null} or is a string of
115.124 - * length zero.
115.125 - *
115.126 - * <li> The radix is either smaller than {@link
115.127 - * java.lang.Character#MIN_RADIX} or larger than {@link
115.128 - * java.lang.Character#MAX_RADIX}.
115.129 - *
115.130 - * <li> Any character of the string is not a digit of the
115.131 - * specified radix, except that the first character may be a minus
115.132 - * sign {@code '-'} (<code>'\u002D'</code>) or plus sign
115.133 - * {@code '+'} (<code>'\u002B'</code>) provided that the
115.134 - * string is longer than length 1.
115.135 - *
115.136 - * <li> The value represented by the string is not a value of type
115.137 - * {@code byte}.
115.138 - * </ul>
115.139 - *
115.140 - * @param s the {@code String} containing the
115.141 - * {@code byte}
115.142 - * representation to be parsed
115.143 - * @param radix the radix to be used while parsing {@code s}
115.144 - * @return the {@code byte} value represented by the string
115.145 - * argument in the specified radix
115.146 - * @throws NumberFormatException If the string does
115.147 - * not contain a parsable {@code byte}.
115.148 - */
115.149 - public static byte parseByte(String s, int radix)
115.150 - throws NumberFormatException {
115.151 - int i = Integer.parseInt(s, radix);
115.152 - if (i < MIN_VALUE || i > MAX_VALUE)
115.153 - throw new NumberFormatException(
115.154 - "Value out of range. Value:\"" + s + "\" Radix:" + radix);
115.155 - return (byte)i;
115.156 - }
115.157 -
115.158 - /**
115.159 - * Parses the string argument as a signed decimal {@code
115.160 - * byte}. The characters in the string must all be decimal digits,
115.161 - * except that the first character may be an ASCII minus sign
115.162 - * {@code '-'} (<code>'\u002D'</code>) to indicate a negative
115.163 - * value or an ASCII plus sign {@code '+'}
115.164 - * (<code>'\u002B'</code>) to indicate a positive value. The
115.165 - * resulting {@code byte} value is returned, exactly as if the
115.166 - * argument and the radix 10 were given as arguments to the {@link
115.167 - * #parseByte(java.lang.String, int)} method.
115.168 - *
115.169 - * @param s a {@code String} containing the
115.170 - * {@code byte} representation to be parsed
115.171 - * @return the {@code byte} value represented by the
115.172 - * argument in decimal
115.173 - * @throws NumberFormatException if the string does not
115.174 - * contain a parsable {@code byte}.
115.175 - */
115.176 - public static byte parseByte(String s) throws NumberFormatException {
115.177 - return parseByte(s, 10);
115.178 - }
115.179 -
115.180 - /**
115.181 - * Returns a {@code Byte} object holding the value
115.182 - * extracted from the specified {@code String} when parsed
115.183 - * with the radix given by the second argument. The first argument
115.184 - * is interpreted as representing a signed {@code byte} in
115.185 - * the radix specified by the second argument, exactly as if the
115.186 - * argument were given to the {@link #parseByte(java.lang.String,
115.187 - * int)} method. The result is a {@code Byte} object that
115.188 - * represents the {@code byte} value specified by the string.
115.189 - *
115.190 - * <p> In other words, this method returns a {@code Byte} object
115.191 - * equal to the value of:
115.192 - *
115.193 - * <blockquote>
115.194 - * {@code new Byte(Byte.parseByte(s, radix))}
115.195 - * </blockquote>
115.196 - *
115.197 - * @param s the string to be parsed
115.198 - * @param radix the radix to be used in interpreting {@code s}
115.199 - * @return a {@code Byte} object holding the value
115.200 - * represented by the string argument in the
115.201 - * specified radix.
115.202 - * @throws NumberFormatException If the {@code String} does
115.203 - * not contain a parsable {@code byte}.
115.204 - */
115.205 - public static Byte valueOf(String s, int radix)
115.206 - throws NumberFormatException {
115.207 - return valueOf(parseByte(s, radix));
115.208 - }
115.209 -
115.210 - /**
115.211 - * Returns a {@code Byte} object holding the value
115.212 - * given by the specified {@code String}. The argument is
115.213 - * interpreted as representing a signed decimal {@code byte},
115.214 - * exactly as if the argument were given to the {@link
115.215 - * #parseByte(java.lang.String)} method. The result is a
115.216 - * {@code Byte} object that represents the {@code byte}
115.217 - * value specified by the string.
115.218 - *
115.219 - * <p> In other words, this method returns a {@code Byte} object
115.220 - * equal to the value of:
115.221 - *
115.222 - * <blockquote>
115.223 - * {@code new Byte(Byte.parseByte(s))}
115.224 - * </blockquote>
115.225 - *
115.226 - * @param s the string to be parsed
115.227 - * @return a {@code Byte} object holding the value
115.228 - * represented by the string argument
115.229 - * @throws NumberFormatException If the {@code String} does
115.230 - * not contain a parsable {@code byte}.
115.231 - */
115.232 - public static Byte valueOf(String s) throws NumberFormatException {
115.233 - return valueOf(s, 10);
115.234 - }
115.235 -
115.236 - /**
115.237 - * Decodes a {@code String} into a {@code Byte}.
115.238 - * Accepts decimal, hexadecimal, and octal numbers given by
115.239 - * the following grammar:
115.240 - *
115.241 - * <blockquote>
115.242 - * <dl>
115.243 - * <dt><i>DecodableString:</i>
115.244 - * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
115.245 - * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
115.246 - * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
115.247 - * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
115.248 - * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
115.249 - * <p>
115.250 - * <dt><i>Sign:</i>
115.251 - * <dd>{@code -}
115.252 - * <dd>{@code +}
115.253 - * </dl>
115.254 - * </blockquote>
115.255 - *
115.256 - * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
115.257 - * are as defined in section 3.10.1 of
115.258 - * <cite>The Java™ Language Specification</cite>,
115.259 - * except that underscores are not accepted between digits.
115.260 - *
115.261 - * <p>The sequence of characters following an optional
115.262 - * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
115.263 - * "{@code #}", or leading zero) is parsed as by the {@code
115.264 - * Byte.parseByte} method with the indicated radix (10, 16, or 8).
115.265 - * This sequence of characters must represent a positive value or
115.266 - * a {@link NumberFormatException} will be thrown. The result is
115.267 - * negated if first character of the specified {@code String} is
115.268 - * the minus sign. No whitespace characters are permitted in the
115.269 - * {@code String}.
115.270 - *
115.271 - * @param nm the {@code String} to decode.
115.272 - * @return a {@code Byte} object holding the {@code byte}
115.273 - * value represented by {@code nm}
115.274 - * @throws NumberFormatException if the {@code String} does not
115.275 - * contain a parsable {@code byte}.
115.276 - * @see java.lang.Byte#parseByte(java.lang.String, int)
115.277 - */
115.278 - public static Byte decode(String nm) throws NumberFormatException {
115.279 - int i = Integer.decode(nm);
115.280 - if (i < MIN_VALUE || i > MAX_VALUE)
115.281 - throw new NumberFormatException(
115.282 - "Value " + i + " out of range from input " + nm);
115.283 - return valueOf((byte)i);
115.284 - }
115.285 -
115.286 - /**
115.287 - * The value of the {@code Byte}.
115.288 - *
115.289 - * @serial
115.290 - */
115.291 - private final byte value;
115.292 -
115.293 - /**
115.294 - * Constructs a newly allocated {@code Byte} object that
115.295 - * represents the specified {@code byte} value.
115.296 - *
115.297 - * @param value the value to be represented by the
115.298 - * {@code Byte}.
115.299 - */
115.300 - public Byte(byte value) {
115.301 - this.value = value;
115.302 - }
115.303 -
115.304 - /**
115.305 - * Constructs a newly allocated {@code Byte} object that
115.306 - * represents the {@code byte} value indicated by the
115.307 - * {@code String} parameter. The string is converted to a
115.308 - * {@code byte} value in exactly the manner used by the
115.309 - * {@code parseByte} method for radix 10.
115.310 - *
115.311 - * @param s the {@code String} to be converted to a
115.312 - * {@code Byte}
115.313 - * @throws NumberFormatException If the {@code String}
115.314 - * does not contain a parsable {@code byte}.
115.315 - * @see java.lang.Byte#parseByte(java.lang.String, int)
115.316 - */
115.317 - public Byte(String s) throws NumberFormatException {
115.318 - this.value = parseByte(s, 10);
115.319 - }
115.320 -
115.321 - /**
115.322 - * Returns the value of this {@code Byte} as a
115.323 - * {@code byte}.
115.324 - */
115.325 - public byte byteValue() {
115.326 - return value;
115.327 - }
115.328 -
115.329 - /**
115.330 - * Returns the value of this {@code Byte} as a
115.331 - * {@code short}.
115.332 - */
115.333 - public short shortValue() {
115.334 - return (short)value;
115.335 - }
115.336 -
115.337 - /**
115.338 - * Returns the value of this {@code Byte} as an
115.339 - * {@code int}.
115.340 - */
115.341 - public int intValue() {
115.342 - return (int)value;
115.343 - }
115.344 -
115.345 - /**
115.346 - * Returns the value of this {@code Byte} as a
115.347 - * {@code long}.
115.348 - */
115.349 - public long longValue() {
115.350 - return (long)value;
115.351 - }
115.352 -
115.353 - /**
115.354 - * Returns the value of this {@code Byte} as a
115.355 - * {@code float}.
115.356 - */
115.357 - public float floatValue() {
115.358 - return (float)value;
115.359 - }
115.360 -
115.361 - /**
115.362 - * Returns the value of this {@code Byte} as a
115.363 - * {@code double}.
115.364 - */
115.365 - public double doubleValue() {
115.366 - return (double)value;
115.367 - }
115.368 -
115.369 - /**
115.370 - * Returns a {@code String} object representing this
115.371 - * {@code Byte}'s value. The value is converted to signed
115.372 - * decimal representation and returned as a string, exactly as if
115.373 - * the {@code byte} value were given as an argument to the
115.374 - * {@link java.lang.Byte#toString(byte)} method.
115.375 - *
115.376 - * @return a string representation of the value of this object in
115.377 - * base 10.
115.378 - */
115.379 - public String toString() {
115.380 - return Integer.toString((int)value);
115.381 - }
115.382 -
115.383 - /**
115.384 - * Returns a hash code for this {@code Byte}; equal to the result
115.385 - * of invoking {@code intValue()}.
115.386 - *
115.387 - * @return a hash code value for this {@code Byte}
115.388 - */
115.389 - public int hashCode() {
115.390 - return (int)value;
115.391 - }
115.392 -
115.393 - /**
115.394 - * Compares this object to the specified object. The result is
115.395 - * {@code true} if and only if the argument is not
115.396 - * {@code null} and is a {@code Byte} object that
115.397 - * contains the same {@code byte} value as this object.
115.398 - *
115.399 - * @param obj the object to compare with
115.400 - * @return {@code true} if the objects are the same;
115.401 - * {@code false} otherwise.
115.402 - */
115.403 - public boolean equals(Object obj) {
115.404 - if (obj instanceof Byte) {
115.405 - return value == ((Byte)obj).byteValue();
115.406 - }
115.407 - return false;
115.408 - }
115.409 -
115.410 - /**
115.411 - * Compares two {@code Byte} objects numerically.
115.412 - *
115.413 - * @param anotherByte the {@code Byte} to be compared.
115.414 - * @return the value {@code 0} if this {@code Byte} is
115.415 - * equal to the argument {@code Byte}; a value less than
115.416 - * {@code 0} if this {@code Byte} is numerically less
115.417 - * than the argument {@code Byte}; and a value greater than
115.418 - * {@code 0} if this {@code Byte} is numerically
115.419 - * greater than the argument {@code Byte} (signed
115.420 - * comparison).
115.421 - * @since 1.2
115.422 - */
115.423 - public int compareTo(Byte anotherByte) {
115.424 - return compare(this.value, anotherByte.value);
115.425 - }
115.426 -
115.427 - /**
115.428 - * Compares two {@code byte} values numerically.
115.429 - * The value returned is identical to what would be returned by:
115.430 - * <pre>
115.431 - * Byte.valueOf(x).compareTo(Byte.valueOf(y))
115.432 - * </pre>
115.433 - *
115.434 - * @param x the first {@code byte} to compare
115.435 - * @param y the second {@code byte} to compare
115.436 - * @return the value {@code 0} if {@code x == y};
115.437 - * a value less than {@code 0} if {@code x < y}; and
115.438 - * a value greater than {@code 0} if {@code x > y}
115.439 - * @since 1.7
115.440 - */
115.441 - public static int compare(byte x, byte y) {
115.442 - return x - y;
115.443 - }
115.444 -
115.445 - /**
115.446 - * The number of bits used to represent a {@code byte} value in two's
115.447 - * complement binary form.
115.448 - *
115.449 - * @since 1.5
115.450 - */
115.451 - public static final int SIZE = 8;
115.452 -
115.453 - /** use serialVersionUID from JDK 1.1. for interoperability */
115.454 - private static final long serialVersionUID = -7183698231559129828L;
115.455 -}
116.1 --- a/emul/src/main/java/java/lang/CharSequence.java Wed Jan 23 20:16:48 2013 +0100
116.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
116.3 @@ -1,111 +0,0 @@
116.4 -/*
116.5 - * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
116.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
116.7 - *
116.8 - * This code is free software; you can redistribute it and/or modify it
116.9 - * under the terms of the GNU General Public License version 2 only, as
116.10 - * published by the Free Software Foundation. Oracle designates this
116.11 - * particular file as subject to the "Classpath" exception as provided
116.12 - * by Oracle in the LICENSE file that accompanied this code.
116.13 - *
116.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
116.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
116.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
116.17 - * version 2 for more details (a copy is included in the LICENSE file that
116.18 - * accompanied this code).
116.19 - *
116.20 - * You should have received a copy of the GNU General Public License version
116.21 - * 2 along with this work; if not, write to the Free Software Foundation,
116.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
116.23 - *
116.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
116.25 - * or visit www.oracle.com if you need additional information or have any
116.26 - * questions.
116.27 - */
116.28 -
116.29 -package java.lang;
116.30 -
116.31 -
116.32 -/**
116.33 - * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
116.34 - * interface provides uniform, read-only access to many different kinds of
116.35 - * <code>char</code> sequences.
116.36 - * A <code>char</code> value represents a character in the <i>Basic
116.37 - * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
116.38 - * href="Character.html#unicode">Unicode Character Representation</a> for details.
116.39 - *
116.40 - * <p> This interface does not refine the general contracts of the {@link
116.41 - * java.lang.Object#equals(java.lang.Object) equals} and {@link
116.42 - * java.lang.Object#hashCode() hashCode} methods. The result of comparing two
116.43 - * objects that implement <tt>CharSequence</tt> is therefore, in general,
116.44 - * undefined. Each object may be implemented by a different class, and there
116.45 - * is no guarantee that each class will be capable of testing its instances
116.46 - * for equality with those of the other. It is therefore inappropriate to use
116.47 - * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
116.48 - * a map. </p>
116.49 - *
116.50 - * @author Mike McCloskey
116.51 - * @since 1.4
116.52 - * @spec JSR-51
116.53 - */
116.54 -
116.55 -public interface CharSequence {
116.56 -
116.57 - /**
116.58 - * Returns the length of this character sequence. The length is the number
116.59 - * of 16-bit <code>char</code>s in the sequence.</p>
116.60 - *
116.61 - * @return the number of <code>char</code>s in this sequence
116.62 - */
116.63 - int length();
116.64 -
116.65 - /**
116.66 - * Returns the <code>char</code> value at the specified index. An index ranges from zero
116.67 - * to <tt>length() - 1</tt>. The first <code>char</code> value of the sequence is at
116.68 - * index zero, the next at index one, and so on, as for array
116.69 - * indexing. </p>
116.70 - *
116.71 - * <p>If the <code>char</code> value specified by the index is a
116.72 - * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
116.73 - * value is returned.
116.74 - *
116.75 - * @param index the index of the <code>char</code> value to be returned
116.76 - *
116.77 - * @return the specified <code>char</code> value
116.78 - *
116.79 - * @throws IndexOutOfBoundsException
116.80 - * if the <tt>index</tt> argument is negative or not less than
116.81 - * <tt>length()</tt>
116.82 - */
116.83 - char charAt(int index);
116.84 -
116.85 - /**
116.86 - * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
116.87 - * The subsequence starts with the <code>char</code> value at the specified index and
116.88 - * ends with the <code>char</code> value at index <tt>end - 1</tt>. The length
116.89 - * (in <code>char</code>s) of the
116.90 - * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
116.91 - * then an empty sequence is returned. </p>
116.92 - *
116.93 - * @param start the start index, inclusive
116.94 - * @param end the end index, exclusive
116.95 - *
116.96 - * @return the specified subsequence
116.97 - *
116.98 - * @throws IndexOutOfBoundsException
116.99 - * if <tt>start</tt> or <tt>end</tt> are negative,
116.100 - * if <tt>end</tt> is greater than <tt>length()</tt>,
116.101 - * or if <tt>start</tt> is greater than <tt>end</tt>
116.102 - */
116.103 - CharSequence subSequence(int start, int end);
116.104 -
116.105 - /**
116.106 - * Returns a string containing the characters in this sequence in the same
116.107 - * order as this sequence. The length of the string will be the length of
116.108 - * this sequence. </p>
116.109 - *
116.110 - * @return a string consisting of exactly this sequence of characters
116.111 - */
116.112 - public String toString();
116.113 -
116.114 -}
117.1 --- a/emul/src/main/java/java/lang/Character.java Wed Jan 23 20:16:48 2013 +0100
117.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
117.3 @@ -1,2382 +0,0 @@
117.4 -/*
117.5 - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
117.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
117.7 - *
117.8 - * This code is free software; you can redistribute it and/or modify it
117.9 - * under the terms of the GNU General Public License version 2 only, as
117.10 - * published by the Free Software Foundation. Oracle designates this
117.11 - * particular file as subject to the "Classpath" exception as provided
117.12 - * by Oracle in the LICENSE file that accompanied this code.
117.13 - *
117.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
117.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
117.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
117.17 - * version 2 for more details (a copy is included in the LICENSE file that
117.18 - * accompanied this code).
117.19 - *
117.20 - * You should have received a copy of the GNU General Public License version
117.21 - * 2 along with this work; if not, write to the Free Software Foundation,
117.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
117.23 - *
117.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
117.25 - * or visit www.oracle.com if you need additional information or have any
117.26 - * questions.
117.27 - */
117.28 -
117.29 -package java.lang;
117.30 -
117.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
117.32 -
117.33 -/**
117.34 - * The {@code Character} class wraps a value of the primitive
117.35 - * type {@code char} in an object. An object of type
117.36 - * {@code Character} contains a single field whose type is
117.37 - * {@code char}.
117.38 - * <p>
117.39 - * In addition, this class provides several methods for determining
117.40 - * a character's category (lowercase letter, digit, etc.) and for converting
117.41 - * characters from uppercase to lowercase and vice versa.
117.42 - * <p>
117.43 - * Character information is based on the Unicode Standard, version 6.0.0.
117.44 - * <p>
117.45 - * The methods and data of class {@code Character} are defined by
117.46 - * the information in the <i>UnicodeData</i> file that is part of the
117.47 - * Unicode Character Database maintained by the Unicode
117.48 - * Consortium. This file specifies various properties including name
117.49 - * and general category for every defined Unicode code point or
117.50 - * character range.
117.51 - * <p>
117.52 - * The file and its description are available from the Unicode Consortium at:
117.53 - * <ul>
117.54 - * <li><a href="http://www.unicode.org">http://www.unicode.org</a>
117.55 - * </ul>
117.56 - *
117.57 - * <h4><a name="unicode">Unicode Character Representations</a></h4>
117.58 - *
117.59 - * <p>The {@code char} data type (and therefore the value that a
117.60 - * {@code Character} object encapsulates) are based on the
117.61 - * original Unicode specification, which defined characters as
117.62 - * fixed-width 16-bit entities. The Unicode Standard has since been
117.63 - * changed to allow for characters whose representation requires more
117.64 - * than 16 bits. The range of legal <em>code point</em>s is now
117.65 - * U+0000 to U+10FFFF, known as <em>Unicode scalar value</em>.
117.66 - * (Refer to the <a
117.67 - * href="http://www.unicode.org/reports/tr27/#notation"><i>
117.68 - * definition</i></a> of the U+<i>n</i> notation in the Unicode
117.69 - * Standard.)
117.70 - *
117.71 - * <p><a name="BMP">The set of characters from U+0000 to U+FFFF is
117.72 - * sometimes referred to as the <em>Basic Multilingual Plane (BMP)</em>.
117.73 - * <a name="supplementary">Characters</a> whose code points are greater
117.74 - * than U+FFFF are called <em>supplementary character</em>s. The Java
117.75 - * platform uses the UTF-16 representation in {@code char} arrays and
117.76 - * in the {@code String} and {@code StringBuffer} classes. In
117.77 - * this representation, supplementary characters are represented as a pair
117.78 - * of {@code char} values, the first from the <em>high-surrogates</em>
117.79 - * range, (\uD800-\uDBFF), the second from the
117.80 - * <em>low-surrogates</em> range (\uDC00-\uDFFF).
117.81 - *
117.82 - * <p>A {@code char} value, therefore, represents Basic
117.83 - * Multilingual Plane (BMP) code points, including the surrogate
117.84 - * code points, or code units of the UTF-16 encoding. An
117.85 - * {@code int} value represents all Unicode code points,
117.86 - * including supplementary code points. The lower (least significant)
117.87 - * 21 bits of {@code int} are used to represent Unicode code
117.88 - * points and the upper (most significant) 11 bits must be zero.
117.89 - * Unless otherwise specified, the behavior with respect to
117.90 - * supplementary characters and surrogate {@code char} values is
117.91 - * as follows:
117.92 - *
117.93 - * <ul>
117.94 - * <li>The methods that only accept a {@code char} value cannot support
117.95 - * supplementary characters. They treat {@code char} values from the
117.96 - * surrogate ranges as undefined characters. For example,
117.97 - * {@code Character.isLetter('\u005CuD840')} returns {@code false}, even though
117.98 - * this specific value if followed by any low-surrogate value in a string
117.99 - * would represent a letter.
117.100 - *
117.101 - * <li>The methods that accept an {@code int} value support all
117.102 - * Unicode characters, including supplementary characters. For
117.103 - * example, {@code Character.isLetter(0x2F81A)} returns
117.104 - * {@code true} because the code point value represents a letter
117.105 - * (a CJK ideograph).
117.106 - * </ul>
117.107 - *
117.108 - * <p>In the Java SE API documentation, <em>Unicode code point</em> is
117.109 - * used for character values in the range between U+0000 and U+10FFFF,
117.110 - * and <em>Unicode code unit</em> is used for 16-bit
117.111 - * {@code char} values that are code units of the <em>UTF-16</em>
117.112 - * encoding. For more information on Unicode terminology, refer to the
117.113 - * <a href="http://www.unicode.org/glossary/">Unicode Glossary</a>.
117.114 - *
117.115 - * @author Lee Boynton
117.116 - * @author Guy Steele
117.117 - * @author Akira Tanaka
117.118 - * @author Martin Buchholz
117.119 - * @author Ulf Zibis
117.120 - * @since 1.0
117.121 - */
117.122 -public final
117.123 -class Character implements java.io.Serializable, Comparable<Character> {
117.124 - /**
117.125 - * The minimum radix available for conversion to and from strings.
117.126 - * The constant value of this field is the smallest value permitted
117.127 - * for the radix argument in radix-conversion methods such as the
117.128 - * {@code digit} method, the {@code forDigit} method, and the
117.129 - * {@code toString} method of class {@code Integer}.
117.130 - *
117.131 - * @see Character#digit(char, int)
117.132 - * @see Character#forDigit(int, int)
117.133 - * @see Integer#toString(int, int)
117.134 - * @see Integer#valueOf(String)
117.135 - */
117.136 - public static final int MIN_RADIX = 2;
117.137 -
117.138 - /**
117.139 - * The maximum radix available for conversion to and from strings.
117.140 - * The constant value of this field is the largest value permitted
117.141 - * for the radix argument in radix-conversion methods such as the
117.142 - * {@code digit} method, the {@code forDigit} method, and the
117.143 - * {@code toString} method of class {@code Integer}.
117.144 - *
117.145 - * @see Character#digit(char, int)
117.146 - * @see Character#forDigit(int, int)
117.147 - * @see Integer#toString(int, int)
117.148 - * @see Integer#valueOf(String)
117.149 - */
117.150 - public static final int MAX_RADIX = 36;
117.151 -
117.152 - /**
117.153 - * The constant value of this field is the smallest value of type
117.154 - * {@code char}, {@code '\u005Cu0000'}.
117.155 - *
117.156 - * @since 1.0.2
117.157 - */
117.158 - public static final char MIN_VALUE = '\u0000';
117.159 -
117.160 - /**
117.161 - * The constant value of this field is the largest value of type
117.162 - * {@code char}, {@code '\u005CuFFFF'}.
117.163 - *
117.164 - * @since 1.0.2
117.165 - */
117.166 - public static final char MAX_VALUE = '\uFFFF';
117.167 -
117.168 - /**
117.169 - * The {@code Class} instance representing the primitive type
117.170 - * {@code char}.
117.171 - *
117.172 - * @since 1.1
117.173 - */
117.174 - public static final Class<Character> TYPE = Class.getPrimitiveClass("char");
117.175 -
117.176 - /*
117.177 - * Normative general types
117.178 - */
117.179 -
117.180 - /*
117.181 - * General character types
117.182 - */
117.183 -
117.184 - /**
117.185 - * General category "Cn" in the Unicode specification.
117.186 - * @since 1.1
117.187 - */
117.188 - public static final byte UNASSIGNED = 0;
117.189 -
117.190 - /**
117.191 - * General category "Lu" in the Unicode specification.
117.192 - * @since 1.1
117.193 - */
117.194 - public static final byte UPPERCASE_LETTER = 1;
117.195 -
117.196 - /**
117.197 - * General category "Ll" in the Unicode specification.
117.198 - * @since 1.1
117.199 - */
117.200 - public static final byte LOWERCASE_LETTER = 2;
117.201 -
117.202 - /**
117.203 - * General category "Lt" in the Unicode specification.
117.204 - * @since 1.1
117.205 - */
117.206 - public static final byte TITLECASE_LETTER = 3;
117.207 -
117.208 - /**
117.209 - * General category "Lm" in the Unicode specification.
117.210 - * @since 1.1
117.211 - */
117.212 - public static final byte MODIFIER_LETTER = 4;
117.213 -
117.214 - /**
117.215 - * General category "Lo" in the Unicode specification.
117.216 - * @since 1.1
117.217 - */
117.218 - public static final byte OTHER_LETTER = 5;
117.219 -
117.220 - /**
117.221 - * General category "Mn" in the Unicode specification.
117.222 - * @since 1.1
117.223 - */
117.224 - public static final byte NON_SPACING_MARK = 6;
117.225 -
117.226 - /**
117.227 - * General category "Me" in the Unicode specification.
117.228 - * @since 1.1
117.229 - */
117.230 - public static final byte ENCLOSING_MARK = 7;
117.231 -
117.232 - /**
117.233 - * General category "Mc" in the Unicode specification.
117.234 - * @since 1.1
117.235 - */
117.236 - public static final byte COMBINING_SPACING_MARK = 8;
117.237 -
117.238 - /**
117.239 - * General category "Nd" in the Unicode specification.
117.240 - * @since 1.1
117.241 - */
117.242 - public static final byte DECIMAL_DIGIT_NUMBER = 9;
117.243 -
117.244 - /**
117.245 - * General category "Nl" in the Unicode specification.
117.246 - * @since 1.1
117.247 - */
117.248 - public static final byte LETTER_NUMBER = 10;
117.249 -
117.250 - /**
117.251 - * General category "No" in the Unicode specification.
117.252 - * @since 1.1
117.253 - */
117.254 - public static final byte OTHER_NUMBER = 11;
117.255 -
117.256 - /**
117.257 - * General category "Zs" in the Unicode specification.
117.258 - * @since 1.1
117.259 - */
117.260 - public static final byte SPACE_SEPARATOR = 12;
117.261 -
117.262 - /**
117.263 - * General category "Zl" in the Unicode specification.
117.264 - * @since 1.1
117.265 - */
117.266 - public static final byte LINE_SEPARATOR = 13;
117.267 -
117.268 - /**
117.269 - * General category "Zp" in the Unicode specification.
117.270 - * @since 1.1
117.271 - */
117.272 - public static final byte PARAGRAPH_SEPARATOR = 14;
117.273 -
117.274 - /**
117.275 - * General category "Cc" in the Unicode specification.
117.276 - * @since 1.1
117.277 - */
117.278 - public static final byte CONTROL = 15;
117.279 -
117.280 - /**
117.281 - * General category "Cf" in the Unicode specification.
117.282 - * @since 1.1
117.283 - */
117.284 - public static final byte FORMAT = 16;
117.285 -
117.286 - /**
117.287 - * General category "Co" in the Unicode specification.
117.288 - * @since 1.1
117.289 - */
117.290 - public static final byte PRIVATE_USE = 18;
117.291 -
117.292 - /**
117.293 - * General category "Cs" in the Unicode specification.
117.294 - * @since 1.1
117.295 - */
117.296 - public static final byte SURROGATE = 19;
117.297 -
117.298 - /**
117.299 - * General category "Pd" in the Unicode specification.
117.300 - * @since 1.1
117.301 - */
117.302 - public static final byte DASH_PUNCTUATION = 20;
117.303 -
117.304 - /**
117.305 - * General category "Ps" in the Unicode specification.
117.306 - * @since 1.1
117.307 - */
117.308 - public static final byte START_PUNCTUATION = 21;
117.309 -
117.310 - /**
117.311 - * General category "Pe" in the Unicode specification.
117.312 - * @since 1.1
117.313 - */
117.314 - public static final byte END_PUNCTUATION = 22;
117.315 -
117.316 - /**
117.317 - * General category "Pc" in the Unicode specification.
117.318 - * @since 1.1
117.319 - */
117.320 - public static final byte CONNECTOR_PUNCTUATION = 23;
117.321 -
117.322 - /**
117.323 - * General category "Po" in the Unicode specification.
117.324 - * @since 1.1
117.325 - */
117.326 - public static final byte OTHER_PUNCTUATION = 24;
117.327 -
117.328 - /**
117.329 - * General category "Sm" in the Unicode specification.
117.330 - * @since 1.1
117.331 - */
117.332 - public static final byte MATH_SYMBOL = 25;
117.333 -
117.334 - /**
117.335 - * General category "Sc" in the Unicode specification.
117.336 - * @since 1.1
117.337 - */
117.338 - public static final byte CURRENCY_SYMBOL = 26;
117.339 -
117.340 - /**
117.341 - * General category "Sk" in the Unicode specification.
117.342 - * @since 1.1
117.343 - */
117.344 - public static final byte MODIFIER_SYMBOL = 27;
117.345 -
117.346 - /**
117.347 - * General category "So" in the Unicode specification.
117.348 - * @since 1.1
117.349 - */
117.350 - public static final byte OTHER_SYMBOL = 28;
117.351 -
117.352 - /**
117.353 - * General category "Pi" in the Unicode specification.
117.354 - * @since 1.4
117.355 - */
117.356 - public static final byte INITIAL_QUOTE_PUNCTUATION = 29;
117.357 -
117.358 - /**
117.359 - * General category "Pf" in the Unicode specification.
117.360 - * @since 1.4
117.361 - */
117.362 - public static final byte FINAL_QUOTE_PUNCTUATION = 30;
117.363 -
117.364 - /**
117.365 - * Error flag. Use int (code point) to avoid confusion with U+FFFF.
117.366 - */
117.367 - static final int ERROR = 0xFFFFFFFF;
117.368 -
117.369 -
117.370 - /**
117.371 - * Undefined bidirectional character type. Undefined {@code char}
117.372 - * values have undefined directionality in the Unicode specification.
117.373 - * @since 1.4
117.374 - */
117.375 - public static final byte DIRECTIONALITY_UNDEFINED = -1;
117.376 -
117.377 - /**
117.378 - * Strong bidirectional character type "L" in the Unicode specification.
117.379 - * @since 1.4
117.380 - */
117.381 - public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0;
117.382 -
117.383 - /**
117.384 - * Strong bidirectional character type "R" in the Unicode specification.
117.385 - * @since 1.4
117.386 - */
117.387 - public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1;
117.388 -
117.389 - /**
117.390 - * Strong bidirectional character type "AL" in the Unicode specification.
117.391 - * @since 1.4
117.392 - */
117.393 - public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2;
117.394 -
117.395 - /**
117.396 - * Weak bidirectional character type "EN" in the Unicode specification.
117.397 - * @since 1.4
117.398 - */
117.399 - public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3;
117.400 -
117.401 - /**
117.402 - * Weak bidirectional character type "ES" in the Unicode specification.
117.403 - * @since 1.4
117.404 - */
117.405 - public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4;
117.406 -
117.407 - /**
117.408 - * Weak bidirectional character type "ET" in the Unicode specification.
117.409 - * @since 1.4
117.410 - */
117.411 - public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5;
117.412 -
117.413 - /**
117.414 - * Weak bidirectional character type "AN" in the Unicode specification.
117.415 - * @since 1.4
117.416 - */
117.417 - public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6;
117.418 -
117.419 - /**
117.420 - * Weak bidirectional character type "CS" in the Unicode specification.
117.421 - * @since 1.4
117.422 - */
117.423 - public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7;
117.424 -
117.425 - /**
117.426 - * Weak bidirectional character type "NSM" in the Unicode specification.
117.427 - * @since 1.4
117.428 - */
117.429 - public static final byte DIRECTIONALITY_NONSPACING_MARK = 8;
117.430 -
117.431 - /**
117.432 - * Weak bidirectional character type "BN" in the Unicode specification.
117.433 - * @since 1.4
117.434 - */
117.435 - public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9;
117.436 -
117.437 - /**
117.438 - * Neutral bidirectional character type "B" in the Unicode specification.
117.439 - * @since 1.4
117.440 - */
117.441 - public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10;
117.442 -
117.443 - /**
117.444 - * Neutral bidirectional character type "S" in the Unicode specification.
117.445 - * @since 1.4
117.446 - */
117.447 - public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11;
117.448 -
117.449 - /**
117.450 - * Neutral bidirectional character type "WS" in the Unicode specification.
117.451 - * @since 1.4
117.452 - */
117.453 - public static final byte DIRECTIONALITY_WHITESPACE = 12;
117.454 -
117.455 - /**
117.456 - * Neutral bidirectional character type "ON" in the Unicode specification.
117.457 - * @since 1.4
117.458 - */
117.459 - public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13;
117.460 -
117.461 - /**
117.462 - * Strong bidirectional character type "LRE" in the Unicode specification.
117.463 - * @since 1.4
117.464 - */
117.465 - public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14;
117.466 -
117.467 - /**
117.468 - * Strong bidirectional character type "LRO" in the Unicode specification.
117.469 - * @since 1.4
117.470 - */
117.471 - public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15;
117.472 -
117.473 - /**
117.474 - * Strong bidirectional character type "RLE" in the Unicode specification.
117.475 - * @since 1.4
117.476 - */
117.477 - public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16;
117.478 -
117.479 - /**
117.480 - * Strong bidirectional character type "RLO" in the Unicode specification.
117.481 - * @since 1.4
117.482 - */
117.483 - public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17;
117.484 -
117.485 - /**
117.486 - * Weak bidirectional character type "PDF" in the Unicode specification.
117.487 - * @since 1.4
117.488 - */
117.489 - public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;
117.490 -
117.491 - /**
117.492 - * The minimum value of a
117.493 - * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
117.494 - * Unicode high-surrogate code unit</a>
117.495 - * in the UTF-16 encoding, constant {@code '\u005CuD800'}.
117.496 - * A high-surrogate is also known as a <i>leading-surrogate</i>.
117.497 - *
117.498 - * @since 1.5
117.499 - */
117.500 - public static final char MIN_HIGH_SURROGATE = '\uD800';
117.501 -
117.502 - /**
117.503 - * The maximum value of a
117.504 - * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
117.505 - * Unicode high-surrogate code unit</a>
117.506 - * in the UTF-16 encoding, constant {@code '\u005CuDBFF'}.
117.507 - * A high-surrogate is also known as a <i>leading-surrogate</i>.
117.508 - *
117.509 - * @since 1.5
117.510 - */
117.511 - public static final char MAX_HIGH_SURROGATE = '\uDBFF';
117.512 -
117.513 - /**
117.514 - * The minimum value of a
117.515 - * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
117.516 - * Unicode low-surrogate code unit</a>
117.517 - * in the UTF-16 encoding, constant {@code '\u005CuDC00'}.
117.518 - * A low-surrogate is also known as a <i>trailing-surrogate</i>.
117.519 - *
117.520 - * @since 1.5
117.521 - */
117.522 - public static final char MIN_LOW_SURROGATE = '\uDC00';
117.523 -
117.524 - /**
117.525 - * The maximum value of a
117.526 - * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
117.527 - * Unicode low-surrogate code unit</a>
117.528 - * in the UTF-16 encoding, constant {@code '\u005CuDFFF'}.
117.529 - * A low-surrogate is also known as a <i>trailing-surrogate</i>.
117.530 - *
117.531 - * @since 1.5
117.532 - */
117.533 - public static final char MAX_LOW_SURROGATE = '\uDFFF';
117.534 -
117.535 - /**
117.536 - * The minimum value of a Unicode surrogate code unit in the
117.537 - * UTF-16 encoding, constant {@code '\u005CuD800'}.
117.538 - *
117.539 - * @since 1.5
117.540 - */
117.541 - public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
117.542 -
117.543 - /**
117.544 - * The maximum value of a Unicode surrogate code unit in the
117.545 - * UTF-16 encoding, constant {@code '\u005CuDFFF'}.
117.546 - *
117.547 - * @since 1.5
117.548 - */
117.549 - public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
117.550 -
117.551 - /**
117.552 - * The minimum value of a
117.553 - * <a href="http://www.unicode.org/glossary/#supplementary_code_point">
117.554 - * Unicode supplementary code point</a>, constant {@code U+10000}.
117.555 - *
117.556 - * @since 1.5
117.557 - */
117.558 - public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000;
117.559 -
117.560 - /**
117.561 - * The minimum value of a
117.562 - * <a href="http://www.unicode.org/glossary/#code_point">
117.563 - * Unicode code point</a>, constant {@code U+0000}.
117.564 - *
117.565 - * @since 1.5
117.566 - */
117.567 - public static final int MIN_CODE_POINT = 0x000000;
117.568 -
117.569 - /**
117.570 - * The maximum value of a
117.571 - * <a href="http://www.unicode.org/glossary/#code_point">
117.572 - * Unicode code point</a>, constant {@code U+10FFFF}.
117.573 - *
117.574 - * @since 1.5
117.575 - */
117.576 - public static final int MAX_CODE_POINT = 0X10FFFF;
117.577 -
117.578 -
117.579 - /**
117.580 - * Instances of this class represent particular subsets of the Unicode
117.581 - * character set. The only family of subsets defined in the
117.582 - * {@code Character} class is {@link Character.UnicodeBlock}.
117.583 - * Other portions of the Java API may define other subsets for their
117.584 - * own purposes.
117.585 - *
117.586 - * @since 1.2
117.587 - */
117.588 - public static class Subset {
117.589 -
117.590 - private String name;
117.591 -
117.592 - /**
117.593 - * Constructs a new {@code Subset} instance.
117.594 - *
117.595 - * @param name The name of this subset
117.596 - * @exception NullPointerException if name is {@code null}
117.597 - */
117.598 - protected Subset(String name) {
117.599 - if (name == null) {
117.600 - throw new NullPointerException("name");
117.601 - }
117.602 - this.name = name;
117.603 - }
117.604 -
117.605 - /**
117.606 - * Compares two {@code Subset} objects for equality.
117.607 - * This method returns {@code true} if and only if
117.608 - * {@code this} and the argument refer to the same
117.609 - * object; since this method is {@code final}, this
117.610 - * guarantee holds for all subclasses.
117.611 - */
117.612 - public final boolean equals(Object obj) {
117.613 - return (this == obj);
117.614 - }
117.615 -
117.616 - /**
117.617 - * Returns the standard hash code as defined by the
117.618 - * {@link Object#hashCode} method. This method
117.619 - * is {@code final} in order to ensure that the
117.620 - * {@code equals} and {@code hashCode} methods will
117.621 - * be consistent in all subclasses.
117.622 - */
117.623 - public final int hashCode() {
117.624 - return super.hashCode();
117.625 - }
117.626 -
117.627 - /**
117.628 - * Returns the name of this subset.
117.629 - */
117.630 - public final String toString() {
117.631 - return name;
117.632 - }
117.633 - }
117.634 -
117.635 - // See http://www.unicode.org/Public/UNIDATA/Blocks.txt
117.636 - // for the latest specification of Unicode Blocks.
117.637 -
117.638 -
117.639 - /**
117.640 - * The value of the {@code Character}.
117.641 - *
117.642 - * @serial
117.643 - */
117.644 - private final char value;
117.645 -
117.646 - /** use serialVersionUID from JDK 1.0.2 for interoperability */
117.647 - private static final long serialVersionUID = 3786198910865385080L;
117.648 -
117.649 - /**
117.650 - * Constructs a newly allocated {@code Character} object that
117.651 - * represents the specified {@code char} value.
117.652 - *
117.653 - * @param value the value to be represented by the
117.654 - * {@code Character} object.
117.655 - */
117.656 - public Character(char value) {
117.657 - this.value = value;
117.658 - }
117.659 -
117.660 - private static class CharacterCache {
117.661 - private CharacterCache(){}
117.662 -
117.663 - static final Character cache[] = new Character[127 + 1];
117.664 -
117.665 - static {
117.666 - for (int i = 0; i < cache.length; i++)
117.667 - cache[i] = new Character((char)i);
117.668 - }
117.669 - }
117.670 -
117.671 - /**
117.672 - * Returns a <tt>Character</tt> instance representing the specified
117.673 - * <tt>char</tt> value.
117.674 - * If a new <tt>Character</tt> instance is not required, this method
117.675 - * should generally be used in preference to the constructor
117.676 - * {@link #Character(char)}, as this method is likely to yield
117.677 - * significantly better space and time performance by caching
117.678 - * frequently requested values.
117.679 - *
117.680 - * This method will always cache values in the range {@code
117.681 - * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
117.682 - * cache other values outside of this range.
117.683 - *
117.684 - * @param c a char value.
117.685 - * @return a <tt>Character</tt> instance representing <tt>c</tt>.
117.686 - * @since 1.5
117.687 - */
117.688 - public static Character valueOf(char c) {
117.689 - if (c <= 127) { // must cache
117.690 - return CharacterCache.cache[(int)c];
117.691 - }
117.692 - return new Character(c);
117.693 - }
117.694 -
117.695 - /**
117.696 - * Returns the value of this {@code Character} object.
117.697 - * @return the primitive {@code char} value represented by
117.698 - * this object.
117.699 - */
117.700 - public char charValue() {
117.701 - return value;
117.702 - }
117.703 -
117.704 - /**
117.705 - * Returns a hash code for this {@code Character}; equal to the result
117.706 - * of invoking {@code charValue()}.
117.707 - *
117.708 - * @return a hash code value for this {@code Character}
117.709 - */
117.710 - public int hashCode() {
117.711 - return (int)value;
117.712 - }
117.713 -
117.714 - /**
117.715 - * Compares this object against the specified object.
117.716 - * The result is {@code true} if and only if the argument is not
117.717 - * {@code null} and is a {@code Character} object that
117.718 - * represents the same {@code char} value as this object.
117.719 - *
117.720 - * @param obj the object to compare with.
117.721 - * @return {@code true} if the objects are the same;
117.722 - * {@code false} otherwise.
117.723 - */
117.724 - public boolean equals(Object obj) {
117.725 - if (obj instanceof Character) {
117.726 - return value == ((Character)obj).charValue();
117.727 - }
117.728 - return false;
117.729 - }
117.730 -
117.731 - /**
117.732 - * Returns a {@code String} object representing this
117.733 - * {@code Character}'s value. The result is a string of
117.734 - * length 1 whose sole component is the primitive
117.735 - * {@code char} value represented by this
117.736 - * {@code Character} object.
117.737 - *
117.738 - * @return a string representation of this object.
117.739 - */
117.740 - public String toString() {
117.741 - char buf[] = {value};
117.742 - return String.valueOf(buf);
117.743 - }
117.744 -
117.745 - /**
117.746 - * Returns a {@code String} object representing the
117.747 - * specified {@code char}. The result is a string of length
117.748 - * 1 consisting solely of the specified {@code char}.
117.749 - *
117.750 - * @param c the {@code char} to be converted
117.751 - * @return the string representation of the specified {@code char}
117.752 - * @since 1.4
117.753 - */
117.754 - public static String toString(char c) {
117.755 - return String.valueOf(c);
117.756 - }
117.757 -
117.758 - /**
117.759 - * Determines whether the specified code point is a valid
117.760 - * <a href="http://www.unicode.org/glossary/#code_point">
117.761 - * Unicode code point value</a>.
117.762 - *
117.763 - * @param codePoint the Unicode code point to be tested
117.764 - * @return {@code true} if the specified code point value is between
117.765 - * {@link #MIN_CODE_POINT} and
117.766 - * {@link #MAX_CODE_POINT} inclusive;
117.767 - * {@code false} otherwise.
117.768 - * @since 1.5
117.769 - */
117.770 - public static boolean isValidCodePoint(int codePoint) {
117.771 - // Optimized form of:
117.772 - // codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
117.773 - int plane = codePoint >>> 16;
117.774 - return plane < ((MAX_CODE_POINT + 1) >>> 16);
117.775 - }
117.776 -
117.777 - /**
117.778 - * Determines whether the specified character (Unicode code point)
117.779 - * is in the <a href="#BMP">Basic Multilingual Plane (BMP)</a>.
117.780 - * Such code points can be represented using a single {@code char}.
117.781 - *
117.782 - * @param codePoint the character (Unicode code point) to be tested
117.783 - * @return {@code true} if the specified code point is between
117.784 - * {@link #MIN_VALUE} and {@link #MAX_VALUE} inclusive;
117.785 - * {@code false} otherwise.
117.786 - * @since 1.7
117.787 - */
117.788 - public static boolean isBmpCodePoint(int codePoint) {
117.789 - return codePoint >>> 16 == 0;
117.790 - // Optimized form of:
117.791 - // codePoint >= MIN_VALUE && codePoint <= MAX_VALUE
117.792 - // We consistently use logical shift (>>>) to facilitate
117.793 - // additional runtime optimizations.
117.794 - }
117.795 -
117.796 - /**
117.797 - * Determines whether the specified character (Unicode code point)
117.798 - * is in the <a href="#supplementary">supplementary character</a> range.
117.799 - *
117.800 - * @param codePoint the character (Unicode code point) to be tested
117.801 - * @return {@code true} if the specified code point is between
117.802 - * {@link #MIN_SUPPLEMENTARY_CODE_POINT} and
117.803 - * {@link #MAX_CODE_POINT} inclusive;
117.804 - * {@code false} otherwise.
117.805 - * @since 1.5
117.806 - */
117.807 - public static boolean isSupplementaryCodePoint(int codePoint) {
117.808 - return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
117.809 - && codePoint < MAX_CODE_POINT + 1;
117.810 - }
117.811 -
117.812 - /**
117.813 - * Determines if the given {@code char} value is a
117.814 - * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
117.815 - * Unicode high-surrogate code unit</a>
117.816 - * (also known as <i>leading-surrogate code unit</i>).
117.817 - *
117.818 - * <p>Such values do not represent characters by themselves,
117.819 - * but are used in the representation of
117.820 - * <a href="#supplementary">supplementary characters</a>
117.821 - * in the UTF-16 encoding.
117.822 - *
117.823 - * @param ch the {@code char} value to be tested.
117.824 - * @return {@code true} if the {@code char} value is between
117.825 - * {@link #MIN_HIGH_SURROGATE} and
117.826 - * {@link #MAX_HIGH_SURROGATE} inclusive;
117.827 - * {@code false} otherwise.
117.828 - * @see Character#isLowSurrogate(char)
117.829 - * @see Character.UnicodeBlock#of(int)
117.830 - * @since 1.5
117.831 - */
117.832 - public static boolean isHighSurrogate(char ch) {
117.833 - // Help VM constant-fold; MAX_HIGH_SURROGATE + 1 == MIN_LOW_SURROGATE
117.834 - return ch >= MIN_HIGH_SURROGATE && ch < (MAX_HIGH_SURROGATE + 1);
117.835 - }
117.836 -
117.837 - /**
117.838 - * Determines if the given {@code char} value is a
117.839 - * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
117.840 - * Unicode low-surrogate code unit</a>
117.841 - * (also known as <i>trailing-surrogate code unit</i>).
117.842 - *
117.843 - * <p>Such values do not represent characters by themselves,
117.844 - * but are used in the representation of
117.845 - * <a href="#supplementary">supplementary characters</a>
117.846 - * in the UTF-16 encoding.
117.847 - *
117.848 - * @param ch the {@code char} value to be tested.
117.849 - * @return {@code true} if the {@code char} value is between
117.850 - * {@link #MIN_LOW_SURROGATE} and
117.851 - * {@link #MAX_LOW_SURROGATE} inclusive;
117.852 - * {@code false} otherwise.
117.853 - * @see Character#isHighSurrogate(char)
117.854 - * @since 1.5
117.855 - */
117.856 - public static boolean isLowSurrogate(char ch) {
117.857 - return ch >= MIN_LOW_SURROGATE && ch < (MAX_LOW_SURROGATE + 1);
117.858 - }
117.859 -
117.860 - /**
117.861 - * Determines if the given {@code char} value is a Unicode
117.862 - * <i>surrogate code unit</i>.
117.863 - *
117.864 - * <p>Such values do not represent characters by themselves,
117.865 - * but are used in the representation of
117.866 - * <a href="#supplementary">supplementary characters</a>
117.867 - * in the UTF-16 encoding.
117.868 - *
117.869 - * <p>A char value is a surrogate code unit if and only if it is either
117.870 - * a {@linkplain #isLowSurrogate(char) low-surrogate code unit} or
117.871 - * a {@linkplain #isHighSurrogate(char) high-surrogate code unit}.
117.872 - *
117.873 - * @param ch the {@code char} value to be tested.
117.874 - * @return {@code true} if the {@code char} value is between
117.875 - * {@link #MIN_SURROGATE} and
117.876 - * {@link #MAX_SURROGATE} inclusive;
117.877 - * {@code false} otherwise.
117.878 - * @since 1.7
117.879 - */
117.880 - public static boolean isSurrogate(char ch) {
117.881 - return ch >= MIN_SURROGATE && ch < (MAX_SURROGATE + 1);
117.882 - }
117.883 -
117.884 - /**
117.885 - * Determines whether the specified pair of {@code char}
117.886 - * values is a valid
117.887 - * <a href="http://www.unicode.org/glossary/#surrogate_pair">
117.888 - * Unicode surrogate pair</a>.
117.889 -
117.890 - * <p>This method is equivalent to the expression:
117.891 - * <blockquote><pre>
117.892 - * isHighSurrogate(high) && isLowSurrogate(low)
117.893 - * </pre></blockquote>
117.894 - *
117.895 - * @param high the high-surrogate code value to be tested
117.896 - * @param low the low-surrogate code value to be tested
117.897 - * @return {@code true} if the specified high and
117.898 - * low-surrogate code values represent a valid surrogate pair;
117.899 - * {@code false} otherwise.
117.900 - * @since 1.5
117.901 - */
117.902 - public static boolean isSurrogatePair(char high, char low) {
117.903 - return isHighSurrogate(high) && isLowSurrogate(low);
117.904 - }
117.905 -
117.906 - /**
117.907 - * Determines the number of {@code char} values needed to
117.908 - * represent the specified character (Unicode code point). If the
117.909 - * specified character is equal to or greater than 0x10000, then
117.910 - * the method returns 2. Otherwise, the method returns 1.
117.911 - *
117.912 - * <p>This method doesn't validate the specified character to be a
117.913 - * valid Unicode code point. The caller must validate the
117.914 - * character value using {@link #isValidCodePoint(int) isValidCodePoint}
117.915 - * if necessary.
117.916 - *
117.917 - * @param codePoint the character (Unicode code point) to be tested.
117.918 - * @return 2 if the character is a valid supplementary character; 1 otherwise.
117.919 - * @see Character#isSupplementaryCodePoint(int)
117.920 - * @since 1.5
117.921 - */
117.922 - public static int charCount(int codePoint) {
117.923 - return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT ? 2 : 1;
117.924 - }
117.925 -
117.926 - /**
117.927 - * Converts the specified surrogate pair to its supplementary code
117.928 - * point value. This method does not validate the specified
117.929 - * surrogate pair. The caller must validate it using {@link
117.930 - * #isSurrogatePair(char, char) isSurrogatePair} if necessary.
117.931 - *
117.932 - * @param high the high-surrogate code unit
117.933 - * @param low the low-surrogate code unit
117.934 - * @return the supplementary code point composed from the
117.935 - * specified surrogate pair.
117.936 - * @since 1.5
117.937 - */
117.938 - public static int toCodePoint(char high, char low) {
117.939 - // Optimized form of:
117.940 - // return ((high - MIN_HIGH_SURROGATE) << 10)
117.941 - // + (low - MIN_LOW_SURROGATE)
117.942 - // + MIN_SUPPLEMENTARY_CODE_POINT;
117.943 - return ((high << 10) + low) + (MIN_SUPPLEMENTARY_CODE_POINT
117.944 - - (MIN_HIGH_SURROGATE << 10)
117.945 - - MIN_LOW_SURROGATE);
117.946 - }
117.947 -
117.948 - /**
117.949 - * Returns the code point at the given index of the
117.950 - * {@code CharSequence}. If the {@code char} value at
117.951 - * the given index in the {@code CharSequence} is in the
117.952 - * high-surrogate range, the following index is less than the
117.953 - * length of the {@code CharSequence}, and the
117.954 - * {@code char} value at the following index is in the
117.955 - * low-surrogate range, then the supplementary code point
117.956 - * corresponding to this surrogate pair is returned. Otherwise,
117.957 - * the {@code char} value at the given index is returned.
117.958 - *
117.959 - * @param seq a sequence of {@code char} values (Unicode code
117.960 - * units)
117.961 - * @param index the index to the {@code char} values (Unicode
117.962 - * code units) in {@code seq} to be converted
117.963 - * @return the Unicode code point at the given index
117.964 - * @exception NullPointerException if {@code seq} is null.
117.965 - * @exception IndexOutOfBoundsException if the value
117.966 - * {@code index} is negative or not less than
117.967 - * {@link CharSequence#length() seq.length()}.
117.968 - * @since 1.5
117.969 - */
117.970 - public static int codePointAt(CharSequence seq, int index) {
117.971 - char c1 = seq.charAt(index++);
117.972 - if (isHighSurrogate(c1)) {
117.973 - if (index < seq.length()) {
117.974 - char c2 = seq.charAt(index);
117.975 - if (isLowSurrogate(c2)) {
117.976 - return toCodePoint(c1, c2);
117.977 - }
117.978 - }
117.979 - }
117.980 - return c1;
117.981 - }
117.982 -
117.983 - /**
117.984 - * Returns the code point at the given index of the
117.985 - * {@code char} array. If the {@code char} value at
117.986 - * the given index in the {@code char} array is in the
117.987 - * high-surrogate range, the following index is less than the
117.988 - * length of the {@code char} array, and the
117.989 - * {@code char} value at the following index is in the
117.990 - * low-surrogate range, then the supplementary code point
117.991 - * corresponding to this surrogate pair is returned. Otherwise,
117.992 - * the {@code char} value at the given index is returned.
117.993 - *
117.994 - * @param a the {@code char} array
117.995 - * @param index the index to the {@code char} values (Unicode
117.996 - * code units) in the {@code char} array to be converted
117.997 - * @return the Unicode code point at the given index
117.998 - * @exception NullPointerException if {@code a} is null.
117.999 - * @exception IndexOutOfBoundsException if the value
117.1000 - * {@code index} is negative or not less than
117.1001 - * the length of the {@code char} array.
117.1002 - * @since 1.5
117.1003 - */
117.1004 - public static int codePointAt(char[] a, int index) {
117.1005 - return codePointAtImpl(a, index, a.length);
117.1006 - }
117.1007 -
117.1008 - /**
117.1009 - * Returns the code point at the given index of the
117.1010 - * {@code char} array, where only array elements with
117.1011 - * {@code index} less than {@code limit} can be used. If
117.1012 - * the {@code char} value at the given index in the
117.1013 - * {@code char} array is in the high-surrogate range, the
117.1014 - * following index is less than the {@code limit}, and the
117.1015 - * {@code char} value at the following index is in the
117.1016 - * low-surrogate range, then the supplementary code point
117.1017 - * corresponding to this surrogate pair is returned. Otherwise,
117.1018 - * the {@code char} value at the given index is returned.
117.1019 - *
117.1020 - * @param a the {@code char} array
117.1021 - * @param index the index to the {@code char} values (Unicode
117.1022 - * code units) in the {@code char} array to be converted
117.1023 - * @param limit the index after the last array element that
117.1024 - * can be used in the {@code char} array
117.1025 - * @return the Unicode code point at the given index
117.1026 - * @exception NullPointerException if {@code a} is null.
117.1027 - * @exception IndexOutOfBoundsException if the {@code index}
117.1028 - * argument is negative or not less than the {@code limit}
117.1029 - * argument, or if the {@code limit} argument is negative or
117.1030 - * greater than the length of the {@code char} array.
117.1031 - * @since 1.5
117.1032 - */
117.1033 - public static int codePointAt(char[] a, int index, int limit) {
117.1034 - if (index >= limit || limit < 0 || limit > a.length) {
117.1035 - throw new IndexOutOfBoundsException();
117.1036 - }
117.1037 - return codePointAtImpl(a, index, limit);
117.1038 - }
117.1039 -
117.1040 - // throws ArrayIndexOutofBoundsException if index out of bounds
117.1041 - static int codePointAtImpl(char[] a, int index, int limit) {
117.1042 - char c1 = a[index++];
117.1043 - if (isHighSurrogate(c1)) {
117.1044 - if (index < limit) {
117.1045 - char c2 = a[index];
117.1046 - if (isLowSurrogate(c2)) {
117.1047 - return toCodePoint(c1, c2);
117.1048 - }
117.1049 - }
117.1050 - }
117.1051 - return c1;
117.1052 - }
117.1053 -
117.1054 - /**
117.1055 - * Returns the code point preceding the given index of the
117.1056 - * {@code CharSequence}. If the {@code char} value at
117.1057 - * {@code (index - 1)} in the {@code CharSequence} is in
117.1058 - * the low-surrogate range, {@code (index - 2)} is not
117.1059 - * negative, and the {@code char} value at {@code (index - 2)}
117.1060 - * in the {@code CharSequence} is in the
117.1061 - * high-surrogate range, then the supplementary code point
117.1062 - * corresponding to this surrogate pair is returned. Otherwise,
117.1063 - * the {@code char} value at {@code (index - 1)} is
117.1064 - * returned.
117.1065 - *
117.1066 - * @param seq the {@code CharSequence} instance
117.1067 - * @param index the index following the code point that should be returned
117.1068 - * @return the Unicode code point value before the given index.
117.1069 - * @exception NullPointerException if {@code seq} is null.
117.1070 - * @exception IndexOutOfBoundsException if the {@code index}
117.1071 - * argument is less than 1 or greater than {@link
117.1072 - * CharSequence#length() seq.length()}.
117.1073 - * @since 1.5
117.1074 - */
117.1075 - public static int codePointBefore(CharSequence seq, int index) {
117.1076 - char c2 = seq.charAt(--index);
117.1077 - if (isLowSurrogate(c2)) {
117.1078 - if (index > 0) {
117.1079 - char c1 = seq.charAt(--index);
117.1080 - if (isHighSurrogate(c1)) {
117.1081 - return toCodePoint(c1, c2);
117.1082 - }
117.1083 - }
117.1084 - }
117.1085 - return c2;
117.1086 - }
117.1087 -
117.1088 - /**
117.1089 - * Returns the code point preceding the given index of the
117.1090 - * {@code char} array. If the {@code char} value at
117.1091 - * {@code (index - 1)} in the {@code char} array is in
117.1092 - * the low-surrogate range, {@code (index - 2)} is not
117.1093 - * negative, and the {@code char} value at {@code (index - 2)}
117.1094 - * in the {@code char} array is in the
117.1095 - * high-surrogate range, then the supplementary code point
117.1096 - * corresponding to this surrogate pair is returned. Otherwise,
117.1097 - * the {@code char} value at {@code (index - 1)} is
117.1098 - * returned.
117.1099 - *
117.1100 - * @param a the {@code char} array
117.1101 - * @param index the index following the code point that should be returned
117.1102 - * @return the Unicode code point value before the given index.
117.1103 - * @exception NullPointerException if {@code a} is null.
117.1104 - * @exception IndexOutOfBoundsException if the {@code index}
117.1105 - * argument is less than 1 or greater than the length of the
117.1106 - * {@code char} array
117.1107 - * @since 1.5
117.1108 - */
117.1109 - public static int codePointBefore(char[] a, int index) {
117.1110 - return codePointBeforeImpl(a, index, 0);
117.1111 - }
117.1112 -
117.1113 - /**
117.1114 - * Returns the code point preceding the given index of the
117.1115 - * {@code char} array, where only array elements with
117.1116 - * {@code index} greater than or equal to {@code start}
117.1117 - * can be used. If the {@code char} value at {@code (index - 1)}
117.1118 - * in the {@code char} array is in the
117.1119 - * low-surrogate range, {@code (index - 2)} is not less than
117.1120 - * {@code start}, and the {@code char} value at
117.1121 - * {@code (index - 2)} in the {@code char} array is in
117.1122 - * the high-surrogate range, then the supplementary code point
117.1123 - * corresponding to this surrogate pair is returned. Otherwise,
117.1124 - * the {@code char} value at {@code (index - 1)} is
117.1125 - * returned.
117.1126 - *
117.1127 - * @param a the {@code char} array
117.1128 - * @param index the index following the code point that should be returned
117.1129 - * @param start the index of the first array element in the
117.1130 - * {@code char} array
117.1131 - * @return the Unicode code point value before the given index.
117.1132 - * @exception NullPointerException if {@code a} is null.
117.1133 - * @exception IndexOutOfBoundsException if the {@code index}
117.1134 - * argument is not greater than the {@code start} argument or
117.1135 - * is greater than the length of the {@code char} array, or
117.1136 - * if the {@code start} argument is negative or not less than
117.1137 - * the length of the {@code char} array.
117.1138 - * @since 1.5
117.1139 - */
117.1140 - public static int codePointBefore(char[] a, int index, int start) {
117.1141 - if (index <= start || start < 0 || start >= a.length) {
117.1142 - throw new IndexOutOfBoundsException();
117.1143 - }
117.1144 - return codePointBeforeImpl(a, index, start);
117.1145 - }
117.1146 -
117.1147 - // throws ArrayIndexOutofBoundsException if index-1 out of bounds
117.1148 - static int codePointBeforeImpl(char[] a, int index, int start) {
117.1149 - char c2 = a[--index];
117.1150 - if (isLowSurrogate(c2)) {
117.1151 - if (index > start) {
117.1152 - char c1 = a[--index];
117.1153 - if (isHighSurrogate(c1)) {
117.1154 - return toCodePoint(c1, c2);
117.1155 - }
117.1156 - }
117.1157 - }
117.1158 - return c2;
117.1159 - }
117.1160 -
117.1161 - /**
117.1162 - * Returns the leading surrogate (a
117.1163 - * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
117.1164 - * high surrogate code unit</a>) of the
117.1165 - * <a href="http://www.unicode.org/glossary/#surrogate_pair">
117.1166 - * surrogate pair</a>
117.1167 - * representing the specified supplementary character (Unicode
117.1168 - * code point) in the UTF-16 encoding. If the specified character
117.1169 - * is not a
117.1170 - * <a href="Character.html#supplementary">supplementary character</a>,
117.1171 - * an unspecified {@code char} is returned.
117.1172 - *
117.1173 - * <p>If
117.1174 - * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
117.1175 - * is {@code true}, then
117.1176 - * {@link #isHighSurrogate isHighSurrogate}{@code (highSurrogate(x))} and
117.1177 - * {@link #toCodePoint toCodePoint}{@code (highSurrogate(x), }{@link #lowSurrogate lowSurrogate}{@code (x)) == x}
117.1178 - * are also always {@code true}.
117.1179 - *
117.1180 - * @param codePoint a supplementary character (Unicode code point)
117.1181 - * @return the leading surrogate code unit used to represent the
117.1182 - * character in the UTF-16 encoding
117.1183 - * @since 1.7
117.1184 - */
117.1185 - public static char highSurrogate(int codePoint) {
117.1186 - return (char) ((codePoint >>> 10)
117.1187 - + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10)));
117.1188 - }
117.1189 -
117.1190 - /**
117.1191 - * Returns the trailing surrogate (a
117.1192 - * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
117.1193 - * low surrogate code unit</a>) of the
117.1194 - * <a href="http://www.unicode.org/glossary/#surrogate_pair">
117.1195 - * surrogate pair</a>
117.1196 - * representing the specified supplementary character (Unicode
117.1197 - * code point) in the UTF-16 encoding. If the specified character
117.1198 - * is not a
117.1199 - * <a href="Character.html#supplementary">supplementary character</a>,
117.1200 - * an unspecified {@code char} is returned.
117.1201 - *
117.1202 - * <p>If
117.1203 - * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)}
117.1204 - * is {@code true}, then
117.1205 - * {@link #isLowSurrogate isLowSurrogate}{@code (lowSurrogate(x))} and
117.1206 - * {@link #toCodePoint toCodePoint}{@code (}{@link #highSurrogate highSurrogate}{@code (x), lowSurrogate(x)) == x}
117.1207 - * are also always {@code true}.
117.1208 - *
117.1209 - * @param codePoint a supplementary character (Unicode code point)
117.1210 - * @return the trailing surrogate code unit used to represent the
117.1211 - * character in the UTF-16 encoding
117.1212 - * @since 1.7
117.1213 - */
117.1214 - public static char lowSurrogate(int codePoint) {
117.1215 - return (char) ((codePoint & 0x3ff) + MIN_LOW_SURROGATE);
117.1216 - }
117.1217 -
117.1218 - /**
117.1219 - * Converts the specified character (Unicode code point) to its
117.1220 - * UTF-16 representation. If the specified code point is a BMP
117.1221 - * (Basic Multilingual Plane or Plane 0) value, the same value is
117.1222 - * stored in {@code dst[dstIndex]}, and 1 is returned. If the
117.1223 - * specified code point is a supplementary character, its
117.1224 - * surrogate values are stored in {@code dst[dstIndex]}
117.1225 - * (high-surrogate) and {@code dst[dstIndex+1]}
117.1226 - * (low-surrogate), and 2 is returned.
117.1227 - *
117.1228 - * @param codePoint the character (Unicode code point) to be converted.
117.1229 - * @param dst an array of {@code char} in which the
117.1230 - * {@code codePoint}'s UTF-16 value is stored.
117.1231 - * @param dstIndex the start index into the {@code dst}
117.1232 - * array where the converted value is stored.
117.1233 - * @return 1 if the code point is a BMP code point, 2 if the
117.1234 - * code point is a supplementary code point.
117.1235 - * @exception IllegalArgumentException if the specified
117.1236 - * {@code codePoint} is not a valid Unicode code point.
117.1237 - * @exception NullPointerException if the specified {@code dst} is null.
117.1238 - * @exception IndexOutOfBoundsException if {@code dstIndex}
117.1239 - * is negative or not less than {@code dst.length}, or if
117.1240 - * {@code dst} at {@code dstIndex} doesn't have enough
117.1241 - * array element(s) to store the resulting {@code char}
117.1242 - * value(s). (If {@code dstIndex} is equal to
117.1243 - * {@code dst.length-1} and the specified
117.1244 - * {@code codePoint} is a supplementary character, the
117.1245 - * high-surrogate value is not stored in
117.1246 - * {@code dst[dstIndex]}.)
117.1247 - * @since 1.5
117.1248 - */
117.1249 - public static int toChars(int codePoint, char[] dst, int dstIndex) {
117.1250 - if (isBmpCodePoint(codePoint)) {
117.1251 - dst[dstIndex] = (char) codePoint;
117.1252 - return 1;
117.1253 - } else if (isValidCodePoint(codePoint)) {
117.1254 - toSurrogates(codePoint, dst, dstIndex);
117.1255 - return 2;
117.1256 - } else {
117.1257 - throw new IllegalArgumentException();
117.1258 - }
117.1259 - }
117.1260 -
117.1261 - /**
117.1262 - * Converts the specified character (Unicode code point) to its
117.1263 - * UTF-16 representation stored in a {@code char} array. If
117.1264 - * the specified code point is a BMP (Basic Multilingual Plane or
117.1265 - * Plane 0) value, the resulting {@code char} array has
117.1266 - * the same value as {@code codePoint}. If the specified code
117.1267 - * point is a supplementary code point, the resulting
117.1268 - * {@code char} array has the corresponding surrogate pair.
117.1269 - *
117.1270 - * @param codePoint a Unicode code point
117.1271 - * @return a {@code char} array having
117.1272 - * {@code codePoint}'s UTF-16 representation.
117.1273 - * @exception IllegalArgumentException if the specified
117.1274 - * {@code codePoint} is not a valid Unicode code point.
117.1275 - * @since 1.5
117.1276 - */
117.1277 - public static char[] toChars(int codePoint) {
117.1278 - if (isBmpCodePoint(codePoint)) {
117.1279 - return new char[] { (char) codePoint };
117.1280 - } else if (isValidCodePoint(codePoint)) {
117.1281 - char[] result = new char[2];
117.1282 - toSurrogates(codePoint, result, 0);
117.1283 - return result;
117.1284 - } else {
117.1285 - throw new IllegalArgumentException();
117.1286 - }
117.1287 - }
117.1288 -
117.1289 - static void toSurrogates(int codePoint, char[] dst, int index) {
117.1290 - // We write elements "backwards" to guarantee all-or-nothing
117.1291 - dst[index+1] = lowSurrogate(codePoint);
117.1292 - dst[index] = highSurrogate(codePoint);
117.1293 - }
117.1294 -
117.1295 - /**
117.1296 - * Returns the number of Unicode code points in the text range of
117.1297 - * the specified char sequence. The text range begins at the
117.1298 - * specified {@code beginIndex} and extends to the
117.1299 - * {@code char} at index {@code endIndex - 1}. Thus the
117.1300 - * length (in {@code char}s) of the text range is
117.1301 - * {@code endIndex-beginIndex}. Unpaired surrogates within
117.1302 - * the text range count as one code point each.
117.1303 - *
117.1304 - * @param seq the char sequence
117.1305 - * @param beginIndex the index to the first {@code char} of
117.1306 - * the text range.
117.1307 - * @param endIndex the index after the last {@code char} of
117.1308 - * the text range.
117.1309 - * @return the number of Unicode code points in the specified text
117.1310 - * range
117.1311 - * @exception NullPointerException if {@code seq} is null.
117.1312 - * @exception IndexOutOfBoundsException if the
117.1313 - * {@code beginIndex} is negative, or {@code endIndex}
117.1314 - * is larger than the length of the given sequence, or
117.1315 - * {@code beginIndex} is larger than {@code endIndex}.
117.1316 - * @since 1.5
117.1317 - */
117.1318 - public static int codePointCount(CharSequence seq, int beginIndex, int endIndex) {
117.1319 - int length = seq.length();
117.1320 - if (beginIndex < 0 || endIndex > length || beginIndex > endIndex) {
117.1321 - throw new IndexOutOfBoundsException();
117.1322 - }
117.1323 - int n = endIndex - beginIndex;
117.1324 - for (int i = beginIndex; i < endIndex; ) {
117.1325 - if (isHighSurrogate(seq.charAt(i++)) && i < endIndex &&
117.1326 - isLowSurrogate(seq.charAt(i))) {
117.1327 - n--;
117.1328 - i++;
117.1329 - }
117.1330 - }
117.1331 - return n;
117.1332 - }
117.1333 -
117.1334 - /**
117.1335 - * Returns the number of Unicode code points in a subarray of the
117.1336 - * {@code char} array argument. The {@code offset}
117.1337 - * argument is the index of the first {@code char} of the
117.1338 - * subarray and the {@code count} argument specifies the
117.1339 - * length of the subarray in {@code char}s. Unpaired
117.1340 - * surrogates within the subarray count as one code point each.
117.1341 - *
117.1342 - * @param a the {@code char} array
117.1343 - * @param offset the index of the first {@code char} in the
117.1344 - * given {@code char} array
117.1345 - * @param count the length of the subarray in {@code char}s
117.1346 - * @return the number of Unicode code points in the specified subarray
117.1347 - * @exception NullPointerException if {@code a} is null.
117.1348 - * @exception IndexOutOfBoundsException if {@code offset} or
117.1349 - * {@code count} is negative, or if {@code offset +
117.1350 - * count} is larger than the length of the given array.
117.1351 - * @since 1.5
117.1352 - */
117.1353 - public static int codePointCount(char[] a, int offset, int count) {
117.1354 - if (count > a.length - offset || offset < 0 || count < 0) {
117.1355 - throw new IndexOutOfBoundsException();
117.1356 - }
117.1357 - return codePointCountImpl(a, offset, count);
117.1358 - }
117.1359 -
117.1360 - static int codePointCountImpl(char[] a, int offset, int count) {
117.1361 - int endIndex = offset + count;
117.1362 - int n = count;
117.1363 - for (int i = offset; i < endIndex; ) {
117.1364 - if (isHighSurrogate(a[i++]) && i < endIndex &&
117.1365 - isLowSurrogate(a[i])) {
117.1366 - n--;
117.1367 - i++;
117.1368 - }
117.1369 - }
117.1370 - return n;
117.1371 - }
117.1372 -
117.1373 - /**
117.1374 - * Returns the index within the given char sequence that is offset
117.1375 - * from the given {@code index} by {@code codePointOffset}
117.1376 - * code points. Unpaired surrogates within the text range given by
117.1377 - * {@code index} and {@code codePointOffset} count as
117.1378 - * one code point each.
117.1379 - *
117.1380 - * @param seq the char sequence
117.1381 - * @param index the index to be offset
117.1382 - * @param codePointOffset the offset in code points
117.1383 - * @return the index within the char sequence
117.1384 - * @exception NullPointerException if {@code seq} is null.
117.1385 - * @exception IndexOutOfBoundsException if {@code index}
117.1386 - * is negative or larger then the length of the char sequence,
117.1387 - * or if {@code codePointOffset} is positive and the
117.1388 - * subsequence starting with {@code index} has fewer than
117.1389 - * {@code codePointOffset} code points, or if
117.1390 - * {@code codePointOffset} is negative and the subsequence
117.1391 - * before {@code index} has fewer than the absolute value
117.1392 - * of {@code codePointOffset} code points.
117.1393 - * @since 1.5
117.1394 - */
117.1395 - public static int offsetByCodePoints(CharSequence seq, int index,
117.1396 - int codePointOffset) {
117.1397 - int length = seq.length();
117.1398 - if (index < 0 || index > length) {
117.1399 - throw new IndexOutOfBoundsException();
117.1400 - }
117.1401 -
117.1402 - int x = index;
117.1403 - if (codePointOffset >= 0) {
117.1404 - int i;
117.1405 - for (i = 0; x < length && i < codePointOffset; i++) {
117.1406 - if (isHighSurrogate(seq.charAt(x++)) && x < length &&
117.1407 - isLowSurrogate(seq.charAt(x))) {
117.1408 - x++;
117.1409 - }
117.1410 - }
117.1411 - if (i < codePointOffset) {
117.1412 - throw new IndexOutOfBoundsException();
117.1413 - }
117.1414 - } else {
117.1415 - int i;
117.1416 - for (i = codePointOffset; x > 0 && i < 0; i++) {
117.1417 - if (isLowSurrogate(seq.charAt(--x)) && x > 0 &&
117.1418 - isHighSurrogate(seq.charAt(x-1))) {
117.1419 - x--;
117.1420 - }
117.1421 - }
117.1422 - if (i < 0) {
117.1423 - throw new IndexOutOfBoundsException();
117.1424 - }
117.1425 - }
117.1426 - return x;
117.1427 - }
117.1428 -
117.1429 - /**
117.1430 - * Returns the index within the given {@code char} subarray
117.1431 - * that is offset from the given {@code index} by
117.1432 - * {@code codePointOffset} code points. The
117.1433 - * {@code start} and {@code count} arguments specify a
117.1434 - * subarray of the {@code char} array. Unpaired surrogates
117.1435 - * within the text range given by {@code index} and
117.1436 - * {@code codePointOffset} count as one code point each.
117.1437 - *
117.1438 - * @param a the {@code char} array
117.1439 - * @param start the index of the first {@code char} of the
117.1440 - * subarray
117.1441 - * @param count the length of the subarray in {@code char}s
117.1442 - * @param index the index to be offset
117.1443 - * @param codePointOffset the offset in code points
117.1444 - * @return the index within the subarray
117.1445 - * @exception NullPointerException if {@code a} is null.
117.1446 - * @exception IndexOutOfBoundsException
117.1447 - * if {@code start} or {@code count} is negative,
117.1448 - * or if {@code start + count} is larger than the length of
117.1449 - * the given array,
117.1450 - * or if {@code index} is less than {@code start} or
117.1451 - * larger then {@code start + count},
117.1452 - * or if {@code codePointOffset} is positive and the text range
117.1453 - * starting with {@code index} and ending with {@code start + count - 1}
117.1454 - * has fewer than {@code codePointOffset} code
117.1455 - * points,
117.1456 - * or if {@code codePointOffset} is negative and the text range
117.1457 - * starting with {@code start} and ending with {@code index - 1}
117.1458 - * has fewer than the absolute value of
117.1459 - * {@code codePointOffset} code points.
117.1460 - * @since 1.5
117.1461 - */
117.1462 - public static int offsetByCodePoints(char[] a, int start, int count,
117.1463 - int index, int codePointOffset) {
117.1464 - if (count > a.length-start || start < 0 || count < 0
117.1465 - || index < start || index > start+count) {
117.1466 - throw new IndexOutOfBoundsException();
117.1467 - }
117.1468 - return offsetByCodePointsImpl(a, start, count, index, codePointOffset);
117.1469 - }
117.1470 -
117.1471 - static int offsetByCodePointsImpl(char[]a, int start, int count,
117.1472 - int index, int codePointOffset) {
117.1473 - int x = index;
117.1474 - if (codePointOffset >= 0) {
117.1475 - int limit = start + count;
117.1476 - int i;
117.1477 - for (i = 0; x < limit && i < codePointOffset; i++) {
117.1478 - if (isHighSurrogate(a[x++]) && x < limit &&
117.1479 - isLowSurrogate(a[x])) {
117.1480 - x++;
117.1481 - }
117.1482 - }
117.1483 - if (i < codePointOffset) {
117.1484 - throw new IndexOutOfBoundsException();
117.1485 - }
117.1486 - } else {
117.1487 - int i;
117.1488 - for (i = codePointOffset; x > start && i < 0; i++) {
117.1489 - if (isLowSurrogate(a[--x]) && x > start &&
117.1490 - isHighSurrogate(a[x-1])) {
117.1491 - x--;
117.1492 - }
117.1493 - }
117.1494 - if (i < 0) {
117.1495 - throw new IndexOutOfBoundsException();
117.1496 - }
117.1497 - }
117.1498 - return x;
117.1499 - }
117.1500 -
117.1501 - /**
117.1502 - * Determines if the specified character is a lowercase character.
117.1503 - * <p>
117.1504 - * A character is lowercase if its general category type, provided
117.1505 - * by {@code Character.getType(ch)}, is
117.1506 - * {@code LOWERCASE_LETTER}, or it has contributory property
117.1507 - * Other_Lowercase as defined by the Unicode Standard.
117.1508 - * <p>
117.1509 - * The following are examples of lowercase characters:
117.1510 - * <p><blockquote><pre>
117.1511 - * a b c d e f g h i j k l m n o p q r s t u v w x y z
117.1512 - * '\u00DF' '\u00E0' '\u00E1' '\u00E2' '\u00E3' '\u00E4' '\u00E5' '\u00E6'
117.1513 - * '\u00E7' '\u00E8' '\u00E9' '\u00EA' '\u00EB' '\u00EC' '\u00ED' '\u00EE'
117.1514 - * '\u00EF' '\u00F0' '\u00F1' '\u00F2' '\u00F3' '\u00F4' '\u00F5' '\u00F6'
117.1515 - * '\u00F8' '\u00F9' '\u00FA' '\u00FB' '\u00FC' '\u00FD' '\u00FE' '\u00FF'
117.1516 - * </pre></blockquote>
117.1517 - * <p> Many other Unicode characters are lowercase too.
117.1518 - *
117.1519 - * <p><b>Note:</b> This method cannot handle <a
117.1520 - * href="#supplementary"> supplementary characters</a>. To support
117.1521 - * all Unicode characters, including supplementary characters, use
117.1522 - * the {@link #isLowerCase(int)} method.
117.1523 - *
117.1524 - * @param ch the character to be tested.
117.1525 - * @return {@code true} if the character is lowercase;
117.1526 - * {@code false} otherwise.
117.1527 - * @see Character#isLowerCase(char)
117.1528 - * @see Character#isTitleCase(char)
117.1529 - * @see Character#toLowerCase(char)
117.1530 - * @see Character#getType(char)
117.1531 - */
117.1532 - public static boolean isLowerCase(char ch) {
117.1533 - return ch == toLowerCase(ch);
117.1534 - }
117.1535 -
117.1536 - /**
117.1537 - * Determines if the specified character is an uppercase character.
117.1538 - * <p>
117.1539 - * A character is uppercase if its general category type, provided by
117.1540 - * {@code Character.getType(ch)}, is {@code UPPERCASE_LETTER}.
117.1541 - * or it has contributory property Other_Uppercase as defined by the Unicode Standard.
117.1542 - * <p>
117.1543 - * The following are examples of uppercase characters:
117.1544 - * <p><blockquote><pre>
117.1545 - * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
117.1546 - * '\u00C0' '\u00C1' '\u00C2' '\u00C3' '\u00C4' '\u00C5' '\u00C6' '\u00C7'
117.1547 - * '\u00C8' '\u00C9' '\u00CA' '\u00CB' '\u00CC' '\u00CD' '\u00CE' '\u00CF'
117.1548 - * '\u00D0' '\u00D1' '\u00D2' '\u00D3' '\u00D4' '\u00D5' '\u00D6' '\u00D8'
117.1549 - * '\u00D9' '\u00DA' '\u00DB' '\u00DC' '\u00DD' '\u00DE'
117.1550 - * </pre></blockquote>
117.1551 - * <p> Many other Unicode characters are uppercase too.<p>
117.1552 - *
117.1553 - * <p><b>Note:</b> This method cannot handle <a
117.1554 - * href="#supplementary"> supplementary characters</a>. To support
117.1555 - * all Unicode characters, including supplementary characters, use
117.1556 - * the {@link #isUpperCase(int)} method.
117.1557 - *
117.1558 - * @param ch the character to be tested.
117.1559 - * @return {@code true} if the character is uppercase;
117.1560 - * {@code false} otherwise.
117.1561 - * @see Character#isLowerCase(char)
117.1562 - * @see Character#isTitleCase(char)
117.1563 - * @see Character#toUpperCase(char)
117.1564 - * @see Character#getType(char)
117.1565 - * @since 1.0
117.1566 - */
117.1567 - public static boolean isUpperCase(char ch) {
117.1568 - return ch == toUpperCase(ch);
117.1569 - }
117.1570 -
117.1571 - /**
117.1572 - * Determines if the specified character is a titlecase character.
117.1573 - * <p>
117.1574 - * A character is a titlecase character if its general
117.1575 - * category type, provided by {@code Character.getType(ch)},
117.1576 - * is {@code TITLECASE_LETTER}.
117.1577 - * <p>
117.1578 - * Some characters look like pairs of Latin letters. For example, there
117.1579 - * is an uppercase letter that looks like "LJ" and has a corresponding
117.1580 - * lowercase letter that looks like "lj". A third form, which looks like "Lj",
117.1581 - * is the appropriate form to use when rendering a word in lowercase
117.1582 - * with initial capitals, as for a book title.
117.1583 - * <p>
117.1584 - * These are some of the Unicode characters for which this method returns
117.1585 - * {@code true}:
117.1586 - * <ul>
117.1587 - * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
117.1588 - * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
117.1589 - * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
117.1590 - * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
117.1591 - * </ul>
117.1592 - * <p> Many other Unicode characters are titlecase too.<p>
117.1593 - *
117.1594 - * <p><b>Note:</b> This method cannot handle <a
117.1595 - * href="#supplementary"> supplementary characters</a>. To support
117.1596 - * all Unicode characters, including supplementary characters, use
117.1597 - * the {@link #isTitleCase(int)} method.
117.1598 - *
117.1599 - * @param ch the character to be tested.
117.1600 - * @return {@code true} if the character is titlecase;
117.1601 - * {@code false} otherwise.
117.1602 - * @see Character#isLowerCase(char)
117.1603 - * @see Character#isUpperCase(char)
117.1604 - * @see Character#toTitleCase(char)
117.1605 - * @see Character#getType(char)
117.1606 - * @since 1.0.2
117.1607 - */
117.1608 - public static boolean isTitleCase(char ch) {
117.1609 - return isTitleCase((int)ch);
117.1610 - }
117.1611 -
117.1612 - /**
117.1613 - * Determines if the specified character (Unicode code point) is a titlecase character.
117.1614 - * <p>
117.1615 - * A character is a titlecase character if its general
117.1616 - * category type, provided by {@link Character#getType(int) getType(codePoint)},
117.1617 - * is {@code TITLECASE_LETTER}.
117.1618 - * <p>
117.1619 - * Some characters look like pairs of Latin letters. For example, there
117.1620 - * is an uppercase letter that looks like "LJ" and has a corresponding
117.1621 - * lowercase letter that looks like "lj". A third form, which looks like "Lj",
117.1622 - * is the appropriate form to use when rendering a word in lowercase
117.1623 - * with initial capitals, as for a book title.
117.1624 - * <p>
117.1625 - * These are some of the Unicode characters for which this method returns
117.1626 - * {@code true}:
117.1627 - * <ul>
117.1628 - * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON}
117.1629 - * <li>{@code LATIN CAPITAL LETTER L WITH SMALL LETTER J}
117.1630 - * <li>{@code LATIN CAPITAL LETTER N WITH SMALL LETTER J}
117.1631 - * <li>{@code LATIN CAPITAL LETTER D WITH SMALL LETTER Z}
117.1632 - * </ul>
117.1633 - * <p> Many other Unicode characters are titlecase too.<p>
117.1634 - *
117.1635 - * @param codePoint the character (Unicode code point) to be tested.
117.1636 - * @return {@code true} if the character is titlecase;
117.1637 - * {@code false} otherwise.
117.1638 - * @see Character#isLowerCase(int)
117.1639 - * @see Character#isUpperCase(int)
117.1640 - * @see Character#toTitleCase(int)
117.1641 - * @see Character#getType(int)
117.1642 - * @since 1.5
117.1643 - */
117.1644 - public static boolean isTitleCase(int codePoint) {
117.1645 - return getType(codePoint) == Character.TITLECASE_LETTER;
117.1646 - }
117.1647 -
117.1648 - /**
117.1649 - * Determines if the specified character is a digit.
117.1650 - * <p>
117.1651 - * A character is a digit if its general category type, provided
117.1652 - * by {@code Character.getType(ch)}, is
117.1653 - * {@code DECIMAL_DIGIT_NUMBER}.
117.1654 - * <p>
117.1655 - * Some Unicode character ranges that contain digits:
117.1656 - * <ul>
117.1657 - * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
117.1658 - * ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
117.1659 - * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
117.1660 - * Arabic-Indic digits
117.1661 - * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
117.1662 - * Extended Arabic-Indic digits
117.1663 - * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
117.1664 - * Devanagari digits
117.1665 - * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
117.1666 - * Fullwidth digits
117.1667 - * </ul>
117.1668 - *
117.1669 - * Many other character ranges contain digits as well.
117.1670 - *
117.1671 - * <p><b>Note:</b> This method cannot handle <a
117.1672 - * href="#supplementary"> supplementary characters</a>. To support
117.1673 - * all Unicode characters, including supplementary characters, use
117.1674 - * the {@link #isDigit(int)} method.
117.1675 - *
117.1676 - * @param ch the character to be tested.
117.1677 - * @return {@code true} if the character is a digit;
117.1678 - * {@code false} otherwise.
117.1679 - * @see Character#digit(char, int)
117.1680 - * @see Character#forDigit(int, int)
117.1681 - * @see Character#getType(char)
117.1682 - */
117.1683 - public static boolean isDigit(char ch) {
117.1684 - return String.valueOf(ch).matches("\\d");
117.1685 - }
117.1686 -
117.1687 - /**
117.1688 - * Determines if the specified character (Unicode code point) is a digit.
117.1689 - * <p>
117.1690 - * A character is a digit if its general category type, provided
117.1691 - * by {@link Character#getType(int) getType(codePoint)}, is
117.1692 - * {@code DECIMAL_DIGIT_NUMBER}.
117.1693 - * <p>
117.1694 - * Some Unicode character ranges that contain digits:
117.1695 - * <ul>
117.1696 - * <li>{@code '\u005Cu0030'} through {@code '\u005Cu0039'},
117.1697 - * ISO-LATIN-1 digits ({@code '0'} through {@code '9'})
117.1698 - * <li>{@code '\u005Cu0660'} through {@code '\u005Cu0669'},
117.1699 - * Arabic-Indic digits
117.1700 - * <li>{@code '\u005Cu06F0'} through {@code '\u005Cu06F9'},
117.1701 - * Extended Arabic-Indic digits
117.1702 - * <li>{@code '\u005Cu0966'} through {@code '\u005Cu096F'},
117.1703 - * Devanagari digits
117.1704 - * <li>{@code '\u005CuFF10'} through {@code '\u005CuFF19'},
117.1705 - * Fullwidth digits
117.1706 - * </ul>
117.1707 - *
117.1708 - * Many other character ranges contain digits as well.
117.1709 - *
117.1710 - * @param codePoint the character (Unicode code point) to be tested.
117.1711 - * @return {@code true} if the character is a digit;
117.1712 - * {@code false} otherwise.
117.1713 - * @see Character#forDigit(int, int)
117.1714 - * @see Character#getType(int)
117.1715 - * @since 1.5
117.1716 - */
117.1717 - public static boolean isDigit(int codePoint) {
117.1718 - return fromCodeChars(codePoint).matches("\\d");
117.1719 - }
117.1720 -
117.1721 - @JavaScriptBody(args = "c", body = "return String.fromCharCode(c);")
117.1722 - private native static String fromCodeChars(int codePoint);
117.1723 -
117.1724 - /**
117.1725 - * Determines if a character is defined in Unicode.
117.1726 - * <p>
117.1727 - * A character is defined if at least one of the following is true:
117.1728 - * <ul>
117.1729 - * <li>It has an entry in the UnicodeData file.
117.1730 - * <li>It has a value in a range defined by the UnicodeData file.
117.1731 - * </ul>
117.1732 - *
117.1733 - * <p><b>Note:</b> This method cannot handle <a
117.1734 - * href="#supplementary"> supplementary characters</a>. To support
117.1735 - * all Unicode characters, including supplementary characters, use
117.1736 - * the {@link #isDefined(int)} method.
117.1737 - *
117.1738 - * @param ch the character to be tested
117.1739 - * @return {@code true} if the character has a defined meaning
117.1740 - * in Unicode; {@code false} otherwise.
117.1741 - * @see Character#isDigit(char)
117.1742 - * @see Character#isLetter(char)
117.1743 - * @see Character#isLetterOrDigit(char)
117.1744 - * @see Character#isLowerCase(char)
117.1745 - * @see Character#isTitleCase(char)
117.1746 - * @see Character#isUpperCase(char)
117.1747 - * @since 1.0.2
117.1748 - */
117.1749 - public static boolean isDefined(char ch) {
117.1750 - return isDefined((int)ch);
117.1751 - }
117.1752 -
117.1753 - /**
117.1754 - * Determines if a character (Unicode code point) is defined in Unicode.
117.1755 - * <p>
117.1756 - * A character is defined if at least one of the following is true:
117.1757 - * <ul>
117.1758 - * <li>It has an entry in the UnicodeData file.
117.1759 - * <li>It has a value in a range defined by the UnicodeData file.
117.1760 - * </ul>
117.1761 - *
117.1762 - * @param codePoint the character (Unicode code point) to be tested.
117.1763 - * @return {@code true} if the character has a defined meaning
117.1764 - * in Unicode; {@code false} otherwise.
117.1765 - * @see Character#isDigit(int)
117.1766 - * @see Character#isLetter(int)
117.1767 - * @see Character#isLetterOrDigit(int)
117.1768 - * @see Character#isLowerCase(int)
117.1769 - * @see Character#isTitleCase(int)
117.1770 - * @see Character#isUpperCase(int)
117.1771 - * @since 1.5
117.1772 - */
117.1773 - public static boolean isDefined(int codePoint) {
117.1774 - return getType(codePoint) != Character.UNASSIGNED;
117.1775 - }
117.1776 -
117.1777 - /**
117.1778 - * Determines if the specified character is a letter.
117.1779 - * <p>
117.1780 - * A character is considered to be a letter if its general
117.1781 - * category type, provided by {@code Character.getType(ch)},
117.1782 - * is any of the following:
117.1783 - * <ul>
117.1784 - * <li> {@code UPPERCASE_LETTER}
117.1785 - * <li> {@code LOWERCASE_LETTER}
117.1786 - * <li> {@code TITLECASE_LETTER}
117.1787 - * <li> {@code MODIFIER_LETTER}
117.1788 - * <li> {@code OTHER_LETTER}
117.1789 - * </ul>
117.1790 - *
117.1791 - * Not all letters have case. Many characters are
117.1792 - * letters but are neither uppercase nor lowercase nor titlecase.
117.1793 - *
117.1794 - * <p><b>Note:</b> This method cannot handle <a
117.1795 - * href="#supplementary"> supplementary characters</a>. To support
117.1796 - * all Unicode characters, including supplementary characters, use
117.1797 - * the {@link #isLetter(int)} method.
117.1798 - *
117.1799 - * @param ch the character to be tested.
117.1800 - * @return {@code true} if the character is a letter;
117.1801 - * {@code false} otherwise.
117.1802 - * @see Character#isDigit(char)
117.1803 - * @see Character#isJavaIdentifierStart(char)
117.1804 - * @see Character#isJavaLetter(char)
117.1805 - * @see Character#isJavaLetterOrDigit(char)
117.1806 - * @see Character#isLetterOrDigit(char)
117.1807 - * @see Character#isLowerCase(char)
117.1808 - * @see Character#isTitleCase(char)
117.1809 - * @see Character#isUnicodeIdentifierStart(char)
117.1810 - * @see Character#isUpperCase(char)
117.1811 - */
117.1812 - public static boolean isLetter(char ch) {
117.1813 - return String.valueOf(ch).matches("\\w") && !isDigit(ch);
117.1814 - }
117.1815 -
117.1816 - /**
117.1817 - * Determines if the specified character (Unicode code point) is a letter.
117.1818 - * <p>
117.1819 - * A character is considered to be a letter if its general
117.1820 - * category type, provided by {@link Character#getType(int) getType(codePoint)},
117.1821 - * is any of the following:
117.1822 - * <ul>
117.1823 - * <li> {@code UPPERCASE_LETTER}
117.1824 - * <li> {@code LOWERCASE_LETTER}
117.1825 - * <li> {@code TITLECASE_LETTER}
117.1826 - * <li> {@code MODIFIER_LETTER}
117.1827 - * <li> {@code OTHER_LETTER}
117.1828 - * </ul>
117.1829 - *
117.1830 - * Not all letters have case. Many characters are
117.1831 - * letters but are neither uppercase nor lowercase nor titlecase.
117.1832 - *
117.1833 - * @param codePoint the character (Unicode code point) to be tested.
117.1834 - * @return {@code true} if the character is a letter;
117.1835 - * {@code false} otherwise.
117.1836 - * @see Character#isDigit(int)
117.1837 - * @see Character#isJavaIdentifierStart(int)
117.1838 - * @see Character#isLetterOrDigit(int)
117.1839 - * @see Character#isLowerCase(int)
117.1840 - * @see Character#isTitleCase(int)
117.1841 - * @see Character#isUnicodeIdentifierStart(int)
117.1842 - * @see Character#isUpperCase(int)
117.1843 - * @since 1.5
117.1844 - */
117.1845 - public static boolean isLetter(int codePoint) {
117.1846 - return fromCodeChars(codePoint).matches("\\w") && !isDigit(codePoint);
117.1847 - }
117.1848 -
117.1849 - /**
117.1850 - * Determines if the specified character is a letter or digit.
117.1851 - * <p>
117.1852 - * A character is considered to be a letter or digit if either
117.1853 - * {@code Character.isLetter(char ch)} or
117.1854 - * {@code Character.isDigit(char ch)} returns
117.1855 - * {@code true} for the character.
117.1856 - *
117.1857 - * <p><b>Note:</b> This method cannot handle <a
117.1858 - * href="#supplementary"> supplementary characters</a>. To support
117.1859 - * all Unicode characters, including supplementary characters, use
117.1860 - * the {@link #isLetterOrDigit(int)} method.
117.1861 - *
117.1862 - * @param ch the character to be tested.
117.1863 - * @return {@code true} if the character is a letter or digit;
117.1864 - * {@code false} otherwise.
117.1865 - * @see Character#isDigit(char)
117.1866 - * @see Character#isJavaIdentifierPart(char)
117.1867 - * @see Character#isJavaLetter(char)
117.1868 - * @see Character#isJavaLetterOrDigit(char)
117.1869 - * @see Character#isLetter(char)
117.1870 - * @see Character#isUnicodeIdentifierPart(char)
117.1871 - * @since 1.0.2
117.1872 - */
117.1873 - public static boolean isLetterOrDigit(char ch) {
117.1874 - return String.valueOf(ch).matches("\\w");
117.1875 - }
117.1876 -
117.1877 - /**
117.1878 - * Determines if the specified character (Unicode code point) is a letter or digit.
117.1879 - * <p>
117.1880 - * A character is considered to be a letter or digit if either
117.1881 - * {@link #isLetter(int) isLetter(codePoint)} or
117.1882 - * {@link #isDigit(int) isDigit(codePoint)} returns
117.1883 - * {@code true} for the character.
117.1884 - *
117.1885 - * @param codePoint the character (Unicode code point) to be tested.
117.1886 - * @return {@code true} if the character is a letter or digit;
117.1887 - * {@code false} otherwise.
117.1888 - * @see Character#isDigit(int)
117.1889 - * @see Character#isJavaIdentifierPart(int)
117.1890 - * @see Character#isLetter(int)
117.1891 - * @see Character#isUnicodeIdentifierPart(int)
117.1892 - * @since 1.5
117.1893 - */
117.1894 - public static boolean isLetterOrDigit(int codePoint) {
117.1895 - return fromCodeChars(codePoint).matches("\\w");
117.1896 - }
117.1897 -
117.1898 - static int getType(int x) {
117.1899 - throw new UnsupportedOperationException();
117.1900 - }
117.1901 -
117.1902 - /**
117.1903 - * Converts the character argument to lowercase using case
117.1904 - * mapping information from the UnicodeData file.
117.1905 - * <p>
117.1906 - * Note that
117.1907 - * {@code Character.isLowerCase(Character.toLowerCase(ch))}
117.1908 - * does not always return {@code true} for some ranges of
117.1909 - * characters, particularly those that are symbols or ideographs.
117.1910 - *
117.1911 - * <p>In general, {@link String#toLowerCase()} should be used to map
117.1912 - * characters to lowercase. {@code String} case mapping methods
117.1913 - * have several benefits over {@code Character} case mapping methods.
117.1914 - * {@code String} case mapping methods can perform locale-sensitive
117.1915 - * mappings, context-sensitive mappings, and 1:M character mappings, whereas
117.1916 - * the {@code Character} case mapping methods cannot.
117.1917 - *
117.1918 - * <p><b>Note:</b> This method cannot handle <a
117.1919 - * href="#supplementary"> supplementary characters</a>. To support
117.1920 - * all Unicode characters, including supplementary characters, use
117.1921 - * the {@link #toLowerCase(int)} method.
117.1922 - *
117.1923 - * @param ch the character to be converted.
117.1924 - * @return the lowercase equivalent of the character, if any;
117.1925 - * otherwise, the character itself.
117.1926 - * @see Character#isLowerCase(char)
117.1927 - * @see String#toLowerCase()
117.1928 - */
117.1929 - public static char toLowerCase(char ch) {
117.1930 - return String.valueOf(ch).toLowerCase().charAt(0);
117.1931 - }
117.1932 -
117.1933 - /**
117.1934 - * Converts the character argument to uppercase using case mapping
117.1935 - * information from the UnicodeData file.
117.1936 - * <p>
117.1937 - * Note that
117.1938 - * {@code Character.isUpperCase(Character.toUpperCase(ch))}
117.1939 - * does not always return {@code true} for some ranges of
117.1940 - * characters, particularly those that are symbols or ideographs.
117.1941 - *
117.1942 - * <p>In general, {@link String#toUpperCase()} should be used to map
117.1943 - * characters to uppercase. {@code String} case mapping methods
117.1944 - * have several benefits over {@code Character} case mapping methods.
117.1945 - * {@code String} case mapping methods can perform locale-sensitive
117.1946 - * mappings, context-sensitive mappings, and 1:M character mappings, whereas
117.1947 - * the {@code Character} case mapping methods cannot.
117.1948 - *
117.1949 - * <p><b>Note:</b> This method cannot handle <a
117.1950 - * href="#supplementary"> supplementary characters</a>. To support
117.1951 - * all Unicode characters, including supplementary characters, use
117.1952 - * the {@link #toUpperCase(int)} method.
117.1953 - *
117.1954 - * @param ch the character to be converted.
117.1955 - * @return the uppercase equivalent of the character, if any;
117.1956 - * otherwise, the character itself.
117.1957 - * @see Character#isUpperCase(char)
117.1958 - * @see String#toUpperCase()
117.1959 - */
117.1960 - public static char toUpperCase(char ch) {
117.1961 - return String.valueOf(ch).toUpperCase().charAt(0);
117.1962 - }
117.1963 -
117.1964 - /**
117.1965 - * Returns the numeric value of the character {@code ch} in the
117.1966 - * specified radix.
117.1967 - * <p>
117.1968 - * If the radix is not in the range {@code MIN_RADIX} ≤
117.1969 - * {@code radix} ≤ {@code MAX_RADIX} or if the
117.1970 - * value of {@code ch} is not a valid digit in the specified
117.1971 - * radix, {@code -1} is returned. A character is a valid digit
117.1972 - * if at least one of the following is true:
117.1973 - * <ul>
117.1974 - * <li>The method {@code isDigit} is {@code true} of the character
117.1975 - * and the Unicode decimal digit value of the character (or its
117.1976 - * single-character decomposition) is less than the specified radix.
117.1977 - * In this case the decimal digit value is returned.
117.1978 - * <li>The character is one of the uppercase Latin letters
117.1979 - * {@code 'A'} through {@code 'Z'} and its code is less than
117.1980 - * {@code radix + 'A' - 10}.
117.1981 - * In this case, {@code ch - 'A' + 10}
117.1982 - * is returned.
117.1983 - * <li>The character is one of the lowercase Latin letters
117.1984 - * {@code 'a'} through {@code 'z'} and its code is less than
117.1985 - * {@code radix + 'a' - 10}.
117.1986 - * In this case, {@code ch - 'a' + 10}
117.1987 - * is returned.
117.1988 - * <li>The character is one of the fullwidth uppercase Latin letters A
117.1989 - * ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
117.1990 - * and its code is less than
117.1991 - * {@code radix + '\u005CuFF21' - 10}.
117.1992 - * In this case, {@code ch - '\u005CuFF21' + 10}
117.1993 - * is returned.
117.1994 - * <li>The character is one of the fullwidth lowercase Latin letters a
117.1995 - * ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
117.1996 - * and its code is less than
117.1997 - * {@code radix + '\u005CuFF41' - 10}.
117.1998 - * In this case, {@code ch - '\u005CuFF41' + 10}
117.1999 - * is returned.
117.2000 - * </ul>
117.2001 - *
117.2002 - * <p><b>Note:</b> This method cannot handle <a
117.2003 - * href="#supplementary"> supplementary characters</a>. To support
117.2004 - * all Unicode characters, including supplementary characters, use
117.2005 - * the {@link #digit(int, int)} method.
117.2006 - *
117.2007 - * @param ch the character to be converted.
117.2008 - * @param radix the radix.
117.2009 - * @return the numeric value represented by the character in the
117.2010 - * specified radix.
117.2011 - * @see Character#forDigit(int, int)
117.2012 - * @see Character#isDigit(char)
117.2013 - */
117.2014 - public static int digit(char ch, int radix) {
117.2015 - return digit((int)ch, radix);
117.2016 - }
117.2017 -
117.2018 - /**
117.2019 - * Returns the numeric value of the specified character (Unicode
117.2020 - * code point) in the specified radix.
117.2021 - *
117.2022 - * <p>If the radix is not in the range {@code MIN_RADIX} ≤
117.2023 - * {@code radix} ≤ {@code MAX_RADIX} or if the
117.2024 - * character is not a valid digit in the specified
117.2025 - * radix, {@code -1} is returned. A character is a valid digit
117.2026 - * if at least one of the following is true:
117.2027 - * <ul>
117.2028 - * <li>The method {@link #isDigit(int) isDigit(codePoint)} is {@code true} of the character
117.2029 - * and the Unicode decimal digit value of the character (or its
117.2030 - * single-character decomposition) is less than the specified radix.
117.2031 - * In this case the decimal digit value is returned.
117.2032 - * <li>The character is one of the uppercase Latin letters
117.2033 - * {@code 'A'} through {@code 'Z'} and its code is less than
117.2034 - * {@code radix + 'A' - 10}.
117.2035 - * In this case, {@code codePoint - 'A' + 10}
117.2036 - * is returned.
117.2037 - * <li>The character is one of the lowercase Latin letters
117.2038 - * {@code 'a'} through {@code 'z'} and its code is less than
117.2039 - * {@code radix + 'a' - 10}.
117.2040 - * In this case, {@code codePoint - 'a' + 10}
117.2041 - * is returned.
117.2042 - * <li>The character is one of the fullwidth uppercase Latin letters A
117.2043 - * ({@code '\u005CuFF21'}) through Z ({@code '\u005CuFF3A'})
117.2044 - * and its code is less than
117.2045 - * {@code radix + '\u005CuFF21' - 10}.
117.2046 - * In this case,
117.2047 - * {@code codePoint - '\u005CuFF21' + 10}
117.2048 - * is returned.
117.2049 - * <li>The character is one of the fullwidth lowercase Latin letters a
117.2050 - * ({@code '\u005CuFF41'}) through z ({@code '\u005CuFF5A'})
117.2051 - * and its code is less than
117.2052 - * {@code radix + '\u005CuFF41'- 10}.
117.2053 - * In this case,
117.2054 - * {@code codePoint - '\u005CuFF41' + 10}
117.2055 - * is returned.
117.2056 - * </ul>
117.2057 - *
117.2058 - * @param codePoint the character (Unicode code point) to be converted.
117.2059 - * @param radix the radix.
117.2060 - * @return the numeric value represented by the character in the
117.2061 - * specified radix.
117.2062 - * @see Character#forDigit(int, int)
117.2063 - * @see Character#isDigit(int)
117.2064 - * @since 1.5
117.2065 - */
117.2066 - public static int digit(int codePoint, int radix) {
117.2067 - throw new UnsupportedOperationException();
117.2068 - }
117.2069 -
117.2070 - /**
117.2071 - * Returns the {@code int} value that the specified Unicode
117.2072 - * character represents. For example, the character
117.2073 - * {@code '\u005Cu216C'} (the roman numeral fifty) will return
117.2074 - * an int with a value of 50.
117.2075 - * <p>
117.2076 - * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
117.2077 - * {@code '\u005Cu005A'}), lowercase
117.2078 - * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
117.2079 - * full width variant ({@code '\u005CuFF21'} through
117.2080 - * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
117.2081 - * {@code '\u005CuFF5A'}) forms have numeric values from 10
117.2082 - * through 35. This is independent of the Unicode specification,
117.2083 - * which does not assign numeric values to these {@code char}
117.2084 - * values.
117.2085 - * <p>
117.2086 - * If the character does not have a numeric value, then -1 is returned.
117.2087 - * If the character has a numeric value that cannot be represented as a
117.2088 - * nonnegative integer (for example, a fractional value), then -2
117.2089 - * is returned.
117.2090 - *
117.2091 - * <p><b>Note:</b> This method cannot handle <a
117.2092 - * href="#supplementary"> supplementary characters</a>. To support
117.2093 - * all Unicode characters, including supplementary characters, use
117.2094 - * the {@link #getNumericValue(int)} method.
117.2095 - *
117.2096 - * @param ch the character to be converted.
117.2097 - * @return the numeric value of the character, as a nonnegative {@code int}
117.2098 - * value; -2 if the character has a numeric value that is not a
117.2099 - * nonnegative integer; -1 if the character has no numeric value.
117.2100 - * @see Character#forDigit(int, int)
117.2101 - * @see Character#isDigit(char)
117.2102 - * @since 1.1
117.2103 - */
117.2104 - public static int getNumericValue(char ch) {
117.2105 - return getNumericValue((int)ch);
117.2106 - }
117.2107 -
117.2108 - /**
117.2109 - * Returns the {@code int} value that the specified
117.2110 - * character (Unicode code point) represents. For example, the character
117.2111 - * {@code '\u005Cu216C'} (the Roman numeral fifty) will return
117.2112 - * an {@code int} with a value of 50.
117.2113 - * <p>
117.2114 - * The letters A-Z in their uppercase ({@code '\u005Cu0041'} through
117.2115 - * {@code '\u005Cu005A'}), lowercase
117.2116 - * ({@code '\u005Cu0061'} through {@code '\u005Cu007A'}), and
117.2117 - * full width variant ({@code '\u005CuFF21'} through
117.2118 - * {@code '\u005CuFF3A'} and {@code '\u005CuFF41'} through
117.2119 - * {@code '\u005CuFF5A'}) forms have numeric values from 10
117.2120 - * through 35. This is independent of the Unicode specification,
117.2121 - * which does not assign numeric values to these {@code char}
117.2122 - * values.
117.2123 - * <p>
117.2124 - * If the character does not have a numeric value, then -1 is returned.
117.2125 - * If the character has a numeric value that cannot be represented as a
117.2126 - * nonnegative integer (for example, a fractional value), then -2
117.2127 - * is returned.
117.2128 - *
117.2129 - * @param codePoint the character (Unicode code point) to be converted.
117.2130 - * @return the numeric value of the character, as a nonnegative {@code int}
117.2131 - * value; -2 if the character has a numeric value that is not a
117.2132 - * nonnegative integer; -1 if the character has no numeric value.
117.2133 - * @see Character#forDigit(int, int)
117.2134 - * @see Character#isDigit(int)
117.2135 - * @since 1.5
117.2136 - */
117.2137 - public static int getNumericValue(int codePoint) {
117.2138 - throw new UnsupportedOperationException();
117.2139 - }
117.2140 -
117.2141 - /**
117.2142 - * Determines if the specified character is ISO-LATIN-1 white space.
117.2143 - * This method returns {@code true} for the following five
117.2144 - * characters only:
117.2145 - * <table>
117.2146 - * <tr><td>{@code '\t'}</td> <td>{@code U+0009}</td>
117.2147 - * <td>{@code HORIZONTAL TABULATION}</td></tr>
117.2148 - * <tr><td>{@code '\n'}</td> <td>{@code U+000A}</td>
117.2149 - * <td>{@code NEW LINE}</td></tr>
117.2150 - * <tr><td>{@code '\f'}</td> <td>{@code U+000C}</td>
117.2151 - * <td>{@code FORM FEED}</td></tr>
117.2152 - * <tr><td>{@code '\r'}</td> <td>{@code U+000D}</td>
117.2153 - * <td>{@code CARRIAGE RETURN}</td></tr>
117.2154 - * <tr><td>{@code ' '}</td> <td>{@code U+0020}</td>
117.2155 - * <td>{@code SPACE}</td></tr>
117.2156 - * </table>
117.2157 - *
117.2158 - * @param ch the character to be tested.
117.2159 - * @return {@code true} if the character is ISO-LATIN-1 white
117.2160 - * space; {@code false} otherwise.
117.2161 - * @see Character#isSpaceChar(char)
117.2162 - * @see Character#isWhitespace(char)
117.2163 - * @deprecated Replaced by isWhitespace(char).
117.2164 - */
117.2165 - @Deprecated
117.2166 - public static boolean isSpace(char ch) {
117.2167 - return (ch <= 0x0020) &&
117.2168 - (((((1L << 0x0009) |
117.2169 - (1L << 0x000A) |
117.2170 - (1L << 0x000C) |
117.2171 - (1L << 0x000D) |
117.2172 - (1L << 0x0020)) >> ch) & 1L) != 0);
117.2173 - }
117.2174 -
117.2175 -
117.2176 -
117.2177 - /**
117.2178 - * Determines if the specified character is white space according to Java.
117.2179 - * A character is a Java whitespace character if and only if it satisfies
117.2180 - * one of the following criteria:
117.2181 - * <ul>
117.2182 - * <li> It is a Unicode space character ({@code SPACE_SEPARATOR},
117.2183 - * {@code LINE_SEPARATOR}, or {@code PARAGRAPH_SEPARATOR})
117.2184 - * but is not also a non-breaking space ({@code '\u005Cu00A0'},
117.2185 - * {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
117.2186 - * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
117.2187 - * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
117.2188 - * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
117.2189 - * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
117.2190 - * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
117.2191 - * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
117.2192 - * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
117.2193 - * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
117.2194 - * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
117.2195 - * </ul>
117.2196 - *
117.2197 - * <p><b>Note:</b> This method cannot handle <a
117.2198 - * href="#supplementary"> supplementary characters</a>. To support
117.2199 - * all Unicode characters, including supplementary characters, use
117.2200 - * the {@link #isWhitespace(int)} method.
117.2201 - *
117.2202 - * @param ch the character to be tested.
117.2203 - * @return {@code true} if the character is a Java whitespace
117.2204 - * character; {@code false} otherwise.
117.2205 - * @see Character#isSpaceChar(char)
117.2206 - * @since 1.1
117.2207 - */
117.2208 - public static boolean isWhitespace(char ch) {
117.2209 - return isWhitespace((int)ch);
117.2210 - }
117.2211 -
117.2212 - /**
117.2213 - * Determines if the specified character (Unicode code point) is
117.2214 - * white space according to Java. A character is a Java
117.2215 - * whitespace character if and only if it satisfies one of the
117.2216 - * following criteria:
117.2217 - * <ul>
117.2218 - * <li> It is a Unicode space character ({@link #SPACE_SEPARATOR},
117.2219 - * {@link #LINE_SEPARATOR}, or {@link #PARAGRAPH_SEPARATOR})
117.2220 - * but is not also a non-breaking space ({@code '\u005Cu00A0'},
117.2221 - * {@code '\u005Cu2007'}, {@code '\u005Cu202F'}).
117.2222 - * <li> It is {@code '\u005Ct'}, U+0009 HORIZONTAL TABULATION.
117.2223 - * <li> It is {@code '\u005Cn'}, U+000A LINE FEED.
117.2224 - * <li> It is {@code '\u005Cu000B'}, U+000B VERTICAL TABULATION.
117.2225 - * <li> It is {@code '\u005Cf'}, U+000C FORM FEED.
117.2226 - * <li> It is {@code '\u005Cr'}, U+000D CARRIAGE RETURN.
117.2227 - * <li> It is {@code '\u005Cu001C'}, U+001C FILE SEPARATOR.
117.2228 - * <li> It is {@code '\u005Cu001D'}, U+001D GROUP SEPARATOR.
117.2229 - * <li> It is {@code '\u005Cu001E'}, U+001E RECORD SEPARATOR.
117.2230 - * <li> It is {@code '\u005Cu001F'}, U+001F UNIT SEPARATOR.
117.2231 - * </ul>
117.2232 - * <p>
117.2233 - *
117.2234 - * @param codePoint the character (Unicode code point) to be tested.
117.2235 - * @return {@code true} if the character is a Java whitespace
117.2236 - * character; {@code false} otherwise.
117.2237 - * @see Character#isSpaceChar(int)
117.2238 - * @since 1.5
117.2239 - */
117.2240 - public static boolean isWhitespace(int codePoint) {
117.2241 - throw new UnsupportedOperationException();
117.2242 - }
117.2243 -
117.2244 - /**
117.2245 - * Determines if the specified character is an ISO control
117.2246 - * character. A character is considered to be an ISO control
117.2247 - * character if its code is in the range {@code '\u005Cu0000'}
117.2248 - * through {@code '\u005Cu001F'} or in the range
117.2249 - * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
117.2250 - *
117.2251 - * <p><b>Note:</b> This method cannot handle <a
117.2252 - * href="#supplementary"> supplementary characters</a>. To support
117.2253 - * all Unicode characters, including supplementary characters, use
117.2254 - * the {@link #isISOControl(int)} method.
117.2255 - *
117.2256 - * @param ch the character to be tested.
117.2257 - * @return {@code true} if the character is an ISO control character;
117.2258 - * {@code false} otherwise.
117.2259 - *
117.2260 - * @see Character#isSpaceChar(char)
117.2261 - * @see Character#isWhitespace(char)
117.2262 - * @since 1.1
117.2263 - */
117.2264 - public static boolean isISOControl(char ch) {
117.2265 - return isISOControl((int)ch);
117.2266 - }
117.2267 -
117.2268 - /**
117.2269 - * Determines if the referenced character (Unicode code point) is an ISO control
117.2270 - * character. A character is considered to be an ISO control
117.2271 - * character if its code is in the range {@code '\u005Cu0000'}
117.2272 - * through {@code '\u005Cu001F'} or in the range
117.2273 - * {@code '\u005Cu007F'} through {@code '\u005Cu009F'}.
117.2274 - *
117.2275 - * @param codePoint the character (Unicode code point) to be tested.
117.2276 - * @return {@code true} if the character is an ISO control character;
117.2277 - * {@code false} otherwise.
117.2278 - * @see Character#isSpaceChar(int)
117.2279 - * @see Character#isWhitespace(int)
117.2280 - * @since 1.5
117.2281 - */
117.2282 - public static boolean isISOControl(int codePoint) {
117.2283 - // Optimized form of:
117.2284 - // (codePoint >= 0x00 && codePoint <= 0x1F) ||
117.2285 - // (codePoint >= 0x7F && codePoint <= 0x9F);
117.2286 - return codePoint <= 0x9F &&
117.2287 - (codePoint >= 0x7F || (codePoint >>> 5 == 0));
117.2288 - }
117.2289 -
117.2290 - /**
117.2291 - * Determines the character representation for a specific digit in
117.2292 - * the specified radix. If the value of {@code radix} is not a
117.2293 - * valid radix, or the value of {@code digit} is not a valid
117.2294 - * digit in the specified radix, the null character
117.2295 - * ({@code '\u005Cu0000'}) is returned.
117.2296 - * <p>
117.2297 - * The {@code radix} argument is valid if it is greater than or
117.2298 - * equal to {@code MIN_RADIX} and less than or equal to
117.2299 - * {@code MAX_RADIX}. The {@code digit} argument is valid if
117.2300 - * {@code 0 <= digit < radix}.
117.2301 - * <p>
117.2302 - * If the digit is less than 10, then
117.2303 - * {@code '0' + digit} is returned. Otherwise, the value
117.2304 - * {@code 'a' + digit - 10} is returned.
117.2305 - *
117.2306 - * @param digit the number to convert to a character.
117.2307 - * @param radix the radix.
117.2308 - * @return the {@code char} representation of the specified digit
117.2309 - * in the specified radix.
117.2310 - * @see Character#MIN_RADIX
117.2311 - * @see Character#MAX_RADIX
117.2312 - * @see Character#digit(char, int)
117.2313 - */
117.2314 - public static char forDigit(int digit, int radix) {
117.2315 - if ((digit >= radix) || (digit < 0)) {
117.2316 - return '\0';
117.2317 - }
117.2318 - if ((radix < Character.MIN_RADIX) || (radix > Character.MAX_RADIX)) {
117.2319 - return '\0';
117.2320 - }
117.2321 - if (digit < 10) {
117.2322 - return (char)('0' + digit);
117.2323 - }
117.2324 - return (char)('a' - 10 + digit);
117.2325 - }
117.2326 -
117.2327 - /**
117.2328 - * Compares two {@code Character} objects numerically.
117.2329 - *
117.2330 - * @param anotherCharacter the {@code Character} to be compared.
117.2331 -
117.2332 - * @return the value {@code 0} if the argument {@code Character}
117.2333 - * is equal to this {@code Character}; a value less than
117.2334 - * {@code 0} if this {@code Character} is numerically less
117.2335 - * than the {@code Character} argument; and a value greater than
117.2336 - * {@code 0} if this {@code Character} is numerically greater
117.2337 - * than the {@code Character} argument (unsigned comparison).
117.2338 - * Note that this is strictly a numerical comparison; it is not
117.2339 - * locale-dependent.
117.2340 - * @since 1.2
117.2341 - */
117.2342 - public int compareTo(Character anotherCharacter) {
117.2343 - return compare(this.value, anotherCharacter.value);
117.2344 - }
117.2345 -
117.2346 - /**
117.2347 - * Compares two {@code char} values numerically.
117.2348 - * The value returned is identical to what would be returned by:
117.2349 - * <pre>
117.2350 - * Character.valueOf(x).compareTo(Character.valueOf(y))
117.2351 - * </pre>
117.2352 - *
117.2353 - * @param x the first {@code char} to compare
117.2354 - * @param y the second {@code char} to compare
117.2355 - * @return the value {@code 0} if {@code x == y};
117.2356 - * a value less than {@code 0} if {@code x < y}; and
117.2357 - * a value greater than {@code 0} if {@code x > y}
117.2358 - * @since 1.7
117.2359 - */
117.2360 - public static int compare(char x, char y) {
117.2361 - return x - y;
117.2362 - }
117.2363 -
117.2364 -
117.2365 - /**
117.2366 - * The number of bits used to represent a <tt>char</tt> value in unsigned
117.2367 - * binary form, constant {@code 16}.
117.2368 - *
117.2369 - * @since 1.5
117.2370 - */
117.2371 - public static final int SIZE = 16;
117.2372 -
117.2373 - /**
117.2374 - * Returns the value obtained by reversing the order of the bytes in the
117.2375 - * specified <tt>char</tt> value.
117.2376 - *
117.2377 - * @return the value obtained by reversing (or, equivalently, swapping)
117.2378 - * the bytes in the specified <tt>char</tt> value.
117.2379 - * @since 1.5
117.2380 - */
117.2381 - public static char reverseBytes(char ch) {
117.2382 - return (char) (((ch & 0xFF00) >> 8) | (ch << 8));
117.2383 - }
117.2384 -
117.2385 -}
118.1 --- a/emul/src/main/java/java/lang/Class.java Wed Jan 23 20:16:48 2013 +0100
118.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
118.3 @@ -1,1205 +0,0 @@
118.4 -/*
118.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
118.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
118.7 - *
118.8 - * This code is free software; you can redistribute it and/or modify it
118.9 - * under the terms of the GNU General Public License version 2 only, as
118.10 - * published by the Free Software Foundation. Oracle designates this
118.11 - * particular file as subject to the "Classpath" exception as provided
118.12 - * by Oracle in the LICENSE file that accompanied this code.
118.13 - *
118.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
118.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
118.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
118.17 - * version 2 for more details (a copy is included in the LICENSE file that
118.18 - * accompanied this code).
118.19 - *
118.20 - * You should have received a copy of the GNU General Public License version
118.21 - * 2 along with this work; if not, write to the Free Software Foundation,
118.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
118.23 - *
118.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
118.25 - * or visit www.oracle.com if you need additional information or have any
118.26 - * questions.
118.27 - */
118.28 -
118.29 -package java.lang;
118.30 -
118.31 -import java.io.ByteArrayInputStream;
118.32 -import org.apidesign.bck2brwsr.emul.AnnotationImpl;
118.33 -import java.io.InputStream;
118.34 -import java.lang.annotation.Annotation;
118.35 -import java.lang.reflect.Field;
118.36 -import java.lang.reflect.Method;
118.37 -import java.lang.reflect.TypeVariable;
118.38 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
118.39 -import org.apidesign.bck2brwsr.emul.MethodImpl;
118.40 -
118.41 -/**
118.42 - * Instances of the class {@code Class} represent classes and
118.43 - * interfaces in a running Java application. An enum is a kind of
118.44 - * class and an annotation is a kind of interface. Every array also
118.45 - * belongs to a class that is reflected as a {@code Class} object
118.46 - * that is shared by all arrays with the same element type and number
118.47 - * of dimensions. The primitive Java types ({@code boolean},
118.48 - * {@code byte}, {@code char}, {@code short},
118.49 - * {@code int}, {@code long}, {@code float}, and
118.50 - * {@code double}), and the keyword {@code void} are also
118.51 - * represented as {@code Class} objects.
118.52 - *
118.53 - * <p> {@code Class} has no public constructor. Instead {@code Class}
118.54 - * objects are constructed automatically by the Java Virtual Machine as classes
118.55 - * are loaded and by calls to the {@code defineClass} method in the class
118.56 - * loader.
118.57 - *
118.58 - * <p> The following example uses a {@code Class} object to print the
118.59 - * class name of an object:
118.60 - *
118.61 - * <p> <blockquote><pre>
118.62 - * void printClassName(Object obj) {
118.63 - * System.out.println("The class of " + obj +
118.64 - * " is " + obj.getClass().getName());
118.65 - * }
118.66 - * </pre></blockquote>
118.67 - *
118.68 - * <p> It is also possible to get the {@code Class} object for a named
118.69 - * type (or for void) using a class literal. See Section 15.8.2 of
118.70 - * <cite>The Java™ Language Specification</cite>.
118.71 - * For example:
118.72 - *
118.73 - * <p> <blockquote>
118.74 - * {@code System.out.println("The name of class Foo is: "+Foo.class.getName());}
118.75 - * </blockquote>
118.76 - *
118.77 - * @param <T> the type of the class modeled by this {@code Class}
118.78 - * object. For example, the type of {@code String.class} is {@code
118.79 - * Class<String>}. Use {@code Class<?>} if the class being modeled is
118.80 - * unknown.
118.81 - *
118.82 - * @author unascribed
118.83 - * @see java.lang.ClassLoader#defineClass(byte[], int, int)
118.84 - * @since JDK1.0
118.85 - */
118.86 -public final
118.87 - class Class<T> implements java.io.Serializable,
118.88 - java.lang.reflect.GenericDeclaration,
118.89 - java.lang.reflect.Type,
118.90 - java.lang.reflect.AnnotatedElement {
118.91 - private static final int ANNOTATION= 0x00002000;
118.92 - private static final int ENUM = 0x00004000;
118.93 - private static final int SYNTHETIC = 0x00001000;
118.94 -
118.95 - /*
118.96 - * Constructor. Only the Java Virtual Machine creates Class
118.97 - * objects.
118.98 - */
118.99 - private Class() {}
118.100 -
118.101 -
118.102 - /**
118.103 - * Converts the object to a string. The string representation is the
118.104 - * string "class" or "interface", followed by a space, and then by the
118.105 - * fully qualified name of the class in the format returned by
118.106 - * {@code getName}. If this {@code Class} object represents a
118.107 - * primitive type, this method returns the name of the primitive type. If
118.108 - * this {@code Class} object represents void this method returns
118.109 - * "void".
118.110 - *
118.111 - * @return a string representation of this class object.
118.112 - */
118.113 - public String toString() {
118.114 - return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
118.115 - + getName();
118.116 - }
118.117 -
118.118 -
118.119 - /**
118.120 - * Returns the {@code Class} object associated with the class or
118.121 - * interface with the given string name. Invoking this method is
118.122 - * equivalent to:
118.123 - *
118.124 - * <blockquote>
118.125 - * {@code Class.forName(className, true, currentLoader)}
118.126 - * </blockquote>
118.127 - *
118.128 - * where {@code currentLoader} denotes the defining class loader of
118.129 - * the current class.
118.130 - *
118.131 - * <p> For example, the following code fragment returns the
118.132 - * runtime {@code Class} descriptor for the class named
118.133 - * {@code java.lang.Thread}:
118.134 - *
118.135 - * <blockquote>
118.136 - * {@code Class t = Class.forName("java.lang.Thread")}
118.137 - * </blockquote>
118.138 - * <p>
118.139 - * A call to {@code forName("X")} causes the class named
118.140 - * {@code X} to be initialized.
118.141 - *
118.142 - * @param className the fully qualified name of the desired class.
118.143 - * @return the {@code Class} object for the class with the
118.144 - * specified name.
118.145 - * @exception LinkageError if the linkage fails
118.146 - * @exception ExceptionInInitializerError if the initialization provoked
118.147 - * by this method fails
118.148 - * @exception ClassNotFoundException if the class cannot be located
118.149 - */
118.150 - public static Class<?> forName(String className)
118.151 - throws ClassNotFoundException {
118.152 - if (className.startsWith("[")) {
118.153 - Class<?> arrType = defineArray(className);
118.154 - Class<?> c = arrType;
118.155 - while (c != null && c.isArray()) {
118.156 - c = c.getComponentType0(); // verify component type is sane
118.157 - }
118.158 - return arrType;
118.159 - }
118.160 - Class<?> c = loadCls(className, className.replace('.', '_'));
118.161 - if (c == null) {
118.162 - throw new ClassNotFoundException(className);
118.163 - }
118.164 - return c;
118.165 - }
118.166 -
118.167 - @JavaScriptBody(args = {"n", "c" }, body =
118.168 - "if (vm[c]) return vm[c].$class;\n"
118.169 - + "if (vm.loadClass) {\n"
118.170 - + " vm.loadClass(n);\n"
118.171 - + " if (vm[c]) return vm[c].$class;\n"
118.172 - + "}\n"
118.173 - + "return null;"
118.174 - )
118.175 - private static native Class<?> loadCls(String n, String c);
118.176 -
118.177 -
118.178 - /**
118.179 - * Creates a new instance of the class represented by this {@code Class}
118.180 - * object. The class is instantiated as if by a {@code new}
118.181 - * expression with an empty argument list. The class is initialized if it
118.182 - * has not already been initialized.
118.183 - *
118.184 - * <p>Note that this method propagates any exception thrown by the
118.185 - * nullary constructor, including a checked exception. Use of
118.186 - * this method effectively bypasses the compile-time exception
118.187 - * checking that would otherwise be performed by the compiler.
118.188 - * The {@link
118.189 - * java.lang.reflect.Constructor#newInstance(java.lang.Object...)
118.190 - * Constructor.newInstance} method avoids this problem by wrapping
118.191 - * any exception thrown by the constructor in a (checked) {@link
118.192 - * java.lang.reflect.InvocationTargetException}.
118.193 - *
118.194 - * @return a newly allocated instance of the class represented by this
118.195 - * object.
118.196 - * @exception IllegalAccessException if the class or its nullary
118.197 - * constructor is not accessible.
118.198 - * @exception InstantiationException
118.199 - * if this {@code Class} represents an abstract class,
118.200 - * an interface, an array class, a primitive type, or void;
118.201 - * or if the class has no nullary constructor;
118.202 - * or if the instantiation fails for some other reason.
118.203 - * @exception ExceptionInInitializerError if the initialization
118.204 - * provoked by this method fails.
118.205 - * @exception SecurityException
118.206 - * If a security manager, <i>s</i>, is present and any of the
118.207 - * following conditions is met:
118.208 - *
118.209 - * <ul>
118.210 - *
118.211 - * <li> invocation of
118.212 - * {@link SecurityManager#checkMemberAccess
118.213 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
118.214 - * creation of new instances of this class
118.215 - *
118.216 - * <li> the caller's class loader is not the same as or an
118.217 - * ancestor of the class loader for the current class and
118.218 - * invocation of {@link SecurityManager#checkPackageAccess
118.219 - * s.checkPackageAccess()} denies access to the package
118.220 - * of this class
118.221 - *
118.222 - * </ul>
118.223 - *
118.224 - */
118.225 - @JavaScriptBody(args = { "self", "illegal" }, body =
118.226 - "\nvar c = self.cnstr;"
118.227 - + "\nif (c['cons__V']) {"
118.228 - + "\n if ((c.cons__V.access & 0x1) != 0) {"
118.229 - + "\n var inst = c();"
118.230 - + "\n c.cons__V.call(inst);"
118.231 - + "\n return inst;"
118.232 - + "\n }"
118.233 - + "\n return illegal;"
118.234 - + "\n}"
118.235 - + "\nreturn null;"
118.236 - )
118.237 - private static native Object newInstance0(Class<?> self, Object illegal);
118.238 -
118.239 - public T newInstance()
118.240 - throws InstantiationException, IllegalAccessException
118.241 - {
118.242 - Object illegal = new Object();
118.243 - Object inst = newInstance0(this, illegal);
118.244 - if (inst == null) {
118.245 - throw new InstantiationException(getName());
118.246 - }
118.247 - if (inst == illegal) {
118.248 - throw new IllegalAccessException();
118.249 - }
118.250 - return (T)inst;
118.251 - }
118.252 -
118.253 - /**
118.254 - * Determines if the specified {@code Object} is assignment-compatible
118.255 - * with the object represented by this {@code Class}. This method is
118.256 - * the dynamic equivalent of the Java language {@code instanceof}
118.257 - * operator. The method returns {@code true} if the specified
118.258 - * {@code Object} argument is non-null and can be cast to the
118.259 - * reference type represented by this {@code Class} object without
118.260 - * raising a {@code ClassCastException.} It returns {@code false}
118.261 - * otherwise.
118.262 - *
118.263 - * <p> Specifically, if this {@code Class} object represents a
118.264 - * declared class, this method returns {@code true} if the specified
118.265 - * {@code Object} argument is an instance of the represented class (or
118.266 - * of any of its subclasses); it returns {@code false} otherwise. If
118.267 - * this {@code Class} object represents an array class, this method
118.268 - * returns {@code true} if the specified {@code Object} argument
118.269 - * can be converted to an object of the array class by an identity
118.270 - * conversion or by a widening reference conversion; it returns
118.271 - * {@code false} otherwise. If this {@code Class} object
118.272 - * represents an interface, this method returns {@code true} if the
118.273 - * class or any superclass of the specified {@code Object} argument
118.274 - * implements this interface; it returns {@code false} otherwise. If
118.275 - * this {@code Class} object represents a primitive type, this method
118.276 - * returns {@code false}.
118.277 - *
118.278 - * @param obj the object to check
118.279 - * @return true if {@code obj} is an instance of this class
118.280 - *
118.281 - * @since JDK1.1
118.282 - */
118.283 - public boolean isInstance(Object obj) {
118.284 - String prop = "$instOf_" + getName().replace('.', '_');
118.285 - return hasProperty(obj, prop);
118.286 - }
118.287 -
118.288 - @JavaScriptBody(args = { "who", "prop" }, body =
118.289 - "if (who[prop]) return true; else return false;"
118.290 - )
118.291 - private static native boolean hasProperty(Object who, String prop);
118.292 -
118.293 -
118.294 - /**
118.295 - * Determines if the class or interface represented by this
118.296 - * {@code Class} object is either the same as, or is a superclass or
118.297 - * superinterface of, the class or interface represented by the specified
118.298 - * {@code Class} parameter. It returns {@code true} if so;
118.299 - * otherwise it returns {@code false}. If this {@code Class}
118.300 - * object represents a primitive type, this method returns
118.301 - * {@code true} if the specified {@code Class} parameter is
118.302 - * exactly this {@code Class} object; otherwise it returns
118.303 - * {@code false}.
118.304 - *
118.305 - * <p> Specifically, this method tests whether the type represented by the
118.306 - * specified {@code Class} parameter can be converted to the type
118.307 - * represented by this {@code Class} object via an identity conversion
118.308 - * or via a widening reference conversion. See <em>The Java Language
118.309 - * Specification</em>, sections 5.1.1 and 5.1.4 , for details.
118.310 - *
118.311 - * @param cls the {@code Class} object to be checked
118.312 - * @return the {@code boolean} value indicating whether objects of the
118.313 - * type {@code cls} can be assigned to objects of this class
118.314 - * @exception NullPointerException if the specified Class parameter is
118.315 - * null.
118.316 - * @since JDK1.1
118.317 - */
118.318 - public native boolean isAssignableFrom(Class<?> cls);
118.319 -
118.320 -
118.321 - /**
118.322 - * Determines if the specified {@code Class} object represents an
118.323 - * interface type.
118.324 - *
118.325 - * @return {@code true} if this object represents an interface;
118.326 - * {@code false} otherwise.
118.327 - */
118.328 - public boolean isInterface() {
118.329 - return (getAccess() & 0x200) != 0;
118.330 - }
118.331 -
118.332 - @JavaScriptBody(args = {}, body = "return this.access;")
118.333 - private native int getAccess();
118.334 -
118.335 -
118.336 - /**
118.337 - * Determines if this {@code Class} object represents an array class.
118.338 - *
118.339 - * @return {@code true} if this object represents an array class;
118.340 - * {@code false} otherwise.
118.341 - * @since JDK1.1
118.342 - */
118.343 - public boolean isArray() {
118.344 - return hasProperty(this, "array"); // NOI18N
118.345 - }
118.346 -
118.347 -
118.348 - /**
118.349 - * Determines if the specified {@code Class} object represents a
118.350 - * primitive type.
118.351 - *
118.352 - * <p> There are nine predefined {@code Class} objects to represent
118.353 - * the eight primitive types and void. These are created by the Java
118.354 - * Virtual Machine, and have the same names as the primitive types that
118.355 - * they represent, namely {@code boolean}, {@code byte},
118.356 - * {@code char}, {@code short}, {@code int},
118.357 - * {@code long}, {@code float}, and {@code double}.
118.358 - *
118.359 - * <p> These objects may only be accessed via the following public static
118.360 - * final variables, and are the only {@code Class} objects for which
118.361 - * this method returns {@code true}.
118.362 - *
118.363 - * @return true if and only if this class represents a primitive type
118.364 - *
118.365 - * @see java.lang.Boolean#TYPE
118.366 - * @see java.lang.Character#TYPE
118.367 - * @see java.lang.Byte#TYPE
118.368 - * @see java.lang.Short#TYPE
118.369 - * @see java.lang.Integer#TYPE
118.370 - * @see java.lang.Long#TYPE
118.371 - * @see java.lang.Float#TYPE
118.372 - * @see java.lang.Double#TYPE
118.373 - * @see java.lang.Void#TYPE
118.374 - * @since JDK1.1
118.375 - */
118.376 - @JavaScriptBody(args = {}, body =
118.377 - "if (this.primitive) return true;"
118.378 - + "else return false;"
118.379 - )
118.380 - public native boolean isPrimitive();
118.381 -
118.382 - /**
118.383 - * Returns true if this {@code Class} object represents an annotation
118.384 - * type. Note that if this method returns true, {@link #isInterface()}
118.385 - * would also return true, as all annotation types are also interfaces.
118.386 - *
118.387 - * @return {@code true} if this class object represents an annotation
118.388 - * type; {@code false} otherwise
118.389 - * @since 1.5
118.390 - */
118.391 - public boolean isAnnotation() {
118.392 - return (getModifiers() & ANNOTATION) != 0;
118.393 - }
118.394 -
118.395 - /**
118.396 - * Returns {@code true} if this class is a synthetic class;
118.397 - * returns {@code false} otherwise.
118.398 - * @return {@code true} if and only if this class is a synthetic class as
118.399 - * defined by the Java Language Specification.
118.400 - * @since 1.5
118.401 - */
118.402 - public boolean isSynthetic() {
118.403 - return (getModifiers() & SYNTHETIC) != 0;
118.404 - }
118.405 -
118.406 - /**
118.407 - * Returns the name of the entity (class, interface, array class,
118.408 - * primitive type, or void) represented by this {@code Class} object,
118.409 - * as a {@code String}.
118.410 - *
118.411 - * <p> If this class object represents a reference type that is not an
118.412 - * array type then the binary name of the class is returned, as specified
118.413 - * by
118.414 - * <cite>The Java™ Language Specification</cite>.
118.415 - *
118.416 - * <p> If this class object represents a primitive type or void, then the
118.417 - * name returned is a {@code String} equal to the Java language
118.418 - * keyword corresponding to the primitive type or void.
118.419 - *
118.420 - * <p> If this class object represents a class of arrays, then the internal
118.421 - * form of the name consists of the name of the element type preceded by
118.422 - * one or more '{@code [}' characters representing the depth of the array
118.423 - * nesting. The encoding of element type names is as follows:
118.424 - *
118.425 - * <blockquote><table summary="Element types and encodings">
118.426 - * <tr><th> Element Type <th> <th> Encoding
118.427 - * <tr><td> boolean <td> <td align=center> Z
118.428 - * <tr><td> byte <td> <td align=center> B
118.429 - * <tr><td> char <td> <td align=center> C
118.430 - * <tr><td> class or interface
118.431 - * <td> <td align=center> L<i>classname</i>;
118.432 - * <tr><td> double <td> <td align=center> D
118.433 - * <tr><td> float <td> <td align=center> F
118.434 - * <tr><td> int <td> <td align=center> I
118.435 - * <tr><td> long <td> <td align=center> J
118.436 - * <tr><td> short <td> <td align=center> S
118.437 - * </table></blockquote>
118.438 - *
118.439 - * <p> The class or interface name <i>classname</i> is the binary name of
118.440 - * the class specified above.
118.441 - *
118.442 - * <p> Examples:
118.443 - * <blockquote><pre>
118.444 - * String.class.getName()
118.445 - * returns "java.lang.String"
118.446 - * byte.class.getName()
118.447 - * returns "byte"
118.448 - * (new Object[3]).getClass().getName()
118.449 - * returns "[Ljava.lang.Object;"
118.450 - * (new int[3][4][5][6][7][8][9]).getClass().getName()
118.451 - * returns "[[[[[[[I"
118.452 - * </pre></blockquote>
118.453 - *
118.454 - * @return the name of the class or interface
118.455 - * represented by this object.
118.456 - */
118.457 - public String getName() {
118.458 - return jvmName().replace('/', '.');
118.459 - }
118.460 -
118.461 - @JavaScriptBody(args = {}, body = "return this.jvmName;")
118.462 - private native String jvmName();
118.463 -
118.464 -
118.465 - /**
118.466 - * Returns an array of {@code TypeVariable} objects that represent the
118.467 - * type variables declared by the generic declaration represented by this
118.468 - * {@code GenericDeclaration} object, in declaration order. Returns an
118.469 - * array of length 0 if the underlying generic declaration declares no type
118.470 - * variables.
118.471 - *
118.472 - * @return an array of {@code TypeVariable} objects that represent
118.473 - * the type variables declared by this generic declaration
118.474 - * @throws java.lang.reflect.GenericSignatureFormatError if the generic
118.475 - * signature of this generic declaration does not conform to
118.476 - * the format specified in
118.477 - * <cite>The Java™ Virtual Machine Specification</cite>
118.478 - * @since 1.5
118.479 - */
118.480 - public TypeVariable<Class<T>>[] getTypeParameters() {
118.481 - throw new UnsupportedOperationException();
118.482 - }
118.483 -
118.484 - /**
118.485 - * Returns the {@code Class} representing the superclass of the entity
118.486 - * (class, interface, primitive type or void) represented by this
118.487 - * {@code Class}. If this {@code Class} represents either the
118.488 - * {@code Object} class, an interface, a primitive type, or void, then
118.489 - * null is returned. If this object represents an array class then the
118.490 - * {@code Class} object representing the {@code Object} class is
118.491 - * returned.
118.492 - *
118.493 - * @return the superclass of the class represented by this object.
118.494 - */
118.495 - @JavaScriptBody(args = {}, body = "return this.superclass;")
118.496 - public native Class<? super T> getSuperclass();
118.497 -
118.498 - /**
118.499 - * Returns the Java language modifiers for this class or interface, encoded
118.500 - * in an integer. The modifiers consist of the Java Virtual Machine's
118.501 - * constants for {@code public}, {@code protected},
118.502 - * {@code private}, {@code final}, {@code static},
118.503 - * {@code abstract} and {@code interface}; they should be decoded
118.504 - * using the methods of class {@code Modifier}.
118.505 - *
118.506 - * <p> If the underlying class is an array class, then its
118.507 - * {@code public}, {@code private} and {@code protected}
118.508 - * modifiers are the same as those of its component type. If this
118.509 - * {@code Class} represents a primitive type or void, its
118.510 - * {@code public} modifier is always {@code true}, and its
118.511 - * {@code protected} and {@code private} modifiers are always
118.512 - * {@code false}. If this object represents an array class, a
118.513 - * primitive type or void, then its {@code final} modifier is always
118.514 - * {@code true} and its interface modifier is always
118.515 - * {@code false}. The values of its other modifiers are not determined
118.516 - * by this specification.
118.517 - *
118.518 - * <p> The modifier encodings are defined in <em>The Java Virtual Machine
118.519 - * Specification</em>, table 4.1.
118.520 - *
118.521 - * @return the {@code int} representing the modifiers for this class
118.522 - * @see java.lang.reflect.Modifier
118.523 - * @since JDK1.1
118.524 - */
118.525 - public native int getModifiers();
118.526 -
118.527 -
118.528 - /**
118.529 - * Returns the simple name of the underlying class as given in the
118.530 - * source code. Returns an empty string if the underlying class is
118.531 - * anonymous.
118.532 - *
118.533 - * <p>The simple name of an array is the simple name of the
118.534 - * component type with "[]" appended. In particular the simple
118.535 - * name of an array whose component type is anonymous is "[]".
118.536 - *
118.537 - * @return the simple name of the underlying class
118.538 - * @since 1.5
118.539 - */
118.540 - public String getSimpleName() {
118.541 - if (isArray())
118.542 - return getComponentType().getSimpleName()+"[]";
118.543 -
118.544 - String simpleName = getSimpleBinaryName();
118.545 - if (simpleName == null) { // top level class
118.546 - simpleName = getName();
118.547 - return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
118.548 - }
118.549 - // According to JLS3 "Binary Compatibility" (13.1) the binary
118.550 - // name of non-package classes (not top level) is the binary
118.551 - // name of the immediately enclosing class followed by a '$' followed by:
118.552 - // (for nested and inner classes): the simple name.
118.553 - // (for local classes): 1 or more digits followed by the simple name.
118.554 - // (for anonymous classes): 1 or more digits.
118.555 -
118.556 - // Since getSimpleBinaryName() will strip the binary name of
118.557 - // the immediatly enclosing class, we are now looking at a
118.558 - // string that matches the regular expression "\$[0-9]*"
118.559 - // followed by a simple name (considering the simple of an
118.560 - // anonymous class to be the empty string).
118.561 -
118.562 - // Remove leading "\$[0-9]*" from the name
118.563 - int length = simpleName.length();
118.564 - if (length < 1 || simpleName.charAt(0) != '$')
118.565 - throw new IllegalStateException("Malformed class name");
118.566 - int index = 1;
118.567 - while (index < length && isAsciiDigit(simpleName.charAt(index)))
118.568 - index++;
118.569 - // Eventually, this is the empty string iff this is an anonymous class
118.570 - return simpleName.substring(index);
118.571 - }
118.572 -
118.573 - /**
118.574 - * Returns the "simple binary name" of the underlying class, i.e.,
118.575 - * the binary name without the leading enclosing class name.
118.576 - * Returns {@code null} if the underlying class is a top level
118.577 - * class.
118.578 - */
118.579 - private String getSimpleBinaryName() {
118.580 - Class<?> enclosingClass = null; // XXX getEnclosingClass();
118.581 - if (enclosingClass == null) // top level class
118.582 - return null;
118.583 - // Otherwise, strip the enclosing class' name
118.584 - try {
118.585 - return getName().substring(enclosingClass.getName().length());
118.586 - } catch (IndexOutOfBoundsException ex) {
118.587 - throw new IllegalStateException("Malformed class name");
118.588 - }
118.589 - }
118.590 -
118.591 - /**
118.592 - * Returns an array containing {@code Field} objects reflecting all
118.593 - * the accessible public fields of the class or interface represented by
118.594 - * this {@code Class} object. The elements in the array returned are
118.595 - * not sorted and are not in any particular order. This method returns an
118.596 - * array of length 0 if the class or interface has no accessible public
118.597 - * fields, or if it represents an array class, a primitive type, or void.
118.598 - *
118.599 - * <p> Specifically, if this {@code Class} object represents a class,
118.600 - * this method returns the public fields of this class and of all its
118.601 - * superclasses. If this {@code Class} object represents an
118.602 - * interface, this method returns the fields of this interface and of all
118.603 - * its superinterfaces.
118.604 - *
118.605 - * <p> The implicit length field for array class is not reflected by this
118.606 - * method. User code should use the methods of class {@code Array} to
118.607 - * manipulate arrays.
118.608 - *
118.609 - * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
118.610 - *
118.611 - * @return the array of {@code Field} objects representing the
118.612 - * public fields
118.613 - * @exception SecurityException
118.614 - * If a security manager, <i>s</i>, is present and any of the
118.615 - * following conditions is met:
118.616 - *
118.617 - * <ul>
118.618 - *
118.619 - * <li> invocation of
118.620 - * {@link SecurityManager#checkMemberAccess
118.621 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
118.622 - * access to the fields within this class
118.623 - *
118.624 - * <li> the caller's class loader is not the same as or an
118.625 - * ancestor of the class loader for the current class and
118.626 - * invocation of {@link SecurityManager#checkPackageAccess
118.627 - * s.checkPackageAccess()} denies access to the package
118.628 - * of this class
118.629 - *
118.630 - * </ul>
118.631 - *
118.632 - * @since JDK1.1
118.633 - */
118.634 - public Field[] getFields() throws SecurityException {
118.635 - throw new SecurityException();
118.636 - }
118.637 -
118.638 - /**
118.639 - * Returns an array containing {@code Method} objects reflecting all
118.640 - * the public <em>member</em> methods of the class or interface represented
118.641 - * by this {@code Class} object, including those declared by the class
118.642 - * or interface and those inherited from superclasses and
118.643 - * superinterfaces. Array classes return all the (public) member methods
118.644 - * inherited from the {@code Object} class. The elements in the array
118.645 - * returned are not sorted and are not in any particular order. This
118.646 - * method returns an array of length 0 if this {@code Class} object
118.647 - * represents a class or interface that has no public member methods, or if
118.648 - * this {@code Class} object represents a primitive type or void.
118.649 - *
118.650 - * <p> The class initialization method {@code <clinit>} is not
118.651 - * included in the returned array. If the class declares multiple public
118.652 - * member methods with the same parameter types, they are all included in
118.653 - * the returned array.
118.654 - *
118.655 - * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
118.656 - *
118.657 - * @return the array of {@code Method} objects representing the
118.658 - * public methods of this class
118.659 - * @exception SecurityException
118.660 - * If a security manager, <i>s</i>, is present and any of the
118.661 - * following conditions is met:
118.662 - *
118.663 - * <ul>
118.664 - *
118.665 - * <li> invocation of
118.666 - * {@link SecurityManager#checkMemberAccess
118.667 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
118.668 - * access to the methods within this class
118.669 - *
118.670 - * <li> the caller's class loader is not the same as or an
118.671 - * ancestor of the class loader for the current class and
118.672 - * invocation of {@link SecurityManager#checkPackageAccess
118.673 - * s.checkPackageAccess()} denies access to the package
118.674 - * of this class
118.675 - *
118.676 - * </ul>
118.677 - *
118.678 - * @since JDK1.1
118.679 - */
118.680 - public Method[] getMethods() throws SecurityException {
118.681 - return MethodImpl.findMethods(this, 0x01);
118.682 - }
118.683 -
118.684 - /**
118.685 - * Returns a {@code Field} object that reflects the specified public
118.686 - * member field of the class or interface represented by this
118.687 - * {@code Class} object. The {@code name} parameter is a
118.688 - * {@code String} specifying the simple name of the desired field.
118.689 - *
118.690 - * <p> The field to be reflected is determined by the algorithm that
118.691 - * follows. Let C be the class represented by this object:
118.692 - * <OL>
118.693 - * <LI> If C declares a public field with the name specified, that is the
118.694 - * field to be reflected.</LI>
118.695 - * <LI> If no field was found in step 1 above, this algorithm is applied
118.696 - * recursively to each direct superinterface of C. The direct
118.697 - * superinterfaces are searched in the order they were declared.</LI>
118.698 - * <LI> If no field was found in steps 1 and 2 above, and C has a
118.699 - * superclass S, then this algorithm is invoked recursively upon S.
118.700 - * If C has no superclass, then a {@code NoSuchFieldException}
118.701 - * is thrown.</LI>
118.702 - * </OL>
118.703 - *
118.704 - * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
118.705 - *
118.706 - * @param name the field name
118.707 - * @return the {@code Field} object of this class specified by
118.708 - * {@code name}
118.709 - * @exception NoSuchFieldException if a field with the specified name is
118.710 - * not found.
118.711 - * @exception NullPointerException if {@code name} is {@code null}
118.712 - * @exception SecurityException
118.713 - * If a security manager, <i>s</i>, is present and any of the
118.714 - * following conditions is met:
118.715 - *
118.716 - * <ul>
118.717 - *
118.718 - * <li> invocation of
118.719 - * {@link SecurityManager#checkMemberAccess
118.720 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
118.721 - * access to the field
118.722 - *
118.723 - * <li> the caller's class loader is not the same as or an
118.724 - * ancestor of the class loader for the current class and
118.725 - * invocation of {@link SecurityManager#checkPackageAccess
118.726 - * s.checkPackageAccess()} denies access to the package
118.727 - * of this class
118.728 - *
118.729 - * </ul>
118.730 - *
118.731 - * @since JDK1.1
118.732 - */
118.733 - public Field getField(String name)
118.734 - throws SecurityException {
118.735 - throw new SecurityException();
118.736 - }
118.737 -
118.738 -
118.739 - /**
118.740 - * Returns a {@code Method} object that reflects the specified public
118.741 - * member method of the class or interface represented by this
118.742 - * {@code Class} object. The {@code name} parameter is a
118.743 - * {@code String} specifying the simple name of the desired method. The
118.744 - * {@code parameterTypes} parameter is an array of {@code Class}
118.745 - * objects that identify the method's formal parameter types, in declared
118.746 - * order. If {@code parameterTypes} is {@code null}, it is
118.747 - * treated as if it were an empty array.
118.748 - *
118.749 - * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
118.750 - * {@code NoSuchMethodException} is raised. Otherwise, the method to
118.751 - * be reflected is determined by the algorithm that follows. Let C be the
118.752 - * class represented by this object:
118.753 - * <OL>
118.754 - * <LI> C is searched for any <I>matching methods</I>. If no matching
118.755 - * method is found, the algorithm of step 1 is invoked recursively on
118.756 - * the superclass of C.</LI>
118.757 - * <LI> If no method was found in step 1 above, the superinterfaces of C
118.758 - * are searched for a matching method. If any such method is found, it
118.759 - * is reflected.</LI>
118.760 - * </OL>
118.761 - *
118.762 - * To find a matching method in a class C: If C declares exactly one
118.763 - * public method with the specified name and exactly the same formal
118.764 - * parameter types, that is the method reflected. If more than one such
118.765 - * method is found in C, and one of these methods has a return type that is
118.766 - * more specific than any of the others, that method is reflected;
118.767 - * otherwise one of the methods is chosen arbitrarily.
118.768 - *
118.769 - * <p>Note that there may be more than one matching method in a
118.770 - * class because while the Java language forbids a class to
118.771 - * declare multiple methods with the same signature but different
118.772 - * return types, the Java virtual machine does not. This
118.773 - * increased flexibility in the virtual machine can be used to
118.774 - * implement various language features. For example, covariant
118.775 - * returns can be implemented with {@linkplain
118.776 - * java.lang.reflect.Method#isBridge bridge methods}; the bridge
118.777 - * method and the method being overridden would have the same
118.778 - * signature but different return types.
118.779 - *
118.780 - * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
118.781 - *
118.782 - * @param name the name of the method
118.783 - * @param parameterTypes the list of parameters
118.784 - * @return the {@code Method} object that matches the specified
118.785 - * {@code name} and {@code parameterTypes}
118.786 - * @exception NoSuchMethodException if a matching method is not found
118.787 - * or if the name is "<init>"or "<clinit>".
118.788 - * @exception NullPointerException if {@code name} is {@code null}
118.789 - * @exception SecurityException
118.790 - * If a security manager, <i>s</i>, is present and any of the
118.791 - * following conditions is met:
118.792 - *
118.793 - * <ul>
118.794 - *
118.795 - * <li> invocation of
118.796 - * {@link SecurityManager#checkMemberAccess
118.797 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
118.798 - * access to the method
118.799 - *
118.800 - * <li> the caller's class loader is not the same as or an
118.801 - * ancestor of the class loader for the current class and
118.802 - * invocation of {@link SecurityManager#checkPackageAccess
118.803 - * s.checkPackageAccess()} denies access to the package
118.804 - * of this class
118.805 - *
118.806 - * </ul>
118.807 - *
118.808 - * @since JDK1.1
118.809 - */
118.810 - public Method getMethod(String name, Class<?>... parameterTypes)
118.811 - throws SecurityException, NoSuchMethodException {
118.812 - Method m = MethodImpl.findMethod(this, name, parameterTypes);
118.813 - if (m == null) {
118.814 - StringBuilder sb = new StringBuilder();
118.815 - sb.append(getName()).append('.').append(name).append('(');
118.816 - String sep = "";
118.817 - for (int i = 0; i < parameterTypes.length; i++) {
118.818 - sb.append(sep).append(parameterTypes[i].getName());
118.819 - sep = ", ";
118.820 - }
118.821 - sb.append(')');
118.822 - throw new NoSuchMethodException(sb.toString());
118.823 - }
118.824 - return m;
118.825 - }
118.826 -
118.827 - /**
118.828 - * Character.isDigit answers {@code true} to some non-ascii
118.829 - * digits. This one does not.
118.830 - */
118.831 - private static boolean isAsciiDigit(char c) {
118.832 - return '0' <= c && c <= '9';
118.833 - }
118.834 -
118.835 - /**
118.836 - * Returns the canonical name of the underlying class as
118.837 - * defined by the Java Language Specification. Returns null if
118.838 - * the underlying class does not have a canonical name (i.e., if
118.839 - * it is a local or anonymous class or an array whose component
118.840 - * type does not have a canonical name).
118.841 - * @return the canonical name of the underlying class if it exists, and
118.842 - * {@code null} otherwise.
118.843 - * @since 1.5
118.844 - */
118.845 - public String getCanonicalName() {
118.846 - if (isArray()) {
118.847 - String canonicalName = getComponentType().getCanonicalName();
118.848 - if (canonicalName != null)
118.849 - return canonicalName + "[]";
118.850 - else
118.851 - return null;
118.852 - }
118.853 -// if (isLocalOrAnonymousClass())
118.854 -// return null;
118.855 -// Class<?> enclosingClass = getEnclosingClass();
118.856 - Class<?> enclosingClass = null;
118.857 - if (enclosingClass == null) { // top level class
118.858 - return getName();
118.859 - } else {
118.860 - String enclosingName = enclosingClass.getCanonicalName();
118.861 - if (enclosingName == null)
118.862 - return null;
118.863 - return enclosingName + "." + getSimpleName();
118.864 - }
118.865 - }
118.866 -
118.867 - /**
118.868 - * Finds a resource with a given name. The rules for searching resources
118.869 - * associated with a given class are implemented by the defining
118.870 - * {@linkplain ClassLoader class loader} of the class. This method
118.871 - * delegates to this object's class loader. If this object was loaded by
118.872 - * the bootstrap class loader, the method delegates to {@link
118.873 - * ClassLoader#getSystemResourceAsStream}.
118.874 - *
118.875 - * <p> Before delegation, an absolute resource name is constructed from the
118.876 - * given resource name using this algorithm:
118.877 - *
118.878 - * <ul>
118.879 - *
118.880 - * <li> If the {@code name} begins with a {@code '/'}
118.881 - * (<tt>'\u002f'</tt>), then the absolute name of the resource is the
118.882 - * portion of the {@code name} following the {@code '/'}.
118.883 - *
118.884 - * <li> Otherwise, the absolute name is of the following form:
118.885 - *
118.886 - * <blockquote>
118.887 - * {@code modified_package_name/name}
118.888 - * </blockquote>
118.889 - *
118.890 - * <p> Where the {@code modified_package_name} is the package name of this
118.891 - * object with {@code '/'} substituted for {@code '.'}
118.892 - * (<tt>'\u002e'</tt>).
118.893 - *
118.894 - * </ul>
118.895 - *
118.896 - * @param name name of the desired resource
118.897 - * @return A {@link java.io.InputStream} object or {@code null} if
118.898 - * no resource with this name is found
118.899 - * @throws NullPointerException If {@code name} is {@code null}
118.900 - * @since JDK1.1
118.901 - */
118.902 - public InputStream getResourceAsStream(String name) {
118.903 - name = resolveName(name);
118.904 - byte[] arr = getResourceAsStream0(name);
118.905 - return arr == null ? null : new ByteArrayInputStream(arr);
118.906 - }
118.907 -
118.908 - @JavaScriptBody(args = "name", body =
118.909 - "return (vm.loadBytes) ? vm.loadBytes(name) : null;"
118.910 - )
118.911 - private static native byte[] getResourceAsStream0(String name);
118.912 -
118.913 - /**
118.914 - * Finds a resource with a given name. The rules for searching resources
118.915 - * associated with a given class are implemented by the defining
118.916 - * {@linkplain ClassLoader class loader} of the class. This method
118.917 - * delegates to this object's class loader. If this object was loaded by
118.918 - * the bootstrap class loader, the method delegates to {@link
118.919 - * ClassLoader#getSystemResource}.
118.920 - *
118.921 - * <p> Before delegation, an absolute resource name is constructed from the
118.922 - * given resource name using this algorithm:
118.923 - *
118.924 - * <ul>
118.925 - *
118.926 - * <li> If the {@code name} begins with a {@code '/'}
118.927 - * (<tt>'\u002f'</tt>), then the absolute name of the resource is the
118.928 - * portion of the {@code name} following the {@code '/'}.
118.929 - *
118.930 - * <li> Otherwise, the absolute name is of the following form:
118.931 - *
118.932 - * <blockquote>
118.933 - * {@code modified_package_name/name}
118.934 - * </blockquote>
118.935 - *
118.936 - * <p> Where the {@code modified_package_name} is the package name of this
118.937 - * object with {@code '/'} substituted for {@code '.'}
118.938 - * (<tt>'\u002e'</tt>).
118.939 - *
118.940 - * </ul>
118.941 - *
118.942 - * @param name name of the desired resource
118.943 - * @return A {@link java.net.URL} object or {@code null} if no
118.944 - * resource with this name is found
118.945 - * @since JDK1.1
118.946 - */
118.947 - public java.net.URL getResource(String name) {
118.948 - name = resolveName(name);
118.949 - ClassLoader cl = null;
118.950 - if (cl==null) {
118.951 - // A system class.
118.952 - return ClassLoader.getSystemResource(name);
118.953 - }
118.954 - return cl.getResource(name);
118.955 - }
118.956 -
118.957 -
118.958 - /**
118.959 - * Add a package name prefix if the name is not absolute Remove leading "/"
118.960 - * if name is absolute
118.961 - */
118.962 - private String resolveName(String name) {
118.963 - if (name == null) {
118.964 - return name;
118.965 - }
118.966 - if (!name.startsWith("/")) {
118.967 - Class<?> c = this;
118.968 - while (c.isArray()) {
118.969 - c = c.getComponentType();
118.970 - }
118.971 - String baseName = c.getName();
118.972 - int index = baseName.lastIndexOf('.');
118.973 - if (index != -1) {
118.974 - name = baseName.substring(0, index).replace('.', '/')
118.975 - +"/"+name;
118.976 - }
118.977 - } else {
118.978 - name = name.substring(1);
118.979 - }
118.980 - return name;
118.981 - }
118.982 -
118.983 - /**
118.984 - * Returns the class loader for the class. Some implementations may use
118.985 - * null to represent the bootstrap class loader. This method will return
118.986 - * null in such implementations if this class was loaded by the bootstrap
118.987 - * class loader.
118.988 - *
118.989 - * <p> If a security manager is present, and the caller's class loader is
118.990 - * not null and the caller's class loader is not the same as or an ancestor of
118.991 - * the class loader for the class whose class loader is requested, then
118.992 - * this method calls the security manager's {@code checkPermission}
118.993 - * method with a {@code RuntimePermission("getClassLoader")}
118.994 - * permission to ensure it's ok to access the class loader for the class.
118.995 - *
118.996 - * <p>If this object
118.997 - * represents a primitive type or void, null is returned.
118.998 - *
118.999 - * @return the class loader that loaded the class or interface
118.1000 - * represented by this object.
118.1001 - * @throws SecurityException
118.1002 - * if a security manager exists and its
118.1003 - * {@code checkPermission} method denies
118.1004 - * access to the class loader for the class.
118.1005 - * @see java.lang.ClassLoader
118.1006 - * @see SecurityManager#checkPermission
118.1007 - * @see java.lang.RuntimePermission
118.1008 - */
118.1009 - public ClassLoader getClassLoader() {
118.1010 - throw new SecurityException();
118.1011 - }
118.1012 -
118.1013 - /**
118.1014 - * Returns the {@code Class} representing the component type of an
118.1015 - * array. If this class does not represent an array class this method
118.1016 - * returns null.
118.1017 - *
118.1018 - * @return the {@code Class} representing the component type of this
118.1019 - * class if this class is an array
118.1020 - * @see java.lang.reflect.Array
118.1021 - * @since JDK1.1
118.1022 - */
118.1023 - public Class<?> getComponentType() {
118.1024 - if (isArray()) {
118.1025 - try {
118.1026 - return getComponentType0();
118.1027 - } catch (ClassNotFoundException cnfe) {
118.1028 - throw new IllegalStateException(cnfe);
118.1029 - }
118.1030 - }
118.1031 - return null;
118.1032 - }
118.1033 -
118.1034 - private Class<?> getComponentType0() throws ClassNotFoundException {
118.1035 - String n = getName().substring(1);
118.1036 - switch (n.charAt(0)) {
118.1037 - case 'L':
118.1038 - n = n.substring(1, n.length() - 1);
118.1039 - return Class.forName(n);
118.1040 - case 'I':
118.1041 - return Integer.TYPE;
118.1042 - case 'J':
118.1043 - return Long.TYPE;
118.1044 - case 'D':
118.1045 - return Double.TYPE;
118.1046 - case 'F':
118.1047 - return Float.TYPE;
118.1048 - case 'B':
118.1049 - return Byte.TYPE;
118.1050 - case 'Z':
118.1051 - return Boolean.TYPE;
118.1052 - case 'S':
118.1053 - return Short.TYPE;
118.1054 - case 'V':
118.1055 - return Void.TYPE;
118.1056 - case 'C':
118.1057 - return Character.TYPE;
118.1058 - case '[':
118.1059 - return defineArray(n);
118.1060 - default:
118.1061 - throw new ClassNotFoundException("Unknown component type of " + getName());
118.1062 - }
118.1063 - }
118.1064 -
118.1065 - @JavaScriptBody(args = { "sig" }, body =
118.1066 - "var c = Array[sig];\n" +
118.1067 - "if (c) return c;\n" +
118.1068 - "c = vm.java_lang_Class(true);\n" +
118.1069 - "c.jvmName = sig;\n" +
118.1070 - "c.superclass = vm.java_lang_Object(false).$class;\n" +
118.1071 - "c.array = true;\n" +
118.1072 - "Array[sig] = c;\n" +
118.1073 - "return c;"
118.1074 - )
118.1075 - private static native Class<?> defineArray(String sig);
118.1076 -
118.1077 - /**
118.1078 - * Returns true if and only if this class was declared as an enum in the
118.1079 - * source code.
118.1080 - *
118.1081 - * @return true if and only if this class was declared as an enum in the
118.1082 - * source code
118.1083 - * @since 1.5
118.1084 - */
118.1085 - public boolean isEnum() {
118.1086 - // An enum must both directly extend java.lang.Enum and have
118.1087 - // the ENUM bit set; classes for specialized enum constants
118.1088 - // don't do the former.
118.1089 - return (this.getModifiers() & ENUM) != 0 &&
118.1090 - this.getSuperclass() == java.lang.Enum.class;
118.1091 - }
118.1092 -
118.1093 - /**
118.1094 - * Casts an object to the class or interface represented
118.1095 - * by this {@code Class} object.
118.1096 - *
118.1097 - * @param obj the object to be cast
118.1098 - * @return the object after casting, or null if obj is null
118.1099 - *
118.1100 - * @throws ClassCastException if the object is not
118.1101 - * null and is not assignable to the type T.
118.1102 - *
118.1103 - * @since 1.5
118.1104 - */
118.1105 - public T cast(Object obj) {
118.1106 - if (obj != null && !isInstance(obj))
118.1107 - throw new ClassCastException(cannotCastMsg(obj));
118.1108 - return (T) obj;
118.1109 - }
118.1110 -
118.1111 - private String cannotCastMsg(Object obj) {
118.1112 - return "Cannot cast " + obj.getClass().getName() + " to " + getName();
118.1113 - }
118.1114 -
118.1115 - /**
118.1116 - * Casts this {@code Class} object to represent a subclass of the class
118.1117 - * represented by the specified class object. Checks that that the cast
118.1118 - * is valid, and throws a {@code ClassCastException} if it is not. If
118.1119 - * this method succeeds, it always returns a reference to this class object.
118.1120 - *
118.1121 - * <p>This method is useful when a client needs to "narrow" the type of
118.1122 - * a {@code Class} object to pass it to an API that restricts the
118.1123 - * {@code Class} objects that it is willing to accept. A cast would
118.1124 - * generate a compile-time warning, as the correctness of the cast
118.1125 - * could not be checked at runtime (because generic types are implemented
118.1126 - * by erasure).
118.1127 - *
118.1128 - * @return this {@code Class} object, cast to represent a subclass of
118.1129 - * the specified class object.
118.1130 - * @throws ClassCastException if this {@code Class} object does not
118.1131 - * represent a subclass of the specified class (here "subclass" includes
118.1132 - * the class itself).
118.1133 - * @since 1.5
118.1134 - */
118.1135 - public <U> Class<? extends U> asSubclass(Class<U> clazz) {
118.1136 - if (clazz.isAssignableFrom(this))
118.1137 - return (Class<? extends U>) this;
118.1138 - else
118.1139 - throw new ClassCastException(this.toString());
118.1140 - }
118.1141 -
118.1142 - @JavaScriptBody(args = { "ac" },
118.1143 - body =
118.1144 - "if (this.anno) {"
118.1145 - + " return this.anno['L' + ac.jvmName + ';'];"
118.1146 - + "} else return null;"
118.1147 - )
118.1148 - private Object getAnnotationData(Class<?> annotationClass) {
118.1149 - throw new UnsupportedOperationException();
118.1150 - }
118.1151 - /**
118.1152 - * @throws NullPointerException {@inheritDoc}
118.1153 - * @since 1.5
118.1154 - */
118.1155 - public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
118.1156 - Object data = getAnnotationData(annotationClass);
118.1157 - return data == null ? null : AnnotationImpl.create(annotationClass, data);
118.1158 - }
118.1159 -
118.1160 - /**
118.1161 - * @throws NullPointerException {@inheritDoc}
118.1162 - * @since 1.5
118.1163 - */
118.1164 - @JavaScriptBody(args = { "ac" },
118.1165 - body = "if (this.anno && this.anno['L' + ac.jvmName + ';']) { return true; }"
118.1166 - + "else return false;"
118.1167 - )
118.1168 - public boolean isAnnotationPresent(
118.1169 - Class<? extends Annotation> annotationClass) {
118.1170 - if (annotationClass == null)
118.1171 - throw new NullPointerException();
118.1172 -
118.1173 - return getAnnotation(annotationClass) != null;
118.1174 - }
118.1175 -
118.1176 - @JavaScriptBody(args = {}, body = "return this.anno;")
118.1177 - private Object getAnnotationData() {
118.1178 - throw new UnsupportedOperationException();
118.1179 - }
118.1180 -
118.1181 - /**
118.1182 - * @since 1.5
118.1183 - */
118.1184 - public Annotation[] getAnnotations() {
118.1185 - Object data = getAnnotationData();
118.1186 - return data == null ? new Annotation[0] : AnnotationImpl.create(data);
118.1187 - }
118.1188 -
118.1189 - /**
118.1190 - * @since 1.5
118.1191 - */
118.1192 - public Annotation[] getDeclaredAnnotations() {
118.1193 - throw new UnsupportedOperationException();
118.1194 - }
118.1195 -
118.1196 - @JavaScriptBody(args = "type", body = ""
118.1197 - + "var c = vm.java_lang_Class(true);"
118.1198 - + "c.jvmName = type;"
118.1199 - + "c.primitive = true;"
118.1200 - + "return c;"
118.1201 - )
118.1202 - native static Class getPrimitiveClass(String type);
118.1203 -
118.1204 - @JavaScriptBody(args = {}, body =
118.1205 - "return vm.desiredAssertionStatus ? vm.desiredAssertionStatus : false;"
118.1206 - )
118.1207 - public native boolean desiredAssertionStatus();
118.1208 -}
119.1 --- a/emul/src/main/java/java/lang/ClassCastException.java Wed Jan 23 20:16:48 2013 +0100
119.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
119.3 @@ -1,60 +0,0 @@
119.4 -/*
119.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
119.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
119.7 - *
119.8 - * This code is free software; you can redistribute it and/or modify it
119.9 - * under the terms of the GNU General Public License version 2 only, as
119.10 - * published by the Free Software Foundation. Oracle designates this
119.11 - * particular file as subject to the "Classpath" exception as provided
119.12 - * by Oracle in the LICENSE file that accompanied this code.
119.13 - *
119.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
119.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
119.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
119.17 - * version 2 for more details (a copy is included in the LICENSE file that
119.18 - * accompanied this code).
119.19 - *
119.20 - * You should have received a copy of the GNU General Public License version
119.21 - * 2 along with this work; if not, write to the Free Software Foundation,
119.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
119.23 - *
119.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
119.25 - * or visit www.oracle.com if you need additional information or have any
119.26 - * questions.
119.27 - */
119.28 -
119.29 -package java.lang;
119.30 -
119.31 -/**
119.32 - * Thrown to indicate that the code has attempted to cast an object
119.33 - * to a subclass of which it is not an instance. For example, the
119.34 - * following code generates a <code>ClassCastException</code>:
119.35 - * <p><blockquote><pre>
119.36 - * Object x = new Integer(0);
119.37 - * System.out.println((String)x);
119.38 - * </pre></blockquote>
119.39 - *
119.40 - * @author unascribed
119.41 - * @since JDK1.0
119.42 - */
119.43 -public
119.44 -class ClassCastException extends RuntimeException {
119.45 - private static final long serialVersionUID = -9223365651070458532L;
119.46 -
119.47 - /**
119.48 - * Constructs a <code>ClassCastException</code> with no detail message.
119.49 - */
119.50 - public ClassCastException() {
119.51 - super();
119.52 - }
119.53 -
119.54 - /**
119.55 - * Constructs a <code>ClassCastException</code> with the specified
119.56 - * detail message.
119.57 - *
119.58 - * @param s the detail message.
119.59 - */
119.60 - public ClassCastException(String s) {
119.61 - super(s);
119.62 - }
119.63 -}
120.1 --- a/emul/src/main/java/java/lang/ClassFormatError.java Wed Jan 23 20:16:48 2013 +0100
120.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
120.3 @@ -1,56 +0,0 @@
120.4 -/*
120.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
120.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
120.7 - *
120.8 - * This code is free software; you can redistribute it and/or modify it
120.9 - * under the terms of the GNU General Public License version 2 only, as
120.10 - * published by the Free Software Foundation. Oracle designates this
120.11 - * particular file as subject to the "Classpath" exception as provided
120.12 - * by Oracle in the LICENSE file that accompanied this code.
120.13 - *
120.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
120.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
120.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
120.17 - * version 2 for more details (a copy is included in the LICENSE file that
120.18 - * accompanied this code).
120.19 - *
120.20 - * You should have received a copy of the GNU General Public License version
120.21 - * 2 along with this work; if not, write to the Free Software Foundation,
120.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
120.23 - *
120.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
120.25 - * or visit www.oracle.com if you need additional information or have any
120.26 - * questions.
120.27 - */
120.28 -
120.29 -package java.lang;
120.30 -
120.31 -/**
120.32 - * Thrown when the Java Virtual Machine attempts to read a class
120.33 - * file and determines that the file is malformed or otherwise cannot
120.34 - * be interpreted as a class file.
120.35 - *
120.36 - * @author unascribed
120.37 - * @since JDK1.0
120.38 - */
120.39 -public
120.40 -class ClassFormatError extends LinkageError {
120.41 - private static final long serialVersionUID = -8420114879011949195L;
120.42 -
120.43 - /**
120.44 - * Constructs a <code>ClassFormatError</code> with no detail message.
120.45 - */
120.46 - public ClassFormatError() {
120.47 - super();
120.48 - }
120.49 -
120.50 - /**
120.51 - * Constructs a <code>ClassFormatError</code> with the specified
120.52 - * detail message.
120.53 - *
120.54 - * @param s the detail message.
120.55 - */
120.56 - public ClassFormatError(String s) {
120.57 - super(s);
120.58 - }
120.59 -}
121.1 --- a/emul/src/main/java/java/lang/ClassLoader.java Wed Jan 23 20:16:48 2013 +0100
121.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
121.3 @@ -1,914 +0,0 @@
121.4 -/*
121.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
121.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
121.7 - *
121.8 - * This code is free software; you can redistribute it and/or modify it
121.9 - * under the terms of the GNU General Public License version 2 only, as
121.10 - * published by the Free Software Foundation. Oracle designates this
121.11 - * particular file as subject to the "Classpath" exception as provided
121.12 - * by Oracle in the LICENSE file that accompanied this code.
121.13 - *
121.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
121.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
121.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
121.17 - * version 2 for more details (a copy is included in the LICENSE file that
121.18 - * accompanied this code).
121.19 - *
121.20 - * You should have received a copy of the GNU General Public License version
121.21 - * 2 along with this work; if not, write to the Free Software Foundation,
121.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
121.23 - *
121.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
121.25 - * or visit www.oracle.com if you need additional information or have any
121.26 - * questions.
121.27 - */
121.28 -package java.lang;
121.29 -
121.30 -import java.io.InputStream;
121.31 -import java.io.IOException;
121.32 -import java.net.URL;
121.33 -import java.util.Enumeration;
121.34 -import java.util.NoSuchElementException;
121.35 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
121.36 -
121.37 -/**
121.38 - * A class loader is an object that is responsible for loading classes. The
121.39 - * class <tt>ClassLoader</tt> is an abstract class. Given the <a
121.40 - * href="#name">binary name</a> of a class, a class loader should attempt to
121.41 - * locate or generate data that constitutes a definition for the class. A
121.42 - * typical strategy is to transform the name into a file name and then read a
121.43 - * "class file" of that name from a file system.
121.44 - *
121.45 - * <p> Every {@link Class <tt>Class</tt>} object contains a {@link
121.46 - * Class#getClassLoader() reference} to the <tt>ClassLoader</tt> that defined
121.47 - * it.
121.48 - *
121.49 - * <p> <tt>Class</tt> objects for array classes are not created by class
121.50 - * loaders, but are created automatically as required by the Java runtime.
121.51 - * The class loader for an array class, as returned by {@link
121.52 - * Class#getClassLoader()} is the same as the class loader for its element
121.53 - * type; if the element type is a primitive type, then the array class has no
121.54 - * class loader.
121.55 - *
121.56 - * <p> Applications implement subclasses of <tt>ClassLoader</tt> in order to
121.57 - * extend the manner in which the Java virtual machine dynamically loads
121.58 - * classes.
121.59 - *
121.60 - * <p> Class loaders may typically be used by security managers to indicate
121.61 - * security domains.
121.62 - *
121.63 - * <p> The <tt>ClassLoader</tt> class uses a delegation model to search for
121.64 - * classes and resources. Each instance of <tt>ClassLoader</tt> has an
121.65 - * associated parent class loader. When requested to find a class or
121.66 - * resource, a <tt>ClassLoader</tt> instance will delegate the search for the
121.67 - * class or resource to its parent class loader before attempting to find the
121.68 - * class or resource itself. The virtual machine's built-in class loader,
121.69 - * called the "bootstrap class loader", does not itself have a parent but may
121.70 - * serve as the parent of a <tt>ClassLoader</tt> instance.
121.71 - *
121.72 - * <p> Class loaders that support concurrent loading of classes are known as
121.73 - * <em>parallel capable</em> class loaders and are required to register
121.74 - * themselves at their class initialization time by invoking the
121.75 - * {@link
121.76 - * #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>}
121.77 - * method. Note that the <tt>ClassLoader</tt> class is registered as parallel
121.78 - * capable by default. However, its subclasses still need to register themselves
121.79 - * if they are parallel capable. <br>
121.80 - * In environments in which the delegation model is not strictly
121.81 - * hierarchical, class loaders need to be parallel capable, otherwise class
121.82 - * loading can lead to deadlocks because the loader lock is held for the
121.83 - * duration of the class loading process (see {@link #loadClass
121.84 - * <tt>loadClass</tt>} methods).
121.85 - *
121.86 - * <p> Normally, the Java virtual machine loads classes from the local file
121.87 - * system in a platform-dependent manner. For example, on UNIX systems, the
121.88 - * virtual machine loads classes from the directory defined by the
121.89 - * <tt>CLASSPATH</tt> environment variable.
121.90 - *
121.91 - * <p> However, some classes may not originate from a file; they may originate
121.92 - * from other sources, such as the network, or they could be constructed by an
121.93 - * application. The method {@link #defineClass(String, byte[], int, int)
121.94 - * <tt>defineClass</tt>} converts an array of bytes into an instance of class
121.95 - * <tt>Class</tt>. Instances of this newly defined class can be created using
121.96 - * {@link Class#newInstance <tt>Class.newInstance</tt>}.
121.97 - *
121.98 - * <p> The methods and constructors of objects created by a class loader may
121.99 - * reference other classes. To determine the class(es) referred to, the Java
121.100 - * virtual machine invokes the {@link #loadClass <tt>loadClass</tt>} method of
121.101 - * the class loader that originally created the class.
121.102 - *
121.103 - * <p> For example, an application could create a network class loader to
121.104 - * download class files from a server. Sample code might look like:
121.105 - *
121.106 - * <blockquote><pre>
121.107 - * ClassLoader loader = new NetworkClassLoader(host, port);
121.108 - * Object main = loader.loadClass("Main", true).newInstance();
121.109 - * . . .
121.110 - * </pre></blockquote>
121.111 - *
121.112 - * <p> The network class loader subclass must define the methods {@link
121.113 - * #findClass <tt>findClass</tt>} and <tt>loadClassData</tt> to load a class
121.114 - * from the network. Once it has downloaded the bytes that make up the class,
121.115 - * it should use the method {@link #defineClass <tt>defineClass</tt>} to
121.116 - * create a class instance. A sample implementation is:
121.117 - *
121.118 - * <blockquote><pre>
121.119 - * class NetworkClassLoader extends ClassLoader {
121.120 - * String host;
121.121 - * int port;
121.122 - *
121.123 - * public Class findClass(String name) {
121.124 - * byte[] b = loadClassData(name);
121.125 - * return defineClass(name, b, 0, b.length);
121.126 - * }
121.127 - *
121.128 - * private byte[] loadClassData(String name) {
121.129 - * // load the class data from the connection
121.130 - * . . .
121.131 - * }
121.132 - * }
121.133 - * </pre></blockquote>
121.134 - *
121.135 - * <h4> <a name="name">Binary names</a> </h4>
121.136 - *
121.137 - * <p> Any class name provided as a {@link String} parameter to methods in
121.138 - * <tt>ClassLoader</tt> must be a binary name as defined by
121.139 - * <cite>The Java™ Language Specification</cite>.
121.140 - *
121.141 - * <p> Examples of valid class names include:
121.142 - * <blockquote><pre>
121.143 - * "java.lang.String"
121.144 - * "javax.swing.JSpinner$DefaultEditor"
121.145 - * "java.security.KeyStore$Builder$FileBuilder$1"
121.146 - * "java.net.URLClassLoader$3$1"
121.147 - * </pre></blockquote>
121.148 - *
121.149 - * @see #resolveClass(Class)
121.150 - * @since 1.0
121.151 - */
121.152 -public abstract class ClassLoader {
121.153 -
121.154 - @JavaScriptBody(args = {}, body = "")
121.155 - private static native void registerNatives();
121.156 - static {
121.157 - registerNatives();
121.158 - }
121.159 -
121.160 - // The parent class loader for delegation
121.161 - // Note: VM hardcoded the offset of this field, thus all new fields
121.162 - // must be added *after* it.
121.163 - private final ClassLoader parent;
121.164 -
121.165 -
121.166 - /**
121.167 - * Creates a new class loader using the specified parent class loader for
121.168 - * delegation.
121.169 - *
121.170 - * <p> If there is a security manager, its {@link
121.171 - * SecurityManager#checkCreateClassLoader()
121.172 - * <tt>checkCreateClassLoader</tt>} method is invoked. This may result in
121.173 - * a security exception. </p>
121.174 - *
121.175 - * @param parent
121.176 - * The parent class loader
121.177 - *
121.178 - * @throws SecurityException
121.179 - * If a security manager exists and its
121.180 - * <tt>checkCreateClassLoader</tt> method doesn't allow creation
121.181 - * of a new class loader.
121.182 - *
121.183 - * @since 1.2
121.184 - */
121.185 - protected ClassLoader(ClassLoader parent) {
121.186 - throw new SecurityException();
121.187 - }
121.188 -
121.189 - /**
121.190 - * Creates a new class loader using the <tt>ClassLoader</tt> returned by
121.191 - * the method {@link #getSystemClassLoader()
121.192 - * <tt>getSystemClassLoader()</tt>} as the parent class loader.
121.193 - *
121.194 - * <p> If there is a security manager, its {@link
121.195 - * SecurityManager#checkCreateClassLoader()
121.196 - * <tt>checkCreateClassLoader</tt>} method is invoked. This may result in
121.197 - * a security exception. </p>
121.198 - *
121.199 - * @throws SecurityException
121.200 - * If a security manager exists and its
121.201 - * <tt>checkCreateClassLoader</tt> method doesn't allow creation
121.202 - * of a new class loader.
121.203 - */
121.204 - protected ClassLoader() {
121.205 - throw new SecurityException();
121.206 - }
121.207 -
121.208 - // -- Class --
121.209 -
121.210 - /**
121.211 - * Loads the class with the specified <a href="#name">binary name</a>.
121.212 - * This method searches for classes in the same manner as the {@link
121.213 - * #loadClass(String, boolean)} method. It is invoked by the Java virtual
121.214 - * machine to resolve class references. Invoking this method is equivalent
121.215 - * to invoking {@link #loadClass(String, boolean) <tt>loadClass(name,
121.216 - * false)</tt>}. </p>
121.217 - *
121.218 - * @param name
121.219 - * The <a href="#name">binary name</a> of the class
121.220 - *
121.221 - * @return The resulting <tt>Class</tt> object
121.222 - *
121.223 - * @throws ClassNotFoundException
121.224 - * If the class was not found
121.225 - */
121.226 - public Class<?> loadClass(String name) throws ClassNotFoundException {
121.227 - return loadClass(name, false);
121.228 - }
121.229 -
121.230 - /**
121.231 - * Loads the class with the specified <a href="#name">binary name</a>. The
121.232 - * default implementation of this method searches for classes in the
121.233 - * following order:
121.234 - *
121.235 - * <p><ol>
121.236 - *
121.237 - * <li><p> Invoke {@link #findLoadedClass(String)} to check if the class
121.238 - * has already been loaded. </p></li>
121.239 - *
121.240 - * <li><p> Invoke the {@link #loadClass(String) <tt>loadClass</tt>} method
121.241 - * on the parent class loader. If the parent is <tt>null</tt> the class
121.242 - * loader built-in to the virtual machine is used, instead. </p></li>
121.243 - *
121.244 - * <li><p> Invoke the {@link #findClass(String)} method to find the
121.245 - * class. </p></li>
121.246 - *
121.247 - * </ol>
121.248 - *
121.249 - * <p> If the class was found using the above steps, and the
121.250 - * <tt>resolve</tt> flag is true, this method will then invoke the {@link
121.251 - * #resolveClass(Class)} method on the resulting <tt>Class</tt> object.
121.252 - *
121.253 - * <p> Subclasses of <tt>ClassLoader</tt> are encouraged to override {@link
121.254 - * #findClass(String)}, rather than this method. </p>
121.255 - *
121.256 - * <p> Unless overridden, this method synchronizes on the result of
121.257 - * {@link #getClassLoadingLock <tt>getClassLoadingLock</tt>} method
121.258 - * during the entire class loading process.
121.259 - *
121.260 - * @param name
121.261 - * The <a href="#name">binary name</a> of the class
121.262 - *
121.263 - * @param resolve
121.264 - * If <tt>true</tt> then resolve the class
121.265 - *
121.266 - * @return The resulting <tt>Class</tt> object
121.267 - *
121.268 - * @throws ClassNotFoundException
121.269 - * If the class could not be found
121.270 - */
121.271 - protected Class<?> loadClass(String name, boolean resolve)
121.272 - throws ClassNotFoundException
121.273 - {
121.274 - synchronized (getClassLoadingLock(name)) {
121.275 - // First, check if the class has already been loaded
121.276 - Class c = findLoadedClass(name);
121.277 - if (c == null) {
121.278 - try {
121.279 - if (parent != null) {
121.280 - c = parent.loadClass(name, false);
121.281 - } else {
121.282 - c = findBootstrapClassOrNull(name);
121.283 - }
121.284 - } catch (ClassNotFoundException e) {
121.285 - // ClassNotFoundException thrown if class not found
121.286 - // from the non-null parent class loader
121.287 - }
121.288 -
121.289 - if (c == null) {
121.290 - // If still not found, then invoke findClass in order
121.291 - // to find the class.
121.292 - c = findClass(name);
121.293 -
121.294 -// // this is the defining class loader; record the stats
121.295 -// sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
121.296 -// sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
121.297 -// sun.misc.PerfCounter.getFindClasses().increment();
121.298 - }
121.299 - }
121.300 - if (resolve) {
121.301 - resolveClass(c);
121.302 - }
121.303 - return c;
121.304 - }
121.305 - }
121.306 -
121.307 - /**
121.308 - * Returns the lock object for class loading operations.
121.309 - * For backward compatibility, the default implementation of this method
121.310 - * behaves as follows. If this ClassLoader object is registered as
121.311 - * parallel capable, the method returns a dedicated object associated
121.312 - * with the specified class name. Otherwise, the method returns this
121.313 - * ClassLoader object. </p>
121.314 - *
121.315 - * @param className
121.316 - * The name of the to-be-loaded class
121.317 - *
121.318 - * @return the lock for class loading operations
121.319 - *
121.320 - * @throws NullPointerException
121.321 - * If registered as parallel capable and <tt>className</tt> is null
121.322 - *
121.323 - * @see #loadClass(String, boolean)
121.324 - *
121.325 - * @since 1.7
121.326 - */
121.327 - protected Object getClassLoadingLock(String className) {
121.328 - Object lock = this;
121.329 - return lock;
121.330 - }
121.331 -
121.332 - /**
121.333 - * Finds the class with the specified <a href="#name">binary name</a>.
121.334 - * This method should be overridden by class loader implementations that
121.335 - * follow the delegation model for loading classes, and will be invoked by
121.336 - * the {@link #loadClass <tt>loadClass</tt>} method after checking the
121.337 - * parent class loader for the requested class. The default implementation
121.338 - * throws a <tt>ClassNotFoundException</tt>. </p>
121.339 - *
121.340 - * @param name
121.341 - * The <a href="#name">binary name</a> of the class
121.342 - *
121.343 - * @return The resulting <tt>Class</tt> object
121.344 - *
121.345 - * @throws ClassNotFoundException
121.346 - * If the class could not be found
121.347 - *
121.348 - * @since 1.2
121.349 - */
121.350 - protected Class<?> findClass(String name) throws ClassNotFoundException {
121.351 - throw new ClassNotFoundException(name);
121.352 - }
121.353 -
121.354 - /**
121.355 - * Converts an array of bytes into an instance of class <tt>Class</tt>.
121.356 - * Before the <tt>Class</tt> can be used it must be resolved. This method
121.357 - * is deprecated in favor of the version that takes a <a
121.358 - * href="#name">binary name</a> as its first argument, and is more secure.
121.359 - *
121.360 - * @param b
121.361 - * The bytes that make up the class data. The bytes in positions
121.362 - * <tt>off</tt> through <tt>off+len-1</tt> should have the format
121.363 - * of a valid class file as defined by
121.364 - * <cite>The Java™ Virtual Machine Specification</cite>.
121.365 - *
121.366 - * @param off
121.367 - * The start offset in <tt>b</tt> of the class data
121.368 - *
121.369 - * @param len
121.370 - * The length of the class data
121.371 - *
121.372 - * @return The <tt>Class</tt> object that was created from the specified
121.373 - * class data
121.374 - *
121.375 - * @throws ClassFormatError
121.376 - * If the data did not contain a valid class
121.377 - *
121.378 - * @throws IndexOutOfBoundsException
121.379 - * If either <tt>off</tt> or <tt>len</tt> is negative, or if
121.380 - * <tt>off+len</tt> is greater than <tt>b.length</tt>.
121.381 - *
121.382 - * @throws SecurityException
121.383 - * If an attempt is made to add this class to a package that
121.384 - * contains classes that were signed by a different set of
121.385 - * certificates than this class, or if an attempt is made
121.386 - * to define a class in a package with a fully-qualified name
121.387 - * that starts with "{@code java.}".
121.388 - *
121.389 - * @see #loadClass(String, boolean)
121.390 - * @see #resolveClass(Class)
121.391 - *
121.392 - * @deprecated Replaced by {@link #defineClass(String, byte[], int, int)
121.393 - * defineClass(String, byte[], int, int)}
121.394 - */
121.395 - @Deprecated
121.396 - protected final Class<?> defineClass(byte[] b, int off, int len)
121.397 - throws ClassFormatError
121.398 - {
121.399 - throw new SecurityException();
121.400 - }
121.401 -
121.402 - /**
121.403 - * Converts an array of bytes into an instance of class <tt>Class</tt>.
121.404 - * Before the <tt>Class</tt> can be used it must be resolved.
121.405 - *
121.406 - * <p> This method assigns a default {@link java.security.ProtectionDomain
121.407 - * <tt>ProtectionDomain</tt>} to the newly defined class. The
121.408 - * <tt>ProtectionDomain</tt> is effectively granted the same set of
121.409 - * permissions returned when {@link
121.410 - * java.security.Policy#getPermissions(java.security.CodeSource)
121.411 - * <tt>Policy.getPolicy().getPermissions(new CodeSource(null, null))</tt>}
121.412 - * is invoked. The default domain is created on the first invocation of
121.413 - * {@link #defineClass(String, byte[], int, int) <tt>defineClass</tt>},
121.414 - * and re-used on subsequent invocations.
121.415 - *
121.416 - * <p> To assign a specific <tt>ProtectionDomain</tt> to the class, use
121.417 - * the {@link #defineClass(String, byte[], int, int,
121.418 - * java.security.ProtectionDomain) <tt>defineClass</tt>} method that takes a
121.419 - * <tt>ProtectionDomain</tt> as one of its arguments. </p>
121.420 - *
121.421 - * @param name
121.422 - * The expected <a href="#name">binary name</a> of the class, or
121.423 - * <tt>null</tt> if not known
121.424 - *
121.425 - * @param b
121.426 - * The bytes that make up the class data. The bytes in positions
121.427 - * <tt>off</tt> through <tt>off+len-1</tt> should have the format
121.428 - * of a valid class file as defined by
121.429 - * <cite>The Java™ Virtual Machine Specification</cite>.
121.430 - *
121.431 - * @param off
121.432 - * The start offset in <tt>b</tt> of the class data
121.433 - *
121.434 - * @param len
121.435 - * The length of the class data
121.436 - *
121.437 - * @return The <tt>Class</tt> object that was created from the specified
121.438 - * class data.
121.439 - *
121.440 - * @throws ClassFormatError
121.441 - * If the data did not contain a valid class
121.442 - *
121.443 - * @throws IndexOutOfBoundsException
121.444 - * If either <tt>off</tt> or <tt>len</tt> is negative, or if
121.445 - * <tt>off+len</tt> is greater than <tt>b.length</tt>.
121.446 - *
121.447 - * @throws SecurityException
121.448 - * If an attempt is made to add this class to a package that
121.449 - * contains classes that were signed by a different set of
121.450 - * certificates than this class (which is unsigned), or if
121.451 - * <tt>name</tt> begins with "<tt>java.</tt>".
121.452 - *
121.453 - * @see #loadClass(String, boolean)
121.454 - * @see #resolveClass(Class)
121.455 - * @see java.security.CodeSource
121.456 - * @see java.security.SecureClassLoader
121.457 - *
121.458 - * @since 1.1
121.459 - */
121.460 - protected final Class<?> defineClass(String name, byte[] b, int off, int len)
121.461 - throws ClassFormatError
121.462 - {
121.463 - throw new SecurityException();
121.464 - }
121.465 -
121.466 - /**
121.467 - * Links the specified class. This (misleadingly named) method may be
121.468 - * used by a class loader to link a class. If the class <tt>c</tt> has
121.469 - * already been linked, then this method simply returns. Otherwise, the
121.470 - * class is linked as described in the "Execution" chapter of
121.471 - * <cite>The Java™ Language Specification</cite>.
121.472 - * </p>
121.473 - *
121.474 - * @param c
121.475 - * The class to link
121.476 - *
121.477 - * @throws NullPointerException
121.478 - * If <tt>c</tt> is <tt>null</tt>.
121.479 - *
121.480 - * @see #defineClass(String, byte[], int, int)
121.481 - */
121.482 - protected final void resolveClass(Class<?> c) {
121.483 - resolveClass0(c);
121.484 - }
121.485 -
121.486 - private native void resolveClass0(Class c);
121.487 -
121.488 -
121.489 - /**
121.490 - * Returns the class with the given <a href="#name">binary name</a> if this
121.491 - * loader has been recorded by the Java virtual machine as an initiating
121.492 - * loader of a class with that <a href="#name">binary name</a>. Otherwise
121.493 - * <tt>null</tt> is returned. </p>
121.494 - *
121.495 - * @param name
121.496 - * The <a href="#name">binary name</a> of the class
121.497 - *
121.498 - * @return The <tt>Class</tt> object, or <tt>null</tt> if the class has
121.499 - * not been loaded
121.500 - *
121.501 - * @since 1.1
121.502 - */
121.503 - protected final Class<?> findLoadedClass(String name) {
121.504 - if (!checkName(name))
121.505 - return null;
121.506 - return findLoadedClass0(name);
121.507 - }
121.508 -
121.509 - private native final Class findLoadedClass0(String name);
121.510 -
121.511 - /**
121.512 - * Sets the signers of a class. This should be invoked after defining a
121.513 - * class. </p>
121.514 - *
121.515 - * @param c
121.516 - * The <tt>Class</tt> object
121.517 - *
121.518 - * @param signers
121.519 - * The signers for the class
121.520 - *
121.521 - * @since 1.1
121.522 - */
121.523 - protected final void setSigners(Class<?> c, Object[] signers) {
121.524 - //c.setSigners(signers);
121.525 - throw new UnsupportedOperationException();
121.526 - }
121.527 -
121.528 -
121.529 - // -- Resource --
121.530 -
121.531 - /**
121.532 - * Finds the resource with the given name. A resource is some data
121.533 - * (images, audio, text, etc) that can be accessed by class code in a way
121.534 - * that is independent of the location of the code.
121.535 - *
121.536 - * <p> The name of a resource is a '<tt>/</tt>'-separated path name that
121.537 - * identifies the resource.
121.538 - *
121.539 - * <p> This method will first search the parent class loader for the
121.540 - * resource; if the parent is <tt>null</tt> the path of the class loader
121.541 - * built-in to the virtual machine is searched. That failing, this method
121.542 - * will invoke {@link #findResource(String)} to find the resource. </p>
121.543 - *
121.544 - * @param name
121.545 - * The resource name
121.546 - *
121.547 - * @return A <tt>URL</tt> object for reading the resource, or
121.548 - * <tt>null</tt> if the resource could not be found or the invoker
121.549 - * doesn't have adequate privileges to get the resource.
121.550 - *
121.551 - * @since 1.1
121.552 - */
121.553 - public URL getResource(String name) {
121.554 - URL url;
121.555 - if (parent != null) {
121.556 - url = parent.getResource(name);
121.557 - } else {
121.558 - url = getBootstrapResource(name);
121.559 - }
121.560 - if (url == null) {
121.561 - url = findResource(name);
121.562 - }
121.563 - return url;
121.564 - }
121.565 -
121.566 - /**
121.567 - * Finds all the resources with the given name. A resource is some data
121.568 - * (images, audio, text, etc) that can be accessed by class code in a way
121.569 - * that is independent of the location of the code.
121.570 - *
121.571 - * <p>The name of a resource is a <tt>/</tt>-separated path name that
121.572 - * identifies the resource.
121.573 - *
121.574 - * <p> The search order is described in the documentation for {@link
121.575 - * #getResource(String)}. </p>
121.576 - *
121.577 - * @param name
121.578 - * The resource name
121.579 - *
121.580 - * @return An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
121.581 - * the resource. If no resources could be found, the enumeration
121.582 - * will be empty. Resources that the class loader doesn't have
121.583 - * access to will not be in the enumeration.
121.584 - *
121.585 - * @throws IOException
121.586 - * If I/O errors occur
121.587 - *
121.588 - * @see #findResources(String)
121.589 - *
121.590 - * @since 1.2
121.591 - */
121.592 - public Enumeration<URL> getResources(String name) throws IOException {
121.593 - Enumeration[] tmp = new Enumeration[2];
121.594 - if (parent != null) {
121.595 - tmp[0] = parent.getResources(name);
121.596 - } else {
121.597 - tmp[0] = getBootstrapResources(name);
121.598 - }
121.599 - tmp[1] = findResources(name);
121.600 -
121.601 - return new CompoundEnumeration(tmp);
121.602 - }
121.603 -
121.604 - /**
121.605 - * Finds the resource with the given name. Class loader implementations
121.606 - * should override this method to specify where to find resources. </p>
121.607 - *
121.608 - * @param name
121.609 - * The resource name
121.610 - *
121.611 - * @return A <tt>URL</tt> object for reading the resource, or
121.612 - * <tt>null</tt> if the resource could not be found
121.613 - *
121.614 - * @since 1.2
121.615 - */
121.616 - protected URL findResource(String name) {
121.617 - return null;
121.618 - }
121.619 -
121.620 - /**
121.621 - * Returns an enumeration of {@link java.net.URL <tt>URL</tt>} objects
121.622 - * representing all the resources with the given name. Class loader
121.623 - * implementations should override this method to specify where to load
121.624 - * resources from. </p>
121.625 - *
121.626 - * @param name
121.627 - * The resource name
121.628 - *
121.629 - * @return An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
121.630 - * the resources
121.631 - *
121.632 - * @throws IOException
121.633 - * If I/O errors occur
121.634 - *
121.635 - * @since 1.2
121.636 - */
121.637 - protected Enumeration<URL> findResources(String name) throws IOException {
121.638 - return new CompoundEnumeration(new Enumeration[0]);
121.639 - }
121.640 -
121.641 - // index 0: java.lang.ClassLoader.class
121.642 - // index 1: the immediate caller of index 0.
121.643 - // index 2: the immediate caller of index 1.
121.644 - private static native Class<? extends ClassLoader> getCaller(int index);
121.645 -
121.646 - /**
121.647 - * Registers the caller as parallel capable.</p>
121.648 - * The registration succeeds if and only if all of the following
121.649 - * conditions are met: <br>
121.650 - * 1. no instance of the caller has been created</p>
121.651 - * 2. all of the super classes (except class Object) of the caller are
121.652 - * registered as parallel capable</p>
121.653 - * Note that once a class loader is registered as parallel capable, there
121.654 - * is no way to change it back. </p>
121.655 - *
121.656 - * @return true if the caller is successfully registered as
121.657 - * parallel capable and false if otherwise.
121.658 - *
121.659 - * @since 1.7
121.660 - */
121.661 -// protected static boolean registerAsParallelCapable() {
121.662 -// return false;
121.663 -// }
121.664 -
121.665 - /**
121.666 - * Find a resource of the specified name from the search path used to load
121.667 - * classes. This method locates the resource through the system class
121.668 - * loader (see {@link #getSystemClassLoader()}). </p>
121.669 - *
121.670 - * @param name
121.671 - * The resource name
121.672 - *
121.673 - * @return A {@link java.net.URL <tt>URL</tt>} object for reading the
121.674 - * resource, or <tt>null</tt> if the resource could not be found
121.675 - *
121.676 - * @since 1.1
121.677 - */
121.678 - public static URL getSystemResource(String name) {
121.679 - ClassLoader system = getSystemClassLoader();
121.680 - if (system == null) {
121.681 - return getBootstrapResource(name);
121.682 - }
121.683 - return system.getResource(name);
121.684 - }
121.685 -
121.686 - /**
121.687 - * Finds all resources of the specified name from the search path used to
121.688 - * load classes. The resources thus found are returned as an
121.689 - * {@link java.util.Enumeration <tt>Enumeration</tt>} of {@link
121.690 - * java.net.URL <tt>URL</tt>} objects.
121.691 - *
121.692 - * <p> The search order is described in the documentation for {@link
121.693 - * #getSystemResource(String)}. </p>
121.694 - *
121.695 - * @param name
121.696 - * The resource name
121.697 - *
121.698 - * @return An enumeration of resource {@link java.net.URL <tt>URL</tt>}
121.699 - * objects
121.700 - *
121.701 - * @throws IOException
121.702 - * If I/O errors occur
121.703 -
121.704 - * @since 1.2
121.705 - */
121.706 - public static Enumeration<URL> getSystemResources(String name)
121.707 - throws IOException
121.708 - {
121.709 - ClassLoader system = getSystemClassLoader();
121.710 - if (system == null) {
121.711 - return getBootstrapResources(name);
121.712 - }
121.713 - return system.getResources(name);
121.714 - }
121.715 -
121.716 -
121.717 -
121.718 - /**
121.719 - * Returns an input stream for reading the specified resource.
121.720 - *
121.721 - * <p> The search order is described in the documentation for {@link
121.722 - * #getResource(String)}. </p>
121.723 - *
121.724 - * @param name
121.725 - * The resource name
121.726 - *
121.727 - * @return An input stream for reading the resource, or <tt>null</tt>
121.728 - * if the resource could not be found
121.729 - *
121.730 - * @since 1.1
121.731 - */
121.732 - public InputStream getResourceAsStream(String name) {
121.733 - URL url = getResource(name);
121.734 - try {
121.735 - return url != null ? url.openStream() : null;
121.736 - } catch (IOException e) {
121.737 - return null;
121.738 - }
121.739 - }
121.740 -
121.741 - /**
121.742 - * Open for reading, a resource of the specified name from the search path
121.743 - * used to load classes. This method locates the resource through the
121.744 - * system class loader (see {@link #getSystemClassLoader()}). </p>
121.745 - *
121.746 - * @param name
121.747 - * The resource name
121.748 - *
121.749 - * @return An input stream for reading the resource, or <tt>null</tt>
121.750 - * if the resource could not be found
121.751 - *
121.752 - * @since 1.1
121.753 - */
121.754 - public static InputStream getSystemResourceAsStream(String name) {
121.755 - URL url = getSystemResource(name);
121.756 - try {
121.757 - return url != null ? url.openStream() : null;
121.758 - } catch (IOException e) {
121.759 - return null;
121.760 - }
121.761 - }
121.762 -
121.763 -
121.764 - // -- Hierarchy --
121.765 -
121.766 - /**
121.767 - * Returns the parent class loader for delegation. Some implementations may
121.768 - * use <tt>null</tt> to represent the bootstrap class loader. This method
121.769 - * will return <tt>null</tt> in such implementations if this class loader's
121.770 - * parent is the bootstrap class loader.
121.771 - *
121.772 - * <p> If a security manager is present, and the invoker's class loader is
121.773 - * not <tt>null</tt> and is not an ancestor of this class loader, then this
121.774 - * method invokes the security manager's {@link
121.775 - * SecurityManager#checkPermission(java.security.Permission)
121.776 - * <tt>checkPermission</tt>} method with a {@link
121.777 - * RuntimePermission#RuntimePermission(String)
121.778 - * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
121.779 - * access to the parent class loader is permitted. If not, a
121.780 - * <tt>SecurityException</tt> will be thrown. </p>
121.781 - *
121.782 - * @return The parent <tt>ClassLoader</tt>
121.783 - *
121.784 - * @throws SecurityException
121.785 - * If a security manager exists and its <tt>checkPermission</tt>
121.786 - * method doesn't allow access to this class loader's parent class
121.787 - * loader.
121.788 - *
121.789 - * @since 1.2
121.790 - */
121.791 - public final ClassLoader getParent() {
121.792 - throw new SecurityException();
121.793 - }
121.794 -
121.795 - /**
121.796 - * Returns the system class loader for delegation. This is the default
121.797 - * delegation parent for new <tt>ClassLoader</tt> instances, and is
121.798 - * typically the class loader used to start the application.
121.799 - *
121.800 - * <p> This method is first invoked early in the runtime's startup
121.801 - * sequence, at which point it creates the system class loader and sets it
121.802 - * as the context class loader of the invoking <tt>Thread</tt>.
121.803 - *
121.804 - * <p> The default system class loader is an implementation-dependent
121.805 - * instance of this class.
121.806 - *
121.807 - * <p> If the system property "<tt>java.system.class.loader</tt>" is defined
121.808 - * when this method is first invoked then the value of that property is
121.809 - * taken to be the name of a class that will be returned as the system
121.810 - * class loader. The class is loaded using the default system class loader
121.811 - * and must define a public constructor that takes a single parameter of
121.812 - * type <tt>ClassLoader</tt> which is used as the delegation parent. An
121.813 - * instance is then created using this constructor with the default system
121.814 - * class loader as the parameter. The resulting class loader is defined
121.815 - * to be the system class loader.
121.816 - *
121.817 - * <p> If a security manager is present, and the invoker's class loader is
121.818 - * not <tt>null</tt> and the invoker's class loader is not the same as or
121.819 - * an ancestor of the system class loader, then this method invokes the
121.820 - * security manager's {@link
121.821 - * SecurityManager#checkPermission(java.security.Permission)
121.822 - * <tt>checkPermission</tt>} method with a {@link
121.823 - * RuntimePermission#RuntimePermission(String)
121.824 - * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
121.825 - * access to the system class loader. If not, a
121.826 - * <tt>SecurityException</tt> will be thrown. </p>
121.827 - *
121.828 - * @return The system <tt>ClassLoader</tt> for delegation, or
121.829 - * <tt>null</tt> if none
121.830 - *
121.831 - * @throws SecurityException
121.832 - * If a security manager exists and its <tt>checkPermission</tt>
121.833 - * method doesn't allow access to the system class loader.
121.834 - *
121.835 - * @throws IllegalStateException
121.836 - * If invoked recursively during the construction of the class
121.837 - * loader specified by the "<tt>java.system.class.loader</tt>"
121.838 - * property.
121.839 - *
121.840 - * @throws Error
121.841 - * If the system property "<tt>java.system.class.loader</tt>"
121.842 - * is defined but the named class could not be loaded, the
121.843 - * provider class does not define the required constructor, or an
121.844 - * exception is thrown by that constructor when it is invoked. The
121.845 - * underlying cause of the error can be retrieved via the
121.846 - * {@link Throwable#getCause()} method.
121.847 - *
121.848 - * @revised 1.4
121.849 - */
121.850 - public static ClassLoader getSystemClassLoader() {
121.851 - throw new SecurityException();
121.852 - }
121.853 -
121.854 - // Returns true if the specified class loader can be found in this class
121.855 - // loader's delegation chain.
121.856 - boolean isAncestor(ClassLoader cl) {
121.857 - ClassLoader acl = this;
121.858 - do {
121.859 - acl = acl.parent;
121.860 - if (cl == acl) {
121.861 - return true;
121.862 - }
121.863 - } while (acl != null);
121.864 - return false;
121.865 - }
121.866 -
121.867 - private boolean checkName(String name) {
121.868 - throw new UnsupportedOperationException();
121.869 - }
121.870 -
121.871 - private Class findBootstrapClassOrNull(String name) {
121.872 - throw new UnsupportedOperationException();
121.873 - }
121.874 -
121.875 - private static URL getBootstrapResource(String name) {
121.876 - throw new UnsupportedOperationException();
121.877 - }
121.878 -
121.879 - private static Enumeration<URL> getBootstrapResources(String name) {
121.880 - throw new UnsupportedOperationException();
121.881 - }
121.882 -
121.883 - private static class CompoundEnumeration implements Enumeration<URL> {
121.884 - private URL next;
121.885 - private int index;
121.886 - private final Enumeration[] arr;
121.887 -
121.888 - public CompoundEnumeration(Enumeration[] arr) {
121.889 - this.arr = arr;
121.890 - this.index = 0;
121.891 - }
121.892 -
121.893 - public boolean hasMoreElements() {
121.894 - if (next == null) {
121.895 - if (arr[index].hasMoreElements()) {
121.896 - next = (URL) arr[index].nextElement();
121.897 - } else {
121.898 - if (index < arr.length) {
121.899 - index++;
121.900 - return hasMoreElements();
121.901 - }
121.902 - }
121.903 - }
121.904 - return next != null;
121.905 - }
121.906 -
121.907 - public URL nextElement() {
121.908 - if (!hasMoreElements()) {
121.909 - throw new NoSuchElementException();
121.910 - }
121.911 - URL r = next;
121.912 - next = null;
121.913 - return r;
121.914 - }
121.915 -
121.916 - }
121.917 -}
122.1 --- a/emul/src/main/java/java/lang/ClassNotFoundException.java Wed Jan 23 20:16:48 2013 +0100
122.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
122.3 @@ -1,125 +0,0 @@
122.4 -/*
122.5 - * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
122.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
122.7 - *
122.8 - * This code is free software; you can redistribute it and/or modify it
122.9 - * under the terms of the GNU General Public License version 2 only, as
122.10 - * published by the Free Software Foundation. Oracle designates this
122.11 - * particular file as subject to the "Classpath" exception as provided
122.12 - * by Oracle in the LICENSE file that accompanied this code.
122.13 - *
122.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
122.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
122.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
122.17 - * version 2 for more details (a copy is included in the LICENSE file that
122.18 - * accompanied this code).
122.19 - *
122.20 - * You should have received a copy of the GNU General Public License version
122.21 - * 2 along with this work; if not, write to the Free Software Foundation,
122.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
122.23 - *
122.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
122.25 - * or visit www.oracle.com if you need additional information or have any
122.26 - * questions.
122.27 - */
122.28 -
122.29 -package java.lang;
122.30 -
122.31 -/**
122.32 - * Thrown when an application tries to load in a class through its
122.33 - * string name using:
122.34 - * <ul>
122.35 - * <li>The <code>forName</code> method in class <code>Class</code>.
122.36 - * <li>The <code>findSystemClass</code> method in class
122.37 - * <code>ClassLoader</code> .
122.38 - * <li>The <code>loadClass</code> method in class <code>ClassLoader</code>.
122.39 - * </ul>
122.40 - * <p>
122.41 - * but no definition for the class with the specified name could be found.
122.42 - *
122.43 - * <p>As of release 1.4, this exception has been retrofitted to conform to
122.44 - * the general purpose exception-chaining mechanism. The "optional exception
122.45 - * that was raised while loading the class" that may be provided at
122.46 - * construction time and accessed via the {@link #getException()} method is
122.47 - * now known as the <i>cause</i>, and may be accessed via the {@link
122.48 - * Throwable#getCause()} method, as well as the aforementioned "legacy method."
122.49 - *
122.50 - * @author unascribed
122.51 - * @see java.lang.Class#forName(java.lang.String)
122.52 - * @see java.lang.ClassLoader#findSystemClass(java.lang.String)
122.53 - * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
122.54 - * @since JDK1.0
122.55 - */
122.56 -public class ClassNotFoundException extends ReflectiveOperationException {
122.57 - /**
122.58 - * use serialVersionUID from JDK 1.1.X for interoperability
122.59 - */
122.60 - private static final long serialVersionUID = 9176873029745254542L;
122.61 -
122.62 - /**
122.63 - * This field holds the exception ex if the
122.64 - * ClassNotFoundException(String s, Throwable ex) constructor was
122.65 - * used to instantiate the object
122.66 - * @serial
122.67 - * @since 1.2
122.68 - */
122.69 - private Throwable ex;
122.70 -
122.71 - /**
122.72 - * Constructs a <code>ClassNotFoundException</code> with no detail message.
122.73 - */
122.74 - public ClassNotFoundException() {
122.75 - super((Throwable)null); // Disallow initCause
122.76 - }
122.77 -
122.78 - /**
122.79 - * Constructs a <code>ClassNotFoundException</code> with the
122.80 - * specified detail message.
122.81 - *
122.82 - * @param s the detail message.
122.83 - */
122.84 - public ClassNotFoundException(String s) {
122.85 - super(s, null); // Disallow initCause
122.86 - }
122.87 -
122.88 - /**
122.89 - * Constructs a <code>ClassNotFoundException</code> with the
122.90 - * specified detail message and optional exception that was
122.91 - * raised while loading the class.
122.92 - *
122.93 - * @param s the detail message
122.94 - * @param ex the exception that was raised while loading the class
122.95 - * @since 1.2
122.96 - */
122.97 - public ClassNotFoundException(String s, Throwable ex) {
122.98 - super(s, null); // Disallow initCause
122.99 - this.ex = ex;
122.100 - }
122.101 -
122.102 - /**
122.103 - * Returns the exception that was raised if an error occurred while
122.104 - * attempting to load the class. Otherwise, returns <tt>null</tt>.
122.105 - *
122.106 - * <p>This method predates the general-purpose exception chaining facility.
122.107 - * The {@link Throwable#getCause()} method is now the preferred means of
122.108 - * obtaining this information.
122.109 - *
122.110 - * @return the <code>Exception</code> that was raised while loading a class
122.111 - * @since 1.2
122.112 - */
122.113 - public Throwable getException() {
122.114 - return ex;
122.115 - }
122.116 -
122.117 - /**
122.118 - * Returns the cause of this exception (the exception that was raised
122.119 - * if an error occurred while attempting to load the class; otherwise
122.120 - * <tt>null</tt>).
122.121 - *
122.122 - * @return the cause of this exception.
122.123 - * @since 1.4
122.124 - */
122.125 - public Throwable getCause() {
122.126 - return ex;
122.127 - }
122.128 -}
123.1 --- a/emul/src/main/java/java/lang/CloneNotSupportedException.java Wed Jan 23 20:16:48 2013 +0100
123.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
123.3 @@ -1,65 +0,0 @@
123.4 -/*
123.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
123.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
123.7 - *
123.8 - * This code is free software; you can redistribute it and/or modify it
123.9 - * under the terms of the GNU General Public License version 2 only, as
123.10 - * published by the Free Software Foundation. Oracle designates this
123.11 - * particular file as subject to the "Classpath" exception as provided
123.12 - * by Oracle in the LICENSE file that accompanied this code.
123.13 - *
123.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
123.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
123.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
123.17 - * version 2 for more details (a copy is included in the LICENSE file that
123.18 - * accompanied this code).
123.19 - *
123.20 - * You should have received a copy of the GNU General Public License version
123.21 - * 2 along with this work; if not, write to the Free Software Foundation,
123.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
123.23 - *
123.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
123.25 - * or visit www.oracle.com if you need additional information or have any
123.26 - * questions.
123.27 - */
123.28 -
123.29 -package java.lang;
123.30 -
123.31 -/**
123.32 - * Thrown to indicate that the <code>clone</code> method in class
123.33 - * <code>Object</code> has been called to clone an object, but that
123.34 - * the object's class does not implement the <code>Cloneable</code>
123.35 - * interface.
123.36 - * <p>
123.37 - * Applications that override the <code>clone</code> method can also
123.38 - * throw this exception to indicate that an object could not or
123.39 - * should not be cloned.
123.40 - *
123.41 - * @author unascribed
123.42 - * @see java.lang.Cloneable
123.43 - * @see java.lang.Object#clone()
123.44 - * @since JDK1.0
123.45 - */
123.46 -
123.47 -public
123.48 -class CloneNotSupportedException extends Exception {
123.49 - private static final long serialVersionUID = 5195511250079656443L;
123.50 -
123.51 - /**
123.52 - * Constructs a <code>CloneNotSupportedException</code> with no
123.53 - * detail message.
123.54 - */
123.55 - public CloneNotSupportedException() {
123.56 - super();
123.57 - }
123.58 -
123.59 - /**
123.60 - * Constructs a <code>CloneNotSupportedException</code> with the
123.61 - * specified detail message.
123.62 - *
123.63 - * @param s the detail message.
123.64 - */
123.65 - public CloneNotSupportedException(String s) {
123.66 - super(s);
123.67 - }
123.68 -}
124.1 --- a/emul/src/main/java/java/lang/Comparable.java Wed Jan 23 20:16:48 2013 +0100
124.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
124.3 @@ -1,137 +0,0 @@
124.4 -/*
124.5 - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
124.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
124.7 - *
124.8 - * This code is free software; you can redistribute it and/or modify it
124.9 - * under the terms of the GNU General Public License version 2 only, as
124.10 - * published by the Free Software Foundation. Oracle designates this
124.11 - * particular file as subject to the "Classpath" exception as provided
124.12 - * by Oracle in the LICENSE file that accompanied this code.
124.13 - *
124.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
124.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
124.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
124.17 - * version 2 for more details (a copy is included in the LICENSE file that
124.18 - * accompanied this code).
124.19 - *
124.20 - * You should have received a copy of the GNU General Public License version
124.21 - * 2 along with this work; if not, write to the Free Software Foundation,
124.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
124.23 - *
124.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
124.25 - * or visit www.oracle.com if you need additional information or have any
124.26 - * questions.
124.27 - */
124.28 -
124.29 -package java.lang;
124.30 -
124.31 -/**
124.32 - * This interface imposes a total ordering on the objects of each class that
124.33 - * implements it. This ordering is referred to as the class's <i>natural
124.34 - * ordering</i>, and the class's <tt>compareTo</tt> method is referred to as
124.35 - * its <i>natural comparison method</i>.<p>
124.36 - *
124.37 - * Lists (and arrays) of objects that implement this interface can be sorted
124.38 - * automatically by {@link Collections#sort(List) Collections.sort} (and
124.39 - * {@link Arrays#sort(Object[]) Arrays.sort}). Objects that implement this
124.40 - * interface can be used as keys in a {@linkplain SortedMap sorted map} or as
124.41 - * elements in a {@linkplain SortedSet sorted set}, without the need to
124.42 - * specify a {@linkplain Comparator comparator}.<p>
124.43 - *
124.44 - * The natural ordering for a class <tt>C</tt> is said to be <i>consistent
124.45 - * with equals</i> if and only if <tt>e1.compareTo(e2) == 0</tt> has
124.46 - * the same boolean value as <tt>e1.equals(e2)</tt> for every
124.47 - * <tt>e1</tt> and <tt>e2</tt> of class <tt>C</tt>. Note that <tt>null</tt>
124.48 - * is not an instance of any class, and <tt>e.compareTo(null)</tt> should
124.49 - * throw a <tt>NullPointerException</tt> even though <tt>e.equals(null)</tt>
124.50 - * returns <tt>false</tt>.<p>
124.51 - *
124.52 - * It is strongly recommended (though not required) that natural orderings be
124.53 - * consistent with equals. This is so because sorted sets (and sorted maps)
124.54 - * without explicit comparators behave "strangely" when they are used with
124.55 - * elements (or keys) whose natural ordering is inconsistent with equals. In
124.56 - * particular, such a sorted set (or sorted map) violates the general contract
124.57 - * for set (or map), which is defined in terms of the <tt>equals</tt>
124.58 - * method.<p>
124.59 - *
124.60 - * For example, if one adds two keys <tt>a</tt> and <tt>b</tt> such that
124.61 - * <tt>(!a.equals(b) && a.compareTo(b) == 0)</tt> to a sorted
124.62 - * set that does not use an explicit comparator, the second <tt>add</tt>
124.63 - * operation returns false (and the size of the sorted set does not increase)
124.64 - * because <tt>a</tt> and <tt>b</tt> are equivalent from the sorted set's
124.65 - * perspective.<p>
124.66 - *
124.67 - * Virtually all Java core classes that implement <tt>Comparable</tt> have natural
124.68 - * orderings that are consistent with equals. One exception is
124.69 - * <tt>java.math.BigDecimal</tt>, whose natural ordering equates
124.70 - * <tt>BigDecimal</tt> objects with equal values and different precisions
124.71 - * (such as 4.0 and 4.00).<p>
124.72 - *
124.73 - * For the mathematically inclined, the <i>relation</i> that defines
124.74 - * the natural ordering on a given class C is:<pre>
124.75 - * {(x, y) such that x.compareTo(y) <= 0}.
124.76 - * </pre> The <i>quotient</i> for this total order is: <pre>
124.77 - * {(x, y) such that x.compareTo(y) == 0}.
124.78 - * </pre>
124.79 - *
124.80 - * It follows immediately from the contract for <tt>compareTo</tt> that the
124.81 - * quotient is an <i>equivalence relation</i> on <tt>C</tt>, and that the
124.82 - * natural ordering is a <i>total order</i> on <tt>C</tt>. When we say that a
124.83 - * class's natural ordering is <i>consistent with equals</i>, we mean that the
124.84 - * quotient for the natural ordering is the equivalence relation defined by
124.85 - * the class's {@link Object#equals(Object) equals(Object)} method:<pre>
124.86 - * {(x, y) such that x.equals(y)}. </pre><p>
124.87 - *
124.88 - * This interface is a member of the
124.89 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
124.90 - * Java Collections Framework</a>.
124.91 - *
124.92 - * @param <T> the type of objects that this object may be compared to
124.93 - *
124.94 - * @author Josh Bloch
124.95 - * @see java.util.Comparator
124.96 - * @since 1.2
124.97 - */
124.98 -
124.99 -public interface Comparable<T> {
124.100 - /**
124.101 - * Compares this object with the specified object for order. Returns a
124.102 - * negative integer, zero, or a positive integer as this object is less
124.103 - * than, equal to, or greater than the specified object.
124.104 - *
124.105 - * <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
124.106 - * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
124.107 - * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
124.108 - * <tt>y.compareTo(x)</tt> throws an exception.)
124.109 - *
124.110 - * <p>The implementor must also ensure that the relation is transitive:
124.111 - * <tt>(x.compareTo(y)>0 && y.compareTo(z)>0)</tt> implies
124.112 - * <tt>x.compareTo(z)>0</tt>.
124.113 - *
124.114 - * <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
124.115 - * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
124.116 - * all <tt>z</tt>.
124.117 - *
124.118 - * <p>It is strongly recommended, but <i>not</i> strictly required that
124.119 - * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>. Generally speaking, any
124.120 - * class that implements the <tt>Comparable</tt> interface and violates
124.121 - * this condition should clearly indicate this fact. The recommended
124.122 - * language is "Note: this class has a natural ordering that is
124.123 - * inconsistent with equals."
124.124 - *
124.125 - * <p>In the foregoing description, the notation
124.126 - * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
124.127 - * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
124.128 - * <tt>0</tt>, or <tt>1</tt> according to whether the value of
124.129 - * <i>expression</i> is negative, zero or positive.
124.130 - *
124.131 - * @param o the object to be compared.
124.132 - * @return a negative integer, zero, or a positive integer as this object
124.133 - * is less than, equal to, or greater than the specified object.
124.134 - *
124.135 - * @throws NullPointerException if the specified object is null
124.136 - * @throws ClassCastException if the specified object's type prevents it
124.137 - * from being compared to this object.
124.138 - */
124.139 - public int compareTo(T o);
124.140 -}
125.1 --- a/emul/src/main/java/java/lang/Deprecated.java Wed Jan 23 20:16:48 2013 +0100
125.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
125.3 @@ -1,44 +0,0 @@
125.4 -/*
125.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
125.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
125.7 - *
125.8 - * This code is free software; you can redistribute it and/or modify it
125.9 - * under the terms of the GNU General Public License version 2 only, as
125.10 - * published by the Free Software Foundation. Oracle designates this
125.11 - * particular file as subject to the "Classpath" exception as provided
125.12 - * by Oracle in the LICENSE file that accompanied this code.
125.13 - *
125.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
125.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
125.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
125.17 - * version 2 for more details (a copy is included in the LICENSE file that
125.18 - * accompanied this code).
125.19 - *
125.20 - * You should have received a copy of the GNU General Public License version
125.21 - * 2 along with this work; if not, write to the Free Software Foundation,
125.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
125.23 - *
125.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
125.25 - * or visit www.oracle.com if you need additional information or have any
125.26 - * questions.
125.27 - */
125.28 -
125.29 -package java.lang;
125.30 -
125.31 -import java.lang.annotation.*;
125.32 -import static java.lang.annotation.ElementType.*;
125.33 -
125.34 -/**
125.35 - * A program element annotated @Deprecated is one that programmers
125.36 - * are discouraged from using, typically because it is dangerous,
125.37 - * or because a better alternative exists. Compilers warn when a
125.38 - * deprecated program element is used or overridden in non-deprecated code.
125.39 - *
125.40 - * @author Neal Gafter
125.41 - * @since 1.5
125.42 - */
125.43 -@Documented
125.44 -@Retention(RetentionPolicy.RUNTIME)
125.45 -@Target(value={CONSTRUCTOR, FIELD, LOCAL_VARIABLE, METHOD, PACKAGE, PARAMETER, TYPE})
125.46 -public @interface Deprecated {
125.47 -}
126.1 --- a/emul/src/main/java/java/lang/Double.java Wed Jan 23 20:16:48 2013 +0100
126.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
126.3 @@ -1,994 +0,0 @@
126.4 -/*
126.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
126.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
126.7 - *
126.8 - * This code is free software; you can redistribute it and/or modify it
126.9 - * under the terms of the GNU General Public License version 2 only, as
126.10 - * published by the Free Software Foundation. Oracle designates this
126.11 - * particular file as subject to the "Classpath" exception as provided
126.12 - * by Oracle in the LICENSE file that accompanied this code.
126.13 - *
126.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
126.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
126.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
126.17 - * version 2 for more details (a copy is included in the LICENSE file that
126.18 - * accompanied this code).
126.19 - *
126.20 - * You should have received a copy of the GNU General Public License version
126.21 - * 2 along with this work; if not, write to the Free Software Foundation,
126.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
126.23 - *
126.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
126.25 - * or visit www.oracle.com if you need additional information or have any
126.26 - * questions.
126.27 - */
126.28 -
126.29 -package java.lang;
126.30 -
126.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
126.32 -
126.33 -/**
126.34 - * The {@code Double} class wraps a value of the primitive type
126.35 - * {@code double} in an object. An object of type
126.36 - * {@code Double} contains a single field whose type is
126.37 - * {@code double}.
126.38 - *
126.39 - * <p>In addition, this class provides several methods for converting a
126.40 - * {@code double} to a {@code String} and a
126.41 - * {@code String} to a {@code double}, as well as other
126.42 - * constants and methods useful when dealing with a
126.43 - * {@code double}.
126.44 - *
126.45 - * @author Lee Boynton
126.46 - * @author Arthur van Hoff
126.47 - * @author Joseph D. Darcy
126.48 - * @since JDK1.0
126.49 - */
126.50 -public final class Double extends Number implements Comparable<Double> {
126.51 - /**
126.52 - * A constant holding the positive infinity of type
126.53 - * {@code double}. It is equal to the value returned by
126.54 - * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
126.55 - */
126.56 - public static final double POSITIVE_INFINITY = 1.0 / 0.0;
126.57 -
126.58 - /**
126.59 - * A constant holding the negative infinity of type
126.60 - * {@code double}. It is equal to the value returned by
126.61 - * {@code Double.longBitsToDouble(0xfff0000000000000L)}.
126.62 - */
126.63 - public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
126.64 -
126.65 - /**
126.66 - * A constant holding a Not-a-Number (NaN) value of type
126.67 - * {@code double}. It is equivalent to the value returned by
126.68 - * {@code Double.longBitsToDouble(0x7ff8000000000000L)}.
126.69 - */
126.70 - public static final double NaN = 0.0d / 0.0;
126.71 -
126.72 - /**
126.73 - * A constant holding the largest positive finite value of type
126.74 - * {@code double},
126.75 - * (2-2<sup>-52</sup>)·2<sup>1023</sup>. It is equal to
126.76 - * the hexadecimal floating-point literal
126.77 - * {@code 0x1.fffffffffffffP+1023} and also equal to
126.78 - * {@code Double.longBitsToDouble(0x7fefffffffffffffL)}.
126.79 - */
126.80 - public static final double MAX_VALUE = 0x1.fffffffffffffP+1023; // 1.7976931348623157e+308
126.81 -
126.82 - /**
126.83 - * A constant holding the smallest positive normal value of type
126.84 - * {@code double}, 2<sup>-1022</sup>. It is equal to the
126.85 - * hexadecimal floating-point literal {@code 0x1.0p-1022} and also
126.86 - * equal to {@code Double.longBitsToDouble(0x0010000000000000L)}.
126.87 - *
126.88 - * @since 1.6
126.89 - */
126.90 - public static final double MIN_NORMAL = 0x1.0p-1022; // 2.2250738585072014E-308
126.91 -
126.92 - /**
126.93 - * A constant holding the smallest positive nonzero value of type
126.94 - * {@code double}, 2<sup>-1074</sup>. It is equal to the
126.95 - * hexadecimal floating-point literal
126.96 - * {@code 0x0.0000000000001P-1022} and also equal to
126.97 - * {@code Double.longBitsToDouble(0x1L)}.
126.98 - */
126.99 - public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324
126.100 -
126.101 - /**
126.102 - * Maximum exponent a finite {@code double} variable may have.
126.103 - * It is equal to the value returned by
126.104 - * {@code Math.getExponent(Double.MAX_VALUE)}.
126.105 - *
126.106 - * @since 1.6
126.107 - */
126.108 - public static final int MAX_EXPONENT = 1023;
126.109 -
126.110 - /**
126.111 - * Minimum exponent a normalized {@code double} variable may
126.112 - * have. It is equal to the value returned by
126.113 - * {@code Math.getExponent(Double.MIN_NORMAL)}.
126.114 - *
126.115 - * @since 1.6
126.116 - */
126.117 - public static final int MIN_EXPONENT = -1022;
126.118 -
126.119 - /**
126.120 - * The number of bits used to represent a {@code double} value.
126.121 - *
126.122 - * @since 1.5
126.123 - */
126.124 - public static final int SIZE = 64;
126.125 -
126.126 - /**
126.127 - * The {@code Class} instance representing the primitive type
126.128 - * {@code double}.
126.129 - *
126.130 - * @since JDK1.1
126.131 - */
126.132 - public static final Class<Double> TYPE = (Class<Double>) Class.getPrimitiveClass("double");
126.133 -
126.134 - /**
126.135 - * Returns a string representation of the {@code double}
126.136 - * argument. All characters mentioned below are ASCII characters.
126.137 - * <ul>
126.138 - * <li>If the argument is NaN, the result is the string
126.139 - * "{@code NaN}".
126.140 - * <li>Otherwise, the result is a string that represents the sign and
126.141 - * magnitude (absolute value) of the argument. If the sign is negative,
126.142 - * the first character of the result is '{@code -}'
126.143 - * (<code>'\u002D'</code>); if the sign is positive, no sign character
126.144 - * appears in the result. As for the magnitude <i>m</i>:
126.145 - * <ul>
126.146 - * <li>If <i>m</i> is infinity, it is represented by the characters
126.147 - * {@code "Infinity"}; thus, positive infinity produces the result
126.148 - * {@code "Infinity"} and negative infinity produces the result
126.149 - * {@code "-Infinity"}.
126.150 - *
126.151 - * <li>If <i>m</i> is zero, it is represented by the characters
126.152 - * {@code "0.0"}; thus, negative zero produces the result
126.153 - * {@code "-0.0"} and positive zero produces the result
126.154 - * {@code "0.0"}.
126.155 - *
126.156 - * <li>If <i>m</i> is greater than or equal to 10<sup>-3</sup> but less
126.157 - * than 10<sup>7</sup>, then it is represented as the integer part of
126.158 - * <i>m</i>, in decimal form with no leading zeroes, followed by
126.159 - * '{@code .}' (<code>'\u002E'</code>), followed by one or
126.160 - * more decimal digits representing the fractional part of <i>m</i>.
126.161 - *
126.162 - * <li>If <i>m</i> is less than 10<sup>-3</sup> or greater than or
126.163 - * equal to 10<sup>7</sup>, then it is represented in so-called
126.164 - * "computerized scientific notation." Let <i>n</i> be the unique
126.165 - * integer such that 10<sup><i>n</i></sup> ≤ <i>m</i> {@literal <}
126.166 - * 10<sup><i>n</i>+1</sup>; then let <i>a</i> be the
126.167 - * mathematically exact quotient of <i>m</i> and
126.168 - * 10<sup><i>n</i></sup> so that 1 ≤ <i>a</i> {@literal <} 10. The
126.169 - * magnitude is then represented as the integer part of <i>a</i>,
126.170 - * as a single decimal digit, followed by '{@code .}'
126.171 - * (<code>'\u002E'</code>), followed by decimal digits
126.172 - * representing the fractional part of <i>a</i>, followed by the
126.173 - * letter '{@code E}' (<code>'\u0045'</code>), followed
126.174 - * by a representation of <i>n</i> as a decimal integer, as
126.175 - * produced by the method {@link Integer#toString(int)}.
126.176 - * </ul>
126.177 - * </ul>
126.178 - * How many digits must be printed for the fractional part of
126.179 - * <i>m</i> or <i>a</i>? There must be at least one digit to represent
126.180 - * the fractional part, and beyond that as many, but only as many, more
126.181 - * digits as are needed to uniquely distinguish the argument value from
126.182 - * adjacent values of type {@code double}. That is, suppose that
126.183 - * <i>x</i> is the exact mathematical value represented by the decimal
126.184 - * representation produced by this method for a finite nonzero argument
126.185 - * <i>d</i>. Then <i>d</i> must be the {@code double} value nearest
126.186 - * to <i>x</i>; or if two {@code double} values are equally close
126.187 - * to <i>x</i>, then <i>d</i> must be one of them and the least
126.188 - * significant bit of the significand of <i>d</i> must be {@code 0}.
126.189 - *
126.190 - * <p>To create localized string representations of a floating-point
126.191 - * value, use subclasses of {@link java.text.NumberFormat}.
126.192 - *
126.193 - * @param d the {@code double} to be converted.
126.194 - * @return a string representation of the argument.
126.195 - */
126.196 - @JavaScriptBody(args="d", body="var r = d.toString();"
126.197 - + "if (r.indexOf('.') === -1) r = r + '.0';"
126.198 - + "return r;")
126.199 - public static String toString(double d) {
126.200 - throw new UnsupportedOperationException();
126.201 - }
126.202 -
126.203 - /**
126.204 - * Returns a hexadecimal string representation of the
126.205 - * {@code double} argument. All characters mentioned below
126.206 - * are ASCII characters.
126.207 - *
126.208 - * <ul>
126.209 - * <li>If the argument is NaN, the result is the string
126.210 - * "{@code NaN}".
126.211 - * <li>Otherwise, the result is a string that represents the sign
126.212 - * and magnitude of the argument. If the sign is negative, the
126.213 - * first character of the result is '{@code -}'
126.214 - * (<code>'\u002D'</code>); if the sign is positive, no sign
126.215 - * character appears in the result. As for the magnitude <i>m</i>:
126.216 - *
126.217 - * <ul>
126.218 - * <li>If <i>m</i> is infinity, it is represented by the string
126.219 - * {@code "Infinity"}; thus, positive infinity produces the
126.220 - * result {@code "Infinity"} and negative infinity produces
126.221 - * the result {@code "-Infinity"}.
126.222 - *
126.223 - * <li>If <i>m</i> is zero, it is represented by the string
126.224 - * {@code "0x0.0p0"}; thus, negative zero produces the result
126.225 - * {@code "-0x0.0p0"} and positive zero produces the result
126.226 - * {@code "0x0.0p0"}.
126.227 - *
126.228 - * <li>If <i>m</i> is a {@code double} value with a
126.229 - * normalized representation, substrings are used to represent the
126.230 - * significand and exponent fields. The significand is
126.231 - * represented by the characters {@code "0x1."}
126.232 - * followed by a lowercase hexadecimal representation of the rest
126.233 - * of the significand as a fraction. Trailing zeros in the
126.234 - * hexadecimal representation are removed unless all the digits
126.235 - * are zero, in which case a single zero is used. Next, the
126.236 - * exponent is represented by {@code "p"} followed
126.237 - * by a decimal string of the unbiased exponent as if produced by
126.238 - * a call to {@link Integer#toString(int) Integer.toString} on the
126.239 - * exponent value.
126.240 - *
126.241 - * <li>If <i>m</i> is a {@code double} value with a subnormal
126.242 - * representation, the significand is represented by the
126.243 - * characters {@code "0x0."} followed by a
126.244 - * hexadecimal representation of the rest of the significand as a
126.245 - * fraction. Trailing zeros in the hexadecimal representation are
126.246 - * removed. Next, the exponent is represented by
126.247 - * {@code "p-1022"}. Note that there must be at
126.248 - * least one nonzero digit in a subnormal significand.
126.249 - *
126.250 - * </ul>
126.251 - *
126.252 - * </ul>
126.253 - *
126.254 - * <table border>
126.255 - * <caption><h3>Examples</h3></caption>
126.256 - * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
126.257 - * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
126.258 - * <tr><td>{@code -1.0}</td> <td>{@code -0x1.0p0}</td>
126.259 - * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
126.260 - * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
126.261 - * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
126.262 - * <tr><td>{@code 0.25}</td> <td>{@code 0x1.0p-2}</td>
126.263 - * <tr><td>{@code Double.MAX_VALUE}</td>
126.264 - * <td>{@code 0x1.fffffffffffffp1023}</td>
126.265 - * <tr><td>{@code Minimum Normal Value}</td>
126.266 - * <td>{@code 0x1.0p-1022}</td>
126.267 - * <tr><td>{@code Maximum Subnormal Value}</td>
126.268 - * <td>{@code 0x0.fffffffffffffp-1022}</td>
126.269 - * <tr><td>{@code Double.MIN_VALUE}</td>
126.270 - * <td>{@code 0x0.0000000000001p-1022}</td>
126.271 - * </table>
126.272 - * @param d the {@code double} to be converted.
126.273 - * @return a hex string representation of the argument.
126.274 - * @since 1.5
126.275 - * @author Joseph D. Darcy
126.276 - */
126.277 - public static String toHexString(double d) {
126.278 - throw new UnsupportedOperationException();
126.279 -// /*
126.280 -// * Modeled after the "a" conversion specifier in C99, section
126.281 -// * 7.19.6.1; however, the output of this method is more
126.282 -// * tightly specified.
126.283 -// */
126.284 -// if (!FpUtils.isFinite(d) )
126.285 -// // For infinity and NaN, use the decimal output.
126.286 -// return Double.toString(d);
126.287 -// else {
126.288 -// // Initialized to maximum size of output.
126.289 -// StringBuffer answer = new StringBuffer(24);
126.290 -//
126.291 -// if (FpUtils.rawCopySign(1.0, d) == -1.0) // value is negative,
126.292 -// answer.append("-"); // so append sign info
126.293 -//
126.294 -// answer.append("0x");
126.295 -//
126.296 -// d = Math.abs(d);
126.297 -//
126.298 -// if(d == 0.0) {
126.299 -// answer.append("0.0p0");
126.300 -// }
126.301 -// else {
126.302 -// boolean subnormal = (d < DoubleConsts.MIN_NORMAL);
126.303 -//
126.304 -// // Isolate significand bits and OR in a high-order bit
126.305 -// // so that the string representation has a known
126.306 -// // length.
126.307 -// long signifBits = (Double.doubleToLongBits(d)
126.308 -// & DoubleConsts.SIGNIF_BIT_MASK) |
126.309 -// 0x1000000000000000L;
126.310 -//
126.311 -// // Subnormal values have a 0 implicit bit; normal
126.312 -// // values have a 1 implicit bit.
126.313 -// answer.append(subnormal ? "0." : "1.");
126.314 -//
126.315 -// // Isolate the low-order 13 digits of the hex
126.316 -// // representation. If all the digits are zero,
126.317 -// // replace with a single 0; otherwise, remove all
126.318 -// // trailing zeros.
126.319 -// String signif = Long.toHexString(signifBits).substring(3,16);
126.320 -// answer.append(signif.equals("0000000000000") ? // 13 zeros
126.321 -// "0":
126.322 -// signif.replaceFirst("0{1,12}$", ""));
126.323 -//
126.324 -// // If the value is subnormal, use the E_min exponent
126.325 -// // value for double; otherwise, extract and report d's
126.326 -// // exponent (the representation of a subnormal uses
126.327 -// // E_min -1).
126.328 -// answer.append("p" + (subnormal ?
126.329 -// DoubleConsts.MIN_EXPONENT:
126.330 -// FpUtils.getExponent(d) ));
126.331 -// }
126.332 -// return answer.toString();
126.333 -// }
126.334 - }
126.335 -
126.336 - /**
126.337 - * Returns a {@code Double} object holding the
126.338 - * {@code double} value represented by the argument string
126.339 - * {@code s}.
126.340 - *
126.341 - * <p>If {@code s} is {@code null}, then a
126.342 - * {@code NullPointerException} is thrown.
126.343 - *
126.344 - * <p>Leading and trailing whitespace characters in {@code s}
126.345 - * are ignored. Whitespace is removed as if by the {@link
126.346 - * String#trim} method; that is, both ASCII space and control
126.347 - * characters are removed. The rest of {@code s} should
126.348 - * constitute a <i>FloatValue</i> as described by the lexical
126.349 - * syntax rules:
126.350 - *
126.351 - * <blockquote>
126.352 - * <dl>
126.353 - * <dt><i>FloatValue:</i>
126.354 - * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
126.355 - * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
126.356 - * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
126.357 - * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
126.358 - * <dd><i>SignedInteger</i>
126.359 - * </dl>
126.360 - *
126.361 - * <p>
126.362 - *
126.363 - * <dl>
126.364 - * <dt><i>HexFloatingPointLiteral</i>:
126.365 - * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
126.366 - * </dl>
126.367 - *
126.368 - * <p>
126.369 - *
126.370 - * <dl>
126.371 - * <dt><i>HexSignificand:</i>
126.372 - * <dd><i>HexNumeral</i>
126.373 - * <dd><i>HexNumeral</i> {@code .}
126.374 - * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
126.375 - * </i>{@code .}<i> HexDigits</i>
126.376 - * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
126.377 - * </i>{@code .} <i>HexDigits</i>
126.378 - * </dl>
126.379 - *
126.380 - * <p>
126.381 - *
126.382 - * <dl>
126.383 - * <dt><i>BinaryExponent:</i>
126.384 - * <dd><i>BinaryExponentIndicator SignedInteger</i>
126.385 - * </dl>
126.386 - *
126.387 - * <p>
126.388 - *
126.389 - * <dl>
126.390 - * <dt><i>BinaryExponentIndicator:</i>
126.391 - * <dd>{@code p}
126.392 - * <dd>{@code P}
126.393 - * </dl>
126.394 - *
126.395 - * </blockquote>
126.396 - *
126.397 - * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
126.398 - * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
126.399 - * <i>FloatTypeSuffix</i> are as defined in the lexical structure
126.400 - * sections of
126.401 - * <cite>The Java™ Language Specification</cite>,
126.402 - * except that underscores are not accepted between digits.
126.403 - * If {@code s} does not have the form of
126.404 - * a <i>FloatValue</i>, then a {@code NumberFormatException}
126.405 - * is thrown. Otherwise, {@code s} is regarded as
126.406 - * representing an exact decimal value in the usual
126.407 - * "computerized scientific notation" or as an exact
126.408 - * hexadecimal value; this exact numerical value is then
126.409 - * conceptually converted to an "infinitely precise"
126.410 - * binary value that is then rounded to type {@code double}
126.411 - * by the usual round-to-nearest rule of IEEE 754 floating-point
126.412 - * arithmetic, which includes preserving the sign of a zero
126.413 - * value.
126.414 - *
126.415 - * Note that the round-to-nearest rule also implies overflow and
126.416 - * underflow behaviour; if the exact value of {@code s} is large
126.417 - * enough in magnitude (greater than or equal to ({@link
126.418 - * #MAX_VALUE} + {@link Math#ulp(double) ulp(MAX_VALUE)}/2),
126.419 - * rounding to {@code double} will result in an infinity and if the
126.420 - * exact value of {@code s} is small enough in magnitude (less
126.421 - * than or equal to {@link #MIN_VALUE}/2), rounding to float will
126.422 - * result in a zero.
126.423 - *
126.424 - * Finally, after rounding a {@code Double} object representing
126.425 - * this {@code double} value is returned.
126.426 - *
126.427 - * <p> To interpret localized string representations of a
126.428 - * floating-point value, use subclasses of {@link
126.429 - * java.text.NumberFormat}.
126.430 - *
126.431 - * <p>Note that trailing format specifiers, specifiers that
126.432 - * determine the type of a floating-point literal
126.433 - * ({@code 1.0f} is a {@code float} value;
126.434 - * {@code 1.0d} is a {@code double} value), do
126.435 - * <em>not</em> influence the results of this method. In other
126.436 - * words, the numerical value of the input string is converted
126.437 - * directly to the target floating-point type. The two-step
126.438 - * sequence of conversions, string to {@code float} followed
126.439 - * by {@code float} to {@code double}, is <em>not</em>
126.440 - * equivalent to converting a string directly to
126.441 - * {@code double}. For example, the {@code float}
126.442 - * literal {@code 0.1f} is equal to the {@code double}
126.443 - * value {@code 0.10000000149011612}; the {@code float}
126.444 - * literal {@code 0.1f} represents a different numerical
126.445 - * value than the {@code double} literal
126.446 - * {@code 0.1}. (The numerical value 0.1 cannot be exactly
126.447 - * represented in a binary floating-point number.)
126.448 - *
126.449 - * <p>To avoid calling this method on an invalid string and having
126.450 - * a {@code NumberFormatException} be thrown, the regular
126.451 - * expression below can be used to screen the input string:
126.452 - *
126.453 - * <code>
126.454 - * <pre>
126.455 - * final String Digits = "(\\p{Digit}+)";
126.456 - * final String HexDigits = "(\\p{XDigit}+)";
126.457 - * // an exponent is 'e' or 'E' followed by an optionally
126.458 - * // signed decimal integer.
126.459 - * final String Exp = "[eE][+-]?"+Digits;
126.460 - * final String fpRegex =
126.461 - * ("[\\x00-\\x20]*"+ // Optional leading "whitespace"
126.462 - * "[+-]?(" + // Optional sign character
126.463 - * "NaN|" + // "NaN" string
126.464 - * "Infinity|" + // "Infinity" string
126.465 - *
126.466 - * // A decimal floating-point string representing a finite positive
126.467 - * // number without a leading sign has at most five basic pieces:
126.468 - * // Digits . Digits ExponentPart FloatTypeSuffix
126.469 - * //
126.470 - * // Since this method allows integer-only strings as input
126.471 - * // in addition to strings of floating-point literals, the
126.472 - * // two sub-patterns below are simplifications of the grammar
126.473 - * // productions from section 3.10.2 of
126.474 - * // <cite>The Java™ Language Specification</cite>.
126.475 - *
126.476 - * // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
126.477 - * "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
126.478 - *
126.479 - * // . Digits ExponentPart_opt FloatTypeSuffix_opt
126.480 - * "(\\.("+Digits+")("+Exp+")?)|"+
126.481 - *
126.482 - * // Hexadecimal strings
126.483 - * "((" +
126.484 - * // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
126.485 - * "(0[xX]" + HexDigits + "(\\.)?)|" +
126.486 - *
126.487 - * // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
126.488 - * "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
126.489 - *
126.490 - * ")[pP][+-]?" + Digits + "))" +
126.491 - * "[fFdD]?))" +
126.492 - * "[\\x00-\\x20]*");// Optional trailing "whitespace"
126.493 - *
126.494 - * if (Pattern.matches(fpRegex, myString))
126.495 - * Double.valueOf(myString); // Will not throw NumberFormatException
126.496 - * else {
126.497 - * // Perform suitable alternative action
126.498 - * }
126.499 - * </pre>
126.500 - * </code>
126.501 - *
126.502 - * @param s the string to be parsed.
126.503 - * @return a {@code Double} object holding the value
126.504 - * represented by the {@code String} argument.
126.505 - * @throws NumberFormatException if the string does not contain a
126.506 - * parsable number.
126.507 - */
126.508 - @JavaScriptBody(args="s", body="return parseFloat(s);")
126.509 - public static Double valueOf(String s) throws NumberFormatException {
126.510 - throw new UnsupportedOperationException();
126.511 -// return new Double(FloatingDecimal.readJavaFormatString(s).doubleValue());
126.512 - }
126.513 -
126.514 - /**
126.515 - * Returns a {@code Double} instance representing the specified
126.516 - * {@code double} value.
126.517 - * If a new {@code Double} instance is not required, this method
126.518 - * should generally be used in preference to the constructor
126.519 - * {@link #Double(double)}, as this method is likely to yield
126.520 - * significantly better space and time performance by caching
126.521 - * frequently requested values.
126.522 - *
126.523 - * @param d a double value.
126.524 - * @return a {@code Double} instance representing {@code d}.
126.525 - * @since 1.5
126.526 - */
126.527 - public static Double valueOf(double d) {
126.528 - return new Double(d);
126.529 - }
126.530 -
126.531 - /**
126.532 - * Returns a new {@code double} initialized to the value
126.533 - * represented by the specified {@code String}, as performed
126.534 - * by the {@code valueOf} method of class
126.535 - * {@code Double}.
126.536 - *
126.537 - * @param s the string to be parsed.
126.538 - * @return the {@code double} value represented by the string
126.539 - * argument.
126.540 - * @throws NullPointerException if the string is null
126.541 - * @throws NumberFormatException if the string does not contain
126.542 - * a parsable {@code double}.
126.543 - * @see java.lang.Double#valueOf(String)
126.544 - * @since 1.2
126.545 - */
126.546 - @JavaScriptBody(args="s", body="return parseFloat(s);")
126.547 - public static double parseDouble(String s) throws NumberFormatException {
126.548 - throw new UnsupportedOperationException();
126.549 -// return FloatingDecimal.readJavaFormatString(s).doubleValue();
126.550 - }
126.551 -
126.552 - /**
126.553 - * Returns {@code true} if the specified number is a
126.554 - * Not-a-Number (NaN) value, {@code false} otherwise.
126.555 - *
126.556 - * @param v the value to be tested.
126.557 - * @return {@code true} if the value of the argument is NaN;
126.558 - * {@code false} otherwise.
126.559 - */
126.560 - static public boolean isNaN(double v) {
126.561 - return (v != v);
126.562 - }
126.563 -
126.564 - /**
126.565 - * Returns {@code true} if the specified number is infinitely
126.566 - * large in magnitude, {@code false} otherwise.
126.567 - *
126.568 - * @param v the value to be tested.
126.569 - * @return {@code true} if the value of the argument is positive
126.570 - * infinity or negative infinity; {@code false} otherwise.
126.571 - */
126.572 - static public boolean isInfinite(double v) {
126.573 - return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
126.574 - }
126.575 -
126.576 - /**
126.577 - * The value of the Double.
126.578 - *
126.579 - * @serial
126.580 - */
126.581 - private final double value;
126.582 -
126.583 - /**
126.584 - * Constructs a newly allocated {@code Double} object that
126.585 - * represents the primitive {@code double} argument.
126.586 - *
126.587 - * @param value the value to be represented by the {@code Double}.
126.588 - */
126.589 - public Double(double value) {
126.590 - this.value = value;
126.591 - }
126.592 -
126.593 - /**
126.594 - * Constructs a newly allocated {@code Double} object that
126.595 - * represents the floating-point value of type {@code double}
126.596 - * represented by the string. The string is converted to a
126.597 - * {@code double} value as if by the {@code valueOf} method.
126.598 - *
126.599 - * @param s a string to be converted to a {@code Double}.
126.600 - * @throws NumberFormatException if the string does not contain a
126.601 - * parsable number.
126.602 - * @see java.lang.Double#valueOf(java.lang.String)
126.603 - */
126.604 - public Double(String s) throws NumberFormatException {
126.605 - // REMIND: this is inefficient
126.606 - this(valueOf(s).doubleValue());
126.607 - }
126.608 -
126.609 - /**
126.610 - * Returns {@code true} if this {@code Double} value is
126.611 - * a Not-a-Number (NaN), {@code false} otherwise.
126.612 - *
126.613 - * @return {@code true} if the value represented by this object is
126.614 - * NaN; {@code false} otherwise.
126.615 - */
126.616 - public boolean isNaN() {
126.617 - return isNaN(value);
126.618 - }
126.619 -
126.620 - /**
126.621 - * Returns {@code true} if this {@code Double} value is
126.622 - * infinitely large in magnitude, {@code false} otherwise.
126.623 - *
126.624 - * @return {@code true} if the value represented by this object is
126.625 - * positive infinity or negative infinity;
126.626 - * {@code false} otherwise.
126.627 - */
126.628 - public boolean isInfinite() {
126.629 - return isInfinite(value);
126.630 - }
126.631 -
126.632 - /**
126.633 - * Returns a string representation of this {@code Double} object.
126.634 - * The primitive {@code double} value represented by this
126.635 - * object is converted to a string exactly as if by the method
126.636 - * {@code toString} of one argument.
126.637 - *
126.638 - * @return a {@code String} representation of this object.
126.639 - * @see java.lang.Double#toString(double)
126.640 - */
126.641 - public String toString() {
126.642 - return toString(value);
126.643 - }
126.644 -
126.645 - /**
126.646 - * Returns the value of this {@code Double} as a {@code byte} (by
126.647 - * casting to a {@code byte}).
126.648 - *
126.649 - * @return the {@code double} value represented by this object
126.650 - * converted to type {@code byte}
126.651 - * @since JDK1.1
126.652 - */
126.653 - public byte byteValue() {
126.654 - return (byte)value;
126.655 - }
126.656 -
126.657 - /**
126.658 - * Returns the value of this {@code Double} as a
126.659 - * {@code short} (by casting to a {@code short}).
126.660 - *
126.661 - * @return the {@code double} value represented by this object
126.662 - * converted to type {@code short}
126.663 - * @since JDK1.1
126.664 - */
126.665 - public short shortValue() {
126.666 - return (short)value;
126.667 - }
126.668 -
126.669 - /**
126.670 - * Returns the value of this {@code Double} as an
126.671 - * {@code int} (by casting to type {@code int}).
126.672 - *
126.673 - * @return the {@code double} value represented by this object
126.674 - * converted to type {@code int}
126.675 - */
126.676 - public int intValue() {
126.677 - return (int)value;
126.678 - }
126.679 -
126.680 - /**
126.681 - * Returns the value of this {@code Double} as a
126.682 - * {@code long} (by casting to type {@code long}).
126.683 - *
126.684 - * @return the {@code double} value represented by this object
126.685 - * converted to type {@code long}
126.686 - */
126.687 - public long longValue() {
126.688 - return (long)value;
126.689 - }
126.690 -
126.691 - /**
126.692 - * Returns the {@code float} value of this
126.693 - * {@code Double} object.
126.694 - *
126.695 - * @return the {@code double} value represented by this object
126.696 - * converted to type {@code float}
126.697 - * @since JDK1.0
126.698 - */
126.699 - public float floatValue() {
126.700 - return (float)value;
126.701 - }
126.702 -
126.703 - /**
126.704 - * Returns the {@code double} value of this
126.705 - * {@code Double} object.
126.706 - *
126.707 - * @return the {@code double} value represented by this object
126.708 - */
126.709 - public double doubleValue() {
126.710 - return (double)value;
126.711 - }
126.712 -
126.713 - /**
126.714 - * Returns a hash code for this {@code Double} object. The
126.715 - * result is the exclusive OR of the two halves of the
126.716 - * {@code long} integer bit representation, exactly as
126.717 - * produced by the method {@link #doubleToLongBits(double)}, of
126.718 - * the primitive {@code double} value represented by this
126.719 - * {@code Double} object. That is, the hash code is the value
126.720 - * of the expression:
126.721 - *
126.722 - * <blockquote>
126.723 - * {@code (int)(v^(v>>>32))}
126.724 - * </blockquote>
126.725 - *
126.726 - * where {@code v} is defined by:
126.727 - *
126.728 - * <blockquote>
126.729 - * {@code long v = Double.doubleToLongBits(this.doubleValue());}
126.730 - * </blockquote>
126.731 - *
126.732 - * @return a {@code hash code} value for this object.
126.733 - */
126.734 - public int hashCode() {
126.735 - long bits = doubleToLongBits(value);
126.736 - return (int)(bits ^ (bits >>> 32));
126.737 - }
126.738 -
126.739 - /**
126.740 - * Compares this object against the specified object. The result
126.741 - * is {@code true} if and only if the argument is not
126.742 - * {@code null} and is a {@code Double} object that
126.743 - * represents a {@code double} that has the same value as the
126.744 - * {@code double} represented by this object. For this
126.745 - * purpose, two {@code double} values are considered to be
126.746 - * the same if and only if the method {@link
126.747 - * #doubleToLongBits(double)} returns the identical
126.748 - * {@code long} value when applied to each.
126.749 - *
126.750 - * <p>Note that in most cases, for two instances of class
126.751 - * {@code Double}, {@code d1} and {@code d2}, the
126.752 - * value of {@code d1.equals(d2)} is {@code true} if and
126.753 - * only if
126.754 - *
126.755 - * <blockquote>
126.756 - * {@code d1.doubleValue() == d2.doubleValue()}
126.757 - * </blockquote>
126.758 - *
126.759 - * <p>also has the value {@code true}. However, there are two
126.760 - * exceptions:
126.761 - * <ul>
126.762 - * <li>If {@code d1} and {@code d2} both represent
126.763 - * {@code Double.NaN}, then the {@code equals} method
126.764 - * returns {@code true}, even though
126.765 - * {@code Double.NaN==Double.NaN} has the value
126.766 - * {@code false}.
126.767 - * <li>If {@code d1} represents {@code +0.0} while
126.768 - * {@code d2} represents {@code -0.0}, or vice versa,
126.769 - * the {@code equal} test has the value {@code false},
126.770 - * even though {@code +0.0==-0.0} has the value {@code true}.
126.771 - * </ul>
126.772 - * This definition allows hash tables to operate properly.
126.773 - * @param obj the object to compare with.
126.774 - * @return {@code true} if the objects are the same;
126.775 - * {@code false} otherwise.
126.776 - * @see java.lang.Double#doubleToLongBits(double)
126.777 - */
126.778 - public boolean equals(Object obj) {
126.779 - return (obj instanceof Double)
126.780 - && (((Double)obj).value) == value;
126.781 - }
126.782 -
126.783 - /**
126.784 - * Returns a representation of the specified floating-point value
126.785 - * according to the IEEE 754 floating-point "double
126.786 - * format" bit layout.
126.787 - *
126.788 - * <p>Bit 63 (the bit that is selected by the mask
126.789 - * {@code 0x8000000000000000L}) represents the sign of the
126.790 - * floating-point number. Bits
126.791 - * 62-52 (the bits that are selected by the mask
126.792 - * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
126.793 - * (the bits that are selected by the mask
126.794 - * {@code 0x000fffffffffffffL}) represent the significand
126.795 - * (sometimes called the mantissa) of the floating-point number.
126.796 - *
126.797 - * <p>If the argument is positive infinity, the result is
126.798 - * {@code 0x7ff0000000000000L}.
126.799 - *
126.800 - * <p>If the argument is negative infinity, the result is
126.801 - * {@code 0xfff0000000000000L}.
126.802 - *
126.803 - * <p>If the argument is NaN, the result is
126.804 - * {@code 0x7ff8000000000000L}.
126.805 - *
126.806 - * <p>In all cases, the result is a {@code long} integer that, when
126.807 - * given to the {@link #longBitsToDouble(long)} method, will produce a
126.808 - * floating-point value the same as the argument to
126.809 - * {@code doubleToLongBits} (except all NaN values are
126.810 - * collapsed to a single "canonical" NaN value).
126.811 - *
126.812 - * @param value a {@code double} precision floating-point number.
126.813 - * @return the bits that represent the floating-point number.
126.814 - */
126.815 - public static long doubleToLongBits(double value) {
126.816 - throw new UnsupportedOperationException();
126.817 -// long result = doubleToRawLongBits(value);
126.818 -// // Check for NaN based on values of bit fields, maximum
126.819 -// // exponent and nonzero significand.
126.820 -// if ( ((result & DoubleConsts.EXP_BIT_MASK) ==
126.821 -// DoubleConsts.EXP_BIT_MASK) &&
126.822 -// (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
126.823 -// result = 0x7ff8000000000000L;
126.824 -// return result;
126.825 - }
126.826 -
126.827 - /**
126.828 - * Returns a representation of the specified floating-point value
126.829 - * according to the IEEE 754 floating-point "double
126.830 - * format" bit layout, preserving Not-a-Number (NaN) values.
126.831 - *
126.832 - * <p>Bit 63 (the bit that is selected by the mask
126.833 - * {@code 0x8000000000000000L}) represents the sign of the
126.834 - * floating-point number. Bits
126.835 - * 62-52 (the bits that are selected by the mask
126.836 - * {@code 0x7ff0000000000000L}) represent the exponent. Bits 51-0
126.837 - * (the bits that are selected by the mask
126.838 - * {@code 0x000fffffffffffffL}) represent the significand
126.839 - * (sometimes called the mantissa) of the floating-point number.
126.840 - *
126.841 - * <p>If the argument is positive infinity, the result is
126.842 - * {@code 0x7ff0000000000000L}.
126.843 - *
126.844 - * <p>If the argument is negative infinity, the result is
126.845 - * {@code 0xfff0000000000000L}.
126.846 - *
126.847 - * <p>If the argument is NaN, the result is the {@code long}
126.848 - * integer representing the actual NaN value. Unlike the
126.849 - * {@code doubleToLongBits} method,
126.850 - * {@code doubleToRawLongBits} does not collapse all the bit
126.851 - * patterns encoding a NaN to a single "canonical" NaN
126.852 - * value.
126.853 - *
126.854 - * <p>In all cases, the result is a {@code long} integer that,
126.855 - * when given to the {@link #longBitsToDouble(long)} method, will
126.856 - * produce a floating-point value the same as the argument to
126.857 - * {@code doubleToRawLongBits}.
126.858 - *
126.859 - * @param value a {@code double} precision floating-point number.
126.860 - * @return the bits that represent the floating-point number.
126.861 - * @since 1.3
126.862 - */
126.863 - public static native long doubleToRawLongBits(double value);
126.864 -
126.865 - /**
126.866 - * Returns the {@code double} value corresponding to a given
126.867 - * bit representation.
126.868 - * The argument is considered to be a representation of a
126.869 - * floating-point value according to the IEEE 754 floating-point
126.870 - * "double format" bit layout.
126.871 - *
126.872 - * <p>If the argument is {@code 0x7ff0000000000000L}, the result
126.873 - * is positive infinity.
126.874 - *
126.875 - * <p>If the argument is {@code 0xfff0000000000000L}, the result
126.876 - * is negative infinity.
126.877 - *
126.878 - * <p>If the argument is any value in the range
126.879 - * {@code 0x7ff0000000000001L} through
126.880 - * {@code 0x7fffffffffffffffL} or in the range
126.881 - * {@code 0xfff0000000000001L} through
126.882 - * {@code 0xffffffffffffffffL}, the result is a NaN. No IEEE
126.883 - * 754 floating-point operation provided by Java can distinguish
126.884 - * between two NaN values of the same type with different bit
126.885 - * patterns. Distinct values of NaN are only distinguishable by
126.886 - * use of the {@code Double.doubleToRawLongBits} method.
126.887 - *
126.888 - * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
126.889 - * values that can be computed from the argument:
126.890 - *
126.891 - * <blockquote><pre>
126.892 - * int s = ((bits >> 63) == 0) ? 1 : -1;
126.893 - * int e = (int)((bits >> 52) & 0x7ffL);
126.894 - * long m = (e == 0) ?
126.895 - * (bits & 0xfffffffffffffL) << 1 :
126.896 - * (bits & 0xfffffffffffffL) | 0x10000000000000L;
126.897 - * </pre></blockquote>
126.898 - *
126.899 - * Then the floating-point result equals the value of the mathematical
126.900 - * expression <i>s</i>·<i>m</i>·2<sup><i>e</i>-1075</sup>.
126.901 - *
126.902 - * <p>Note that this method may not be able to return a
126.903 - * {@code double} NaN with exactly same bit pattern as the
126.904 - * {@code long} argument. IEEE 754 distinguishes between two
126.905 - * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>. The
126.906 - * differences between the two kinds of NaN are generally not
126.907 - * visible in Java. Arithmetic operations on signaling NaNs turn
126.908 - * them into quiet NaNs with a different, but often similar, bit
126.909 - * pattern. However, on some processors merely copying a
126.910 - * signaling NaN also performs that conversion. In particular,
126.911 - * copying a signaling NaN to return it to the calling method
126.912 - * may perform this conversion. So {@code longBitsToDouble}
126.913 - * may not be able to return a {@code double} with a
126.914 - * signaling NaN bit pattern. Consequently, for some
126.915 - * {@code long} values,
126.916 - * {@code doubleToRawLongBits(longBitsToDouble(start))} may
126.917 - * <i>not</i> equal {@code start}. Moreover, which
126.918 - * particular bit patterns represent signaling NaNs is platform
126.919 - * dependent; although all NaN bit patterns, quiet or signaling,
126.920 - * must be in the NaN range identified above.
126.921 - *
126.922 - * @param bits any {@code long} integer.
126.923 - * @return the {@code double} floating-point value with the same
126.924 - * bit pattern.
126.925 - */
126.926 - public static native double longBitsToDouble(long bits);
126.927 -
126.928 - /**
126.929 - * Compares two {@code Double} objects numerically. There
126.930 - * are two ways in which comparisons performed by this method
126.931 - * differ from those performed by the Java language numerical
126.932 - * comparison operators ({@code <, <=, ==, >=, >})
126.933 - * when applied to primitive {@code double} values:
126.934 - * <ul><li>
126.935 - * {@code Double.NaN} is considered by this method
126.936 - * to be equal to itself and greater than all other
126.937 - * {@code double} values (including
126.938 - * {@code Double.POSITIVE_INFINITY}).
126.939 - * <li>
126.940 - * {@code 0.0d} is considered by this method to be greater
126.941 - * than {@code -0.0d}.
126.942 - * </ul>
126.943 - * This ensures that the <i>natural ordering</i> of
126.944 - * {@code Double} objects imposed by this method is <i>consistent
126.945 - * with equals</i>.
126.946 - *
126.947 - * @param anotherDouble the {@code Double} to be compared.
126.948 - * @return the value {@code 0} if {@code anotherDouble} is
126.949 - * numerically equal to this {@code Double}; a value
126.950 - * less than {@code 0} if this {@code Double}
126.951 - * is numerically less than {@code anotherDouble};
126.952 - * and a value greater than {@code 0} if this
126.953 - * {@code Double} is numerically greater than
126.954 - * {@code anotherDouble}.
126.955 - *
126.956 - * @since 1.2
126.957 - */
126.958 - public int compareTo(Double anotherDouble) {
126.959 - return Double.compare(value, anotherDouble.value);
126.960 - }
126.961 -
126.962 - /**
126.963 - * Compares the two specified {@code double} values. The sign
126.964 - * of the integer value returned is the same as that of the
126.965 - * integer that would be returned by the call:
126.966 - * <pre>
126.967 - * new Double(d1).compareTo(new Double(d2))
126.968 - * </pre>
126.969 - *
126.970 - * @param d1 the first {@code double} to compare
126.971 - * @param d2 the second {@code double} to compare
126.972 - * @return the value {@code 0} if {@code d1} is
126.973 - * numerically equal to {@code d2}; a value less than
126.974 - * {@code 0} if {@code d1} is numerically less than
126.975 - * {@code d2}; and a value greater than {@code 0}
126.976 - * if {@code d1} is numerically greater than
126.977 - * {@code d2}.
126.978 - * @since 1.4
126.979 - */
126.980 - public static int compare(double d1, double d2) {
126.981 - if (d1 < d2)
126.982 - return -1; // Neither val is NaN, thisVal is smaller
126.983 - if (d1 > d2)
126.984 - return 1; // Neither val is NaN, thisVal is larger
126.985 -
126.986 - // Cannot use doubleToRawLongBits because of possibility of NaNs.
126.987 - long thisBits = Double.doubleToLongBits(d1);
126.988 - long anotherBits = Double.doubleToLongBits(d2);
126.989 -
126.990 - return (thisBits == anotherBits ? 0 : // Values are equal
126.991 - (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
126.992 - 1)); // (0.0, -0.0) or (NaN, !NaN)
126.993 - }
126.994 -
126.995 - /** use serialVersionUID from JDK 1.0.2 for interoperability */
126.996 - private static final long serialVersionUID = -9172774392245257468L;
126.997 -}
127.1 --- a/emul/src/main/java/java/lang/Enum.java Wed Jan 23 20:16:48 2013 +0100
127.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
127.3 @@ -1,254 +0,0 @@
127.4 -/*
127.5 - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
127.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
127.7 - *
127.8 - * This code is free software; you can redistribute it and/or modify it
127.9 - * under the terms of the GNU General Public License version 2 only, as
127.10 - * published by the Free Software Foundation. Oracle designates this
127.11 - * particular file as subject to the "Classpath" exception as provided
127.12 - * by Oracle in the LICENSE file that accompanied this code.
127.13 - *
127.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
127.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
127.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
127.17 - * version 2 for more details (a copy is included in the LICENSE file that
127.18 - * accompanied this code).
127.19 - *
127.20 - * You should have received a copy of the GNU General Public License version
127.21 - * 2 along with this work; if not, write to the Free Software Foundation,
127.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
127.23 - *
127.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
127.25 - * or visit www.oracle.com if you need additional information or have any
127.26 - * questions.
127.27 - */
127.28 -
127.29 -package java.lang;
127.30 -
127.31 -import java.io.Serializable;
127.32 -import java.io.IOException;
127.33 -
127.34 -/**
127.35 - * This is the common base class of all Java language enumeration types.
127.36 - *
127.37 - * More information about enums, including descriptions of the
127.38 - * implicitly declared methods synthesized by the compiler, can be
127.39 - * found in section 8.9 of
127.40 - * <cite>The Java™ Language Specification</cite>.
127.41 - *
127.42 - * <p> Note that when using an enumeration type as the type of a set
127.43 - * or as the type of the keys in a map, specialized and efficient
127.44 - * {@linkplain java.util.EnumSet set} and {@linkplain
127.45 - * java.util.EnumMap map} implementations are available.
127.46 - *
127.47 - * @param <E> The enum type subclass
127.48 - * @author Josh Bloch
127.49 - * @author Neal Gafter
127.50 - * @see Class#getEnumConstants()
127.51 - * @see java.util.EnumSet
127.52 - * @see java.util.EnumMap
127.53 - * @since 1.5
127.54 - */
127.55 -public abstract class Enum<E extends Enum<E>>
127.56 - implements Comparable<E>, Serializable {
127.57 - /**
127.58 - * The name of this enum constant, as declared in the enum declaration.
127.59 - * Most programmers should use the {@link #toString} method rather than
127.60 - * accessing this field.
127.61 - */
127.62 - private final String name;
127.63 -
127.64 - /**
127.65 - * Returns the name of this enum constant, exactly as declared in its
127.66 - * enum declaration.
127.67 - *
127.68 - * <b>Most programmers should use the {@link #toString} method in
127.69 - * preference to this one, as the toString method may return
127.70 - * a more user-friendly name.</b> This method is designed primarily for
127.71 - * use in specialized situations where correctness depends on getting the
127.72 - * exact name, which will not vary from release to release.
127.73 - *
127.74 - * @return the name of this enum constant
127.75 - */
127.76 - public final String name() {
127.77 - return name;
127.78 - }
127.79 -
127.80 - /**
127.81 - * The ordinal of this enumeration constant (its position
127.82 - * in the enum declaration, where the initial constant is assigned
127.83 - * an ordinal of zero).
127.84 - *
127.85 - * Most programmers will have no use for this field. It is designed
127.86 - * for use by sophisticated enum-based data structures, such as
127.87 - * {@link java.util.EnumSet} and {@link java.util.EnumMap}.
127.88 - */
127.89 - private final int ordinal;
127.90 -
127.91 - /**
127.92 - * Returns the ordinal of this enumeration constant (its position
127.93 - * in its enum declaration, where the initial constant is assigned
127.94 - * an ordinal of zero).
127.95 - *
127.96 - * Most programmers will have no use for this method. It is
127.97 - * designed for use by sophisticated enum-based data structures, such
127.98 - * as {@link java.util.EnumSet} and {@link java.util.EnumMap}.
127.99 - *
127.100 - * @return the ordinal of this enumeration constant
127.101 - */
127.102 - public final int ordinal() {
127.103 - return ordinal;
127.104 - }
127.105 -
127.106 - /**
127.107 - * Sole constructor. Programmers cannot invoke this constructor.
127.108 - * It is for use by code emitted by the compiler in response to
127.109 - * enum type declarations.
127.110 - *
127.111 - * @param name - The name of this enum constant, which is the identifier
127.112 - * used to declare it.
127.113 - * @param ordinal - The ordinal of this enumeration constant (its position
127.114 - * in the enum declaration, where the initial constant is assigned
127.115 - * an ordinal of zero).
127.116 - */
127.117 - protected Enum(String name, int ordinal) {
127.118 - this.name = name;
127.119 - this.ordinal = ordinal;
127.120 - }
127.121 -
127.122 - /**
127.123 - * Returns the name of this enum constant, as contained in the
127.124 - * declaration. This method may be overridden, though it typically
127.125 - * isn't necessary or desirable. An enum type should override this
127.126 - * method when a more "programmer-friendly" string form exists.
127.127 - *
127.128 - * @return the name of this enum constant
127.129 - */
127.130 - public String toString() {
127.131 - return name;
127.132 - }
127.133 -
127.134 - /**
127.135 - * Returns true if the specified object is equal to this
127.136 - * enum constant.
127.137 - *
127.138 - * @param other the object to be compared for equality with this object.
127.139 - * @return true if the specified object is equal to this
127.140 - * enum constant.
127.141 - */
127.142 - public final boolean equals(Object other) {
127.143 - return this==other;
127.144 - }
127.145 -
127.146 - /**
127.147 - * Returns a hash code for this enum constant.
127.148 - *
127.149 - * @return a hash code for this enum constant.
127.150 - */
127.151 - public final int hashCode() {
127.152 - return super.hashCode();
127.153 - }
127.154 -
127.155 - /**
127.156 - * Throws CloneNotSupportedException. This guarantees that enums
127.157 - * are never cloned, which is necessary to preserve their "singleton"
127.158 - * status.
127.159 - *
127.160 - * @return (never returns)
127.161 - */
127.162 - protected final Object clone() throws CloneNotSupportedException {
127.163 - throw new CloneNotSupportedException();
127.164 - }
127.165 -
127.166 - /**
127.167 - * Compares this enum with the specified object for order. Returns a
127.168 - * negative integer, zero, or a positive integer as this object is less
127.169 - * than, equal to, or greater than the specified object.
127.170 - *
127.171 - * Enum constants are only comparable to other enum constants of the
127.172 - * same enum type. The natural order implemented by this
127.173 - * method is the order in which the constants are declared.
127.174 - */
127.175 - public final int compareTo(E o) {
127.176 - Enum other = (Enum)o;
127.177 - Enum self = this;
127.178 - if (self.getClass() != other.getClass() && // optimization
127.179 - self.getDeclaringClass() != other.getDeclaringClass())
127.180 - throw new ClassCastException();
127.181 - return self.ordinal - other.ordinal;
127.182 - }
127.183 -
127.184 - /**
127.185 - * Returns the Class object corresponding to this enum constant's
127.186 - * enum type. Two enum constants e1 and e2 are of the
127.187 - * same enum type if and only if
127.188 - * e1.getDeclaringClass() == e2.getDeclaringClass().
127.189 - * (The value returned by this method may differ from the one returned
127.190 - * by the {@link Object#getClass} method for enum constants with
127.191 - * constant-specific class bodies.)
127.192 - *
127.193 - * @return the Class object corresponding to this enum constant's
127.194 - * enum type
127.195 - */
127.196 - public final Class<E> getDeclaringClass() {
127.197 - Class clazz = getClass();
127.198 - Class zuper = clazz.getSuperclass();
127.199 - return (zuper == Enum.class) ? clazz : zuper;
127.200 - }
127.201 -
127.202 - /**
127.203 - * Returns the enum constant of the specified enum type with the
127.204 - * specified name. The name must match exactly an identifier used
127.205 - * to declare an enum constant in this type. (Extraneous whitespace
127.206 - * characters are not permitted.)
127.207 - *
127.208 - * <p>Note that for a particular enum type {@code T}, the
127.209 - * implicitly declared {@code public static T valueOf(String)}
127.210 - * method on that enum may be used instead of this method to map
127.211 - * from a name to the corresponding enum constant. All the
127.212 - * constants of an enum type can be obtained by calling the
127.213 - * implicit {@code public static T[] values()} method of that
127.214 - * type.
127.215 - *
127.216 - * @param <T> The enum type whose constant is to be returned
127.217 - * @param enumType the {@code Class} object of the enum type from which
127.218 - * to return a constant
127.219 - * @param name the name of the constant to return
127.220 - * @return the enum constant of the specified enum type with the
127.221 - * specified name
127.222 - * @throws IllegalArgumentException if the specified enum type has
127.223 - * no constant with the specified name, or the specified
127.224 - * class object does not represent an enum type
127.225 - * @throws NullPointerException if {@code enumType} or {@code name}
127.226 - * is null
127.227 - * @since 1.5
127.228 - */
127.229 - public static <T extends Enum<T>> T valueOf(Class<T> enumType,
127.230 - String name) {
127.231 - throw new UnsupportedOperationException();
127.232 -// T result = enumType.enumConstantDirectory().get(name);
127.233 -// if (result != null)
127.234 -// return result;
127.235 -// if (name == null)
127.236 -// throw new NullPointerException("Name is null");
127.237 -// throw new IllegalArgumentException(
127.238 -// "No enum constant " + enumType.getCanonicalName() + "." + name);
127.239 - }
127.240 -
127.241 - /**
127.242 - * enum classes cannot have finalize methods.
127.243 - */
127.244 - protected final void finalize() { }
127.245 -
127.246 - /**
127.247 - * prevent default deserialization
127.248 - */
127.249 -// private void readObject(ObjectInputStream in) throws IOException,
127.250 -// ClassNotFoundException {
127.251 -// throw new InvalidObjectException("can't deserialize enum");
127.252 -// }
127.253 -//
127.254 -// private void readObjectNoData() throws ObjectStreamException {
127.255 -// throw new InvalidObjectException("can't deserialize enum");
127.256 -// }
127.257 -}
128.1 --- a/emul/src/main/java/java/lang/Error.java Wed Jan 23 20:16:48 2013 +0100
128.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
128.3 @@ -1,128 +0,0 @@
128.4 -/*
128.5 - * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
128.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
128.7 - *
128.8 - * This code is free software; you can redistribute it and/or modify it
128.9 - * under the terms of the GNU General Public License version 2 only, as
128.10 - * published by the Free Software Foundation. Oracle designates this
128.11 - * particular file as subject to the "Classpath" exception as provided
128.12 - * by Oracle in the LICENSE file that accompanied this code.
128.13 - *
128.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
128.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
128.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
128.17 - * version 2 for more details (a copy is included in the LICENSE file that
128.18 - * accompanied this code).
128.19 - *
128.20 - * You should have received a copy of the GNU General Public License version
128.21 - * 2 along with this work; if not, write to the Free Software Foundation,
128.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
128.23 - *
128.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
128.25 - * or visit www.oracle.com if you need additional information or have any
128.26 - * questions.
128.27 - */
128.28 -
128.29 -package java.lang;
128.30 -
128.31 -/**
128.32 - * An {@code Error} is a subclass of {@code Throwable}
128.33 - * that indicates serious problems that a reasonable application
128.34 - * should not try to catch. Most such errors are abnormal conditions.
128.35 - * The {@code ThreadDeath} error, though a "normal" condition,
128.36 - * is also a subclass of {@code Error} because most applications
128.37 - * should not try to catch it.
128.38 - * <p>
128.39 - * A method is not required to declare in its {@code throws}
128.40 - * clause any subclasses of {@code Error} that might be thrown
128.41 - * during the execution of the method but not caught, since these
128.42 - * errors are abnormal conditions that should never occur.
128.43 - *
128.44 - * That is, {@code Error} and its subclasses are regarded as unchecked
128.45 - * exceptions for the purposes of compile-time checking of exceptions.
128.46 - *
128.47 - * @author Frank Yellin
128.48 - * @see java.lang.ThreadDeath
128.49 - * @jls 11.2 Compile-Time Checking of Exceptions
128.50 - * @since JDK1.0
128.51 - */
128.52 -public class Error extends Throwable {
128.53 - static final long serialVersionUID = 4980196508277280342L;
128.54 -
128.55 - /**
128.56 - * Constructs a new error with {@code null} as its detail message.
128.57 - * The cause is not initialized, and may subsequently be initialized by a
128.58 - * call to {@link #initCause}.
128.59 - */
128.60 - public Error() {
128.61 - super();
128.62 - }
128.63 -
128.64 - /**
128.65 - * Constructs a new error with the specified detail message. The
128.66 - * cause is not initialized, and may subsequently be initialized by
128.67 - * a call to {@link #initCause}.
128.68 - *
128.69 - * @param message the detail message. The detail message is saved for
128.70 - * later retrieval by the {@link #getMessage()} method.
128.71 - */
128.72 - public Error(String message) {
128.73 - super(message);
128.74 - }
128.75 -
128.76 - /**
128.77 - * Constructs a new error with the specified detail message and
128.78 - * cause. <p>Note that the detail message associated with
128.79 - * {@code cause} is <i>not</i> automatically incorporated in
128.80 - * this error's detail message.
128.81 - *
128.82 - * @param message the detail message (which is saved for later retrieval
128.83 - * by the {@link #getMessage()} method).
128.84 - * @param cause the cause (which is saved for later retrieval by the
128.85 - * {@link #getCause()} method). (A {@code null} value is
128.86 - * permitted, and indicates that the cause is nonexistent or
128.87 - * unknown.)
128.88 - * @since 1.4
128.89 - */
128.90 - public Error(String message, Throwable cause) {
128.91 - super(message, cause);
128.92 - }
128.93 -
128.94 - /**
128.95 - * Constructs a new error with the specified cause and a detail
128.96 - * message of {@code (cause==null ? null : cause.toString())} (which
128.97 - * typically contains the class and detail message of {@code cause}).
128.98 - * This constructor is useful for errors that are little more than
128.99 - * wrappers for other throwables.
128.100 - *
128.101 - * @param cause the cause (which is saved for later retrieval by the
128.102 - * {@link #getCause()} method). (A {@code null} value is
128.103 - * permitted, and indicates that the cause is nonexistent or
128.104 - * unknown.)
128.105 - * @since 1.4
128.106 - */
128.107 - public Error(Throwable cause) {
128.108 - super(cause);
128.109 - }
128.110 -
128.111 - /**
128.112 - * Constructs a new error with the specified detail message,
128.113 - * cause, suppression enabled or disabled, and writable stack
128.114 - * trace enabled or disabled.
128.115 - *
128.116 - * @param message the detail message.
128.117 - * @param cause the cause. (A {@code null} value is permitted,
128.118 - * and indicates that the cause is nonexistent or unknown.)
128.119 - * @param enableSuppression whether or not suppression is enabled
128.120 - * or disabled
128.121 - * @param writableStackTrace whether or not the stack trace should
128.122 - * be writable
128.123 - *
128.124 - * @since 1.7
128.125 - */
128.126 - protected Error(String message, Throwable cause,
128.127 - boolean enableSuppression,
128.128 - boolean writableStackTrace) {
128.129 - super(message, cause, enableSuppression, writableStackTrace);
128.130 - }
128.131 -}
129.1 --- a/emul/src/main/java/java/lang/Exception.java Wed Jan 23 20:16:48 2013 +0100
129.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
129.3 @@ -1,124 +0,0 @@
129.4 -/*
129.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
129.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
129.7 - *
129.8 - * This code is free software; you can redistribute it and/or modify it
129.9 - * under the terms of the GNU General Public License version 2 only, as
129.10 - * published by the Free Software Foundation. Oracle designates this
129.11 - * particular file as subject to the "Classpath" exception as provided
129.12 - * by Oracle in the LICENSE file that accompanied this code.
129.13 - *
129.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
129.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
129.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
129.17 - * version 2 for more details (a copy is included in the LICENSE file that
129.18 - * accompanied this code).
129.19 - *
129.20 - * You should have received a copy of the GNU General Public License version
129.21 - * 2 along with this work; if not, write to the Free Software Foundation,
129.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
129.23 - *
129.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
129.25 - * or visit www.oracle.com if you need additional information or have any
129.26 - * questions.
129.27 - */
129.28 -
129.29 -package java.lang;
129.30 -
129.31 -/**
129.32 - * The class {@code Exception} and its subclasses are a form of
129.33 - * {@code Throwable} that indicates conditions that a reasonable
129.34 - * application might want to catch.
129.35 - *
129.36 - * <p>The class {@code Exception} and any subclasses that are not also
129.37 - * subclasses of {@link RuntimeException} are <em>checked
129.38 - * exceptions</em>. Checked exceptions need to be declared in a
129.39 - * method or constructor's {@code throws} clause if they can be thrown
129.40 - * by the execution of the method or constructor and propagate outside
129.41 - * the method or constructor boundary.
129.42 - *
129.43 - * @author Frank Yellin
129.44 - * @see java.lang.Error
129.45 - * @jls 11.2 Compile-Time Checking of Exceptions
129.46 - * @since JDK1.0
129.47 - */
129.48 -public class Exception extends Throwable {
129.49 - static final long serialVersionUID = -3387516993124229948L;
129.50 -
129.51 - /**
129.52 - * Constructs a new exception with {@code null} as its detail message.
129.53 - * The cause is not initialized, and may subsequently be initialized by a
129.54 - * call to {@link #initCause}.
129.55 - */
129.56 - public Exception() {
129.57 - super();
129.58 - }
129.59 -
129.60 - /**
129.61 - * Constructs a new exception with the specified detail message. The
129.62 - * cause is not initialized, and may subsequently be initialized by
129.63 - * a call to {@link #initCause}.
129.64 - *
129.65 - * @param message the detail message. The detail message is saved for
129.66 - * later retrieval by the {@link #getMessage()} method.
129.67 - */
129.68 - public Exception(String message) {
129.69 - super(message);
129.70 - }
129.71 -
129.72 - /**
129.73 - * Constructs a new exception with the specified detail message and
129.74 - * cause. <p>Note that the detail message associated with
129.75 - * {@code cause} is <i>not</i> automatically incorporated in
129.76 - * this exception's detail message.
129.77 - *
129.78 - * @param message the detail message (which is saved for later retrieval
129.79 - * by the {@link #getMessage()} method).
129.80 - * @param cause the cause (which is saved for later retrieval by the
129.81 - * {@link #getCause()} method). (A <tt>null</tt> value is
129.82 - * permitted, and indicates that the cause is nonexistent or
129.83 - * unknown.)
129.84 - * @since 1.4
129.85 - */
129.86 - public Exception(String message, Throwable cause) {
129.87 - super(message, cause);
129.88 - }
129.89 -
129.90 - /**
129.91 - * Constructs a new exception with the specified cause and a detail
129.92 - * message of <tt>(cause==null ? null : cause.toString())</tt> (which
129.93 - * typically contains the class and detail message of <tt>cause</tt>).
129.94 - * This constructor is useful for exceptions that are little more than
129.95 - * wrappers for other throwables (for example, {@link
129.96 - * java.security.PrivilegedActionException}).
129.97 - *
129.98 - * @param cause the cause (which is saved for later retrieval by the
129.99 - * {@link #getCause()} method). (A <tt>null</tt> value is
129.100 - * permitted, and indicates that the cause is nonexistent or
129.101 - * unknown.)
129.102 - * @since 1.4
129.103 - */
129.104 - public Exception(Throwable cause) {
129.105 - super(cause);
129.106 - }
129.107 -
129.108 - /**
129.109 - * Constructs a new exception with the specified detail message,
129.110 - * cause, suppression enabled or disabled, and writable stack
129.111 - * trace enabled or disabled.
129.112 - *
129.113 - * @param message the detail message.
129.114 - * @param cause the cause. (A {@code null} value is permitted,
129.115 - * and indicates that the cause is nonexistent or unknown.)
129.116 - * @param enableSuppression whether or not suppression is enabled
129.117 - * or disabled
129.118 - * @param writableStackTrace whether or not the stack trace should
129.119 - * be writable
129.120 - * @since 1.7
129.121 - */
129.122 - protected Exception(String message, Throwable cause,
129.123 - boolean enableSuppression,
129.124 - boolean writableStackTrace) {
129.125 - super(message, cause, enableSuppression, writableStackTrace);
129.126 - }
129.127 -}
130.1 --- a/emul/src/main/java/java/lang/Float.java Wed Jan 23 20:16:48 2013 +0100
130.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
130.3 @@ -1,905 +0,0 @@
130.4 -/*
130.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
130.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
130.7 - *
130.8 - * This code is free software; you can redistribute it and/or modify it
130.9 - * under the terms of the GNU General Public License version 2 only, as
130.10 - * published by the Free Software Foundation. Oracle designates this
130.11 - * particular file as subject to the "Classpath" exception as provided
130.12 - * by Oracle in the LICENSE file that accompanied this code.
130.13 - *
130.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
130.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
130.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
130.17 - * version 2 for more details (a copy is included in the LICENSE file that
130.18 - * accompanied this code).
130.19 - *
130.20 - * You should have received a copy of the GNU General Public License version
130.21 - * 2 along with this work; if not, write to the Free Software Foundation,
130.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
130.23 - *
130.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
130.25 - * or visit www.oracle.com if you need additional information or have any
130.26 - * questions.
130.27 - */
130.28 -
130.29 -package java.lang;
130.30 -
130.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
130.32 -
130.33 -/**
130.34 - * The {@code Float} class wraps a value of primitive type
130.35 - * {@code float} in an object. An object of type
130.36 - * {@code Float} contains a single field whose type is
130.37 - * {@code float}.
130.38 - *
130.39 - * <p>In addition, this class provides several methods for converting a
130.40 - * {@code float} to a {@code String} and a
130.41 - * {@code String} to a {@code float}, as well as other
130.42 - * constants and methods useful when dealing with a
130.43 - * {@code float}.
130.44 - *
130.45 - * @author Lee Boynton
130.46 - * @author Arthur van Hoff
130.47 - * @author Joseph D. Darcy
130.48 - * @since JDK1.0
130.49 - */
130.50 -public final class Float extends Number implements Comparable<Float> {
130.51 - /**
130.52 - * A constant holding the positive infinity of type
130.53 - * {@code float}. It is equal to the value returned by
130.54 - * {@code Float.intBitsToFloat(0x7f800000)}.
130.55 - */
130.56 - public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
130.57 -
130.58 - /**
130.59 - * A constant holding the negative infinity of type
130.60 - * {@code float}. It is equal to the value returned by
130.61 - * {@code Float.intBitsToFloat(0xff800000)}.
130.62 - */
130.63 - public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
130.64 -
130.65 - /**
130.66 - * A constant holding a Not-a-Number (NaN) value of type
130.67 - * {@code float}. It is equivalent to the value returned by
130.68 - * {@code Float.intBitsToFloat(0x7fc00000)}.
130.69 - */
130.70 - public static final float NaN = 0.0f / 0.0f;
130.71 -
130.72 - /**
130.73 - * A constant holding the largest positive finite value of type
130.74 - * {@code float}, (2-2<sup>-23</sup>)·2<sup>127</sup>.
130.75 - * It is equal to the hexadecimal floating-point literal
130.76 - * {@code 0x1.fffffeP+127f} and also equal to
130.77 - * {@code Float.intBitsToFloat(0x7f7fffff)}.
130.78 - */
130.79 - public static final float MAX_VALUE = 0x1.fffffeP+127f; // 3.4028235e+38f
130.80 -
130.81 - /**
130.82 - * A constant holding the smallest positive normal value of type
130.83 - * {@code float}, 2<sup>-126</sup>. It is equal to the
130.84 - * hexadecimal floating-point literal {@code 0x1.0p-126f} and also
130.85 - * equal to {@code Float.intBitsToFloat(0x00800000)}.
130.86 - *
130.87 - * @since 1.6
130.88 - */
130.89 - public static final float MIN_NORMAL = 0x1.0p-126f; // 1.17549435E-38f
130.90 -
130.91 - /**
130.92 - * A constant holding the smallest positive nonzero value of type
130.93 - * {@code float}, 2<sup>-149</sup>. It is equal to the
130.94 - * hexadecimal floating-point literal {@code 0x0.000002P-126f}
130.95 - * and also equal to {@code Float.intBitsToFloat(0x1)}.
130.96 - */
130.97 - public static final float MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f
130.98 -
130.99 - /**
130.100 - * Maximum exponent a finite {@code float} variable may have. It
130.101 - * is equal to the value returned by {@code
130.102 - * Math.getExponent(Float.MAX_VALUE)}.
130.103 - *
130.104 - * @since 1.6
130.105 - */
130.106 - public static final int MAX_EXPONENT = 127;
130.107 -
130.108 - /**
130.109 - * Minimum exponent a normalized {@code float} variable may have.
130.110 - * It is equal to the value returned by {@code
130.111 - * Math.getExponent(Float.MIN_NORMAL)}.
130.112 - *
130.113 - * @since 1.6
130.114 - */
130.115 - public static final int MIN_EXPONENT = -126;
130.116 -
130.117 - /**
130.118 - * The number of bits used to represent a {@code float} value.
130.119 - *
130.120 - * @since 1.5
130.121 - */
130.122 - public static final int SIZE = 32;
130.123 -
130.124 - /**
130.125 - * The {@code Class} instance representing the primitive type
130.126 - * {@code float}.
130.127 - *
130.128 - * @since JDK1.1
130.129 - */
130.130 - public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
130.131 -
130.132 - /**
130.133 - * Returns a string representation of the {@code float}
130.134 - * argument. All characters mentioned below are ASCII characters.
130.135 - * <ul>
130.136 - * <li>If the argument is NaN, the result is the string
130.137 - * "{@code NaN}".
130.138 - * <li>Otherwise, the result is a string that represents the sign and
130.139 - * magnitude (absolute value) of the argument. If the sign is
130.140 - * negative, the first character of the result is
130.141 - * '{@code -}' (<code>'\u002D'</code>); if the sign is
130.142 - * positive, no sign character appears in the result. As for
130.143 - * the magnitude <i>m</i>:
130.144 - * <ul>
130.145 - * <li>If <i>m</i> is infinity, it is represented by the characters
130.146 - * {@code "Infinity"}; thus, positive infinity produces
130.147 - * the result {@code "Infinity"} and negative infinity
130.148 - * produces the result {@code "-Infinity"}.
130.149 - * <li>If <i>m</i> is zero, it is represented by the characters
130.150 - * {@code "0.0"}; thus, negative zero produces the result
130.151 - * {@code "-0.0"} and positive zero produces the result
130.152 - * {@code "0.0"}.
130.153 - * <li> If <i>m</i> is greater than or equal to 10<sup>-3</sup> but
130.154 - * less than 10<sup>7</sup>, then it is represented as the
130.155 - * integer part of <i>m</i>, in decimal form with no leading
130.156 - * zeroes, followed by '{@code .}'
130.157 - * (<code>'\u002E'</code>), followed by one or more
130.158 - * decimal digits representing the fractional part of
130.159 - * <i>m</i>.
130.160 - * <li> If <i>m</i> is less than 10<sup>-3</sup> or greater than or
130.161 - * equal to 10<sup>7</sup>, then it is represented in
130.162 - * so-called "computerized scientific notation." Let <i>n</i>
130.163 - * be the unique integer such that 10<sup><i>n</i> </sup>≤
130.164 - * <i>m</i> {@literal <} 10<sup><i>n</i>+1</sup>; then let <i>a</i>
130.165 - * be the mathematically exact quotient of <i>m</i> and
130.166 - * 10<sup><i>n</i></sup> so that 1 ≤ <i>a</i> {@literal <} 10.
130.167 - * The magnitude is then represented as the integer part of
130.168 - * <i>a</i>, as a single decimal digit, followed by
130.169 - * '{@code .}' (<code>'\u002E'</code>), followed by
130.170 - * decimal digits representing the fractional part of
130.171 - * <i>a</i>, followed by the letter '{@code E}'
130.172 - * (<code>'\u0045'</code>), followed by a representation
130.173 - * of <i>n</i> as a decimal integer, as produced by the
130.174 - * method {@link java.lang.Integer#toString(int)}.
130.175 - *
130.176 - * </ul>
130.177 - * </ul>
130.178 - * How many digits must be printed for the fractional part of
130.179 - * <i>m</i> or <i>a</i>? There must be at least one digit
130.180 - * to represent the fractional part, and beyond that as many, but
130.181 - * only as many, more digits as are needed to uniquely distinguish
130.182 - * the argument value from adjacent values of type
130.183 - * {@code float}. That is, suppose that <i>x</i> is the
130.184 - * exact mathematical value represented by the decimal
130.185 - * representation produced by this method for a finite nonzero
130.186 - * argument <i>f</i>. Then <i>f</i> must be the {@code float}
130.187 - * value nearest to <i>x</i>; or, if two {@code float} values are
130.188 - * equally close to <i>x</i>, then <i>f</i> must be one of
130.189 - * them and the least significant bit of the significand of
130.190 - * <i>f</i> must be {@code 0}.
130.191 - *
130.192 - * <p>To create localized string representations of a floating-point
130.193 - * value, use subclasses of {@link java.text.NumberFormat}.
130.194 - *
130.195 - * @param f the float to be converted.
130.196 - * @return a string representation of the argument.
130.197 - */
130.198 - public static String toString(float f) {
130.199 - return Double.toString(f);
130.200 - }
130.201 -
130.202 - /**
130.203 - * Returns a hexadecimal string representation of the
130.204 - * {@code float} argument. All characters mentioned below are
130.205 - * ASCII characters.
130.206 - *
130.207 - * <ul>
130.208 - * <li>If the argument is NaN, the result is the string
130.209 - * "{@code NaN}".
130.210 - * <li>Otherwise, the result is a string that represents the sign and
130.211 - * magnitude (absolute value) of the argument. If the sign is negative,
130.212 - * the first character of the result is '{@code -}'
130.213 - * (<code>'\u002D'</code>); if the sign is positive, no sign character
130.214 - * appears in the result. As for the magnitude <i>m</i>:
130.215 - *
130.216 - * <ul>
130.217 - * <li>If <i>m</i> is infinity, it is represented by the string
130.218 - * {@code "Infinity"}; thus, positive infinity produces the
130.219 - * result {@code "Infinity"} and negative infinity produces
130.220 - * the result {@code "-Infinity"}.
130.221 - *
130.222 - * <li>If <i>m</i> is zero, it is represented by the string
130.223 - * {@code "0x0.0p0"}; thus, negative zero produces the result
130.224 - * {@code "-0x0.0p0"} and positive zero produces the result
130.225 - * {@code "0x0.0p0"}.
130.226 - *
130.227 - * <li>If <i>m</i> is a {@code float} value with a
130.228 - * normalized representation, substrings are used to represent the
130.229 - * significand and exponent fields. The significand is
130.230 - * represented by the characters {@code "0x1."}
130.231 - * followed by a lowercase hexadecimal representation of the rest
130.232 - * of the significand as a fraction. Trailing zeros in the
130.233 - * hexadecimal representation are removed unless all the digits
130.234 - * are zero, in which case a single zero is used. Next, the
130.235 - * exponent is represented by {@code "p"} followed
130.236 - * by a decimal string of the unbiased exponent as if produced by
130.237 - * a call to {@link Integer#toString(int) Integer.toString} on the
130.238 - * exponent value.
130.239 - *
130.240 - * <li>If <i>m</i> is a {@code float} value with a subnormal
130.241 - * representation, the significand is represented by the
130.242 - * characters {@code "0x0."} followed by a
130.243 - * hexadecimal representation of the rest of the significand as a
130.244 - * fraction. Trailing zeros in the hexadecimal representation are
130.245 - * removed. Next, the exponent is represented by
130.246 - * {@code "p-126"}. Note that there must be at
130.247 - * least one nonzero digit in a subnormal significand.
130.248 - *
130.249 - * </ul>
130.250 - *
130.251 - * </ul>
130.252 - *
130.253 - * <table border>
130.254 - * <caption><h3>Examples</h3></caption>
130.255 - * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
130.256 - * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
130.257 - * <tr><td>{@code -1.0}</td> <td>{@code -0x1.0p0}</td>
130.258 - * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
130.259 - * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
130.260 - * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
130.261 - * <tr><td>{@code 0.25}</td> <td>{@code 0x1.0p-2}</td>
130.262 - * <tr><td>{@code Float.MAX_VALUE}</td>
130.263 - * <td>{@code 0x1.fffffep127}</td>
130.264 - * <tr><td>{@code Minimum Normal Value}</td>
130.265 - * <td>{@code 0x1.0p-126}</td>
130.266 - * <tr><td>{@code Maximum Subnormal Value}</td>
130.267 - * <td>{@code 0x0.fffffep-126}</td>
130.268 - * <tr><td>{@code Float.MIN_VALUE}</td>
130.269 - * <td>{@code 0x0.000002p-126}</td>
130.270 - * </table>
130.271 - * @param f the {@code float} to be converted.
130.272 - * @return a hex string representation of the argument.
130.273 - * @since 1.5
130.274 - * @author Joseph D. Darcy
130.275 - */
130.276 - public static String toHexString(float f) {
130.277 - throw new UnsupportedOperationException();
130.278 -// if (Math.abs(f) < FloatConsts.MIN_NORMAL
130.279 -// && f != 0.0f ) {// float subnormal
130.280 -// // Adjust exponent to create subnormal double, then
130.281 -// // replace subnormal double exponent with subnormal float
130.282 -// // exponent
130.283 -// String s = Double.toHexString(FpUtils.scalb((double)f,
130.284 -// /* -1022+126 */
130.285 -// DoubleConsts.MIN_EXPONENT-
130.286 -// FloatConsts.MIN_EXPONENT));
130.287 -// return s.replaceFirst("p-1022$", "p-126");
130.288 -// }
130.289 -// else // double string will be the same as float string
130.290 -// return Double.toHexString(f);
130.291 - }
130.292 -
130.293 - /**
130.294 - * Returns a {@code Float} object holding the
130.295 - * {@code float} value represented by the argument string
130.296 - * {@code s}.
130.297 - *
130.298 - * <p>If {@code s} is {@code null}, then a
130.299 - * {@code NullPointerException} is thrown.
130.300 - *
130.301 - * <p>Leading and trailing whitespace characters in {@code s}
130.302 - * are ignored. Whitespace is removed as if by the {@link
130.303 - * String#trim} method; that is, both ASCII space and control
130.304 - * characters are removed. The rest of {@code s} should
130.305 - * constitute a <i>FloatValue</i> as described by the lexical
130.306 - * syntax rules:
130.307 - *
130.308 - * <blockquote>
130.309 - * <dl>
130.310 - * <dt><i>FloatValue:</i>
130.311 - * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
130.312 - * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
130.313 - * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
130.314 - * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
130.315 - * <dd><i>SignedInteger</i>
130.316 - * </dl>
130.317 - *
130.318 - * <p>
130.319 - *
130.320 - * <dl>
130.321 - * <dt><i>HexFloatingPointLiteral</i>:
130.322 - * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
130.323 - * </dl>
130.324 - *
130.325 - * <p>
130.326 - *
130.327 - * <dl>
130.328 - * <dt><i>HexSignificand:</i>
130.329 - * <dd><i>HexNumeral</i>
130.330 - * <dd><i>HexNumeral</i> {@code .}
130.331 - * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
130.332 - * </i>{@code .}<i> HexDigits</i>
130.333 - * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
130.334 - * </i>{@code .} <i>HexDigits</i>
130.335 - * </dl>
130.336 - *
130.337 - * <p>
130.338 - *
130.339 - * <dl>
130.340 - * <dt><i>BinaryExponent:</i>
130.341 - * <dd><i>BinaryExponentIndicator SignedInteger</i>
130.342 - * </dl>
130.343 - *
130.344 - * <p>
130.345 - *
130.346 - * <dl>
130.347 - * <dt><i>BinaryExponentIndicator:</i>
130.348 - * <dd>{@code p}
130.349 - * <dd>{@code P}
130.350 - * </dl>
130.351 - *
130.352 - * </blockquote>
130.353 - *
130.354 - * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
130.355 - * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
130.356 - * <i>FloatTypeSuffix</i> are as defined in the lexical structure
130.357 - * sections of
130.358 - * <cite>The Java™ Language Specification</cite>,
130.359 - * except that underscores are not accepted between digits.
130.360 - * If {@code s} does not have the form of
130.361 - * a <i>FloatValue</i>, then a {@code NumberFormatException}
130.362 - * is thrown. Otherwise, {@code s} is regarded as
130.363 - * representing an exact decimal value in the usual
130.364 - * "computerized scientific notation" or as an exact
130.365 - * hexadecimal value; this exact numerical value is then
130.366 - * conceptually converted to an "infinitely precise"
130.367 - * binary value that is then rounded to type {@code float}
130.368 - * by the usual round-to-nearest rule of IEEE 754 floating-point
130.369 - * arithmetic, which includes preserving the sign of a zero
130.370 - * value.
130.371 - *
130.372 - * Note that the round-to-nearest rule also implies overflow and
130.373 - * underflow behaviour; if the exact value of {@code s} is large
130.374 - * enough in magnitude (greater than or equal to ({@link
130.375 - * #MAX_VALUE} + {@link Math#ulp(float) ulp(MAX_VALUE)}/2),
130.376 - * rounding to {@code float} will result in an infinity and if the
130.377 - * exact value of {@code s} is small enough in magnitude (less
130.378 - * than or equal to {@link #MIN_VALUE}/2), rounding to float will
130.379 - * result in a zero.
130.380 - *
130.381 - * Finally, after rounding a {@code Float} object representing
130.382 - * this {@code float} value is returned.
130.383 - *
130.384 - * <p>To interpret localized string representations of a
130.385 - * floating-point value, use subclasses of {@link
130.386 - * java.text.NumberFormat}.
130.387 - *
130.388 - * <p>Note that trailing format specifiers, specifiers that
130.389 - * determine the type of a floating-point literal
130.390 - * ({@code 1.0f} is a {@code float} value;
130.391 - * {@code 1.0d} is a {@code double} value), do
130.392 - * <em>not</em> influence the results of this method. In other
130.393 - * words, the numerical value of the input string is converted
130.394 - * directly to the target floating-point type. In general, the
130.395 - * two-step sequence of conversions, string to {@code double}
130.396 - * followed by {@code double} to {@code float}, is
130.397 - * <em>not</em> equivalent to converting a string directly to
130.398 - * {@code float}. For example, if first converted to an
130.399 - * intermediate {@code double} and then to
130.400 - * {@code float}, the string<br>
130.401 - * {@code "1.00000017881393421514957253748434595763683319091796875001d"}<br>
130.402 - * results in the {@code float} value
130.403 - * {@code 1.0000002f}; if the string is converted directly to
130.404 - * {@code float}, <code>1.000000<b>1</b>f</code> results.
130.405 - *
130.406 - * <p>To avoid calling this method on an invalid string and having
130.407 - * a {@code NumberFormatException} be thrown, the documentation
130.408 - * for {@link Double#valueOf Double.valueOf} lists a regular
130.409 - * expression which can be used to screen the input.
130.410 - *
130.411 - * @param s the string to be parsed.
130.412 - * @return a {@code Float} object holding the value
130.413 - * represented by the {@code String} argument.
130.414 - * @throws NumberFormatException if the string does not contain a
130.415 - * parsable number.
130.416 - */
130.417 - public static Float valueOf(String s) throws NumberFormatException {
130.418 - throw new UnsupportedOperationException();
130.419 -// return new Float(FloatingDecimal.readJavaFormatString(s).floatValue());
130.420 - }
130.421 -
130.422 - /**
130.423 - * Returns a {@code Float} instance representing the specified
130.424 - * {@code float} value.
130.425 - * If a new {@code Float} instance is not required, this method
130.426 - * should generally be used in preference to the constructor
130.427 - * {@link #Float(float)}, as this method is likely to yield
130.428 - * significantly better space and time performance by caching
130.429 - * frequently requested values.
130.430 - *
130.431 - * @param f a float value.
130.432 - * @return a {@code Float} instance representing {@code f}.
130.433 - * @since 1.5
130.434 - */
130.435 - public static Float valueOf(float f) {
130.436 - return new Float(f);
130.437 - }
130.438 -
130.439 - /**
130.440 - * Returns a new {@code float} initialized to the value
130.441 - * represented by the specified {@code String}, as performed
130.442 - * by the {@code valueOf} method of class {@code Float}.
130.443 - *
130.444 - * @param s the string to be parsed.
130.445 - * @return the {@code float} value represented by the string
130.446 - * argument.
130.447 - * @throws NullPointerException if the string is null
130.448 - * @throws NumberFormatException if the string does not contain a
130.449 - * parsable {@code float}.
130.450 - * @see java.lang.Float#valueOf(String)
130.451 - * @since 1.2
130.452 - */
130.453 - public static float parseFloat(String s) throws NumberFormatException {
130.454 - throw new UnsupportedOperationException();
130.455 -// return FloatingDecimal.readJavaFormatString(s).floatValue();
130.456 - }
130.457 -
130.458 - /**
130.459 - * Returns {@code true} if the specified number is a
130.460 - * Not-a-Number (NaN) value, {@code false} otherwise.
130.461 - *
130.462 - * @param v the value to be tested.
130.463 - * @return {@code true} if the argument is NaN;
130.464 - * {@code false} otherwise.
130.465 - */
130.466 - static public boolean isNaN(float v) {
130.467 - return (v != v);
130.468 - }
130.469 -
130.470 - /**
130.471 - * Returns {@code true} if the specified number is infinitely
130.472 - * large in magnitude, {@code false} otherwise.
130.473 - *
130.474 - * @param v the value to be tested.
130.475 - * @return {@code true} if the argument is positive infinity or
130.476 - * negative infinity; {@code false} otherwise.
130.477 - */
130.478 - static public boolean isInfinite(float v) {
130.479 - return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
130.480 - }
130.481 -
130.482 - /**
130.483 - * The value of the Float.
130.484 - *
130.485 - * @serial
130.486 - */
130.487 - private final float value;
130.488 -
130.489 - /**
130.490 - * Constructs a newly allocated {@code Float} object that
130.491 - * represents the primitive {@code float} argument.
130.492 - *
130.493 - * @param value the value to be represented by the {@code Float}.
130.494 - */
130.495 - public Float(float value) {
130.496 - this.value = value;
130.497 - }
130.498 -
130.499 - /**
130.500 - * Constructs a newly allocated {@code Float} object that
130.501 - * represents the argument converted to type {@code float}.
130.502 - *
130.503 - * @param value the value to be represented by the {@code Float}.
130.504 - */
130.505 - public Float(double value) {
130.506 - this.value = (float)value;
130.507 - }
130.508 -
130.509 - /**
130.510 - * Constructs a newly allocated {@code Float} object that
130.511 - * represents the floating-point value of type {@code float}
130.512 - * represented by the string. The string is converted to a
130.513 - * {@code float} value as if by the {@code valueOf} method.
130.514 - *
130.515 - * @param s a string to be converted to a {@code Float}.
130.516 - * @throws NumberFormatException if the string does not contain a
130.517 - * parsable number.
130.518 - * @see java.lang.Float#valueOf(java.lang.String)
130.519 - */
130.520 - public Float(String s) throws NumberFormatException {
130.521 - // REMIND: this is inefficient
130.522 - this(valueOf(s).floatValue());
130.523 - }
130.524 -
130.525 - /**
130.526 - * Returns {@code true} if this {@code Float} value is a
130.527 - * Not-a-Number (NaN), {@code false} otherwise.
130.528 - *
130.529 - * @return {@code true} if the value represented by this object is
130.530 - * NaN; {@code false} otherwise.
130.531 - */
130.532 - public boolean isNaN() {
130.533 - return isNaN(value);
130.534 - }
130.535 -
130.536 - /**
130.537 - * Returns {@code true} if this {@code Float} value is
130.538 - * infinitely large in magnitude, {@code false} otherwise.
130.539 - *
130.540 - * @return {@code true} if the value represented by this object is
130.541 - * positive infinity or negative infinity;
130.542 - * {@code false} otherwise.
130.543 - */
130.544 - public boolean isInfinite() {
130.545 - return isInfinite(value);
130.546 - }
130.547 -
130.548 - /**
130.549 - * Returns a string representation of this {@code Float} object.
130.550 - * The primitive {@code float} value represented by this object
130.551 - * is converted to a {@code String} exactly as if by the method
130.552 - * {@code toString} of one argument.
130.553 - *
130.554 - * @return a {@code String} representation of this object.
130.555 - * @see java.lang.Float#toString(float)
130.556 - */
130.557 - public String toString() {
130.558 - return Float.toString(value);
130.559 - }
130.560 -
130.561 - /**
130.562 - * Returns the value of this {@code Float} as a {@code byte} (by
130.563 - * casting to a {@code byte}).
130.564 - *
130.565 - * @return the {@code float} value represented by this object
130.566 - * converted to type {@code byte}
130.567 - */
130.568 - public byte byteValue() {
130.569 - return (byte)value;
130.570 - }
130.571 -
130.572 - /**
130.573 - * Returns the value of this {@code Float} as a {@code short} (by
130.574 - * casting to a {@code short}).
130.575 - *
130.576 - * @return the {@code float} value represented by this object
130.577 - * converted to type {@code short}
130.578 - * @since JDK1.1
130.579 - */
130.580 - public short shortValue() {
130.581 - return (short)value;
130.582 - }
130.583 -
130.584 - /**
130.585 - * Returns the value of this {@code Float} as an {@code int} (by
130.586 - * casting to type {@code int}).
130.587 - *
130.588 - * @return the {@code float} value represented by this object
130.589 - * converted to type {@code int}
130.590 - */
130.591 - public int intValue() {
130.592 - return (int)value;
130.593 - }
130.594 -
130.595 - /**
130.596 - * Returns value of this {@code Float} as a {@code long} (by
130.597 - * casting to type {@code long}).
130.598 - *
130.599 - * @return the {@code float} value represented by this object
130.600 - * converted to type {@code long}
130.601 - */
130.602 - public long longValue() {
130.603 - return (long)value;
130.604 - }
130.605 -
130.606 - /**
130.607 - * Returns the {@code float} value of this {@code Float} object.
130.608 - *
130.609 - * @return the {@code float} value represented by this object
130.610 - */
130.611 - public float floatValue() {
130.612 - return value;
130.613 - }
130.614 -
130.615 - /**
130.616 - * Returns the {@code double} value of this {@code Float} object.
130.617 - *
130.618 - * @return the {@code float} value represented by this
130.619 - * object is converted to type {@code double} and the
130.620 - * result of the conversion is returned.
130.621 - */
130.622 - public double doubleValue() {
130.623 - return (double)value;
130.624 - }
130.625 -
130.626 - /**
130.627 - * Returns a hash code for this {@code Float} object. The
130.628 - * result is the integer bit representation, exactly as produced
130.629 - * by the method {@link #floatToIntBits(float)}, of the primitive
130.630 - * {@code float} value represented by this {@code Float}
130.631 - * object.
130.632 - *
130.633 - * @return a hash code value for this object.
130.634 - */
130.635 - public int hashCode() {
130.636 - return floatToIntBits(value);
130.637 - }
130.638 -
130.639 - /**
130.640 -
130.641 - * Compares this object against the specified object. The result
130.642 - * is {@code true} if and only if the argument is not
130.643 - * {@code null} and is a {@code Float} object that
130.644 - * represents a {@code float} with the same value as the
130.645 - * {@code float} represented by this object. For this
130.646 - * purpose, two {@code float} values are considered to be the
130.647 - * same if and only if the method {@link #floatToIntBits(float)}
130.648 - * returns the identical {@code int} value when applied to
130.649 - * each.
130.650 - *
130.651 - * <p>Note that in most cases, for two instances of class
130.652 - * {@code Float}, {@code f1} and {@code f2}, the value
130.653 - * of {@code f1.equals(f2)} is {@code true} if and only if
130.654 - *
130.655 - * <blockquote><pre>
130.656 - * f1.floatValue() == f2.floatValue()
130.657 - * </pre></blockquote>
130.658 - *
130.659 - * <p>also has the value {@code true}. However, there are two exceptions:
130.660 - * <ul>
130.661 - * <li>If {@code f1} and {@code f2} both represent
130.662 - * {@code Float.NaN}, then the {@code equals} method returns
130.663 - * {@code true}, even though {@code Float.NaN==Float.NaN}
130.664 - * has the value {@code false}.
130.665 - * <li>If {@code f1} represents {@code +0.0f} while
130.666 - * {@code f2} represents {@code -0.0f}, or vice
130.667 - * versa, the {@code equal} test has the value
130.668 - * {@code false}, even though {@code 0.0f==-0.0f}
130.669 - * has the value {@code true}.
130.670 - * </ul>
130.671 - *
130.672 - * This definition allows hash tables to operate properly.
130.673 - *
130.674 - * @param obj the object to be compared
130.675 - * @return {@code true} if the objects are the same;
130.676 - * {@code false} otherwise.
130.677 - * @see java.lang.Float#floatToIntBits(float)
130.678 - */
130.679 - public boolean equals(Object obj) {
130.680 - return (obj instanceof Float)
130.681 - && (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
130.682 - }
130.683 -
130.684 - /**
130.685 - * Returns a representation of the specified floating-point value
130.686 - * according to the IEEE 754 floating-point "single format" bit
130.687 - * layout.
130.688 - *
130.689 - * <p>Bit 31 (the bit that is selected by the mask
130.690 - * {@code 0x80000000}) represents the sign of the floating-point
130.691 - * number.
130.692 - * Bits 30-23 (the bits that are selected by the mask
130.693 - * {@code 0x7f800000}) represent the exponent.
130.694 - * Bits 22-0 (the bits that are selected by the mask
130.695 - * {@code 0x007fffff}) represent the significand (sometimes called
130.696 - * the mantissa) of the floating-point number.
130.697 - *
130.698 - * <p>If the argument is positive infinity, the result is
130.699 - * {@code 0x7f800000}.
130.700 - *
130.701 - * <p>If the argument is negative infinity, the result is
130.702 - * {@code 0xff800000}.
130.703 - *
130.704 - * <p>If the argument is NaN, the result is {@code 0x7fc00000}.
130.705 - *
130.706 - * <p>In all cases, the result is an integer that, when given to the
130.707 - * {@link #intBitsToFloat(int)} method, will produce a floating-point
130.708 - * value the same as the argument to {@code floatToIntBits}
130.709 - * (except all NaN values are collapsed to a single
130.710 - * "canonical" NaN value).
130.711 - *
130.712 - * @param value a floating-point number.
130.713 - * @return the bits that represent the floating-point number.
130.714 - */
130.715 - public static int floatToIntBits(float value) {
130.716 - throw new UnsupportedOperationException();
130.717 -// int result = floatToRawIntBits(value);
130.718 -// // Check for NaN based on values of bit fields, maximum
130.719 -// // exponent and nonzero significand.
130.720 -// if ( ((result & FloatConsts.EXP_BIT_MASK) ==
130.721 -// FloatConsts.EXP_BIT_MASK) &&
130.722 -// (result & FloatConsts.SIGNIF_BIT_MASK) != 0)
130.723 -// result = 0x7fc00000;
130.724 -// return result;
130.725 - }
130.726 -
130.727 - /**
130.728 - * Returns a representation of the specified floating-point value
130.729 - * according to the IEEE 754 floating-point "single format" bit
130.730 - * layout, preserving Not-a-Number (NaN) values.
130.731 - *
130.732 - * <p>Bit 31 (the bit that is selected by the mask
130.733 - * {@code 0x80000000}) represents the sign of the floating-point
130.734 - * number.
130.735 - * Bits 30-23 (the bits that are selected by the mask
130.736 - * {@code 0x7f800000}) represent the exponent.
130.737 - * Bits 22-0 (the bits that are selected by the mask
130.738 - * {@code 0x007fffff}) represent the significand (sometimes called
130.739 - * the mantissa) of the floating-point number.
130.740 - *
130.741 - * <p>If the argument is positive infinity, the result is
130.742 - * {@code 0x7f800000}.
130.743 - *
130.744 - * <p>If the argument is negative infinity, the result is
130.745 - * {@code 0xff800000}.
130.746 - *
130.747 - * <p>If the argument is NaN, the result is the integer representing
130.748 - * the actual NaN value. Unlike the {@code floatToIntBits}
130.749 - * method, {@code floatToRawIntBits} does not collapse all the
130.750 - * bit patterns encoding a NaN to a single "canonical"
130.751 - * NaN value.
130.752 - *
130.753 - * <p>In all cases, the result is an integer that, when given to the
130.754 - * {@link #intBitsToFloat(int)} method, will produce a
130.755 - * floating-point value the same as the argument to
130.756 - * {@code floatToRawIntBits}.
130.757 - *
130.758 - * @param value a floating-point number.
130.759 - * @return the bits that represent the floating-point number.
130.760 - * @since 1.3
130.761 - */
130.762 - public static native int floatToRawIntBits(float value);
130.763 -
130.764 - /**
130.765 - * Returns the {@code float} value corresponding to a given
130.766 - * bit representation.
130.767 - * The argument is considered to be a representation of a
130.768 - * floating-point value according to the IEEE 754 floating-point
130.769 - * "single format" bit layout.
130.770 - *
130.771 - * <p>If the argument is {@code 0x7f800000}, the result is positive
130.772 - * infinity.
130.773 - *
130.774 - * <p>If the argument is {@code 0xff800000}, the result is negative
130.775 - * infinity.
130.776 - *
130.777 - * <p>If the argument is any value in the range
130.778 - * {@code 0x7f800001} through {@code 0x7fffffff} or in
130.779 - * the range {@code 0xff800001} through
130.780 - * {@code 0xffffffff}, the result is a NaN. No IEEE 754
130.781 - * floating-point operation provided by Java can distinguish
130.782 - * between two NaN values of the same type with different bit
130.783 - * patterns. Distinct values of NaN are only distinguishable by
130.784 - * use of the {@code Float.floatToRawIntBits} method.
130.785 - *
130.786 - * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
130.787 - * values that can be computed from the argument:
130.788 - *
130.789 - * <blockquote><pre>
130.790 - * int s = ((bits >> 31) == 0) ? 1 : -1;
130.791 - * int e = ((bits >> 23) & 0xff);
130.792 - * int m = (e == 0) ?
130.793 - * (bits & 0x7fffff) << 1 :
130.794 - * (bits & 0x7fffff) | 0x800000;
130.795 - * </pre></blockquote>
130.796 - *
130.797 - * Then the floating-point result equals the value of the mathematical
130.798 - * expression <i>s</i>·<i>m</i>·2<sup><i>e</i>-150</sup>.
130.799 - *
130.800 - * <p>Note that this method may not be able to return a
130.801 - * {@code float} NaN with exactly same bit pattern as the
130.802 - * {@code int} argument. IEEE 754 distinguishes between two
130.803 - * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>. The
130.804 - * differences between the two kinds of NaN are generally not
130.805 - * visible in Java. Arithmetic operations on signaling NaNs turn
130.806 - * them into quiet NaNs with a different, but often similar, bit
130.807 - * pattern. However, on some processors merely copying a
130.808 - * signaling NaN also performs that conversion. In particular,
130.809 - * copying a signaling NaN to return it to the calling method may
130.810 - * perform this conversion. So {@code intBitsToFloat} may
130.811 - * not be able to return a {@code float} with a signaling NaN
130.812 - * bit pattern. Consequently, for some {@code int} values,
130.813 - * {@code floatToRawIntBits(intBitsToFloat(start))} may
130.814 - * <i>not</i> equal {@code start}. Moreover, which
130.815 - * particular bit patterns represent signaling NaNs is platform
130.816 - * dependent; although all NaN bit patterns, quiet or signaling,
130.817 - * must be in the NaN range identified above.
130.818 - *
130.819 - * @param bits an integer.
130.820 - * @return the {@code float} floating-point value with the same bit
130.821 - * pattern.
130.822 - */
130.823 - @JavaScriptBody(args = "bits",
130.824 - body =
130.825 - "if (bits === 0x7f800000) return Number.POSITIVE_INFINITY;\n"
130.826 - + "if (bits === 0xff800000) return Number.NEGATIVE_INFINITY;\n"
130.827 - + "if (bits >= 0x7f800001 && bits <= 0xffffffff) return Number.NaN;\n"
130.828 - + "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
130.829 - + "var e = ((bits >> 23) & 0xff);\n"
130.830 - + "var m = (e == 0) ?\n"
130.831 - + " (bits & 0x7fffff) << 1 :\n"
130.832 - + " (bits & 0x7fffff) | 0x800000;\n"
130.833 - + "return s * m * Math.pow(2.0, e - 150);\n"
130.834 - )
130.835 - public static native float intBitsToFloat(int bits);
130.836 -
130.837 - /**
130.838 - * Compares two {@code Float} objects numerically. There are
130.839 - * two ways in which comparisons performed by this method differ
130.840 - * from those performed by the Java language numerical comparison
130.841 - * operators ({@code <, <=, ==, >=, >}) when
130.842 - * applied to primitive {@code float} values:
130.843 - *
130.844 - * <ul><li>
130.845 - * {@code Float.NaN} is considered by this method to
130.846 - * be equal to itself and greater than all other
130.847 - * {@code float} values
130.848 - * (including {@code Float.POSITIVE_INFINITY}).
130.849 - * <li>
130.850 - * {@code 0.0f} is considered by this method to be greater
130.851 - * than {@code -0.0f}.
130.852 - * </ul>
130.853 - *
130.854 - * This ensures that the <i>natural ordering</i> of {@code Float}
130.855 - * objects imposed by this method is <i>consistent with equals</i>.
130.856 - *
130.857 - * @param anotherFloat the {@code Float} to be compared.
130.858 - * @return the value {@code 0} if {@code anotherFloat} is
130.859 - * numerically equal to this {@code Float}; a value
130.860 - * less than {@code 0} if this {@code Float}
130.861 - * is numerically less than {@code anotherFloat};
130.862 - * and a value greater than {@code 0} if this
130.863 - * {@code Float} is numerically greater than
130.864 - * {@code anotherFloat}.
130.865 - *
130.866 - * @since 1.2
130.867 - * @see Comparable#compareTo(Object)
130.868 - */
130.869 - public int compareTo(Float anotherFloat) {
130.870 - return Float.compare(value, anotherFloat.value);
130.871 - }
130.872 -
130.873 - /**
130.874 - * Compares the two specified {@code float} values. The sign
130.875 - * of the integer value returned is the same as that of the
130.876 - * integer that would be returned by the call:
130.877 - * <pre>
130.878 - * new Float(f1).compareTo(new Float(f2))
130.879 - * </pre>
130.880 - *
130.881 - * @param f1 the first {@code float} to compare.
130.882 - * @param f2 the second {@code float} to compare.
130.883 - * @return the value {@code 0} if {@code f1} is
130.884 - * numerically equal to {@code f2}; a value less than
130.885 - * {@code 0} if {@code f1} is numerically less than
130.886 - * {@code f2}; and a value greater than {@code 0}
130.887 - * if {@code f1} is numerically greater than
130.888 - * {@code f2}.
130.889 - * @since 1.4
130.890 - */
130.891 - public static int compare(float f1, float f2) {
130.892 - if (f1 < f2)
130.893 - return -1; // Neither val is NaN, thisVal is smaller
130.894 - if (f1 > f2)
130.895 - return 1; // Neither val is NaN, thisVal is larger
130.896 -
130.897 - // Cannot use floatToRawIntBits because of possibility of NaNs.
130.898 - int thisBits = Float.floatToIntBits(f1);
130.899 - int anotherBits = Float.floatToIntBits(f2);
130.900 -
130.901 - return (thisBits == anotherBits ? 0 : // Values are equal
130.902 - (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
130.903 - 1)); // (0.0, -0.0) or (NaN, !NaN)
130.904 - }
130.905 -
130.906 - /** use serialVersionUID from JDK 1.0.2 for interoperability */
130.907 - private static final long serialVersionUID = -2671257302660747028L;
130.908 -}
131.1 --- a/emul/src/main/java/java/lang/IllegalAccessException.java Wed Jan 23 20:16:48 2013 +0100
131.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
131.3 @@ -1,78 +0,0 @@
131.4 -/*
131.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
131.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
131.7 - *
131.8 - * This code is free software; you can redistribute it and/or modify it
131.9 - * under the terms of the GNU General Public License version 2 only, as
131.10 - * published by the Free Software Foundation. Oracle designates this
131.11 - * particular file as subject to the "Classpath" exception as provided
131.12 - * by Oracle in the LICENSE file that accompanied this code.
131.13 - *
131.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
131.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
131.17 - * version 2 for more details (a copy is included in the LICENSE file that
131.18 - * accompanied this code).
131.19 - *
131.20 - * You should have received a copy of the GNU General Public License version
131.21 - * 2 along with this work; if not, write to the Free Software Foundation,
131.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
131.23 - *
131.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
131.25 - * or visit www.oracle.com if you need additional information or have any
131.26 - * questions.
131.27 - */
131.28 -
131.29 -package java.lang;
131.30 -
131.31 -/**
131.32 - * An IllegalAccessException is thrown when an application tries
131.33 - * to reflectively create an instance (other than an array),
131.34 - * set or get a field, or invoke a method, but the currently
131.35 - * executing method does not have access to the definition of
131.36 - * the specified class, field, method or constructor.
131.37 - *
131.38 - * @author unascribed
131.39 - * @see Class#newInstance()
131.40 - * @see java.lang.reflect.Field#set(Object, Object)
131.41 - * @see java.lang.reflect.Field#setBoolean(Object, boolean)
131.42 - * @see java.lang.reflect.Field#setByte(Object, byte)
131.43 - * @see java.lang.reflect.Field#setShort(Object, short)
131.44 - * @see java.lang.reflect.Field#setChar(Object, char)
131.45 - * @see java.lang.reflect.Field#setInt(Object, int)
131.46 - * @see java.lang.reflect.Field#setLong(Object, long)
131.47 - * @see java.lang.reflect.Field#setFloat(Object, float)
131.48 - * @see java.lang.reflect.Field#setDouble(Object, double)
131.49 - * @see java.lang.reflect.Field#get(Object)
131.50 - * @see java.lang.reflect.Field#getBoolean(Object)
131.51 - * @see java.lang.reflect.Field#getByte(Object)
131.52 - * @see java.lang.reflect.Field#getShort(Object)
131.53 - * @see java.lang.reflect.Field#getChar(Object)
131.54 - * @see java.lang.reflect.Field#getInt(Object)
131.55 - * @see java.lang.reflect.Field#getLong(Object)
131.56 - * @see java.lang.reflect.Field#getFloat(Object)
131.57 - * @see java.lang.reflect.Field#getDouble(Object)
131.58 - * @see java.lang.reflect.Method#invoke(Object, Object[])
131.59 - * @see java.lang.reflect.Constructor#newInstance(Object[])
131.60 - * @since JDK1.0
131.61 - */
131.62 -public class IllegalAccessException extends ReflectiveOperationException {
131.63 - private static final long serialVersionUID = 6616958222490762034L;
131.64 -
131.65 - /**
131.66 - * Constructs an <code>IllegalAccessException</code> without a
131.67 - * detail message.
131.68 - */
131.69 - public IllegalAccessException() {
131.70 - super();
131.71 - }
131.72 -
131.73 - /**
131.74 - * Constructs an <code>IllegalAccessException</code> with a detail message.
131.75 - *
131.76 - * @param s the detail message.
131.77 - */
131.78 - public IllegalAccessException(String s) {
131.79 - super(s);
131.80 - }
131.81 -}
132.1 --- a/emul/src/main/java/java/lang/IllegalArgumentException.java Wed Jan 23 20:16:48 2013 +0100
132.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
132.3 @@ -1,95 +0,0 @@
132.4 -/*
132.5 - * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
132.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
132.7 - *
132.8 - * This code is free software; you can redistribute it and/or modify it
132.9 - * under the terms of the GNU General Public License version 2 only, as
132.10 - * published by the Free Software Foundation. Oracle designates this
132.11 - * particular file as subject to the "Classpath" exception as provided
132.12 - * by Oracle in the LICENSE file that accompanied this code.
132.13 - *
132.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
132.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
132.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
132.17 - * version 2 for more details (a copy is included in the LICENSE file that
132.18 - * accompanied this code).
132.19 - *
132.20 - * You should have received a copy of the GNU General Public License version
132.21 - * 2 along with this work; if not, write to the Free Software Foundation,
132.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
132.23 - *
132.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
132.25 - * or visit www.oracle.com if you need additional information or have any
132.26 - * questions.
132.27 - */
132.28 -
132.29 -package java.lang;
132.30 -
132.31 -/**
132.32 - * Thrown to indicate that a method has been passed an illegal or
132.33 - * inappropriate argument.
132.34 - *
132.35 - * @author unascribed
132.36 - * @see java.lang.Thread#setPriority(int)
132.37 - * @since JDK1.0
132.38 - */
132.39 -public
132.40 -class IllegalArgumentException extends RuntimeException {
132.41 - /**
132.42 - * Constructs an <code>IllegalArgumentException</code> with no
132.43 - * detail message.
132.44 - */
132.45 - public IllegalArgumentException() {
132.46 - super();
132.47 - }
132.48 -
132.49 - /**
132.50 - * Constructs an <code>IllegalArgumentException</code> with the
132.51 - * specified detail message.
132.52 - *
132.53 - * @param s the detail message.
132.54 - */
132.55 - public IllegalArgumentException(String s) {
132.56 - super(s);
132.57 - }
132.58 -
132.59 - /**
132.60 - * Constructs a new exception with the specified detail message and
132.61 - * cause.
132.62 - *
132.63 - * <p>Note that the detail message associated with <code>cause</code> is
132.64 - * <i>not</i> automatically incorporated in this exception's detail
132.65 - * message.
132.66 - *
132.67 - * @param message the detail message (which is saved for later retrieval
132.68 - * by the {@link Throwable#getMessage()} method).
132.69 - * @param cause the cause (which is saved for later retrieval by the
132.70 - * {@link Throwable#getCause()} method). (A <tt>null</tt> value
132.71 - * is permitted, and indicates that the cause is nonexistent or
132.72 - * unknown.)
132.73 - * @since 1.5
132.74 - */
132.75 - public IllegalArgumentException(String message, Throwable cause) {
132.76 - super(message, cause);
132.77 - }
132.78 -
132.79 - /**
132.80 - * Constructs a new exception with the specified cause and a detail
132.81 - * message of <tt>(cause==null ? null : cause.toString())</tt> (which
132.82 - * typically contains the class and detail message of <tt>cause</tt>).
132.83 - * This constructor is useful for exceptions that are little more than
132.84 - * wrappers for other throwables (for example, {@link
132.85 - * java.security.PrivilegedActionException}).
132.86 - *
132.87 - * @param cause the cause (which is saved for later retrieval by the
132.88 - * {@link Throwable#getCause()} method). (A <tt>null</tt> value is
132.89 - * permitted, and indicates that the cause is nonexistent or
132.90 - * unknown.)
132.91 - * @since 1.5
132.92 - */
132.93 - public IllegalArgumentException(Throwable cause) {
132.94 - super(cause);
132.95 - }
132.96 -
132.97 - private static final long serialVersionUID = -5365630128856068164L;
132.98 -}
133.1 --- a/emul/src/main/java/java/lang/IllegalStateException.java Wed Jan 23 20:16:48 2013 +0100
133.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
133.3 @@ -1,97 +0,0 @@
133.4 -/*
133.5 - * Copyright (c) 1996, 2003, Oracle and/or its affiliates. All rights reserved.
133.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
133.7 - *
133.8 - * This code is free software; you can redistribute it and/or modify it
133.9 - * under the terms of the GNU General Public License version 2 only, as
133.10 - * published by the Free Software Foundation. Oracle designates this
133.11 - * particular file as subject to the "Classpath" exception as provided
133.12 - * by Oracle in the LICENSE file that accompanied this code.
133.13 - *
133.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
133.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
133.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
133.17 - * version 2 for more details (a copy is included in the LICENSE file that
133.18 - * accompanied this code).
133.19 - *
133.20 - * You should have received a copy of the GNU General Public License version
133.21 - * 2 along with this work; if not, write to the Free Software Foundation,
133.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
133.23 - *
133.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
133.25 - * or visit www.oracle.com if you need additional information or have any
133.26 - * questions.
133.27 - */
133.28 -
133.29 -package java.lang;
133.30 -
133.31 -/**
133.32 - * Signals that a method has been invoked at an illegal or
133.33 - * inappropriate time. In other words, the Java environment or
133.34 - * Java application is not in an appropriate state for the requested
133.35 - * operation.
133.36 - *
133.37 - * @author Jonni Kanerva
133.38 - * @since JDK1.1
133.39 - */
133.40 -public
133.41 -class IllegalStateException extends RuntimeException {
133.42 - /**
133.43 - * Constructs an IllegalStateException with no detail message.
133.44 - * A detail message is a String that describes this particular exception.
133.45 - */
133.46 - public IllegalStateException() {
133.47 - super();
133.48 - }
133.49 -
133.50 - /**
133.51 - * Constructs an IllegalStateException with the specified detail
133.52 - * message. A detail message is a String that describes this particular
133.53 - * exception.
133.54 - *
133.55 - * @param s the String that contains a detailed message
133.56 - */
133.57 - public IllegalStateException(String s) {
133.58 - super(s);
133.59 - }
133.60 -
133.61 - /**
133.62 - * Constructs a new exception with the specified detail message and
133.63 - * cause.
133.64 - *
133.65 - * <p>Note that the detail message associated with <code>cause</code> is
133.66 - * <i>not</i> automatically incorporated in this exception's detail
133.67 - * message.
133.68 - *
133.69 - * @param message the detail message (which is saved for later retrieval
133.70 - * by the {@link Throwable#getMessage()} method).
133.71 - * @param cause the cause (which is saved for later retrieval by the
133.72 - * {@link Throwable#getCause()} method). (A <tt>null</tt> value
133.73 - * is permitted, and indicates that the cause is nonexistent or
133.74 - * unknown.)
133.75 - * @since 1.5
133.76 - */
133.77 - public IllegalStateException(String message, Throwable cause) {
133.78 - super(message, cause);
133.79 - }
133.80 -
133.81 - /**
133.82 - * Constructs a new exception with the specified cause and a detail
133.83 - * message of <tt>(cause==null ? null : cause.toString())</tt> (which
133.84 - * typically contains the class and detail message of <tt>cause</tt>).
133.85 - * This constructor is useful for exceptions that are little more than
133.86 - * wrappers for other throwables (for example, {@link
133.87 - * java.security.PrivilegedActionException}).
133.88 - *
133.89 - * @param cause the cause (which is saved for later retrieval by the
133.90 - * {@link Throwable#getCause()} method). (A <tt>null</tt> value is
133.91 - * permitted, and indicates that the cause is nonexistent or
133.92 - * unknown.)
133.93 - * @since 1.5
133.94 - */
133.95 - public IllegalStateException(Throwable cause) {
133.96 - super(cause);
133.97 - }
133.98 -
133.99 - static final long serialVersionUID = -1848914673093119416L;
133.100 -}
134.1 --- a/emul/src/main/java/java/lang/IndexOutOfBoundsException.java Wed Jan 23 20:16:48 2013 +0100
134.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
134.3 @@ -1,58 +0,0 @@
134.4 -/*
134.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
134.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
134.7 - *
134.8 - * This code is free software; you can redistribute it and/or modify it
134.9 - * under the terms of the GNU General Public License version 2 only, as
134.10 - * published by the Free Software Foundation. Oracle designates this
134.11 - * particular file as subject to the "Classpath" exception as provided
134.12 - * by Oracle in the LICENSE file that accompanied this code.
134.13 - *
134.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
134.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
134.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
134.17 - * version 2 for more details (a copy is included in the LICENSE file that
134.18 - * accompanied this code).
134.19 - *
134.20 - * You should have received a copy of the GNU General Public License version
134.21 - * 2 along with this work; if not, write to the Free Software Foundation,
134.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
134.23 - *
134.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
134.25 - * or visit www.oracle.com if you need additional information or have any
134.26 - * questions.
134.27 - */
134.28 -
134.29 -package java.lang;
134.30 -
134.31 -/**
134.32 - * Thrown to indicate that an index of some sort (such as to an array, to a
134.33 - * string, or to a vector) is out of range.
134.34 - * <p>
134.35 - * Applications can subclass this class to indicate similar exceptions.
134.36 - *
134.37 - * @author Frank Yellin
134.38 - * @since JDK1.0
134.39 - */
134.40 -public
134.41 -class IndexOutOfBoundsException extends RuntimeException {
134.42 - private static final long serialVersionUID = 234122996006267687L;
134.43 -
134.44 - /**
134.45 - * Constructs an <code>IndexOutOfBoundsException</code> with no
134.46 - * detail message.
134.47 - */
134.48 - public IndexOutOfBoundsException() {
134.49 - super();
134.50 - }
134.51 -
134.52 - /**
134.53 - * Constructs an <code>IndexOutOfBoundsException</code> with the
134.54 - * specified detail message.
134.55 - *
134.56 - * @param s the detail message.
134.57 - */
134.58 - public IndexOutOfBoundsException(String s) {
134.59 - super(s);
134.60 - }
134.61 -}
135.1 --- a/emul/src/main/java/java/lang/InstantiationException.java Wed Jan 23 20:16:48 2013 +0100
135.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
135.3 @@ -1,65 +0,0 @@
135.4 -/*
135.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
135.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
135.7 - *
135.8 - * This code is free software; you can redistribute it and/or modify it
135.9 - * under the terms of the GNU General Public License version 2 only, as
135.10 - * published by the Free Software Foundation. Oracle designates this
135.11 - * particular file as subject to the "Classpath" exception as provided
135.12 - * by Oracle in the LICENSE file that accompanied this code.
135.13 - *
135.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
135.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
135.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
135.17 - * version 2 for more details (a copy is included in the LICENSE file that
135.18 - * accompanied this code).
135.19 - *
135.20 - * You should have received a copy of the GNU General Public License version
135.21 - * 2 along with this work; if not, write to the Free Software Foundation,
135.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
135.23 - *
135.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
135.25 - * or visit www.oracle.com if you need additional information or have any
135.26 - * questions.
135.27 - */
135.28 -
135.29 -package java.lang;
135.30 -
135.31 -/**
135.32 - * Thrown when an application tries to create an instance of a class
135.33 - * using the {@code newInstance} method in class
135.34 - * {@code Class}, but the specified class object cannot be
135.35 - * instantiated. The instantiation can fail for a variety of
135.36 - * reasons including but not limited to:
135.37 - *
135.38 - * <ul>
135.39 - * <li> the class object represents an abstract class, an interface,
135.40 - * an array class, a primitive type, or {@code void}
135.41 - * <li> the class has no nullary constructor
135.42 - *</ul>
135.43 - *
135.44 - * @author unascribed
135.45 - * @see java.lang.Class#newInstance()
135.46 - * @since JDK1.0
135.47 - */
135.48 -public
135.49 -class InstantiationException extends ReflectiveOperationException {
135.50 - private static final long serialVersionUID = -8441929162975509110L;
135.51 -
135.52 - /**
135.53 - * Constructs an {@code InstantiationException} with no detail message.
135.54 - */
135.55 - public InstantiationException() {
135.56 - super();
135.57 - }
135.58 -
135.59 - /**
135.60 - * Constructs an {@code InstantiationException} with the
135.61 - * specified detail message.
135.62 - *
135.63 - * @param s the detail message.
135.64 - */
135.65 - public InstantiationException(String s) {
135.66 - super(s);
135.67 - }
135.68 -}
136.1 --- a/emul/src/main/java/java/lang/Integer.java Wed Jan 23 20:16:48 2013 +0100
136.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
136.3 @@ -1,1246 +0,0 @@
136.4 -/*
136.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
136.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
136.7 - *
136.8 - * This code is free software; you can redistribute it and/or modify it
136.9 - * under the terms of the GNU General Public License version 2 only, as
136.10 - * published by the Free Software Foundation. Oracle designates this
136.11 - * particular file as subject to the "Classpath" exception as provided
136.12 - * by Oracle in the LICENSE file that accompanied this code.
136.13 - *
136.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
136.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
136.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
136.17 - * version 2 for more details (a copy is included in the LICENSE file that
136.18 - * accompanied this code).
136.19 - *
136.20 - * You should have received a copy of the GNU General Public License version
136.21 - * 2 along with this work; if not, write to the Free Software Foundation,
136.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
136.23 - *
136.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
136.25 - * or visit www.oracle.com if you need additional information or have any
136.26 - * questions.
136.27 - */
136.28 -
136.29 -package java.lang;
136.30 -
136.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
136.32 -
136.33 -/**
136.34 - * The {@code Integer} class wraps a value of the primitive type
136.35 - * {@code int} in an object. An object of type {@code Integer}
136.36 - * contains a single field whose type is {@code int}.
136.37 - *
136.38 - * <p>In addition, this class provides several methods for converting
136.39 - * an {@code int} to a {@code String} and a {@code String} to an
136.40 - * {@code int}, as well as other constants and methods useful when
136.41 - * dealing with an {@code int}.
136.42 - *
136.43 - * <p>Implementation note: The implementations of the "bit twiddling"
136.44 - * methods (such as {@link #highestOneBit(int) highestOneBit} and
136.45 - * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
136.46 - * based on material from Henry S. Warren, Jr.'s <i>Hacker's
136.47 - * Delight</i>, (Addison Wesley, 2002).
136.48 - *
136.49 - * @author Lee Boynton
136.50 - * @author Arthur van Hoff
136.51 - * @author Josh Bloch
136.52 - * @author Joseph D. Darcy
136.53 - * @since JDK1.0
136.54 - */
136.55 -public final class Integer extends Number implements Comparable<Integer> {
136.56 - /**
136.57 - * A constant holding the minimum value an {@code int} can
136.58 - * have, -2<sup>31</sup>.
136.59 - */
136.60 - public static final int MIN_VALUE = 0x80000000;
136.61 -
136.62 - /**
136.63 - * A constant holding the maximum value an {@code int} can
136.64 - * have, 2<sup>31</sup>-1.
136.65 - */
136.66 - public static final int MAX_VALUE = 0x7fffffff;
136.67 -
136.68 - /**
136.69 - * The {@code Class} instance representing the primitive type
136.70 - * {@code int}.
136.71 - *
136.72 - * @since JDK1.1
136.73 - */
136.74 - public static final Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
136.75 -
136.76 - /**
136.77 - * All possible chars for representing a number as a String
136.78 - */
136.79 - final static char[] digits = {
136.80 - '0' , '1' , '2' , '3' , '4' , '5' ,
136.81 - '6' , '7' , '8' , '9' , 'a' , 'b' ,
136.82 - 'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
136.83 - 'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
136.84 - 'o' , 'p' , 'q' , 'r' , 's' , 't' ,
136.85 - 'u' , 'v' , 'w' , 'x' , 'y' , 'z'
136.86 - };
136.87 -
136.88 - /**
136.89 - * Returns a string representation of the first argument in the
136.90 - * radix specified by the second argument.
136.91 - *
136.92 - * <p>If the radix is smaller than {@code Character.MIN_RADIX}
136.93 - * or larger than {@code Character.MAX_RADIX}, then the radix
136.94 - * {@code 10} is used instead.
136.95 - *
136.96 - * <p>If the first argument is negative, the first element of the
136.97 - * result is the ASCII minus character {@code '-'}
136.98 - * (<code>'\u002D'</code>). If the first argument is not
136.99 - * negative, no sign character appears in the result.
136.100 - *
136.101 - * <p>The remaining characters of the result represent the magnitude
136.102 - * of the first argument. If the magnitude is zero, it is
136.103 - * represented by a single zero character {@code '0'}
136.104 - * (<code>'\u0030'</code>); otherwise, the first character of
136.105 - * the representation of the magnitude will not be the zero
136.106 - * character. The following ASCII characters are used as digits:
136.107 - *
136.108 - * <blockquote>
136.109 - * {@code 0123456789abcdefghijklmnopqrstuvwxyz}
136.110 - * </blockquote>
136.111 - *
136.112 - * These are <code>'\u0030'</code> through
136.113 - * <code>'\u0039'</code> and <code>'\u0061'</code> through
136.114 - * <code>'\u007A'</code>. If {@code radix} is
136.115 - * <var>N</var>, then the first <var>N</var> of these characters
136.116 - * are used as radix-<var>N</var> digits in the order shown. Thus,
136.117 - * the digits for hexadecimal (radix 16) are
136.118 - * {@code 0123456789abcdef}. If uppercase letters are
136.119 - * desired, the {@link java.lang.String#toUpperCase()} method may
136.120 - * be called on the result:
136.121 - *
136.122 - * <blockquote>
136.123 - * {@code Integer.toString(n, 16).toUpperCase()}
136.124 - * </blockquote>
136.125 - *
136.126 - * @param i an integer to be converted to a string.
136.127 - * @param radix the radix to use in the string representation.
136.128 - * @return a string representation of the argument in the specified radix.
136.129 - * @see java.lang.Character#MAX_RADIX
136.130 - * @see java.lang.Character#MIN_RADIX
136.131 - */
136.132 - public static String toString(int i, int radix) {
136.133 -
136.134 - if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
136.135 - radix = 10;
136.136 -
136.137 - /* Use the faster version */
136.138 - if (radix == 10) {
136.139 - return toString(i);
136.140 - }
136.141 -
136.142 - char buf[] = new char[33];
136.143 - boolean negative = (i < 0);
136.144 - int charPos = 32;
136.145 -
136.146 - if (!negative) {
136.147 - i = -i;
136.148 - }
136.149 -
136.150 - while (i <= -radix) {
136.151 - buf[charPos--] = digits[-(i % radix)];
136.152 - i = i / radix;
136.153 - }
136.154 - buf[charPos] = digits[-i];
136.155 -
136.156 - if (negative) {
136.157 - buf[--charPos] = '-';
136.158 - }
136.159 -
136.160 - return new String(buf, charPos, (33 - charPos));
136.161 - }
136.162 -
136.163 - /**
136.164 - * Returns a string representation of the integer argument as an
136.165 - * unsigned integer in base 16.
136.166 - *
136.167 - * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
136.168 - * if the argument is negative; otherwise, it is equal to the
136.169 - * argument. This value is converted to a string of ASCII digits
136.170 - * in hexadecimal (base 16) with no extra leading
136.171 - * {@code 0}s. If the unsigned magnitude is zero, it is
136.172 - * represented by a single zero character {@code '0'}
136.173 - * (<code>'\u0030'</code>); otherwise, the first character of
136.174 - * the representation of the unsigned magnitude will not be the
136.175 - * zero character. The following characters are used as
136.176 - * hexadecimal digits:
136.177 - *
136.178 - * <blockquote>
136.179 - * {@code 0123456789abcdef}
136.180 - * </blockquote>
136.181 - *
136.182 - * These are the characters <code>'\u0030'</code> through
136.183 - * <code>'\u0039'</code> and <code>'\u0061'</code> through
136.184 - * <code>'\u0066'</code>. If uppercase letters are
136.185 - * desired, the {@link java.lang.String#toUpperCase()} method may
136.186 - * be called on the result:
136.187 - *
136.188 - * <blockquote>
136.189 - * {@code Integer.toHexString(n).toUpperCase()}
136.190 - * </blockquote>
136.191 - *
136.192 - * @param i an integer to be converted to a string.
136.193 - * @return the string representation of the unsigned integer value
136.194 - * represented by the argument in hexadecimal (base 16).
136.195 - * @since JDK1.0.2
136.196 - */
136.197 - public static String toHexString(int i) {
136.198 - return toUnsignedString(i, 4);
136.199 - }
136.200 -
136.201 - /**
136.202 - * Returns a string representation of the integer argument as an
136.203 - * unsigned integer in base 8.
136.204 - *
136.205 - * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
136.206 - * if the argument is negative; otherwise, it is equal to the
136.207 - * argument. This value is converted to a string of ASCII digits
136.208 - * in octal (base 8) with no extra leading {@code 0}s.
136.209 - *
136.210 - * <p>If the unsigned magnitude is zero, it is represented by a
136.211 - * single zero character {@code '0'}
136.212 - * (<code>'\u0030'</code>); otherwise, the first character of
136.213 - * the representation of the unsigned magnitude will not be the
136.214 - * zero character. The following characters are used as octal
136.215 - * digits:
136.216 - *
136.217 - * <blockquote>
136.218 - * {@code 01234567}
136.219 - * </blockquote>
136.220 - *
136.221 - * These are the characters <code>'\u0030'</code> through
136.222 - * <code>'\u0037'</code>.
136.223 - *
136.224 - * @param i an integer to be converted to a string.
136.225 - * @return the string representation of the unsigned integer value
136.226 - * represented by the argument in octal (base 8).
136.227 - * @since JDK1.0.2
136.228 - */
136.229 - public static String toOctalString(int i) {
136.230 - return toUnsignedString(i, 3);
136.231 - }
136.232 -
136.233 - /**
136.234 - * Returns a string representation of the integer argument as an
136.235 - * unsigned integer in base 2.
136.236 - *
136.237 - * <p>The unsigned integer value is the argument plus 2<sup>32</sup>
136.238 - * if the argument is negative; otherwise it is equal to the
136.239 - * argument. This value is converted to a string of ASCII digits
136.240 - * in binary (base 2) with no extra leading {@code 0}s.
136.241 - * If the unsigned magnitude is zero, it is represented by a
136.242 - * single zero character {@code '0'}
136.243 - * (<code>'\u0030'</code>); otherwise, the first character of
136.244 - * the representation of the unsigned magnitude will not be the
136.245 - * zero character. The characters {@code '0'}
136.246 - * (<code>'\u0030'</code>) and {@code '1'}
136.247 - * (<code>'\u0031'</code>) are used as binary digits.
136.248 - *
136.249 - * @param i an integer to be converted to a string.
136.250 - * @return the string representation of the unsigned integer value
136.251 - * represented by the argument in binary (base 2).
136.252 - * @since JDK1.0.2
136.253 - */
136.254 - public static String toBinaryString(int i) {
136.255 - return toUnsignedString(i, 1);
136.256 - }
136.257 -
136.258 - /**
136.259 - * Convert the integer to an unsigned number.
136.260 - */
136.261 - private static String toUnsignedString(int i, int shift) {
136.262 - char[] buf = new char[32];
136.263 - int charPos = 32;
136.264 - int radix = 1 << shift;
136.265 - int mask = radix - 1;
136.266 - do {
136.267 - buf[--charPos] = digits[i & mask];
136.268 - i >>>= shift;
136.269 - } while (i != 0);
136.270 -
136.271 - return new String(buf, charPos, (32 - charPos));
136.272 - }
136.273 -
136.274 -
136.275 - final static char [] DigitTens = {
136.276 - '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
136.277 - '1', '1', '1', '1', '1', '1', '1', '1', '1', '1',
136.278 - '2', '2', '2', '2', '2', '2', '2', '2', '2', '2',
136.279 - '3', '3', '3', '3', '3', '3', '3', '3', '3', '3',
136.280 - '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
136.281 - '5', '5', '5', '5', '5', '5', '5', '5', '5', '5',
136.282 - '6', '6', '6', '6', '6', '6', '6', '6', '6', '6',
136.283 - '7', '7', '7', '7', '7', '7', '7', '7', '7', '7',
136.284 - '8', '8', '8', '8', '8', '8', '8', '8', '8', '8',
136.285 - '9', '9', '9', '9', '9', '9', '9', '9', '9', '9',
136.286 - } ;
136.287 -
136.288 - final static char [] DigitOnes = {
136.289 - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
136.290 - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
136.291 - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
136.292 - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
136.293 - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
136.294 - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
136.295 - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
136.296 - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
136.297 - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
136.298 - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
136.299 - } ;
136.300 -
136.301 - // I use the "invariant division by multiplication" trick to
136.302 - // accelerate Integer.toString. In particular we want to
136.303 - // avoid division by 10.
136.304 - //
136.305 - // The "trick" has roughly the same performance characteristics
136.306 - // as the "classic" Integer.toString code on a non-JIT VM.
136.307 - // The trick avoids .rem and .div calls but has a longer code
136.308 - // path and is thus dominated by dispatch overhead. In the
136.309 - // JIT case the dispatch overhead doesn't exist and the
136.310 - // "trick" is considerably faster than the classic code.
136.311 - //
136.312 - // TODO-FIXME: convert (x * 52429) into the equiv shift-add
136.313 - // sequence.
136.314 - //
136.315 - // RE: Division by Invariant Integers using Multiplication
136.316 - // T Gralund, P Montgomery
136.317 - // ACM PLDI 1994
136.318 - //
136.319 -
136.320 - /**
136.321 - * Returns a {@code String} object representing the
136.322 - * specified integer. The argument is converted to signed decimal
136.323 - * representation and returned as a string, exactly as if the
136.324 - * argument and radix 10 were given as arguments to the {@link
136.325 - * #toString(int, int)} method.
136.326 - *
136.327 - * @param i an integer to be converted.
136.328 - * @return a string representation of the argument in base 10.
136.329 - */
136.330 - @JavaScriptBody(args = "i", body = "return i.toString();")
136.331 - public static String toString(int i) {
136.332 - if (i == Integer.MIN_VALUE)
136.333 - return "-2147483648";
136.334 - int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
136.335 - char[] buf = new char[size];
136.336 - getChars(i, size, buf);
136.337 - return new String(buf, 0, size);
136.338 - }
136.339 -
136.340 - /**
136.341 - * Places characters representing the integer i into the
136.342 - * character array buf. The characters are placed into
136.343 - * the buffer backwards starting with the least significant
136.344 - * digit at the specified index (exclusive), and working
136.345 - * backwards from there.
136.346 - *
136.347 - * Will fail if i == Integer.MIN_VALUE
136.348 - */
136.349 - static void getChars(int i, int index, char[] buf) {
136.350 - int q, r;
136.351 - int charPos = index;
136.352 - char sign = 0;
136.353 -
136.354 - if (i < 0) {
136.355 - sign = '-';
136.356 - i = -i;
136.357 - }
136.358 -
136.359 - // Generate two digits per iteration
136.360 - while (i >= 65536) {
136.361 - q = i / 100;
136.362 - // really: r = i - (q * 100);
136.363 - r = i - ((q << 6) + (q << 5) + (q << 2));
136.364 - i = q;
136.365 - buf [--charPos] = DigitOnes[r];
136.366 - buf [--charPos] = DigitTens[r];
136.367 - }
136.368 -
136.369 - // Fall thru to fast mode for smaller numbers
136.370 - // assert(i <= 65536, i);
136.371 - for (;;) {
136.372 - q = (i * 52429) >>> (16+3);
136.373 - r = i - ((q << 3) + (q << 1)); // r = i-(q*10) ...
136.374 - buf [--charPos] = digits [r];
136.375 - i = q;
136.376 - if (i == 0) break;
136.377 - }
136.378 - if (sign != 0) {
136.379 - buf [--charPos] = sign;
136.380 - }
136.381 - }
136.382 -
136.383 - final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
136.384 - 99999999, 999999999, Integer.MAX_VALUE };
136.385 -
136.386 - // Requires positive x
136.387 - static int stringSize(int x) {
136.388 - for (int i=0; ; i++)
136.389 - if (x <= sizeTable[i])
136.390 - return i+1;
136.391 - }
136.392 -
136.393 - /**
136.394 - * Parses the string argument as a signed integer in the radix
136.395 - * specified by the second argument. The characters in the string
136.396 - * must all be digits of the specified radix (as determined by
136.397 - * whether {@link java.lang.Character#digit(char, int)} returns a
136.398 - * nonnegative value), except that the first character may be an
136.399 - * ASCII minus sign {@code '-'} (<code>'\u002D'</code>) to
136.400 - * indicate a negative value or an ASCII plus sign {@code '+'}
136.401 - * (<code>'\u002B'</code>) to indicate a positive value. The
136.402 - * resulting integer value is returned.
136.403 - *
136.404 - * <p>An exception of type {@code NumberFormatException} is
136.405 - * thrown if any of the following situations occurs:
136.406 - * <ul>
136.407 - * <li>The first argument is {@code null} or is a string of
136.408 - * length zero.
136.409 - *
136.410 - * <li>The radix is either smaller than
136.411 - * {@link java.lang.Character#MIN_RADIX} or
136.412 - * larger than {@link java.lang.Character#MAX_RADIX}.
136.413 - *
136.414 - * <li>Any character of the string is not a digit of the specified
136.415 - * radix, except that the first character may be a minus sign
136.416 - * {@code '-'} (<code>'\u002D'</code>) or plus sign
136.417 - * {@code '+'} (<code>'\u002B'</code>) provided that the
136.418 - * string is longer than length 1.
136.419 - *
136.420 - * <li>The value represented by the string is not a value of type
136.421 - * {@code int}.
136.422 - * </ul>
136.423 - *
136.424 - * <p>Examples:
136.425 - * <blockquote><pre>
136.426 - * parseInt("0", 10) returns 0
136.427 - * parseInt("473", 10) returns 473
136.428 - * parseInt("+42", 10) returns 42
136.429 - * parseInt("-0", 10) returns 0
136.430 - * parseInt("-FF", 16) returns -255
136.431 - * parseInt("1100110", 2) returns 102
136.432 - * parseInt("2147483647", 10) returns 2147483647
136.433 - * parseInt("-2147483648", 10) returns -2147483648
136.434 - * parseInt("2147483648", 10) throws a NumberFormatException
136.435 - * parseInt("99", 8) throws a NumberFormatException
136.436 - * parseInt("Kona", 10) throws a NumberFormatException
136.437 - * parseInt("Kona", 27) returns 411787
136.438 - * </pre></blockquote>
136.439 - *
136.440 - * @param s the {@code String} containing the integer
136.441 - * representation to be parsed
136.442 - * @param radix the radix to be used while parsing {@code s}.
136.443 - * @return the integer represented by the string argument in the
136.444 - * specified radix.
136.445 - * @exception NumberFormatException if the {@code String}
136.446 - * does not contain a parsable {@code int}.
136.447 - */
136.448 - @JavaScriptBody(args={"s", "radix"}, body="return parseInt(s,radix);")
136.449 - public static int parseInt(String s, int radix)
136.450 - throws NumberFormatException
136.451 - {
136.452 - /*
136.453 - * WARNING: This method may be invoked early during VM initialization
136.454 - * before IntegerCache is initialized. Care must be taken to not use
136.455 - * the valueOf method.
136.456 - */
136.457 -
136.458 - if (s == null) {
136.459 - throw new NumberFormatException("null");
136.460 - }
136.461 -
136.462 - if (radix < Character.MIN_RADIX) {
136.463 - throw new NumberFormatException("radix " + radix +
136.464 - " less than Character.MIN_RADIX");
136.465 - }
136.466 -
136.467 - if (radix > Character.MAX_RADIX) {
136.468 - throw new NumberFormatException("radix " + radix +
136.469 - " greater than Character.MAX_RADIX");
136.470 - }
136.471 -
136.472 - int result = 0;
136.473 - boolean negative = false;
136.474 - int i = 0, len = s.length();
136.475 - int limit = -Integer.MAX_VALUE;
136.476 - int multmin;
136.477 - int digit;
136.478 -
136.479 - if (len > 0) {
136.480 - char firstChar = s.charAt(0);
136.481 - if (firstChar < '0') { // Possible leading "+" or "-"
136.482 - if (firstChar == '-') {
136.483 - negative = true;
136.484 - limit = Integer.MIN_VALUE;
136.485 - } else if (firstChar != '+')
136.486 - throw NumberFormatException.forInputString(s);
136.487 -
136.488 - if (len == 1) // Cannot have lone "+" or "-"
136.489 - throw NumberFormatException.forInputString(s);
136.490 - i++;
136.491 - }
136.492 - multmin = limit / radix;
136.493 - while (i < len) {
136.494 - // Accumulating negatively avoids surprises near MAX_VALUE
136.495 - digit = Character.digit(s.charAt(i++),radix);
136.496 - if (digit < 0) {
136.497 - throw NumberFormatException.forInputString(s);
136.498 - }
136.499 - if (result < multmin) {
136.500 - throw NumberFormatException.forInputString(s);
136.501 - }
136.502 - result *= radix;
136.503 - if (result < limit + digit) {
136.504 - throw NumberFormatException.forInputString(s);
136.505 - }
136.506 - result -= digit;
136.507 - }
136.508 - } else {
136.509 - throw NumberFormatException.forInputString(s);
136.510 - }
136.511 - return negative ? result : -result;
136.512 - }
136.513 -
136.514 - /**
136.515 - * Parses the string argument as a signed decimal integer. The
136.516 - * characters in the string must all be decimal digits, except
136.517 - * that the first character may be an ASCII minus sign {@code '-'}
136.518 - * (<code>'\u002D'</code>) to indicate a negative value or an
136.519 - * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
136.520 - * indicate a positive value. The resulting integer value is
136.521 - * returned, exactly as if the argument and the radix 10 were
136.522 - * given as arguments to the {@link #parseInt(java.lang.String,
136.523 - * int)} method.
136.524 - *
136.525 - * @param s a {@code String} containing the {@code int}
136.526 - * representation to be parsed
136.527 - * @return the integer value represented by the argument in decimal.
136.528 - * @exception NumberFormatException if the string does not contain a
136.529 - * parsable integer.
136.530 - */
136.531 - public static int parseInt(String s) throws NumberFormatException {
136.532 - return parseInt(s,10);
136.533 - }
136.534 -
136.535 - /**
136.536 - * Returns an {@code Integer} object holding the value
136.537 - * extracted from the specified {@code String} when parsed
136.538 - * with the radix given by the second argument. The first argument
136.539 - * is interpreted as representing a signed integer in the radix
136.540 - * specified by the second argument, exactly as if the arguments
136.541 - * were given to the {@link #parseInt(java.lang.String, int)}
136.542 - * method. The result is an {@code Integer} object that
136.543 - * represents the integer value specified by the string.
136.544 - *
136.545 - * <p>In other words, this method returns an {@code Integer}
136.546 - * object equal to the value of:
136.547 - *
136.548 - * <blockquote>
136.549 - * {@code new Integer(Integer.parseInt(s, radix))}
136.550 - * </blockquote>
136.551 - *
136.552 - * @param s the string to be parsed.
136.553 - * @param radix the radix to be used in interpreting {@code s}
136.554 - * @return an {@code Integer} object holding the value
136.555 - * represented by the string argument in the specified
136.556 - * radix.
136.557 - * @exception NumberFormatException if the {@code String}
136.558 - * does not contain a parsable {@code int}.
136.559 - */
136.560 - public static Integer valueOf(String s, int radix) throws NumberFormatException {
136.561 - return Integer.valueOf(parseInt(s,radix));
136.562 - }
136.563 -
136.564 - /**
136.565 - * Returns an {@code Integer} object holding the
136.566 - * value of the specified {@code String}. The argument is
136.567 - * interpreted as representing a signed decimal integer, exactly
136.568 - * as if the argument were given to the {@link
136.569 - * #parseInt(java.lang.String)} method. The result is an
136.570 - * {@code Integer} object that represents the integer value
136.571 - * specified by the string.
136.572 - *
136.573 - * <p>In other words, this method returns an {@code Integer}
136.574 - * object equal to the value of:
136.575 - *
136.576 - * <blockquote>
136.577 - * {@code new Integer(Integer.parseInt(s))}
136.578 - * </blockquote>
136.579 - *
136.580 - * @param s the string to be parsed.
136.581 - * @return an {@code Integer} object holding the value
136.582 - * represented by the string argument.
136.583 - * @exception NumberFormatException if the string cannot be parsed
136.584 - * as an integer.
136.585 - */
136.586 - public static Integer valueOf(String s) throws NumberFormatException {
136.587 - return Integer.valueOf(parseInt(s, 10));
136.588 - }
136.589 -
136.590 - /**
136.591 - * Cache to support the object identity semantics of autoboxing for values between
136.592 - * -128 and 127 (inclusive) as required by JLS.
136.593 - *
136.594 - * The cache is initialized on first usage. The size of the cache
136.595 - * may be controlled by the -XX:AutoBoxCacheMax=<size> option.
136.596 - * During VM initialization, java.lang.Integer.IntegerCache.high property
136.597 - * may be set and saved in the private system properties in the
136.598 - * sun.misc.VM class.
136.599 - */
136.600 -
136.601 - private static class IntegerCache {
136.602 - static final int low = -128;
136.603 - static final int high;
136.604 - static final Integer cache[];
136.605 -
136.606 - static {
136.607 - // high value may be configured by property
136.608 - int h = 127;
136.609 - String integerCacheHighPropValue =
136.610 - AbstractStringBuilder.getProperty("java.lang.Integer.IntegerCache.high");
136.611 - if (integerCacheHighPropValue != null) {
136.612 - int i = parseInt(integerCacheHighPropValue);
136.613 - i = Math.max(i, 127);
136.614 - // Maximum array size is Integer.MAX_VALUE
136.615 - h = Math.min(i, Integer.MAX_VALUE - (-low));
136.616 - }
136.617 - high = h;
136.618 -
136.619 - cache = new Integer[(high - low) + 1];
136.620 - int j = low;
136.621 - for(int k = 0; k < cache.length; k++)
136.622 - cache[k] = new Integer(j++);
136.623 - }
136.624 -
136.625 - private IntegerCache() {}
136.626 - }
136.627 -
136.628 - /**
136.629 - * Returns an {@code Integer} instance representing the specified
136.630 - * {@code int} value. If a new {@code Integer} instance is not
136.631 - * required, this method should generally be used in preference to
136.632 - * the constructor {@link #Integer(int)}, as this method is likely
136.633 - * to yield significantly better space and time performance by
136.634 - * caching frequently requested values.
136.635 - *
136.636 - * This method will always cache values in the range -128 to 127,
136.637 - * inclusive, and may cache other values outside of this range.
136.638 - *
136.639 - * @param i an {@code int} value.
136.640 - * @return an {@code Integer} instance representing {@code i}.
136.641 - * @since 1.5
136.642 - */
136.643 - public static Integer valueOf(int i) {
136.644 - //assert IntegerCache.high >= 127;
136.645 - if (i >= IntegerCache.low && i <= IntegerCache.high)
136.646 - return IntegerCache.cache[i + (-IntegerCache.low)];
136.647 - return new Integer(i);
136.648 - }
136.649 -
136.650 - /**
136.651 - * The value of the {@code Integer}.
136.652 - *
136.653 - * @serial
136.654 - */
136.655 - private final int value;
136.656 -
136.657 - /**
136.658 - * Constructs a newly allocated {@code Integer} object that
136.659 - * represents the specified {@code int} value.
136.660 - *
136.661 - * @param value the value to be represented by the
136.662 - * {@code Integer} object.
136.663 - */
136.664 - public Integer(int value) {
136.665 - this.value = value;
136.666 - }
136.667 -
136.668 - /**
136.669 - * Constructs a newly allocated {@code Integer} object that
136.670 - * represents the {@code int} value indicated by the
136.671 - * {@code String} parameter. The string is converted to an
136.672 - * {@code int} value in exactly the manner used by the
136.673 - * {@code parseInt} method for radix 10.
136.674 - *
136.675 - * @param s the {@code String} to be converted to an
136.676 - * {@code Integer}.
136.677 - * @exception NumberFormatException if the {@code String} does not
136.678 - * contain a parsable integer.
136.679 - * @see java.lang.Integer#parseInt(java.lang.String, int)
136.680 - */
136.681 - public Integer(String s) throws NumberFormatException {
136.682 - this.value = parseInt(s, 10);
136.683 - }
136.684 -
136.685 - /**
136.686 - * Returns the value of this {@code Integer} as a
136.687 - * {@code byte}.
136.688 - */
136.689 - public byte byteValue() {
136.690 - return (byte)value;
136.691 - }
136.692 -
136.693 - /**
136.694 - * Returns the value of this {@code Integer} as a
136.695 - * {@code short}.
136.696 - */
136.697 - public short shortValue() {
136.698 - return (short)value;
136.699 - }
136.700 -
136.701 - /**
136.702 - * Returns the value of this {@code Integer} as an
136.703 - * {@code int}.
136.704 - */
136.705 - public int intValue() {
136.706 - return value;
136.707 - }
136.708 -
136.709 - /**
136.710 - * Returns the value of this {@code Integer} as a
136.711 - * {@code long}.
136.712 - */
136.713 - public long longValue() {
136.714 - return (long)value;
136.715 - }
136.716 -
136.717 - /**
136.718 - * Returns the value of this {@code Integer} as a
136.719 - * {@code float}.
136.720 - */
136.721 - public float floatValue() {
136.722 - return (float)value;
136.723 - }
136.724 -
136.725 - /**
136.726 - * Returns the value of this {@code Integer} as a
136.727 - * {@code double}.
136.728 - */
136.729 - public double doubleValue() {
136.730 - return (double)value;
136.731 - }
136.732 -
136.733 - /**
136.734 - * Returns a {@code String} object representing this
136.735 - * {@code Integer}'s value. The value is converted to signed
136.736 - * decimal representation and returned as a string, exactly as if
136.737 - * the integer value were given as an argument to the {@link
136.738 - * java.lang.Integer#toString(int)} method.
136.739 - *
136.740 - * @return a string representation of the value of this object in
136.741 - * base 10.
136.742 - */
136.743 - public String toString() {
136.744 - return toString(value);
136.745 - }
136.746 -
136.747 - /**
136.748 - * Returns a hash code for this {@code Integer}.
136.749 - *
136.750 - * @return a hash code value for this object, equal to the
136.751 - * primitive {@code int} value represented by this
136.752 - * {@code Integer} object.
136.753 - */
136.754 - public int hashCode() {
136.755 - return value;
136.756 - }
136.757 -
136.758 - /**
136.759 - * Compares this object to the specified object. The result is
136.760 - * {@code true} if and only if the argument is not
136.761 - * {@code null} and is an {@code Integer} object that
136.762 - * contains the same {@code int} value as this object.
136.763 - *
136.764 - * @param obj the object to compare with.
136.765 - * @return {@code true} if the objects are the same;
136.766 - * {@code false} otherwise.
136.767 - */
136.768 - public boolean equals(Object obj) {
136.769 - if (obj instanceof Integer) {
136.770 - return value == ((Integer)obj).intValue();
136.771 - }
136.772 - return false;
136.773 - }
136.774 -
136.775 - /**
136.776 - * Determines the integer value of the system property with the
136.777 - * specified name.
136.778 - *
136.779 - * <p>The first argument is treated as the name of a system property.
136.780 - * System properties are accessible through the
136.781 - * {@link java.lang.System#getProperty(java.lang.String)} method. The
136.782 - * string value of this property is then interpreted as an integer
136.783 - * value and an {@code Integer} object representing this value is
136.784 - * returned. Details of possible numeric formats can be found with
136.785 - * the definition of {@code getProperty}.
136.786 - *
136.787 - * <p>If there is no property with the specified name, if the specified name
136.788 - * is empty or {@code null}, or if the property does not have
136.789 - * the correct numeric format, then {@code null} is returned.
136.790 - *
136.791 - * <p>In other words, this method returns an {@code Integer}
136.792 - * object equal to the value of:
136.793 - *
136.794 - * <blockquote>
136.795 - * {@code getInteger(nm, null)}
136.796 - * </blockquote>
136.797 - *
136.798 - * @param nm property name.
136.799 - * @return the {@code Integer} value of the property.
136.800 - * @see java.lang.System#getProperty(java.lang.String)
136.801 - * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
136.802 - */
136.803 - public static Integer getInteger(String nm) {
136.804 - return getInteger(nm, null);
136.805 - }
136.806 -
136.807 - /**
136.808 - * Determines the integer value of the system property with the
136.809 - * specified name.
136.810 - *
136.811 - * <p>The first argument is treated as the name of a system property.
136.812 - * System properties are accessible through the {@link
136.813 - * java.lang.System#getProperty(java.lang.String)} method. The
136.814 - * string value of this property is then interpreted as an integer
136.815 - * value and an {@code Integer} object representing this value is
136.816 - * returned. Details of possible numeric formats can be found with
136.817 - * the definition of {@code getProperty}.
136.818 - *
136.819 - * <p>The second argument is the default value. An {@code Integer} object
136.820 - * that represents the value of the second argument is returned if there
136.821 - * is no property of the specified name, if the property does not have
136.822 - * the correct numeric format, or if the specified name is empty or
136.823 - * {@code null}.
136.824 - *
136.825 - * <p>In other words, this method returns an {@code Integer} object
136.826 - * equal to the value of:
136.827 - *
136.828 - * <blockquote>
136.829 - * {@code getInteger(nm, new Integer(val))}
136.830 - * </blockquote>
136.831 - *
136.832 - * but in practice it may be implemented in a manner such as:
136.833 - *
136.834 - * <blockquote><pre>
136.835 - * Integer result = getInteger(nm, null);
136.836 - * return (result == null) ? new Integer(val) : result;
136.837 - * </pre></blockquote>
136.838 - *
136.839 - * to avoid the unnecessary allocation of an {@code Integer}
136.840 - * object when the default value is not needed.
136.841 - *
136.842 - * @param nm property name.
136.843 - * @param val default value.
136.844 - * @return the {@code Integer} value of the property.
136.845 - * @see java.lang.System#getProperty(java.lang.String)
136.846 - * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
136.847 - */
136.848 - public static Integer getInteger(String nm, int val) {
136.849 - Integer result = getInteger(nm, null);
136.850 - return (result == null) ? Integer.valueOf(val) : result;
136.851 - }
136.852 -
136.853 - /**
136.854 - * Returns the integer value of the system property with the
136.855 - * specified name. The first argument is treated as the name of a
136.856 - * system property. System properties are accessible through the
136.857 - * {@link java.lang.System#getProperty(java.lang.String)} method.
136.858 - * The string value of this property is then interpreted as an
136.859 - * integer value, as per the {@code Integer.decode} method,
136.860 - * and an {@code Integer} object representing this value is
136.861 - * returned.
136.862 - *
136.863 - * <ul><li>If the property value begins with the two ASCII characters
136.864 - * {@code 0x} or the ASCII character {@code #}, not
136.865 - * followed by a minus sign, then the rest of it is parsed as a
136.866 - * hexadecimal integer exactly as by the method
136.867 - * {@link #valueOf(java.lang.String, int)} with radix 16.
136.868 - * <li>If the property value begins with the ASCII character
136.869 - * {@code 0} followed by another character, it is parsed as an
136.870 - * octal integer exactly as by the method
136.871 - * {@link #valueOf(java.lang.String, int)} with radix 8.
136.872 - * <li>Otherwise, the property value is parsed as a decimal integer
136.873 - * exactly as by the method {@link #valueOf(java.lang.String, int)}
136.874 - * with radix 10.
136.875 - * </ul>
136.876 - *
136.877 - * <p>The second argument is the default value. The default value is
136.878 - * returned if there is no property of the specified name, if the
136.879 - * property does not have the correct numeric format, or if the
136.880 - * specified name is empty or {@code null}.
136.881 - *
136.882 - * @param nm property name.
136.883 - * @param val default value.
136.884 - * @return the {@code Integer} value of the property.
136.885 - * @see java.lang.System#getProperty(java.lang.String)
136.886 - * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
136.887 - * @see java.lang.Integer#decode
136.888 - */
136.889 - public static Integer getInteger(String nm, Integer val) {
136.890 - String v = null;
136.891 - try {
136.892 - v = AbstractStringBuilder.getProperty(nm);
136.893 - } catch (IllegalArgumentException e) {
136.894 - } catch (NullPointerException e) {
136.895 - }
136.896 - if (v != null) {
136.897 - try {
136.898 - return Integer.decode(v);
136.899 - } catch (NumberFormatException e) {
136.900 - }
136.901 - }
136.902 - return val;
136.903 - }
136.904 -
136.905 - /**
136.906 - * Decodes a {@code String} into an {@code Integer}.
136.907 - * Accepts decimal, hexadecimal, and octal numbers given
136.908 - * by the following grammar:
136.909 - *
136.910 - * <blockquote>
136.911 - * <dl>
136.912 - * <dt><i>DecodableString:</i>
136.913 - * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
136.914 - * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
136.915 - * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
136.916 - * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
136.917 - * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
136.918 - * <p>
136.919 - * <dt><i>Sign:</i>
136.920 - * <dd>{@code -}
136.921 - * <dd>{@code +}
136.922 - * </dl>
136.923 - * </blockquote>
136.924 - *
136.925 - * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
136.926 - * are as defined in section 3.10.1 of
136.927 - * <cite>The Java™ Language Specification</cite>,
136.928 - * except that underscores are not accepted between digits.
136.929 - *
136.930 - * <p>The sequence of characters following an optional
136.931 - * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
136.932 - * "{@code #}", or leading zero) is parsed as by the {@code
136.933 - * Integer.parseInt} method with the indicated radix (10, 16, or
136.934 - * 8). This sequence of characters must represent a positive
136.935 - * value or a {@link NumberFormatException} will be thrown. The
136.936 - * result is negated if first character of the specified {@code
136.937 - * String} is the minus sign. No whitespace characters are
136.938 - * permitted in the {@code String}.
136.939 - *
136.940 - * @param nm the {@code String} to decode.
136.941 - * @return an {@code Integer} object holding the {@code int}
136.942 - * value represented by {@code nm}
136.943 - * @exception NumberFormatException if the {@code String} does not
136.944 - * contain a parsable integer.
136.945 - * @see java.lang.Integer#parseInt(java.lang.String, int)
136.946 - */
136.947 - public static Integer decode(String nm) throws NumberFormatException {
136.948 - int radix = 10;
136.949 - int index = 0;
136.950 - boolean negative = false;
136.951 - Integer result;
136.952 -
136.953 - if (nm.length() == 0)
136.954 - throw new NumberFormatException("Zero length string");
136.955 - char firstChar = nm.charAt(0);
136.956 - // Handle sign, if present
136.957 - if (firstChar == '-') {
136.958 - negative = true;
136.959 - index++;
136.960 - } else if (firstChar == '+')
136.961 - index++;
136.962 -
136.963 - // Handle radix specifier, if present
136.964 - if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
136.965 - index += 2;
136.966 - radix = 16;
136.967 - }
136.968 - else if (nm.startsWith("#", index)) {
136.969 - index ++;
136.970 - radix = 16;
136.971 - }
136.972 - else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
136.973 - index ++;
136.974 - radix = 8;
136.975 - }
136.976 -
136.977 - if (nm.startsWith("-", index) || nm.startsWith("+", index))
136.978 - throw new NumberFormatException("Sign character in wrong position");
136.979 -
136.980 - try {
136.981 - result = Integer.valueOf(nm.substring(index), radix);
136.982 - result = negative ? Integer.valueOf(-result.intValue()) : result;
136.983 - } catch (NumberFormatException e) {
136.984 - // If number is Integer.MIN_VALUE, we'll end up here. The next line
136.985 - // handles this case, and causes any genuine format error to be
136.986 - // rethrown.
136.987 - String constant = negative ? ("-" + nm.substring(index))
136.988 - : nm.substring(index);
136.989 - result = Integer.valueOf(constant, radix);
136.990 - }
136.991 - return result;
136.992 - }
136.993 -
136.994 - /**
136.995 - * Compares two {@code Integer} objects numerically.
136.996 - *
136.997 - * @param anotherInteger the {@code Integer} to be compared.
136.998 - * @return the value {@code 0} if this {@code Integer} is
136.999 - * equal to the argument {@code Integer}; a value less than
136.1000 - * {@code 0} if this {@code Integer} is numerically less
136.1001 - * than the argument {@code Integer}; and a value greater
136.1002 - * than {@code 0} if this {@code Integer} is numerically
136.1003 - * greater than the argument {@code Integer} (signed
136.1004 - * comparison).
136.1005 - * @since 1.2
136.1006 - */
136.1007 - public int compareTo(Integer anotherInteger) {
136.1008 - return compare(this.value, anotherInteger.value);
136.1009 - }
136.1010 -
136.1011 - /**
136.1012 - * Compares two {@code int} values numerically.
136.1013 - * The value returned is identical to what would be returned by:
136.1014 - * <pre>
136.1015 - * Integer.valueOf(x).compareTo(Integer.valueOf(y))
136.1016 - * </pre>
136.1017 - *
136.1018 - * @param x the first {@code int} to compare
136.1019 - * @param y the second {@code int} to compare
136.1020 - * @return the value {@code 0} if {@code x == y};
136.1021 - * a value less than {@code 0} if {@code x < y}; and
136.1022 - * a value greater than {@code 0} if {@code x > y}
136.1023 - * @since 1.7
136.1024 - */
136.1025 - public static int compare(int x, int y) {
136.1026 - return (x < y) ? -1 : ((x == y) ? 0 : 1);
136.1027 - }
136.1028 -
136.1029 -
136.1030 - // Bit twiddling
136.1031 -
136.1032 - /**
136.1033 - * The number of bits used to represent an {@code int} value in two's
136.1034 - * complement binary form.
136.1035 - *
136.1036 - * @since 1.5
136.1037 - */
136.1038 - public static final int SIZE = 32;
136.1039 -
136.1040 - /**
136.1041 - * Returns an {@code int} value with at most a single one-bit, in the
136.1042 - * position of the highest-order ("leftmost") one-bit in the specified
136.1043 - * {@code int} value. Returns zero if the specified value has no
136.1044 - * one-bits in its two's complement binary representation, that is, if it
136.1045 - * is equal to zero.
136.1046 - *
136.1047 - * @return an {@code int} value with a single one-bit, in the position
136.1048 - * of the highest-order one-bit in the specified value, or zero if
136.1049 - * the specified value is itself equal to zero.
136.1050 - * @since 1.5
136.1051 - */
136.1052 - public static int highestOneBit(int i) {
136.1053 - // HD, Figure 3-1
136.1054 - i |= (i >> 1);
136.1055 - i |= (i >> 2);
136.1056 - i |= (i >> 4);
136.1057 - i |= (i >> 8);
136.1058 - i |= (i >> 16);
136.1059 - return i - (i >>> 1);
136.1060 - }
136.1061 -
136.1062 - /**
136.1063 - * Returns an {@code int} value with at most a single one-bit, in the
136.1064 - * position of the lowest-order ("rightmost") one-bit in the specified
136.1065 - * {@code int} value. Returns zero if the specified value has no
136.1066 - * one-bits in its two's complement binary representation, that is, if it
136.1067 - * is equal to zero.
136.1068 - *
136.1069 - * @return an {@code int} value with a single one-bit, in the position
136.1070 - * of the lowest-order one-bit in the specified value, or zero if
136.1071 - * the specified value is itself equal to zero.
136.1072 - * @since 1.5
136.1073 - */
136.1074 - public static int lowestOneBit(int i) {
136.1075 - // HD, Section 2-1
136.1076 - return i & -i;
136.1077 - }
136.1078 -
136.1079 - /**
136.1080 - * Returns the number of zero bits preceding the highest-order
136.1081 - * ("leftmost") one-bit in the two's complement binary representation
136.1082 - * of the specified {@code int} value. Returns 32 if the
136.1083 - * specified value has no one-bits in its two's complement representation,
136.1084 - * in other words if it is equal to zero.
136.1085 - *
136.1086 - * <p>Note that this method is closely related to the logarithm base 2.
136.1087 - * For all positive {@code int} values x:
136.1088 - * <ul>
136.1089 - * <li>floor(log<sub>2</sub>(x)) = {@code 31 - numberOfLeadingZeros(x)}
136.1090 - * <li>ceil(log<sub>2</sub>(x)) = {@code 32 - numberOfLeadingZeros(x - 1)}
136.1091 - * </ul>
136.1092 - *
136.1093 - * @return the number of zero bits preceding the highest-order
136.1094 - * ("leftmost") one-bit in the two's complement binary representation
136.1095 - * of the specified {@code int} value, or 32 if the value
136.1096 - * is equal to zero.
136.1097 - * @since 1.5
136.1098 - */
136.1099 - public static int numberOfLeadingZeros(int i) {
136.1100 - // HD, Figure 5-6
136.1101 - if (i == 0)
136.1102 - return 32;
136.1103 - int n = 1;
136.1104 - if (i >>> 16 == 0) { n += 16; i <<= 16; }
136.1105 - if (i >>> 24 == 0) { n += 8; i <<= 8; }
136.1106 - if (i >>> 28 == 0) { n += 4; i <<= 4; }
136.1107 - if (i >>> 30 == 0) { n += 2; i <<= 2; }
136.1108 - n -= i >>> 31;
136.1109 - return n;
136.1110 - }
136.1111 -
136.1112 - /**
136.1113 - * Returns the number of zero bits following the lowest-order ("rightmost")
136.1114 - * one-bit in the two's complement binary representation of the specified
136.1115 - * {@code int} value. Returns 32 if the specified value has no
136.1116 - * one-bits in its two's complement representation, in other words if it is
136.1117 - * equal to zero.
136.1118 - *
136.1119 - * @return the number of zero bits following the lowest-order ("rightmost")
136.1120 - * one-bit in the two's complement binary representation of the
136.1121 - * specified {@code int} value, or 32 if the value is equal
136.1122 - * to zero.
136.1123 - * @since 1.5
136.1124 - */
136.1125 - public static int numberOfTrailingZeros(int i) {
136.1126 - // HD, Figure 5-14
136.1127 - int y;
136.1128 - if (i == 0) return 32;
136.1129 - int n = 31;
136.1130 - y = i <<16; if (y != 0) { n = n -16; i = y; }
136.1131 - y = i << 8; if (y != 0) { n = n - 8; i = y; }
136.1132 - y = i << 4; if (y != 0) { n = n - 4; i = y; }
136.1133 - y = i << 2; if (y != 0) { n = n - 2; i = y; }
136.1134 - return n - ((i << 1) >>> 31);
136.1135 - }
136.1136 -
136.1137 - /**
136.1138 - * Returns the number of one-bits in the two's complement binary
136.1139 - * representation of the specified {@code int} value. This function is
136.1140 - * sometimes referred to as the <i>population count</i>.
136.1141 - *
136.1142 - * @return the number of one-bits in the two's complement binary
136.1143 - * representation of the specified {@code int} value.
136.1144 - * @since 1.5
136.1145 - */
136.1146 - public static int bitCount(int i) {
136.1147 - // HD, Figure 5-2
136.1148 - i = i - ((i >>> 1) & 0x55555555);
136.1149 - i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
136.1150 - i = (i + (i >>> 4)) & 0x0f0f0f0f;
136.1151 - i = i + (i >>> 8);
136.1152 - i = i + (i >>> 16);
136.1153 - return i & 0x3f;
136.1154 - }
136.1155 -
136.1156 - /**
136.1157 - * Returns the value obtained by rotating the two's complement binary
136.1158 - * representation of the specified {@code int} value left by the
136.1159 - * specified number of bits. (Bits shifted out of the left hand, or
136.1160 - * high-order, side reenter on the right, or low-order.)
136.1161 - *
136.1162 - * <p>Note that left rotation with a negative distance is equivalent to
136.1163 - * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
136.1164 - * distance)}. Note also that rotation by any multiple of 32 is a
136.1165 - * no-op, so all but the last five bits of the rotation distance can be
136.1166 - * ignored, even if the distance is negative: {@code rotateLeft(val,
136.1167 - * distance) == rotateLeft(val, distance & 0x1F)}.
136.1168 - *
136.1169 - * @return the value obtained by rotating the two's complement binary
136.1170 - * representation of the specified {@code int} value left by the
136.1171 - * specified number of bits.
136.1172 - * @since 1.5
136.1173 - */
136.1174 - public static int rotateLeft(int i, int distance) {
136.1175 - return (i << distance) | (i >>> -distance);
136.1176 - }
136.1177 -
136.1178 - /**
136.1179 - * Returns the value obtained by rotating the two's complement binary
136.1180 - * representation of the specified {@code int} value right by the
136.1181 - * specified number of bits. (Bits shifted out of the right hand, or
136.1182 - * low-order, side reenter on the left, or high-order.)
136.1183 - *
136.1184 - * <p>Note that right rotation with a negative distance is equivalent to
136.1185 - * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
136.1186 - * distance)}. Note also that rotation by any multiple of 32 is a
136.1187 - * no-op, so all but the last five bits of the rotation distance can be
136.1188 - * ignored, even if the distance is negative: {@code rotateRight(val,
136.1189 - * distance) == rotateRight(val, distance & 0x1F)}.
136.1190 - *
136.1191 - * @return the value obtained by rotating the two's complement binary
136.1192 - * representation of the specified {@code int} value right by the
136.1193 - * specified number of bits.
136.1194 - * @since 1.5
136.1195 - */
136.1196 - public static int rotateRight(int i, int distance) {
136.1197 - return (i >>> distance) | (i << -distance);
136.1198 - }
136.1199 -
136.1200 - /**
136.1201 - * Returns the value obtained by reversing the order of the bits in the
136.1202 - * two's complement binary representation of the specified {@code int}
136.1203 - * value.
136.1204 - *
136.1205 - * @return the value obtained by reversing order of the bits in the
136.1206 - * specified {@code int} value.
136.1207 - * @since 1.5
136.1208 - */
136.1209 - public static int reverse(int i) {
136.1210 - // HD, Figure 7-1
136.1211 - i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;
136.1212 - i = (i & 0x33333333) << 2 | (i >>> 2) & 0x33333333;
136.1213 - i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;
136.1214 - i = (i << 24) | ((i & 0xff00) << 8) |
136.1215 - ((i >>> 8) & 0xff00) | (i >>> 24);
136.1216 - return i;
136.1217 - }
136.1218 -
136.1219 - /**
136.1220 - * Returns the signum function of the specified {@code int} value. (The
136.1221 - * return value is -1 if the specified value is negative; 0 if the
136.1222 - * specified value is zero; and 1 if the specified value is positive.)
136.1223 - *
136.1224 - * @return the signum function of the specified {@code int} value.
136.1225 - * @since 1.5
136.1226 - */
136.1227 - public static int signum(int i) {
136.1228 - // HD, Section 2-7
136.1229 - return (i >> 31) | (-i >>> 31);
136.1230 - }
136.1231 -
136.1232 - /**
136.1233 - * Returns the value obtained by reversing the order of the bytes in the
136.1234 - * two's complement representation of the specified {@code int} value.
136.1235 - *
136.1236 - * @return the value obtained by reversing the bytes in the specified
136.1237 - * {@code int} value.
136.1238 - * @since 1.5
136.1239 - */
136.1240 - public static int reverseBytes(int i) {
136.1241 - return ((i >>> 24) ) |
136.1242 - ((i >> 8) & 0xFF00) |
136.1243 - ((i << 8) & 0xFF0000) |
136.1244 - ((i << 24));
136.1245 - }
136.1246 -
136.1247 - /** use serialVersionUID from JDK 1.0.2 for interoperability */
136.1248 - private static final long serialVersionUID = 1360826667806852920L;
136.1249 -}
137.1 --- a/emul/src/main/java/java/lang/InterruptedException.java Wed Jan 23 20:16:48 2013 +0100
137.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
137.3 @@ -1,69 +0,0 @@
137.4 -/*
137.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
137.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
137.7 - *
137.8 - * This code is free software; you can redistribute it and/or modify it
137.9 - * under the terms of the GNU General Public License version 2 only, as
137.10 - * published by the Free Software Foundation. Oracle designates this
137.11 - * particular file as subject to the "Classpath" exception as provided
137.12 - * by Oracle in the LICENSE file that accompanied this code.
137.13 - *
137.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
137.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
137.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
137.17 - * version 2 for more details (a copy is included in the LICENSE file that
137.18 - * accompanied this code).
137.19 - *
137.20 - * You should have received a copy of the GNU General Public License version
137.21 - * 2 along with this work; if not, write to the Free Software Foundation,
137.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
137.23 - *
137.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
137.25 - * or visit www.oracle.com if you need additional information or have any
137.26 - * questions.
137.27 - */
137.28 -
137.29 -package java.lang;
137.30 -
137.31 -/**
137.32 - * Thrown when a thread is waiting, sleeping, or otherwise occupied,
137.33 - * and the thread is interrupted, either before or during the activity.
137.34 - * Occasionally a method may wish to test whether the current
137.35 - * thread has been interrupted, and if so, to immediately throw
137.36 - * this exception. The following code can be used to achieve
137.37 - * this effect:
137.38 - * <pre>
137.39 - * if (Thread.interrupted()) // Clears interrupted status!
137.40 - * throw new InterruptedException();
137.41 - * </pre>
137.42 - *
137.43 - * @author Frank Yellin
137.44 - * @see java.lang.Object#wait()
137.45 - * @see java.lang.Object#wait(long)
137.46 - * @see java.lang.Object#wait(long, int)
137.47 - * @see java.lang.Thread#sleep(long)
137.48 - * @see java.lang.Thread#interrupt()
137.49 - * @see java.lang.Thread#interrupted()
137.50 - * @since JDK1.0
137.51 - */
137.52 -public
137.53 -class InterruptedException extends Exception {
137.54 - private static final long serialVersionUID = 6700697376100628473L;
137.55 -
137.56 - /**
137.57 - * Constructs an <code>InterruptedException</code> with no detail message.
137.58 - */
137.59 - public InterruptedException() {
137.60 - super();
137.61 - }
137.62 -
137.63 - /**
137.64 - * Constructs an <code>InterruptedException</code> with the
137.65 - * specified detail message.
137.66 - *
137.67 - * @param s the detail message.
137.68 - */
137.69 - public InterruptedException(String s) {
137.70 - super(s);
137.71 - }
137.72 -}
138.1 --- a/emul/src/main/java/java/lang/LinkageError.java Wed Jan 23 20:16:48 2013 +0100
138.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
138.3 @@ -1,69 +0,0 @@
138.4 -/*
138.5 - * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
138.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
138.7 - *
138.8 - * This code is free software; you can redistribute it and/or modify it
138.9 - * under the terms of the GNU General Public License version 2 only, as
138.10 - * published by the Free Software Foundation. Oracle designates this
138.11 - * particular file as subject to the "Classpath" exception as provided
138.12 - * by Oracle in the LICENSE file that accompanied this code.
138.13 - *
138.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
138.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
138.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
138.17 - * version 2 for more details (a copy is included in the LICENSE file that
138.18 - * accompanied this code).
138.19 - *
138.20 - * You should have received a copy of the GNU General Public License version
138.21 - * 2 along with this work; if not, write to the Free Software Foundation,
138.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
138.23 - *
138.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
138.25 - * or visit www.oracle.com if you need additional information or have any
138.26 - * questions.
138.27 - */
138.28 -
138.29 -package java.lang;
138.30 -
138.31 -/**
138.32 - * Subclasses of {@code LinkageError} indicate that a class has
138.33 - * some dependency on another class; however, the latter class has
138.34 - * incompatibly changed after the compilation of the former class.
138.35 - *
138.36 - *
138.37 - * @author Frank Yellin
138.38 - * @since JDK1.0
138.39 - */
138.40 -public
138.41 -class LinkageError extends Error {
138.42 - private static final long serialVersionUID = 3579600108157160122L;
138.43 -
138.44 - /**
138.45 - * Constructs a {@code LinkageError} with no detail message.
138.46 - */
138.47 - public LinkageError() {
138.48 - super();
138.49 - }
138.50 -
138.51 - /**
138.52 - * Constructs a {@code LinkageError} with the specified detail
138.53 - * message.
138.54 - *
138.55 - * @param s the detail message.
138.56 - */
138.57 - public LinkageError(String s) {
138.58 - super(s);
138.59 - }
138.60 -
138.61 - /**
138.62 - * Constructs a {@code LinkageError} with the specified detail
138.63 - * message and cause.
138.64 - *
138.65 - * @param s the detail message.
138.66 - * @param cause the cause, may be {@code null}
138.67 - * @since 1.7
138.68 - */
138.69 - public LinkageError(String s, Throwable cause) {
138.70 - super(s, cause);
138.71 - }
138.72 -}
139.1 --- a/emul/src/main/java/java/lang/Long.java Wed Jan 23 20:16:48 2013 +0100
139.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
139.3 @@ -1,1202 +0,0 @@
139.4 -/*
139.5 - * Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
139.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
139.7 - *
139.8 - * This code is free software; you can redistribute it and/or modify it
139.9 - * under the terms of the GNU General Public License version 2 only, as
139.10 - * published by the Free Software Foundation. Oracle designates this
139.11 - * particular file as subject to the "Classpath" exception as provided
139.12 - * by Oracle in the LICENSE file that accompanied this code.
139.13 - *
139.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
139.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
139.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
139.17 - * version 2 for more details (a copy is included in the LICENSE file that
139.18 - * accompanied this code).
139.19 - *
139.20 - * You should have received a copy of the GNU General Public License version
139.21 - * 2 along with this work; if not, write to the Free Software Foundation,
139.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
139.23 - *
139.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
139.25 - * or visit www.oracle.com if you need additional information or have any
139.26 - * questions.
139.27 - */
139.28 -
139.29 -package java.lang;
139.30 -
139.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
139.32 -
139.33 -/**
139.34 - * The {@code Long} class wraps a value of the primitive type {@code
139.35 - * long} in an object. An object of type {@code Long} contains a
139.36 - * single field whose type is {@code long}.
139.37 - *
139.38 - * <p> In addition, this class provides several methods for converting
139.39 - * a {@code long} to a {@code String} and a {@code String} to a {@code
139.40 - * long}, as well as other constants and methods useful when dealing
139.41 - * with a {@code long}.
139.42 - *
139.43 - * <p>Implementation note: The implementations of the "bit twiddling"
139.44 - * methods (such as {@link #highestOneBit(long) highestOneBit} and
139.45 - * {@link #numberOfTrailingZeros(long) numberOfTrailingZeros}) are
139.46 - * based on material from Henry S. Warren, Jr.'s <i>Hacker's
139.47 - * Delight</i>, (Addison Wesley, 2002).
139.48 - *
139.49 - * @author Lee Boynton
139.50 - * @author Arthur van Hoff
139.51 - * @author Josh Bloch
139.52 - * @author Joseph D. Darcy
139.53 - * @since JDK1.0
139.54 - */
139.55 -public final class Long extends Number implements Comparable<Long> {
139.56 - /**
139.57 - * A constant holding the minimum value a {@code long} can
139.58 - * have, -2<sup>63</sup>.
139.59 - */
139.60 - public static final long MIN_VALUE = 0x8000000000000000L;
139.61 -
139.62 - /**
139.63 - * A constant holding the maximum value a {@code long} can
139.64 - * have, 2<sup>63</sup>-1.
139.65 - */
139.66 - public static final long MAX_VALUE = 0x7fffffffffffffffL;
139.67 -
139.68 - /**
139.69 - * The {@code Class} instance representing the primitive type
139.70 - * {@code long}.
139.71 - *
139.72 - * @since JDK1.1
139.73 - */
139.74 - public static final Class<Long> TYPE = (Class<Long>) Class.getPrimitiveClass("long");
139.75 -
139.76 - /**
139.77 - * Returns a string representation of the first argument in the
139.78 - * radix specified by the second argument.
139.79 - *
139.80 - * <p>If the radix is smaller than {@code Character.MIN_RADIX}
139.81 - * or larger than {@code Character.MAX_RADIX}, then the radix
139.82 - * {@code 10} is used instead.
139.83 - *
139.84 - * <p>If the first argument is negative, the first element of the
139.85 - * result is the ASCII minus sign {@code '-'}
139.86 - * (<code>'\u002d'</code>). If the first argument is not
139.87 - * negative, no sign character appears in the result.
139.88 - *
139.89 - * <p>The remaining characters of the result represent the magnitude
139.90 - * of the first argument. If the magnitude is zero, it is
139.91 - * represented by a single zero character {@code '0'}
139.92 - * (<code>'\u0030'</code>); otherwise, the first character of
139.93 - * the representation of the magnitude will not be the zero
139.94 - * character. The following ASCII characters are used as digits:
139.95 - *
139.96 - * <blockquote>
139.97 - * {@code 0123456789abcdefghijklmnopqrstuvwxyz}
139.98 - * </blockquote>
139.99 - *
139.100 - * These are <code>'\u0030'</code> through
139.101 - * <code>'\u0039'</code> and <code>'\u0061'</code> through
139.102 - * <code>'\u007a'</code>. If {@code radix} is
139.103 - * <var>N</var>, then the first <var>N</var> of these characters
139.104 - * are used as radix-<var>N</var> digits in the order shown. Thus,
139.105 - * the digits for hexadecimal (radix 16) are
139.106 - * {@code 0123456789abcdef}. If uppercase letters are
139.107 - * desired, the {@link java.lang.String#toUpperCase()} method may
139.108 - * be called on the result:
139.109 - *
139.110 - * <blockquote>
139.111 - * {@code Long.toString(n, 16).toUpperCase()}
139.112 - * </blockquote>
139.113 - *
139.114 - * @param i a {@code long} to be converted to a string.
139.115 - * @param radix the radix to use in the string representation.
139.116 - * @return a string representation of the argument in the specified radix.
139.117 - * @see java.lang.Character#MAX_RADIX
139.118 - * @see java.lang.Character#MIN_RADIX
139.119 - */
139.120 - public static String toString(long i, int radix) {
139.121 - if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
139.122 - radix = 10;
139.123 - if (radix == 10)
139.124 - return toString(i);
139.125 - char[] buf = new char[65];
139.126 - int charPos = 64;
139.127 - boolean negative = (i < 0);
139.128 -
139.129 - if (!negative) {
139.130 - i = -i;
139.131 - }
139.132 -
139.133 - while (i <= -radix) {
139.134 - buf[charPos--] = Integer.digits[(int)(-(i % radix))];
139.135 - i = i / radix;
139.136 - }
139.137 - buf[charPos] = Integer.digits[(int)(-i)];
139.138 -
139.139 - if (negative) {
139.140 - buf[--charPos] = '-';
139.141 - }
139.142 -
139.143 - return new String(buf, charPos, (65 - charPos));
139.144 - }
139.145 -
139.146 - /**
139.147 - * Returns a string representation of the {@code long}
139.148 - * argument as an unsigned integer in base 16.
139.149 - *
139.150 - * <p>The unsigned {@code long} value is the argument plus
139.151 - * 2<sup>64</sup> if the argument is negative; otherwise, it is
139.152 - * equal to the argument. This value is converted to a string of
139.153 - * ASCII digits in hexadecimal (base 16) with no extra
139.154 - * leading {@code 0}s. If the unsigned magnitude is zero, it
139.155 - * is represented by a single zero character {@code '0'}
139.156 - * (<code>'\u0030'</code>); otherwise, the first character of
139.157 - * the representation of the unsigned magnitude will not be the
139.158 - * zero character. The following characters are used as
139.159 - * hexadecimal digits:
139.160 - *
139.161 - * <blockquote>
139.162 - * {@code 0123456789abcdef}
139.163 - * </blockquote>
139.164 - *
139.165 - * These are the characters <code>'\u0030'</code> through
139.166 - * <code>'\u0039'</code> and <code>'\u0061'</code> through
139.167 - * <code>'\u0066'</code>. If uppercase letters are desired,
139.168 - * the {@link java.lang.String#toUpperCase()} method may be called
139.169 - * on the result:
139.170 - *
139.171 - * <blockquote>
139.172 - * {@code Long.toHexString(n).toUpperCase()}
139.173 - * </blockquote>
139.174 - *
139.175 - * @param i a {@code long} to be converted to a string.
139.176 - * @return the string representation of the unsigned {@code long}
139.177 - * value represented by the argument in hexadecimal
139.178 - * (base 16).
139.179 - * @since JDK 1.0.2
139.180 - */
139.181 - public static String toHexString(long i) {
139.182 - return toUnsignedString(i, 4);
139.183 - }
139.184 -
139.185 - /**
139.186 - * Returns a string representation of the {@code long}
139.187 - * argument as an unsigned integer in base 8.
139.188 - *
139.189 - * <p>The unsigned {@code long} value is the argument plus
139.190 - * 2<sup>64</sup> if the argument is negative; otherwise, it is
139.191 - * equal to the argument. This value is converted to a string of
139.192 - * ASCII digits in octal (base 8) with no extra leading
139.193 - * {@code 0}s.
139.194 - *
139.195 - * <p>If the unsigned magnitude is zero, it is represented by a
139.196 - * single zero character {@code '0'}
139.197 - * (<code>'\u0030'</code>); otherwise, the first character of
139.198 - * the representation of the unsigned magnitude will not be the
139.199 - * zero character. The following characters are used as octal
139.200 - * digits:
139.201 - *
139.202 - * <blockquote>
139.203 - * {@code 01234567}
139.204 - * </blockquote>
139.205 - *
139.206 - * These are the characters <code>'\u0030'</code> through
139.207 - * <code>'\u0037'</code>.
139.208 - *
139.209 - * @param i a {@code long} to be converted to a string.
139.210 - * @return the string representation of the unsigned {@code long}
139.211 - * value represented by the argument in octal (base 8).
139.212 - * @since JDK 1.0.2
139.213 - */
139.214 - public static String toOctalString(long i) {
139.215 - return toUnsignedString(i, 3);
139.216 - }
139.217 -
139.218 - /**
139.219 - * Returns a string representation of the {@code long}
139.220 - * argument as an unsigned integer in base 2.
139.221 - *
139.222 - * <p>The unsigned {@code long} value is the argument plus
139.223 - * 2<sup>64</sup> if the argument is negative; otherwise, it is
139.224 - * equal to the argument. This value is converted to a string of
139.225 - * ASCII digits in binary (base 2) with no extra leading
139.226 - * {@code 0}s. If the unsigned magnitude is zero, it is
139.227 - * represented by a single zero character {@code '0'}
139.228 - * (<code>'\u0030'</code>); otherwise, the first character of
139.229 - * the representation of the unsigned magnitude will not be the
139.230 - * zero character. The characters {@code '0'}
139.231 - * (<code>'\u0030'</code>) and {@code '1'}
139.232 - * (<code>'\u0031'</code>) are used as binary digits.
139.233 - *
139.234 - * @param i a {@code long} to be converted to a string.
139.235 - * @return the string representation of the unsigned {@code long}
139.236 - * value represented by the argument in binary (base 2).
139.237 - * @since JDK 1.0.2
139.238 - */
139.239 - public static String toBinaryString(long i) {
139.240 - return toUnsignedString(i, 1);
139.241 - }
139.242 -
139.243 - /**
139.244 - * Convert the integer to an unsigned number.
139.245 - */
139.246 - private static String toUnsignedString(long i, int shift) {
139.247 - char[] buf = new char[64];
139.248 - int charPos = 64;
139.249 - int radix = 1 << shift;
139.250 - long mask = radix - 1;
139.251 - do {
139.252 - buf[--charPos] = Integer.digits[(int)(i & mask)];
139.253 - i >>>= shift;
139.254 - } while (i != 0);
139.255 - return new String(buf, charPos, (64 - charPos));
139.256 - }
139.257 -
139.258 - /**
139.259 - * Returns a {@code String} object representing the specified
139.260 - * {@code long}. The argument is converted to signed decimal
139.261 - * representation and returned as a string, exactly as if the
139.262 - * argument and the radix 10 were given as arguments to the {@link
139.263 - * #toString(long, int)} method.
139.264 - *
139.265 - * @param i a {@code long} to be converted.
139.266 - * @return a string representation of the argument in base 10.
139.267 - */
139.268 - @JavaScriptBody(args = "i", body = "return i.toString();")
139.269 - public static String toString(long i) {
139.270 - if (i == Long.MIN_VALUE)
139.271 - return "-9223372036854775808";
139.272 - int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
139.273 - char[] buf = new char[size];
139.274 - getChars(i, size, buf);
139.275 - return new String(buf, 0, size);
139.276 - }
139.277 -
139.278 - /**
139.279 - * Places characters representing the integer i into the
139.280 - * character array buf. The characters are placed into
139.281 - * the buffer backwards starting with the least significant
139.282 - * digit at the specified index (exclusive), and working
139.283 - * backwards from there.
139.284 - *
139.285 - * Will fail if i == Long.MIN_VALUE
139.286 - */
139.287 - static void getChars(long i, int index, char[] buf) {
139.288 - long q;
139.289 - int r;
139.290 - int charPos = index;
139.291 - char sign = 0;
139.292 -
139.293 - if (i < 0) {
139.294 - sign = '-';
139.295 - i = -i;
139.296 - }
139.297 -
139.298 - // Get 2 digits/iteration using longs until quotient fits into an int
139.299 - while (i > Integer.MAX_VALUE) {
139.300 - q = i / 100;
139.301 - // really: r = i - (q * 100);
139.302 - r = (int)(i - ((q << 6) + (q << 5) + (q << 2)));
139.303 - i = q;
139.304 - buf[--charPos] = Integer.DigitOnes[r];
139.305 - buf[--charPos] = Integer.DigitTens[r];
139.306 - }
139.307 -
139.308 - // Get 2 digits/iteration using ints
139.309 - int q2;
139.310 - int i2 = (int)i;
139.311 - while (i2 >= 65536) {
139.312 - q2 = i2 / 100;
139.313 - // really: r = i2 - (q * 100);
139.314 - r = i2 - ((q2 << 6) + (q2 << 5) + (q2 << 2));
139.315 - i2 = q2;
139.316 - buf[--charPos] = Integer.DigitOnes[r];
139.317 - buf[--charPos] = Integer.DigitTens[r];
139.318 - }
139.319 -
139.320 - // Fall thru to fast mode for smaller numbers
139.321 - // assert(i2 <= 65536, i2);
139.322 - for (;;) {
139.323 - q2 = (i2 * 52429) >>> (16+3);
139.324 - r = i2 - ((q2 << 3) + (q2 << 1)); // r = i2-(q2*10) ...
139.325 - buf[--charPos] = Integer.digits[r];
139.326 - i2 = q2;
139.327 - if (i2 == 0) break;
139.328 - }
139.329 - if (sign != 0) {
139.330 - buf[--charPos] = sign;
139.331 - }
139.332 - }
139.333 -
139.334 - // Requires positive x
139.335 - static int stringSize(long x) {
139.336 - long p = 10;
139.337 - for (int i=1; i<19; i++) {
139.338 - if (x < p)
139.339 - return i;
139.340 - p = 10*p;
139.341 - }
139.342 - return 19;
139.343 - }
139.344 -
139.345 - /**
139.346 - * Parses the string argument as a signed {@code long} in the
139.347 - * radix specified by the second argument. The characters in the
139.348 - * string must all be digits of the specified radix (as determined
139.349 - * by whether {@link java.lang.Character#digit(char, int)} returns
139.350 - * a nonnegative value), except that the first character may be an
139.351 - * ASCII minus sign {@code '-'} (<code>'\u002D'</code>) to
139.352 - * indicate a negative value or an ASCII plus sign {@code '+'}
139.353 - * (<code>'\u002B'</code>) to indicate a positive value. The
139.354 - * resulting {@code long} value is returned.
139.355 - *
139.356 - * <p>Note that neither the character {@code L}
139.357 - * (<code>'\u004C'</code>) nor {@code l}
139.358 - * (<code>'\u006C'</code>) is permitted to appear at the end
139.359 - * of the string as a type indicator, as would be permitted in
139.360 - * Java programming language source code - except that either
139.361 - * {@code L} or {@code l} may appear as a digit for a
139.362 - * radix greater than 22.
139.363 - *
139.364 - * <p>An exception of type {@code NumberFormatException} is
139.365 - * thrown if any of the following situations occurs:
139.366 - * <ul>
139.367 - *
139.368 - * <li>The first argument is {@code null} or is a string of
139.369 - * length zero.
139.370 - *
139.371 - * <li>The {@code radix} is either smaller than {@link
139.372 - * java.lang.Character#MIN_RADIX} or larger than {@link
139.373 - * java.lang.Character#MAX_RADIX}.
139.374 - *
139.375 - * <li>Any character of the string is not a digit of the specified
139.376 - * radix, except that the first character may be a minus sign
139.377 - * {@code '-'} (<code>'\u002d'</code>) or plus sign {@code
139.378 - * '+'} (<code>'\u002B'</code>) provided that the string is
139.379 - * longer than length 1.
139.380 - *
139.381 - * <li>The value represented by the string is not a value of type
139.382 - * {@code long}.
139.383 - * </ul>
139.384 - *
139.385 - * <p>Examples:
139.386 - * <blockquote><pre>
139.387 - * parseLong("0", 10) returns 0L
139.388 - * parseLong("473", 10) returns 473L
139.389 - * parseLong("+42", 10) returns 42L
139.390 - * parseLong("-0", 10) returns 0L
139.391 - * parseLong("-FF", 16) returns -255L
139.392 - * parseLong("1100110", 2) returns 102L
139.393 - * parseLong("99", 8) throws a NumberFormatException
139.394 - * parseLong("Hazelnut", 10) throws a NumberFormatException
139.395 - * parseLong("Hazelnut", 36) returns 1356099454469L
139.396 - * </pre></blockquote>
139.397 - *
139.398 - * @param s the {@code String} containing the
139.399 - * {@code long} representation to be parsed.
139.400 - * @param radix the radix to be used while parsing {@code s}.
139.401 - * @return the {@code long} represented by the string argument in
139.402 - * the specified radix.
139.403 - * @throws NumberFormatException if the string does not contain a
139.404 - * parsable {@code long}.
139.405 - */
139.406 - public static long parseLong(String s, int radix)
139.407 - throws NumberFormatException
139.408 - {
139.409 - if (s == null) {
139.410 - throw new NumberFormatException("null");
139.411 - }
139.412 -
139.413 - if (radix < Character.MIN_RADIX) {
139.414 - throw new NumberFormatException("radix " + radix +
139.415 - " less than Character.MIN_RADIX");
139.416 - }
139.417 - if (radix > Character.MAX_RADIX) {
139.418 - throw new NumberFormatException("radix " + radix +
139.419 - " greater than Character.MAX_RADIX");
139.420 - }
139.421 -
139.422 - long result = 0;
139.423 - boolean negative = false;
139.424 - int i = 0, len = s.length();
139.425 - long limit = -Long.MAX_VALUE;
139.426 - long multmin;
139.427 - int digit;
139.428 -
139.429 - if (len > 0) {
139.430 - char firstChar = s.charAt(0);
139.431 - if (firstChar < '0') { // Possible leading "+" or "-"
139.432 - if (firstChar == '-') {
139.433 - negative = true;
139.434 - limit = Long.MIN_VALUE;
139.435 - } else if (firstChar != '+')
139.436 - throw NumberFormatException.forInputString(s);
139.437 -
139.438 - if (len == 1) // Cannot have lone "+" or "-"
139.439 - throw NumberFormatException.forInputString(s);
139.440 - i++;
139.441 - }
139.442 - multmin = limit / radix;
139.443 - while (i < len) {
139.444 - // Accumulating negatively avoids surprises near MAX_VALUE
139.445 - digit = Character.digit(s.charAt(i++),radix);
139.446 - if (digit < 0) {
139.447 - throw NumberFormatException.forInputString(s);
139.448 - }
139.449 - if (result < multmin) {
139.450 - throw NumberFormatException.forInputString(s);
139.451 - }
139.452 - result *= radix;
139.453 - if (result < limit + digit) {
139.454 - throw NumberFormatException.forInputString(s);
139.455 - }
139.456 - result -= digit;
139.457 - }
139.458 - } else {
139.459 - throw NumberFormatException.forInputString(s);
139.460 - }
139.461 - return negative ? result : -result;
139.462 - }
139.463 -
139.464 - /**
139.465 - * Parses the string argument as a signed decimal {@code long}.
139.466 - * The characters in the string must all be decimal digits, except
139.467 - * that the first character may be an ASCII minus sign {@code '-'}
139.468 - * (<code>\u002D'</code>) to indicate a negative value or an
139.469 - * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
139.470 - * indicate a positive value. The resulting {@code long} value is
139.471 - * returned, exactly as if the argument and the radix {@code 10}
139.472 - * were given as arguments to the {@link
139.473 - * #parseLong(java.lang.String, int)} method.
139.474 - *
139.475 - * <p>Note that neither the character {@code L}
139.476 - * (<code>'\u004C'</code>) nor {@code l}
139.477 - * (<code>'\u006C'</code>) is permitted to appear at the end
139.478 - * of the string as a type indicator, as would be permitted in
139.479 - * Java programming language source code.
139.480 - *
139.481 - * @param s a {@code String} containing the {@code long}
139.482 - * representation to be parsed
139.483 - * @return the {@code long} represented by the argument in
139.484 - * decimal.
139.485 - * @throws NumberFormatException if the string does not contain a
139.486 - * parsable {@code long}.
139.487 - */
139.488 - public static long parseLong(String s) throws NumberFormatException {
139.489 - return parseLong(s, 10);
139.490 - }
139.491 -
139.492 - /**
139.493 - * Returns a {@code Long} object holding the value
139.494 - * extracted from the specified {@code String} when parsed
139.495 - * with the radix given by the second argument. The first
139.496 - * argument is interpreted as representing a signed
139.497 - * {@code long} in the radix specified by the second
139.498 - * argument, exactly as if the arguments were given to the {@link
139.499 - * #parseLong(java.lang.String, int)} method. The result is a
139.500 - * {@code Long} object that represents the {@code long}
139.501 - * value specified by the string.
139.502 - *
139.503 - * <p>In other words, this method returns a {@code Long} object equal
139.504 - * to the value of:
139.505 - *
139.506 - * <blockquote>
139.507 - * {@code new Long(Long.parseLong(s, radix))}
139.508 - * </blockquote>
139.509 - *
139.510 - * @param s the string to be parsed
139.511 - * @param radix the radix to be used in interpreting {@code s}
139.512 - * @return a {@code Long} object holding the value
139.513 - * represented by the string argument in the specified
139.514 - * radix.
139.515 - * @throws NumberFormatException If the {@code String} does not
139.516 - * contain a parsable {@code long}.
139.517 - */
139.518 - public static Long valueOf(String s, int radix) throws NumberFormatException {
139.519 - return Long.valueOf(parseLong(s, radix));
139.520 - }
139.521 -
139.522 - /**
139.523 - * Returns a {@code Long} object holding the value
139.524 - * of the specified {@code String}. The argument is
139.525 - * interpreted as representing a signed decimal {@code long},
139.526 - * exactly as if the argument were given to the {@link
139.527 - * #parseLong(java.lang.String)} method. The result is a
139.528 - * {@code Long} object that represents the integer value
139.529 - * specified by the string.
139.530 - *
139.531 - * <p>In other words, this method returns a {@code Long} object
139.532 - * equal to the value of:
139.533 - *
139.534 - * <blockquote>
139.535 - * {@code new Long(Long.parseLong(s))}
139.536 - * </blockquote>
139.537 - *
139.538 - * @param s the string to be parsed.
139.539 - * @return a {@code Long} object holding the value
139.540 - * represented by the string argument.
139.541 - * @throws NumberFormatException If the string cannot be parsed
139.542 - * as a {@code long}.
139.543 - */
139.544 - public static Long valueOf(String s) throws NumberFormatException
139.545 - {
139.546 - return Long.valueOf(parseLong(s, 10));
139.547 - }
139.548 -
139.549 - private static class LongCache {
139.550 - private LongCache(){}
139.551 -
139.552 - static final Long cache[] = new Long[-(-128) + 127 + 1];
139.553 -
139.554 - static {
139.555 - for(int i = 0; i < cache.length; i++)
139.556 - cache[i] = new Long(i - 128);
139.557 - }
139.558 - }
139.559 -
139.560 - /**
139.561 - * Returns a {@code Long} instance representing the specified
139.562 - * {@code long} value.
139.563 - * If a new {@code Long} instance is not required, this method
139.564 - * should generally be used in preference to the constructor
139.565 - * {@link #Long(long)}, as this method is likely to yield
139.566 - * significantly better space and time performance by caching
139.567 - * frequently requested values.
139.568 - *
139.569 - * Note that unlike the {@linkplain Integer#valueOf(int)
139.570 - * corresponding method} in the {@code Integer} class, this method
139.571 - * is <em>not</em> required to cache values within a particular
139.572 - * range.
139.573 - *
139.574 - * @param l a long value.
139.575 - * @return a {@code Long} instance representing {@code l}.
139.576 - * @since 1.5
139.577 - */
139.578 - public static Long valueOf(long l) {
139.579 - final int offset = 128;
139.580 - if (l >= -128 && l <= 127) { // will cache
139.581 - return LongCache.cache[(int)l + offset];
139.582 - }
139.583 - return new Long(l);
139.584 - }
139.585 -
139.586 - /**
139.587 - * Decodes a {@code String} into a {@code Long}.
139.588 - * Accepts decimal, hexadecimal, and octal numbers given by the
139.589 - * following grammar:
139.590 - *
139.591 - * <blockquote>
139.592 - * <dl>
139.593 - * <dt><i>DecodableString:</i>
139.594 - * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
139.595 - * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
139.596 - * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
139.597 - * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
139.598 - * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
139.599 - * <p>
139.600 - * <dt><i>Sign:</i>
139.601 - * <dd>{@code -}
139.602 - * <dd>{@code +}
139.603 - * </dl>
139.604 - * </blockquote>
139.605 - *
139.606 - * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
139.607 - * are as defined in section 3.10.1 of
139.608 - * <cite>The Java™ Language Specification</cite>,
139.609 - * except that underscores are not accepted between digits.
139.610 - *
139.611 - * <p>The sequence of characters following an optional
139.612 - * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
139.613 - * "{@code #}", or leading zero) is parsed as by the {@code
139.614 - * Long.parseLong} method with the indicated radix (10, 16, or 8).
139.615 - * This sequence of characters must represent a positive value or
139.616 - * a {@link NumberFormatException} will be thrown. The result is
139.617 - * negated if first character of the specified {@code String} is
139.618 - * the minus sign. No whitespace characters are permitted in the
139.619 - * {@code String}.
139.620 - *
139.621 - * @param nm the {@code String} to decode.
139.622 - * @return a {@code Long} object holding the {@code long}
139.623 - * value represented by {@code nm}
139.624 - * @throws NumberFormatException if the {@code String} does not
139.625 - * contain a parsable {@code long}.
139.626 - * @see java.lang.Long#parseLong(String, int)
139.627 - * @since 1.2
139.628 - */
139.629 - public static Long decode(String nm) throws NumberFormatException {
139.630 - int radix = 10;
139.631 - int index = 0;
139.632 - boolean negative = false;
139.633 - Long result;
139.634 -
139.635 - if (nm.length() == 0)
139.636 - throw new NumberFormatException("Zero length string");
139.637 - char firstChar = nm.charAt(0);
139.638 - // Handle sign, if present
139.639 - if (firstChar == '-') {
139.640 - negative = true;
139.641 - index++;
139.642 - } else if (firstChar == '+')
139.643 - index++;
139.644 -
139.645 - // Handle radix specifier, if present
139.646 - if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) {
139.647 - index += 2;
139.648 - radix = 16;
139.649 - }
139.650 - else if (nm.startsWith("#", index)) {
139.651 - index ++;
139.652 - radix = 16;
139.653 - }
139.654 - else if (nm.startsWith("0", index) && nm.length() > 1 + index) {
139.655 - index ++;
139.656 - radix = 8;
139.657 - }
139.658 -
139.659 - if (nm.startsWith("-", index) || nm.startsWith("+", index))
139.660 - throw new NumberFormatException("Sign character in wrong position");
139.661 -
139.662 - try {
139.663 - result = Long.valueOf(nm.substring(index), radix);
139.664 - result = negative ? Long.valueOf(-result.longValue()) : result;
139.665 - } catch (NumberFormatException e) {
139.666 - // If number is Long.MIN_VALUE, we'll end up here. The next line
139.667 - // handles this case, and causes any genuine format error to be
139.668 - // rethrown.
139.669 - String constant = negative ? ("-" + nm.substring(index))
139.670 - : nm.substring(index);
139.671 - result = Long.valueOf(constant, radix);
139.672 - }
139.673 - return result;
139.674 - }
139.675 -
139.676 - /**
139.677 - * The value of the {@code Long}.
139.678 - *
139.679 - * @serial
139.680 - */
139.681 - private final long value;
139.682 -
139.683 - /**
139.684 - * Constructs a newly allocated {@code Long} object that
139.685 - * represents the specified {@code long} argument.
139.686 - *
139.687 - * @param value the value to be represented by the
139.688 - * {@code Long} object.
139.689 - */
139.690 - public Long(long value) {
139.691 - this.value = value;
139.692 - }
139.693 -
139.694 - /**
139.695 - * Constructs a newly allocated {@code Long} object that
139.696 - * represents the {@code long} value indicated by the
139.697 - * {@code String} parameter. The string is converted to a
139.698 - * {@code long} value in exactly the manner used by the
139.699 - * {@code parseLong} method for radix 10.
139.700 - *
139.701 - * @param s the {@code String} to be converted to a
139.702 - * {@code Long}.
139.703 - * @throws NumberFormatException if the {@code String} does not
139.704 - * contain a parsable {@code long}.
139.705 - * @see java.lang.Long#parseLong(java.lang.String, int)
139.706 - */
139.707 - public Long(String s) throws NumberFormatException {
139.708 - this.value = parseLong(s, 10);
139.709 - }
139.710 -
139.711 - /**
139.712 - * Returns the value of this {@code Long} as a
139.713 - * {@code byte}.
139.714 - */
139.715 - public byte byteValue() {
139.716 - return (byte)value;
139.717 - }
139.718 -
139.719 - /**
139.720 - * Returns the value of this {@code Long} as a
139.721 - * {@code short}.
139.722 - */
139.723 - public short shortValue() {
139.724 - return (short)value;
139.725 - }
139.726 -
139.727 - /**
139.728 - * Returns the value of this {@code Long} as an
139.729 - * {@code int}.
139.730 - */
139.731 - public int intValue() {
139.732 - return (int)value;
139.733 - }
139.734 -
139.735 - /**
139.736 - * Returns the value of this {@code Long} as a
139.737 - * {@code long} value.
139.738 - */
139.739 - public long longValue() {
139.740 - return (long)value;
139.741 - }
139.742 -
139.743 - /**
139.744 - * Returns the value of this {@code Long} as a
139.745 - * {@code float}.
139.746 - */
139.747 - public float floatValue() {
139.748 - return (float)value;
139.749 - }
139.750 -
139.751 - /**
139.752 - * Returns the value of this {@code Long} as a
139.753 - * {@code double}.
139.754 - */
139.755 - public double doubleValue() {
139.756 - return (double)value;
139.757 - }
139.758 -
139.759 - /**
139.760 - * Returns a {@code String} object representing this
139.761 - * {@code Long}'s value. The value is converted to signed
139.762 - * decimal representation and returned as a string, exactly as if
139.763 - * the {@code long} value were given as an argument to the
139.764 - * {@link java.lang.Long#toString(long)} method.
139.765 - *
139.766 - * @return a string representation of the value of this object in
139.767 - * base 10.
139.768 - */
139.769 - public String toString() {
139.770 - return toString(value);
139.771 - }
139.772 -
139.773 - /**
139.774 - * Returns a hash code for this {@code Long}. The result is
139.775 - * the exclusive OR of the two halves of the primitive
139.776 - * {@code long} value held by this {@code Long}
139.777 - * object. That is, the hashcode is the value of the expression:
139.778 - *
139.779 - * <blockquote>
139.780 - * {@code (int)(this.longValue()^(this.longValue()>>>32))}
139.781 - * </blockquote>
139.782 - *
139.783 - * @return a hash code value for this object.
139.784 - */
139.785 - public int hashCode() {
139.786 - return (int)(value ^ (value >>> 32));
139.787 - }
139.788 -
139.789 - /**
139.790 - * Compares this object to the specified object. The result is
139.791 - * {@code true} if and only if the argument is not
139.792 - * {@code null} and is a {@code Long} object that
139.793 - * contains the same {@code long} value as this object.
139.794 - *
139.795 - * @param obj the object to compare with.
139.796 - * @return {@code true} if the objects are the same;
139.797 - * {@code false} otherwise.
139.798 - */
139.799 - public boolean equals(Object obj) {
139.800 - if (obj instanceof Long) {
139.801 - return value == ((Long)obj).longValue();
139.802 - }
139.803 - return false;
139.804 - }
139.805 -
139.806 - /**
139.807 - * Determines the {@code long} value of the system property
139.808 - * with the specified name.
139.809 - *
139.810 - * <p>The first argument is treated as the name of a system property.
139.811 - * System properties are accessible through the {@link
139.812 - * java.lang.System#getProperty(java.lang.String)} method. The
139.813 - * string value of this property is then interpreted as a
139.814 - * {@code long} value and a {@code Long} object
139.815 - * representing this value is returned. Details of possible
139.816 - * numeric formats can be found with the definition of
139.817 - * {@code getProperty}.
139.818 - *
139.819 - * <p>If there is no property with the specified name, if the
139.820 - * specified name is empty or {@code null}, or if the
139.821 - * property does not have the correct numeric format, then
139.822 - * {@code null} is returned.
139.823 - *
139.824 - * <p>In other words, this method returns a {@code Long} object equal to
139.825 - * the value of:
139.826 - *
139.827 - * <blockquote>
139.828 - * {@code getLong(nm, null)}
139.829 - * </blockquote>
139.830 - *
139.831 - * @param nm property name.
139.832 - * @return the {@code Long} value of the property.
139.833 - * @see java.lang.System#getProperty(java.lang.String)
139.834 - * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
139.835 - */
139.836 - public static Long getLong(String nm) {
139.837 - return getLong(nm, null);
139.838 - }
139.839 -
139.840 - /**
139.841 - * Determines the {@code long} value of the system property
139.842 - * with the specified name.
139.843 - *
139.844 - * <p>The first argument is treated as the name of a system property.
139.845 - * System properties are accessible through the {@link
139.846 - * java.lang.System#getProperty(java.lang.String)} method. The
139.847 - * string value of this property is then interpreted as a
139.848 - * {@code long} value and a {@code Long} object
139.849 - * representing this value is returned. Details of possible
139.850 - * numeric formats can be found with the definition of
139.851 - * {@code getProperty}.
139.852 - *
139.853 - * <p>The second argument is the default value. A {@code Long} object
139.854 - * that represents the value of the second argument is returned if there
139.855 - * is no property of the specified name, if the property does not have
139.856 - * the correct numeric format, or if the specified name is empty or null.
139.857 - *
139.858 - * <p>In other words, this method returns a {@code Long} object equal
139.859 - * to the value of:
139.860 - *
139.861 - * <blockquote>
139.862 - * {@code getLong(nm, new Long(val))}
139.863 - * </blockquote>
139.864 - *
139.865 - * but in practice it may be implemented in a manner such as:
139.866 - *
139.867 - * <blockquote><pre>
139.868 - * Long result = getLong(nm, null);
139.869 - * return (result == null) ? new Long(val) : result;
139.870 - * </pre></blockquote>
139.871 - *
139.872 - * to avoid the unnecessary allocation of a {@code Long} object when
139.873 - * the default value is not needed.
139.874 - *
139.875 - * @param nm property name.
139.876 - * @param val default value.
139.877 - * @return the {@code Long} value of the property.
139.878 - * @see java.lang.System#getProperty(java.lang.String)
139.879 - * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
139.880 - */
139.881 - public static Long getLong(String nm, long val) {
139.882 - Long result = Long.getLong(nm, null);
139.883 - return (result == null) ? Long.valueOf(val) : result;
139.884 - }
139.885 -
139.886 - /**
139.887 - * Returns the {@code long} value of the system property with
139.888 - * the specified name. The first argument is treated as the name
139.889 - * of a system property. System properties are accessible through
139.890 - * the {@link java.lang.System#getProperty(java.lang.String)}
139.891 - * method. The string value of this property is then interpreted
139.892 - * as a {@code long} value, as per the
139.893 - * {@code Long.decode} method, and a {@code Long} object
139.894 - * representing this value is returned.
139.895 - *
139.896 - * <ul>
139.897 - * <li>If the property value begins with the two ASCII characters
139.898 - * {@code 0x} or the ASCII character {@code #}, not followed by
139.899 - * a minus sign, then the rest of it is parsed as a hexadecimal integer
139.900 - * exactly as for the method {@link #valueOf(java.lang.String, int)}
139.901 - * with radix 16.
139.902 - * <li>If the property value begins with the ASCII character
139.903 - * {@code 0} followed by another character, it is parsed as
139.904 - * an octal integer exactly as by the method {@link
139.905 - * #valueOf(java.lang.String, int)} with radix 8.
139.906 - * <li>Otherwise the property value is parsed as a decimal
139.907 - * integer exactly as by the method
139.908 - * {@link #valueOf(java.lang.String, int)} with radix 10.
139.909 - * </ul>
139.910 - *
139.911 - * <p>Note that, in every case, neither {@code L}
139.912 - * (<code>'\u004C'</code>) nor {@code l}
139.913 - * (<code>'\u006C'</code>) is permitted to appear at the end
139.914 - * of the property value as a type indicator, as would be
139.915 - * permitted in Java programming language source code.
139.916 - *
139.917 - * <p>The second argument is the default value. The default value is
139.918 - * returned if there is no property of the specified name, if the
139.919 - * property does not have the correct numeric format, or if the
139.920 - * specified name is empty or {@code null}.
139.921 - *
139.922 - * @param nm property name.
139.923 - * @param val default value.
139.924 - * @return the {@code Long} value of the property.
139.925 - * @see java.lang.System#getProperty(java.lang.String)
139.926 - * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
139.927 - * @see java.lang.Long#decode
139.928 - */
139.929 - public static Long getLong(String nm, Long val) {
139.930 - String v = null;
139.931 - try {
139.932 - v = AbstractStringBuilder.getProperty(nm);
139.933 - } catch (IllegalArgumentException e) {
139.934 - } catch (NullPointerException e) {
139.935 - }
139.936 - if (v != null) {
139.937 - try {
139.938 - return Long.decode(v);
139.939 - } catch (NumberFormatException e) {
139.940 - }
139.941 - }
139.942 - return val;
139.943 - }
139.944 -
139.945 - /**
139.946 - * Compares two {@code Long} objects numerically.
139.947 - *
139.948 - * @param anotherLong the {@code Long} to be compared.
139.949 - * @return the value {@code 0} if this {@code Long} is
139.950 - * equal to the argument {@code Long}; a value less than
139.951 - * {@code 0} if this {@code Long} is numerically less
139.952 - * than the argument {@code Long}; and a value greater
139.953 - * than {@code 0} if this {@code Long} is numerically
139.954 - * greater than the argument {@code Long} (signed
139.955 - * comparison).
139.956 - * @since 1.2
139.957 - */
139.958 - public int compareTo(Long anotherLong) {
139.959 - return compare(this.value, anotherLong.value);
139.960 - }
139.961 -
139.962 - /**
139.963 - * Compares two {@code long} values numerically.
139.964 - * The value returned is identical to what would be returned by:
139.965 - * <pre>
139.966 - * Long.valueOf(x).compareTo(Long.valueOf(y))
139.967 - * </pre>
139.968 - *
139.969 - * @param x the first {@code long} to compare
139.970 - * @param y the second {@code long} to compare
139.971 - * @return the value {@code 0} if {@code x == y};
139.972 - * a value less than {@code 0} if {@code x < y}; and
139.973 - * a value greater than {@code 0} if {@code x > y}
139.974 - * @since 1.7
139.975 - */
139.976 - public static int compare(long x, long y) {
139.977 - return (x < y) ? -1 : ((x == y) ? 0 : 1);
139.978 - }
139.979 -
139.980 -
139.981 - // Bit Twiddling
139.982 -
139.983 - /**
139.984 - * The number of bits used to represent a {@code long} value in two's
139.985 - * complement binary form.
139.986 - *
139.987 - * @since 1.5
139.988 - */
139.989 - public static final int SIZE = 64;
139.990 -
139.991 - /**
139.992 - * Returns a {@code long} value with at most a single one-bit, in the
139.993 - * position of the highest-order ("leftmost") one-bit in the specified
139.994 - * {@code long} value. Returns zero if the specified value has no
139.995 - * one-bits in its two's complement binary representation, that is, if it
139.996 - * is equal to zero.
139.997 - *
139.998 - * @return a {@code long} value with a single one-bit, in the position
139.999 - * of the highest-order one-bit in the specified value, or zero if
139.1000 - * the specified value is itself equal to zero.
139.1001 - * @since 1.5
139.1002 - */
139.1003 - public static long highestOneBit(long i) {
139.1004 - // HD, Figure 3-1
139.1005 - i |= (i >> 1);
139.1006 - i |= (i >> 2);
139.1007 - i |= (i >> 4);
139.1008 - i |= (i >> 8);
139.1009 - i |= (i >> 16);
139.1010 - i |= (i >> 32);
139.1011 - return i - (i >>> 1);
139.1012 - }
139.1013 -
139.1014 - /**
139.1015 - * Returns a {@code long} value with at most a single one-bit, in the
139.1016 - * position of the lowest-order ("rightmost") one-bit in the specified
139.1017 - * {@code long} value. Returns zero if the specified value has no
139.1018 - * one-bits in its two's complement binary representation, that is, if it
139.1019 - * is equal to zero.
139.1020 - *
139.1021 - * @return a {@code long} value with a single one-bit, in the position
139.1022 - * of the lowest-order one-bit in the specified value, or zero if
139.1023 - * the specified value is itself equal to zero.
139.1024 - * @since 1.5
139.1025 - */
139.1026 - public static long lowestOneBit(long i) {
139.1027 - // HD, Section 2-1
139.1028 - return i & -i;
139.1029 - }
139.1030 -
139.1031 - /**
139.1032 - * Returns the number of zero bits preceding the highest-order
139.1033 - * ("leftmost") one-bit in the two's complement binary representation
139.1034 - * of the specified {@code long} value. Returns 64 if the
139.1035 - * specified value has no one-bits in its two's complement representation,
139.1036 - * in other words if it is equal to zero.
139.1037 - *
139.1038 - * <p>Note that this method is closely related to the logarithm base 2.
139.1039 - * For all positive {@code long} values x:
139.1040 - * <ul>
139.1041 - * <li>floor(log<sub>2</sub>(x)) = {@code 63 - numberOfLeadingZeros(x)}
139.1042 - * <li>ceil(log<sub>2</sub>(x)) = {@code 64 - numberOfLeadingZeros(x - 1)}
139.1043 - * </ul>
139.1044 - *
139.1045 - * @return the number of zero bits preceding the highest-order
139.1046 - * ("leftmost") one-bit in the two's complement binary representation
139.1047 - * of the specified {@code long} value, or 64 if the value
139.1048 - * is equal to zero.
139.1049 - * @since 1.5
139.1050 - */
139.1051 - public static int numberOfLeadingZeros(long i) {
139.1052 - // HD, Figure 5-6
139.1053 - if (i == 0)
139.1054 - return 64;
139.1055 - int n = 1;
139.1056 - int x = (int)(i >>> 32);
139.1057 - if (x == 0) { n += 32; x = (int)i; }
139.1058 - if (x >>> 16 == 0) { n += 16; x <<= 16; }
139.1059 - if (x >>> 24 == 0) { n += 8; x <<= 8; }
139.1060 - if (x >>> 28 == 0) { n += 4; x <<= 4; }
139.1061 - if (x >>> 30 == 0) { n += 2; x <<= 2; }
139.1062 - n -= x >>> 31;
139.1063 - return n;
139.1064 - }
139.1065 -
139.1066 - /**
139.1067 - * Returns the number of zero bits following the lowest-order ("rightmost")
139.1068 - * one-bit in the two's complement binary representation of the specified
139.1069 - * {@code long} value. Returns 64 if the specified value has no
139.1070 - * one-bits in its two's complement representation, in other words if it is
139.1071 - * equal to zero.
139.1072 - *
139.1073 - * @return the number of zero bits following the lowest-order ("rightmost")
139.1074 - * one-bit in the two's complement binary representation of the
139.1075 - * specified {@code long} value, or 64 if the value is equal
139.1076 - * to zero.
139.1077 - * @since 1.5
139.1078 - */
139.1079 - public static int numberOfTrailingZeros(long i) {
139.1080 - // HD, Figure 5-14
139.1081 - int x, y;
139.1082 - if (i == 0) return 64;
139.1083 - int n = 63;
139.1084 - y = (int)i; if (y != 0) { n = n -32; x = y; } else x = (int)(i>>>32);
139.1085 - y = x <<16; if (y != 0) { n = n -16; x = y; }
139.1086 - y = x << 8; if (y != 0) { n = n - 8; x = y; }
139.1087 - y = x << 4; if (y != 0) { n = n - 4; x = y; }
139.1088 - y = x << 2; if (y != 0) { n = n - 2; x = y; }
139.1089 - return n - ((x << 1) >>> 31);
139.1090 - }
139.1091 -
139.1092 - /**
139.1093 - * Returns the number of one-bits in the two's complement binary
139.1094 - * representation of the specified {@code long} value. This function is
139.1095 - * sometimes referred to as the <i>population count</i>.
139.1096 - *
139.1097 - * @return the number of one-bits in the two's complement binary
139.1098 - * representation of the specified {@code long} value.
139.1099 - * @since 1.5
139.1100 - */
139.1101 - public static int bitCount(long i) {
139.1102 - // HD, Figure 5-14
139.1103 - i = i - ((i >>> 1) & 0x5555555555555555L);
139.1104 - i = (i & 0x3333333333333333L) + ((i >>> 2) & 0x3333333333333333L);
139.1105 - i = (i + (i >>> 4)) & 0x0f0f0f0f0f0f0f0fL;
139.1106 - i = i + (i >>> 8);
139.1107 - i = i + (i >>> 16);
139.1108 - i = i + (i >>> 32);
139.1109 - return (int)i & 0x7f;
139.1110 - }
139.1111 -
139.1112 - /**
139.1113 - * Returns the value obtained by rotating the two's complement binary
139.1114 - * representation of the specified {@code long} value left by the
139.1115 - * specified number of bits. (Bits shifted out of the left hand, or
139.1116 - * high-order, side reenter on the right, or low-order.)
139.1117 - *
139.1118 - * <p>Note that left rotation with a negative distance is equivalent to
139.1119 - * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val,
139.1120 - * distance)}. Note also that rotation by any multiple of 64 is a
139.1121 - * no-op, so all but the last six bits of the rotation distance can be
139.1122 - * ignored, even if the distance is negative: {@code rotateLeft(val,
139.1123 - * distance) == rotateLeft(val, distance & 0x3F)}.
139.1124 - *
139.1125 - * @return the value obtained by rotating the two's complement binary
139.1126 - * representation of the specified {@code long} value left by the
139.1127 - * specified number of bits.
139.1128 - * @since 1.5
139.1129 - */
139.1130 - public static long rotateLeft(long i, int distance) {
139.1131 - return (i << distance) | (i >>> -distance);
139.1132 - }
139.1133 -
139.1134 - /**
139.1135 - * Returns the value obtained by rotating the two's complement binary
139.1136 - * representation of the specified {@code long} value right by the
139.1137 - * specified number of bits. (Bits shifted out of the right hand, or
139.1138 - * low-order, side reenter on the left, or high-order.)
139.1139 - *
139.1140 - * <p>Note that right rotation with a negative distance is equivalent to
139.1141 - * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val,
139.1142 - * distance)}. Note also that rotation by any multiple of 64 is a
139.1143 - * no-op, so all but the last six bits of the rotation distance can be
139.1144 - * ignored, even if the distance is negative: {@code rotateRight(val,
139.1145 - * distance) == rotateRight(val, distance & 0x3F)}.
139.1146 - *
139.1147 - * @return the value obtained by rotating the two's complement binary
139.1148 - * representation of the specified {@code long} value right by the
139.1149 - * specified number of bits.
139.1150 - * @since 1.5
139.1151 - */
139.1152 - public static long rotateRight(long i, int distance) {
139.1153 - return (i >>> distance) | (i << -distance);
139.1154 - }
139.1155 -
139.1156 - /**
139.1157 - * Returns the value obtained by reversing the order of the bits in the
139.1158 - * two's complement binary representation of the specified {@code long}
139.1159 - * value.
139.1160 - *
139.1161 - * @return the value obtained by reversing order of the bits in the
139.1162 - * specified {@code long} value.
139.1163 - * @since 1.5
139.1164 - */
139.1165 - public static long reverse(long i) {
139.1166 - // HD, Figure 7-1
139.1167 - i = (i & 0x5555555555555555L) << 1 | (i >>> 1) & 0x5555555555555555L;
139.1168 - i = (i & 0x3333333333333333L) << 2 | (i >>> 2) & 0x3333333333333333L;
139.1169 - i = (i & 0x0f0f0f0f0f0f0f0fL) << 4 | (i >>> 4) & 0x0f0f0f0f0f0f0f0fL;
139.1170 - i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
139.1171 - i = (i << 48) | ((i & 0xffff0000L) << 16) |
139.1172 - ((i >>> 16) & 0xffff0000L) | (i >>> 48);
139.1173 - return i;
139.1174 - }
139.1175 -
139.1176 - /**
139.1177 - * Returns the signum function of the specified {@code long} value. (The
139.1178 - * return value is -1 if the specified value is negative; 0 if the
139.1179 - * specified value is zero; and 1 if the specified value is positive.)
139.1180 - *
139.1181 - * @return the signum function of the specified {@code long} value.
139.1182 - * @since 1.5
139.1183 - */
139.1184 - public static int signum(long i) {
139.1185 - // HD, Section 2-7
139.1186 - return (int) ((i >> 63) | (-i >>> 63));
139.1187 - }
139.1188 -
139.1189 - /**
139.1190 - * Returns the value obtained by reversing the order of the bytes in the
139.1191 - * two's complement representation of the specified {@code long} value.
139.1192 - *
139.1193 - * @return the value obtained by reversing the bytes in the specified
139.1194 - * {@code long} value.
139.1195 - * @since 1.5
139.1196 - */
139.1197 - public static long reverseBytes(long i) {
139.1198 - i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL;
139.1199 - return (i << 48) | ((i & 0xffff0000L) << 16) |
139.1200 - ((i >>> 16) & 0xffff0000L) | (i >>> 48);
139.1201 - }
139.1202 -
139.1203 - /** use serialVersionUID from JDK 1.0.2 for interoperability */
139.1204 - private static final long serialVersionUID = 4290774380558885855L;
139.1205 -}
140.1 --- a/emul/src/main/java/java/lang/Math.java Wed Jan 23 20:16:48 2013 +0100
140.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
140.3 @@ -1,1244 +0,0 @@
140.4 -/*
140.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
140.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
140.7 - *
140.8 - * This code is free software; you can redistribute it and/or modify it
140.9 - * under the terms of the GNU General Public License version 2 only, as
140.10 - * published by the Free Software Foundation. Oracle designates this
140.11 - * particular file as subject to the "Classpath" exception as provided
140.12 - * by Oracle in the LICENSE file that accompanied this code.
140.13 - *
140.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
140.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
140.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
140.17 - * version 2 for more details (a copy is included in the LICENSE file that
140.18 - * accompanied this code).
140.19 - *
140.20 - * You should have received a copy of the GNU General Public License version
140.21 - * 2 along with this work; if not, write to the Free Software Foundation,
140.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
140.23 - *
140.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
140.25 - * or visit www.oracle.com if you need additional information or have any
140.26 - * questions.
140.27 - */
140.28 -
140.29 -package java.lang;
140.30 -
140.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
140.32 -
140.33 -
140.34 -/**
140.35 - * The class {@code Math} contains methods for performing basic
140.36 - * numeric operations such as the elementary exponential, logarithm,
140.37 - * square root, and trigonometric functions.
140.38 - *
140.39 - * <p>Unlike some of the numeric methods of class
140.40 - * {@code StrictMath}, all implementations of the equivalent
140.41 - * functions of class {@code Math} are not defined to return the
140.42 - * bit-for-bit same results. This relaxation permits
140.43 - * better-performing implementations where strict reproducibility is
140.44 - * not required.
140.45 - *
140.46 - * <p>By default many of the {@code Math} methods simply call
140.47 - * the equivalent method in {@code StrictMath} for their
140.48 - * implementation. Code generators are encouraged to use
140.49 - * platform-specific native libraries or microprocessor instructions,
140.50 - * where available, to provide higher-performance implementations of
140.51 - * {@code Math} methods. Such higher-performance
140.52 - * implementations still must conform to the specification for
140.53 - * {@code Math}.
140.54 - *
140.55 - * <p>The quality of implementation specifications concern two
140.56 - * properties, accuracy of the returned result and monotonicity of the
140.57 - * method. Accuracy of the floating-point {@code Math} methods
140.58 - * is measured in terms of <i>ulps</i>, units in the last place. For
140.59 - * a given floating-point format, an ulp of a specific real number
140.60 - * value is the distance between the two floating-point values
140.61 - * bracketing that numerical value. When discussing the accuracy of a
140.62 - * method as a whole rather than at a specific argument, the number of
140.63 - * ulps cited is for the worst-case error at any argument. If a
140.64 - * method always has an error less than 0.5 ulps, the method always
140.65 - * returns the floating-point number nearest the exact result; such a
140.66 - * method is <i>correctly rounded</i>. A correctly rounded method is
140.67 - * generally the best a floating-point approximation can be; however,
140.68 - * it is impractical for many floating-point methods to be correctly
140.69 - * rounded. Instead, for the {@code Math} class, a larger error
140.70 - * bound of 1 or 2 ulps is allowed for certain methods. Informally,
140.71 - * with a 1 ulp error bound, when the exact result is a representable
140.72 - * number, the exact result should be returned as the computed result;
140.73 - * otherwise, either of the two floating-point values which bracket
140.74 - * the exact result may be returned. For exact results large in
140.75 - * magnitude, one of the endpoints of the bracket may be infinite.
140.76 - * Besides accuracy at individual arguments, maintaining proper
140.77 - * relations between the method at different arguments is also
140.78 - * important. Therefore, most methods with more than 0.5 ulp errors
140.79 - * are required to be <i>semi-monotonic</i>: whenever the mathematical
140.80 - * function is non-decreasing, so is the floating-point approximation,
140.81 - * likewise, whenever the mathematical function is non-increasing, so
140.82 - * is the floating-point approximation. Not all approximations that
140.83 - * have 1 ulp accuracy will automatically meet the monotonicity
140.84 - * requirements.
140.85 - *
140.86 - * @author unascribed
140.87 - * @author Joseph D. Darcy
140.88 - * @since JDK1.0
140.89 - */
140.90 -
140.91 -public final class Math {
140.92 -
140.93 - /**
140.94 - * Don't let anyone instantiate this class.
140.95 - */
140.96 - private Math() {}
140.97 -
140.98 - /**
140.99 - * The {@code double} value that is closer than any other to
140.100 - * <i>e</i>, the base of the natural logarithms.
140.101 - */
140.102 - public static final double E = 2.7182818284590452354;
140.103 -
140.104 - /**
140.105 - * The {@code double} value that is closer than any other to
140.106 - * <i>pi</i>, the ratio of the circumference of a circle to its
140.107 - * diameter.
140.108 - */
140.109 - public static final double PI = 3.14159265358979323846;
140.110 -
140.111 - /**
140.112 - * Returns the trigonometric sine of an angle. Special cases:
140.113 - * <ul><li>If the argument is NaN or an infinity, then the
140.114 - * result is NaN.
140.115 - * <li>If the argument is zero, then the result is a zero with the
140.116 - * same sign as the argument.</ul>
140.117 - *
140.118 - * <p>The computed result must be within 1 ulp of the exact result.
140.119 - * Results must be semi-monotonic.
140.120 - *
140.121 - * @param a an angle, in radians.
140.122 - * @return the sine of the argument.
140.123 - */
140.124 - @JavaScriptBody(args="a", body="return Math.sin(a);")
140.125 - public static double sin(double a) {
140.126 - throw new UnsupportedOperationException();
140.127 - }
140.128 -
140.129 - /**
140.130 - * Returns the trigonometric cosine of an angle. Special cases:
140.131 - * <ul><li>If the argument is NaN or an infinity, then the
140.132 - * result is NaN.</ul>
140.133 - *
140.134 - * <p>The computed result must be within 1 ulp of the exact result.
140.135 - * Results must be semi-monotonic.
140.136 - *
140.137 - * @param a an angle, in radians.
140.138 - * @return the cosine of the argument.
140.139 - */
140.140 - @JavaScriptBody(args="a", body="return Math.cos(a);")
140.141 - public static double cos(double a) {
140.142 - throw new UnsupportedOperationException();
140.143 - }
140.144 -
140.145 - /**
140.146 - * Returns the trigonometric tangent of an angle. Special cases:
140.147 - * <ul><li>If the argument is NaN or an infinity, then the result
140.148 - * is NaN.
140.149 - * <li>If the argument is zero, then the result is a zero with the
140.150 - * same sign as the argument.</ul>
140.151 - *
140.152 - * <p>The computed result must be within 1 ulp of the exact result.
140.153 - * Results must be semi-monotonic.
140.154 - *
140.155 - * @param a an angle, in radians.
140.156 - * @return the tangent of the argument.
140.157 - */
140.158 - @JavaScriptBody(args="a", body="return Math.tan(a);")
140.159 - public static double tan(double a) {
140.160 - throw new UnsupportedOperationException();
140.161 - }
140.162 -
140.163 - /**
140.164 - * Returns the arc sine of a value; the returned angle is in the
140.165 - * range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
140.166 - * <ul><li>If the argument is NaN or its absolute value is greater
140.167 - * than 1, then the result is NaN.
140.168 - * <li>If the argument is zero, then the result is a zero with the
140.169 - * same sign as the argument.</ul>
140.170 - *
140.171 - * <p>The computed result must be within 1 ulp of the exact result.
140.172 - * Results must be semi-monotonic.
140.173 - *
140.174 - * @param a the value whose arc sine is to be returned.
140.175 - * @return the arc sine of the argument.
140.176 - */
140.177 - @JavaScriptBody(args="a", body="return Math.asin(a);")
140.178 - public static double asin(double a) {
140.179 - throw new UnsupportedOperationException();
140.180 - }
140.181 -
140.182 - /**
140.183 - * Returns the arc cosine of a value; the returned angle is in the
140.184 - * range 0.0 through <i>pi</i>. Special case:
140.185 - * <ul><li>If the argument is NaN or its absolute value is greater
140.186 - * than 1, then the result is NaN.</ul>
140.187 - *
140.188 - * <p>The computed result must be within 1 ulp of the exact result.
140.189 - * Results must be semi-monotonic.
140.190 - *
140.191 - * @param a the value whose arc cosine is to be returned.
140.192 - * @return the arc cosine of the argument.
140.193 - */
140.194 - @JavaScriptBody(args="a", body="return Math.acos(a);")
140.195 - public static double acos(double a) {
140.196 - throw new UnsupportedOperationException();
140.197 - }
140.198 -
140.199 - /**
140.200 - * Returns the arc tangent of a value; the returned angle is in the
140.201 - * range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
140.202 - * <ul><li>If the argument is NaN, then the result is NaN.
140.203 - * <li>If the argument is zero, then the result is a zero with the
140.204 - * same sign as the argument.</ul>
140.205 - *
140.206 - * <p>The computed result must be within 1 ulp of the exact result.
140.207 - * Results must be semi-monotonic.
140.208 - *
140.209 - * @param a the value whose arc tangent is to be returned.
140.210 - * @return the arc tangent of the argument.
140.211 - */
140.212 - @JavaScriptBody(args="a", body="return Math.atan(a);")
140.213 - public static double atan(double a) {
140.214 - throw new UnsupportedOperationException();
140.215 - }
140.216 -
140.217 - /**
140.218 - * Converts an angle measured in degrees to an approximately
140.219 - * equivalent angle measured in radians. The conversion from
140.220 - * degrees to radians is generally inexact.
140.221 - *
140.222 - * @param angdeg an angle, in degrees
140.223 - * @return the measurement of the angle {@code angdeg}
140.224 - * in radians.
140.225 - * @since 1.2
140.226 - */
140.227 - public static double toRadians(double angdeg) {
140.228 - return angdeg / 180.0 * PI;
140.229 - }
140.230 -
140.231 - /**
140.232 - * Converts an angle measured in radians to an approximately
140.233 - * equivalent angle measured in degrees. The conversion from
140.234 - * radians to degrees is generally inexact; users should
140.235 - * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
140.236 - * equal {@code 0.0}.
140.237 - *
140.238 - * @param angrad an angle, in radians
140.239 - * @return the measurement of the angle {@code angrad}
140.240 - * in degrees.
140.241 - * @since 1.2
140.242 - */
140.243 - public static double toDegrees(double angrad) {
140.244 - return angrad * 180.0 / PI;
140.245 - }
140.246 -
140.247 - /**
140.248 - * Returns Euler's number <i>e</i> raised to the power of a
140.249 - * {@code double} value. Special cases:
140.250 - * <ul><li>If the argument is NaN, the result is NaN.
140.251 - * <li>If the argument is positive infinity, then the result is
140.252 - * positive infinity.
140.253 - * <li>If the argument is negative infinity, then the result is
140.254 - * positive zero.</ul>
140.255 - *
140.256 - * <p>The computed result must be within 1 ulp of the exact result.
140.257 - * Results must be semi-monotonic.
140.258 - *
140.259 - * @param a the exponent to raise <i>e</i> to.
140.260 - * @return the value <i>e</i><sup>{@code a}</sup>,
140.261 - * where <i>e</i> is the base of the natural logarithms.
140.262 - */
140.263 - @JavaScriptBody(args="a", body="return Math.exp(a);")
140.264 - public static double exp(double a) {
140.265 - throw new UnsupportedOperationException();
140.266 - }
140.267 -
140.268 - /**
140.269 - * Returns the natural logarithm (base <i>e</i>) of a {@code double}
140.270 - * value. Special cases:
140.271 - * <ul><li>If the argument is NaN or less than zero, then the result
140.272 - * is NaN.
140.273 - * <li>If the argument is positive infinity, then the result is
140.274 - * positive infinity.
140.275 - * <li>If the argument is positive zero or negative zero, then the
140.276 - * result is negative infinity.</ul>
140.277 - *
140.278 - * <p>The computed result must be within 1 ulp of the exact result.
140.279 - * Results must be semi-monotonic.
140.280 - *
140.281 - * @param a a value
140.282 - * @return the value ln {@code a}, the natural logarithm of
140.283 - * {@code a}.
140.284 - */
140.285 - @JavaScriptBody(args="a", body="return Math.log(a);")
140.286 - public static double log(double a) {
140.287 - throw new UnsupportedOperationException();
140.288 - }
140.289 -
140.290 - /**
140.291 - * Returns the base 10 logarithm of a {@code double} value.
140.292 - * Special cases:
140.293 - *
140.294 - * <ul><li>If the argument is NaN or less than zero, then the result
140.295 - * is NaN.
140.296 - * <li>If the argument is positive infinity, then the result is
140.297 - * positive infinity.
140.298 - * <li>If the argument is positive zero or negative zero, then the
140.299 - * result is negative infinity.
140.300 - * <li> If the argument is equal to 10<sup><i>n</i></sup> for
140.301 - * integer <i>n</i>, then the result is <i>n</i>.
140.302 - * </ul>
140.303 - *
140.304 - * <p>The computed result must be within 1 ulp of the exact result.
140.305 - * Results must be semi-monotonic.
140.306 - *
140.307 - * @param a a value
140.308 - * @return the base 10 logarithm of {@code a}.
140.309 - * @since 1.5
140.310 - */
140.311 - @JavaScriptBody(args="a", body="return Math.log(a) / Math.LN10;")
140.312 - public static double log10(double a) {
140.313 - throw new UnsupportedOperationException();
140.314 - }
140.315 -
140.316 - /**
140.317 - * Returns the correctly rounded positive square root of a
140.318 - * {@code double} value.
140.319 - * Special cases:
140.320 - * <ul><li>If the argument is NaN or less than zero, then the result
140.321 - * is NaN.
140.322 - * <li>If the argument is positive infinity, then the result is positive
140.323 - * infinity.
140.324 - * <li>If the argument is positive zero or negative zero, then the
140.325 - * result is the same as the argument.</ul>
140.326 - * Otherwise, the result is the {@code double} value closest to
140.327 - * the true mathematical square root of the argument value.
140.328 - *
140.329 - * @param a a value.
140.330 - * @return the positive square root of {@code a}.
140.331 - * If the argument is NaN or less than zero, the result is NaN.
140.332 - */
140.333 - @JavaScriptBody(args="a", body="return Math.sqrt(a);")
140.334 - public static double sqrt(double a) {
140.335 - throw new UnsupportedOperationException();
140.336 - }
140.337 -
140.338 - /**
140.339 - * Returns the smallest (closest to negative infinity)
140.340 - * {@code double} value that is greater than or equal to the
140.341 - * argument and is equal to a mathematical integer. Special cases:
140.342 - * <ul><li>If the argument value is already equal to a
140.343 - * mathematical integer, then the result is the same as the
140.344 - * argument. <li>If the argument is NaN or an infinity or
140.345 - * positive zero or negative zero, then the result is the same as
140.346 - * the argument. <li>If the argument value is less than zero but
140.347 - * greater than -1.0, then the result is negative zero.</ul> Note
140.348 - * that the value of {@code Math.ceil(x)} is exactly the
140.349 - * value of {@code -Math.floor(-x)}.
140.350 - *
140.351 - *
140.352 - * @param a a value.
140.353 - * @return the smallest (closest to negative infinity)
140.354 - * floating-point value that is greater than or equal to
140.355 - * the argument and is equal to a mathematical integer.
140.356 - */
140.357 - @JavaScriptBody(args="a", body="return Math.ceil(a);")
140.358 - public static double ceil(double a) {
140.359 - throw new UnsupportedOperationException();
140.360 - }
140.361 -
140.362 - /**
140.363 - * Returns the largest (closest to positive infinity)
140.364 - * {@code double} value that is less than or equal to the
140.365 - * argument and is equal to a mathematical integer. Special cases:
140.366 - * <ul><li>If the argument value is already equal to a
140.367 - * mathematical integer, then the result is the same as the
140.368 - * argument. <li>If the argument is NaN or an infinity or
140.369 - * positive zero or negative zero, then the result is the same as
140.370 - * the argument.</ul>
140.371 - *
140.372 - * @param a a value.
140.373 - * @return the largest (closest to positive infinity)
140.374 - * floating-point value that less than or equal to the argument
140.375 - * and is equal to a mathematical integer.
140.376 - */
140.377 - @JavaScriptBody(args="a", body="return Math.floor(a);")
140.378 - public static double floor(double a) {
140.379 - throw new UnsupportedOperationException();
140.380 - }
140.381 -
140.382 - /**
140.383 - * Returns the angle <i>theta</i> from the conversion of rectangular
140.384 - * coordinates ({@code x}, {@code y}) to polar
140.385 - * coordinates (r, <i>theta</i>).
140.386 - * This method computes the phase <i>theta</i> by computing an arc tangent
140.387 - * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
140.388 - * cases:
140.389 - * <ul><li>If either argument is NaN, then the result is NaN.
140.390 - * <li>If the first argument is positive zero and the second argument
140.391 - * is positive, or the first argument is positive and finite and the
140.392 - * second argument is positive infinity, then the result is positive
140.393 - * zero.
140.394 - * <li>If the first argument is negative zero and the second argument
140.395 - * is positive, or the first argument is negative and finite and the
140.396 - * second argument is positive infinity, then the result is negative zero.
140.397 - * <li>If the first argument is positive zero and the second argument
140.398 - * is negative, or the first argument is positive and finite and the
140.399 - * second argument is negative infinity, then the result is the
140.400 - * {@code double} value closest to <i>pi</i>.
140.401 - * <li>If the first argument is negative zero and the second argument
140.402 - * is negative, or the first argument is negative and finite and the
140.403 - * second argument is negative infinity, then the result is the
140.404 - * {@code double} value closest to -<i>pi</i>.
140.405 - * <li>If the first argument is positive and the second argument is
140.406 - * positive zero or negative zero, or the first argument is positive
140.407 - * infinity and the second argument is finite, then the result is the
140.408 - * {@code double} value closest to <i>pi</i>/2.
140.409 - * <li>If the first argument is negative and the second argument is
140.410 - * positive zero or negative zero, or the first argument is negative
140.411 - * infinity and the second argument is finite, then the result is the
140.412 - * {@code double} value closest to -<i>pi</i>/2.
140.413 - * <li>If both arguments are positive infinity, then the result is the
140.414 - * {@code double} value closest to <i>pi</i>/4.
140.415 - * <li>If the first argument is positive infinity and the second argument
140.416 - * is negative infinity, then the result is the {@code double}
140.417 - * value closest to 3*<i>pi</i>/4.
140.418 - * <li>If the first argument is negative infinity and the second argument
140.419 - * is positive infinity, then the result is the {@code double} value
140.420 - * closest to -<i>pi</i>/4.
140.421 - * <li>If both arguments are negative infinity, then the result is the
140.422 - * {@code double} value closest to -3*<i>pi</i>/4.</ul>
140.423 - *
140.424 - * <p>The computed result must be within 2 ulps of the exact result.
140.425 - * Results must be semi-monotonic.
140.426 - *
140.427 - * @param y the ordinate coordinate
140.428 - * @param x the abscissa coordinate
140.429 - * @return the <i>theta</i> component of the point
140.430 - * (<i>r</i>, <i>theta</i>)
140.431 - * in polar coordinates that corresponds to the point
140.432 - * (<i>x</i>, <i>y</i>) in Cartesian coordinates.
140.433 - */
140.434 - @JavaScriptBody(args={"y", "x"}, body="return Math.atan2(y, x);")
140.435 - public static double atan2(double y, double x) {
140.436 - throw new UnsupportedOperationException();
140.437 - }
140.438 -
140.439 - /**
140.440 - * Returns the value of the first argument raised to the power of the
140.441 - * second argument. Special cases:
140.442 - *
140.443 - * <ul><li>If the second argument is positive or negative zero, then the
140.444 - * result is 1.0.
140.445 - * <li>If the second argument is 1.0, then the result is the same as the
140.446 - * first argument.
140.447 - * <li>If the second argument is NaN, then the result is NaN.
140.448 - * <li>If the first argument is NaN and the second argument is nonzero,
140.449 - * then the result is NaN.
140.450 - *
140.451 - * <li>If
140.452 - * <ul>
140.453 - * <li>the absolute value of the first argument is greater than 1
140.454 - * and the second argument is positive infinity, or
140.455 - * <li>the absolute value of the first argument is less than 1 and
140.456 - * the second argument is negative infinity,
140.457 - * </ul>
140.458 - * then the result is positive infinity.
140.459 - *
140.460 - * <li>If
140.461 - * <ul>
140.462 - * <li>the absolute value of the first argument is greater than 1 and
140.463 - * the second argument is negative infinity, or
140.464 - * <li>the absolute value of the
140.465 - * first argument is less than 1 and the second argument is positive
140.466 - * infinity,
140.467 - * </ul>
140.468 - * then the result is positive zero.
140.469 - *
140.470 - * <li>If the absolute value of the first argument equals 1 and the
140.471 - * second argument is infinite, then the result is NaN.
140.472 - *
140.473 - * <li>If
140.474 - * <ul>
140.475 - * <li>the first argument is positive zero and the second argument
140.476 - * is greater than zero, or
140.477 - * <li>the first argument is positive infinity and the second
140.478 - * argument is less than zero,
140.479 - * </ul>
140.480 - * then the result is positive zero.
140.481 - *
140.482 - * <li>If
140.483 - * <ul>
140.484 - * <li>the first argument is positive zero and the second argument
140.485 - * is less than zero, or
140.486 - * <li>the first argument is positive infinity and the second
140.487 - * argument is greater than zero,
140.488 - * </ul>
140.489 - * then the result is positive infinity.
140.490 - *
140.491 - * <li>If
140.492 - * <ul>
140.493 - * <li>the first argument is negative zero and the second argument
140.494 - * is greater than zero but not a finite odd integer, or
140.495 - * <li>the first argument is negative infinity and the second
140.496 - * argument is less than zero but not a finite odd integer,
140.497 - * </ul>
140.498 - * then the result is positive zero.
140.499 - *
140.500 - * <li>If
140.501 - * <ul>
140.502 - * <li>the first argument is negative zero and the second argument
140.503 - * is a positive finite odd integer, or
140.504 - * <li>the first argument is negative infinity and the second
140.505 - * argument is a negative finite odd integer,
140.506 - * </ul>
140.507 - * then the result is negative zero.
140.508 - *
140.509 - * <li>If
140.510 - * <ul>
140.511 - * <li>the first argument is negative zero and the second argument
140.512 - * is less than zero but not a finite odd integer, or
140.513 - * <li>the first argument is negative infinity and the second
140.514 - * argument is greater than zero but not a finite odd integer,
140.515 - * </ul>
140.516 - * then the result is positive infinity.
140.517 - *
140.518 - * <li>If
140.519 - * <ul>
140.520 - * <li>the first argument is negative zero and the second argument
140.521 - * is a negative finite odd integer, or
140.522 - * <li>the first argument is negative infinity and the second
140.523 - * argument is a positive finite odd integer,
140.524 - * </ul>
140.525 - * then the result is negative infinity.
140.526 - *
140.527 - * <li>If the first argument is finite and less than zero
140.528 - * <ul>
140.529 - * <li> if the second argument is a finite even integer, the
140.530 - * result is equal to the result of raising the absolute value of
140.531 - * the first argument to the power of the second argument
140.532 - *
140.533 - * <li>if the second argument is a finite odd integer, the result
140.534 - * is equal to the negative of the result of raising the absolute
140.535 - * value of the first argument to the power of the second
140.536 - * argument
140.537 - *
140.538 - * <li>if the second argument is finite and not an integer, then
140.539 - * the result is NaN.
140.540 - * </ul>
140.541 - *
140.542 - * <li>If both arguments are integers, then the result is exactly equal
140.543 - * to the mathematical result of raising the first argument to the power
140.544 - * of the second argument if that result can in fact be represented
140.545 - * exactly as a {@code double} value.</ul>
140.546 - *
140.547 - * <p>(In the foregoing descriptions, a floating-point value is
140.548 - * considered to be an integer if and only if it is finite and a
140.549 - * fixed point of the method {@link #ceil ceil} or,
140.550 - * equivalently, a fixed point of the method {@link #floor
140.551 - * floor}. A value is a fixed point of a one-argument
140.552 - * method if and only if the result of applying the method to the
140.553 - * value is equal to the value.)
140.554 - *
140.555 - * <p>The computed result must be within 1 ulp of the exact result.
140.556 - * Results must be semi-monotonic.
140.557 - *
140.558 - * @param a the base.
140.559 - * @param b the exponent.
140.560 - * @return the value {@code a}<sup>{@code b}</sup>.
140.561 - */
140.562 - @JavaScriptBody(args={"a", "b"}, body="return Math.pow(a, b);")
140.563 - public static double pow(double a, double b) {
140.564 - throw new UnsupportedOperationException();
140.565 - }
140.566 -
140.567 - /**
140.568 - * Returns the closest {@code int} to the argument, with ties
140.569 - * rounding up.
140.570 - *
140.571 - * <p>
140.572 - * Special cases:
140.573 - * <ul><li>If the argument is NaN, the result is 0.
140.574 - * <li>If the argument is negative infinity or any value less than or
140.575 - * equal to the value of {@code Integer.MIN_VALUE}, the result is
140.576 - * equal to the value of {@code Integer.MIN_VALUE}.
140.577 - * <li>If the argument is positive infinity or any value greater than or
140.578 - * equal to the value of {@code Integer.MAX_VALUE}, the result is
140.579 - * equal to the value of {@code Integer.MAX_VALUE}.</ul>
140.580 - *
140.581 - * @param a a floating-point value to be rounded to an integer.
140.582 - * @return the value of the argument rounded to the nearest
140.583 - * {@code int} value.
140.584 - * @see java.lang.Integer#MAX_VALUE
140.585 - * @see java.lang.Integer#MIN_VALUE
140.586 - */
140.587 - @JavaScriptBody(args="a", body="return Math.round(a);")
140.588 - public static int round(float a) {
140.589 - throw new UnsupportedOperationException();
140.590 - }
140.591 -
140.592 - /**
140.593 - * Returns the closest {@code long} to the argument, with ties
140.594 - * rounding up.
140.595 - *
140.596 - * <p>Special cases:
140.597 - * <ul><li>If the argument is NaN, the result is 0.
140.598 - * <li>If the argument is negative infinity or any value less than or
140.599 - * equal to the value of {@code Long.MIN_VALUE}, the result is
140.600 - * equal to the value of {@code Long.MIN_VALUE}.
140.601 - * <li>If the argument is positive infinity or any value greater than or
140.602 - * equal to the value of {@code Long.MAX_VALUE}, the result is
140.603 - * equal to the value of {@code Long.MAX_VALUE}.</ul>
140.604 - *
140.605 - * @param a a floating-point value to be rounded to a
140.606 - * {@code long}.
140.607 - * @return the value of the argument rounded to the nearest
140.608 - * {@code long} value.
140.609 - * @see java.lang.Long#MAX_VALUE
140.610 - * @see java.lang.Long#MIN_VALUE
140.611 - */
140.612 - @JavaScriptBody(args="a", body="return Math.round(a);")
140.613 - public static long round(double a) {
140.614 - throw new UnsupportedOperationException();
140.615 - }
140.616 -
140.617 -// private static Random randomNumberGenerator;
140.618 -//
140.619 -// private static synchronized Random initRNG() {
140.620 -// Random rnd = randomNumberGenerator;
140.621 -// return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
140.622 -// }
140.623 -
140.624 - /**
140.625 - * Returns a {@code double} value with a positive sign, greater
140.626 - * than or equal to {@code 0.0} and less than {@code 1.0}.
140.627 - * Returned values are chosen pseudorandomly with (approximately)
140.628 - * uniform distribution from that range.
140.629 - *
140.630 - * <p>When this method is first called, it creates a single new
140.631 - * pseudorandom-number generator, exactly as if by the expression
140.632 - *
140.633 - * <blockquote>{@code new java.util.Random()}</blockquote>
140.634 - *
140.635 - * This new pseudorandom-number generator is used thereafter for
140.636 - * all calls to this method and is used nowhere else.
140.637 - *
140.638 - * <p>This method is properly synchronized to allow correct use by
140.639 - * more than one thread. However, if many threads need to generate
140.640 - * pseudorandom numbers at a great rate, it may reduce contention
140.641 - * for each thread to have its own pseudorandom-number generator.
140.642 - *
140.643 - * @return a pseudorandom {@code double} greater than or equal
140.644 - * to {@code 0.0} and less than {@code 1.0}.
140.645 - * @see Random#nextDouble()
140.646 - */
140.647 - @JavaScriptBody(args={}, body="return Math.random();")
140.648 - public static double random() {
140.649 - throw new UnsupportedOperationException();
140.650 - }
140.651 -
140.652 - /**
140.653 - * Returns the absolute value of an {@code int} value.
140.654 - * If the argument is not negative, the argument is returned.
140.655 - * If the argument is negative, the negation of the argument is returned.
140.656 - *
140.657 - * <p>Note that if the argument is equal to the value of
140.658 - * {@link Integer#MIN_VALUE}, the most negative representable
140.659 - * {@code int} value, the result is that same value, which is
140.660 - * negative.
140.661 - *
140.662 - * @param a the argument whose absolute value is to be determined
140.663 - * @return the absolute value of the argument.
140.664 - */
140.665 - public static int abs(int a) {
140.666 - return (a < 0) ? -a : a;
140.667 - }
140.668 -
140.669 - /**
140.670 - * Returns the absolute value of a {@code long} value.
140.671 - * If the argument is not negative, the argument is returned.
140.672 - * If the argument is negative, the negation of the argument is returned.
140.673 - *
140.674 - * <p>Note that if the argument is equal to the value of
140.675 - * {@link Long#MIN_VALUE}, the most negative representable
140.676 - * {@code long} value, the result is that same value, which
140.677 - * is negative.
140.678 - *
140.679 - * @param a the argument whose absolute value is to be determined
140.680 - * @return the absolute value of the argument.
140.681 - */
140.682 - public static long abs(long a) {
140.683 - return (a < 0) ? -a : a;
140.684 - }
140.685 -
140.686 - /**
140.687 - * Returns the absolute value of a {@code float} value.
140.688 - * If the argument is not negative, the argument is returned.
140.689 - * If the argument is negative, the negation of the argument is returned.
140.690 - * Special cases:
140.691 - * <ul><li>If the argument is positive zero or negative zero, the
140.692 - * result is positive zero.
140.693 - * <li>If the argument is infinite, the result is positive infinity.
140.694 - * <li>If the argument is NaN, the result is NaN.</ul>
140.695 - * In other words, the result is the same as the value of the expression:
140.696 - * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
140.697 - *
140.698 - * @param a the argument whose absolute value is to be determined
140.699 - * @return the absolute value of the argument.
140.700 - */
140.701 - public static float abs(float a) {
140.702 - return (a <= 0.0F) ? 0.0F - a : a;
140.703 - }
140.704 -
140.705 - /**
140.706 - * Returns the absolute value of a {@code double} value.
140.707 - * If the argument is not negative, the argument is returned.
140.708 - * If the argument is negative, the negation of the argument is returned.
140.709 - * Special cases:
140.710 - * <ul><li>If the argument is positive zero or negative zero, the result
140.711 - * is positive zero.
140.712 - * <li>If the argument is infinite, the result is positive infinity.
140.713 - * <li>If the argument is NaN, the result is NaN.</ul>
140.714 - * In other words, the result is the same as the value of the expression:
140.715 - * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
140.716 - *
140.717 - * @param a the argument whose absolute value is to be determined
140.718 - * @return the absolute value of the argument.
140.719 - */
140.720 - public static double abs(double a) {
140.721 - return (a <= 0.0D) ? 0.0D - a : a;
140.722 - }
140.723 -
140.724 - /**
140.725 - * Returns the greater of two {@code int} values. That is, the
140.726 - * result is the argument closer to the value of
140.727 - * {@link Integer#MAX_VALUE}. If the arguments have the same value,
140.728 - * the result is that same value.
140.729 - *
140.730 - * @param a an argument.
140.731 - * @param b another argument.
140.732 - * @return the larger of {@code a} and {@code b}.
140.733 - */
140.734 - public static int max(int a, int b) {
140.735 - return (a >= b) ? a : b;
140.736 - }
140.737 -
140.738 - /**
140.739 - * Returns the greater of two {@code long} values. That is, the
140.740 - * result is the argument closer to the value of
140.741 - * {@link Long#MAX_VALUE}. If the arguments have the same value,
140.742 - * the result is that same value.
140.743 - *
140.744 - * @param a an argument.
140.745 - * @param b another argument.
140.746 - * @return the larger of {@code a} and {@code b}.
140.747 - */
140.748 - public static long max(long a, long b) {
140.749 - return (a >= b) ? a : b;
140.750 - }
140.751 -
140.752 - /**
140.753 - * Returns the greater of two {@code float} values. That is,
140.754 - * the result is the argument closer to positive infinity. If the
140.755 - * arguments have the same value, the result is that same
140.756 - * value. If either value is NaN, then the result is NaN. Unlike
140.757 - * the numerical comparison operators, this method considers
140.758 - * negative zero to be strictly smaller than positive zero. If one
140.759 - * argument is positive zero and the other negative zero, the
140.760 - * result is positive zero.
140.761 - *
140.762 - * @param a an argument.
140.763 - * @param b another argument.
140.764 - * @return the larger of {@code a} and {@code b}.
140.765 - */
140.766 - @JavaScriptBody(args={"a", "b"},
140.767 - body="return Math.max(a,b);"
140.768 - )
140.769 - public static float max(float a, float b) {
140.770 - throw new UnsupportedOperationException();
140.771 - }
140.772 -
140.773 - /**
140.774 - * Returns the greater of two {@code double} values. That
140.775 - * is, the result is the argument closer to positive infinity. If
140.776 - * the arguments have the same value, the result is that same
140.777 - * value. If either value is NaN, then the result is NaN. Unlike
140.778 - * the numerical comparison operators, this method considers
140.779 - * negative zero to be strictly smaller than positive zero. If one
140.780 - * argument is positive zero and the other negative zero, the
140.781 - * result is positive zero.
140.782 - *
140.783 - * @param a an argument.
140.784 - * @param b another argument.
140.785 - * @return the larger of {@code a} and {@code b}.
140.786 - */
140.787 - @JavaScriptBody(args={"a", "b"},
140.788 - body="return Math.max(a,b);"
140.789 - )
140.790 - public static double max(double a, double b) {
140.791 - throw new UnsupportedOperationException();
140.792 - }
140.793 -
140.794 - /**
140.795 - * Returns the smaller of two {@code int} values. That is,
140.796 - * the result the argument closer to the value of
140.797 - * {@link Integer#MIN_VALUE}. If the arguments have the same
140.798 - * value, the result is that same value.
140.799 - *
140.800 - * @param a an argument.
140.801 - * @param b another argument.
140.802 - * @return the smaller of {@code a} and {@code b}.
140.803 - */
140.804 - public static int min(int a, int b) {
140.805 - return (a <= b) ? a : b;
140.806 - }
140.807 -
140.808 - /**
140.809 - * Returns the smaller of two {@code long} values. That is,
140.810 - * the result is the argument closer to the value of
140.811 - * {@link Long#MIN_VALUE}. If the arguments have the same
140.812 - * value, the result is that same value.
140.813 - *
140.814 - * @param a an argument.
140.815 - * @param b another argument.
140.816 - * @return the smaller of {@code a} and {@code b}.
140.817 - */
140.818 - public static long min(long a, long b) {
140.819 - return (a <= b) ? a : b;
140.820 - }
140.821 -
140.822 - /**
140.823 - * Returns the smaller of two {@code float} values. That is,
140.824 - * the result is the value closer to negative infinity. If the
140.825 - * arguments have the same value, the result is that same
140.826 - * value. If either value is NaN, then the result is NaN. Unlike
140.827 - * the numerical comparison operators, this method considers
140.828 - * negative zero to be strictly smaller than positive zero. If
140.829 - * one argument is positive zero and the other is negative zero,
140.830 - * the result is negative zero.
140.831 - *
140.832 - * @param a an argument.
140.833 - * @param b another argument.
140.834 - * @return the smaller of {@code a} and {@code b}.
140.835 - */
140.836 - @JavaScriptBody(args={"a", "b"},
140.837 - body="return Math.min(a,b);"
140.838 - )
140.839 - public static float min(float a, float b) {
140.840 - throw new UnsupportedOperationException();
140.841 - }
140.842 -
140.843 - /**
140.844 - * Returns the smaller of two {@code double} values. That
140.845 - * is, the result is the value closer to negative infinity. If the
140.846 - * arguments have the same value, the result is that same
140.847 - * value. If either value is NaN, then the result is NaN. Unlike
140.848 - * the numerical comparison operators, this method considers
140.849 - * negative zero to be strictly smaller than positive zero. If one
140.850 - * argument is positive zero and the other is negative zero, the
140.851 - * result is negative zero.
140.852 - *
140.853 - * @param a an argument.
140.854 - * @param b another argument.
140.855 - * @return the smaller of {@code a} and {@code b}.
140.856 - */
140.857 - @JavaScriptBody(args={"a", "b"},
140.858 - body="return Math.min(a,b);"
140.859 - )
140.860 - public static double min(double a, double b) {
140.861 - throw new UnsupportedOperationException();
140.862 - }
140.863 -
140.864 - /**
140.865 - * Returns the size of an ulp of the argument. An ulp of a
140.866 - * {@code double} value is the positive distance between this
140.867 - * floating-point value and the {@code double} value next
140.868 - * larger in magnitude. Note that for non-NaN <i>x</i>,
140.869 - * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
140.870 - *
140.871 - * <p>Special Cases:
140.872 - * <ul>
140.873 - * <li> If the argument is NaN, then the result is NaN.
140.874 - * <li> If the argument is positive or negative infinity, then the
140.875 - * result is positive infinity.
140.876 - * <li> If the argument is positive or negative zero, then the result is
140.877 - * {@code Double.MIN_VALUE}.
140.878 - * <li> If the argument is ±{@code Double.MAX_VALUE}, then
140.879 - * the result is equal to 2<sup>971</sup>.
140.880 - * </ul>
140.881 - *
140.882 - * @param d the floating-point value whose ulp is to be returned
140.883 - * @return the size of an ulp of the argument
140.884 - * @author Joseph D. Darcy
140.885 - * @since 1.5
140.886 - */
140.887 -// public static double ulp(double d) {
140.888 -// return sun.misc.FpUtils.ulp(d);
140.889 -// }
140.890 -
140.891 - /**
140.892 - * Returns the size of an ulp of the argument. An ulp of a
140.893 - * {@code float} value is the positive distance between this
140.894 - * floating-point value and the {@code float} value next
140.895 - * larger in magnitude. Note that for non-NaN <i>x</i>,
140.896 - * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
140.897 - *
140.898 - * <p>Special Cases:
140.899 - * <ul>
140.900 - * <li> If the argument is NaN, then the result is NaN.
140.901 - * <li> If the argument is positive or negative infinity, then the
140.902 - * result is positive infinity.
140.903 - * <li> If the argument is positive or negative zero, then the result is
140.904 - * {@code Float.MIN_VALUE}.
140.905 - * <li> If the argument is ±{@code Float.MAX_VALUE}, then
140.906 - * the result is equal to 2<sup>104</sup>.
140.907 - * </ul>
140.908 - *
140.909 - * @param f the floating-point value whose ulp is to be returned
140.910 - * @return the size of an ulp of the argument
140.911 - * @author Joseph D. Darcy
140.912 - * @since 1.5
140.913 - */
140.914 -// public static float ulp(float f) {
140.915 -// return sun.misc.FpUtils.ulp(f);
140.916 -// }
140.917 -
140.918 - /**
140.919 - * Returns the signum function of the argument; zero if the argument
140.920 - * is zero, 1.0 if the argument is greater than zero, -1.0 if the
140.921 - * argument is less than zero.
140.922 - *
140.923 - * <p>Special Cases:
140.924 - * <ul>
140.925 - * <li> If the argument is NaN, then the result is NaN.
140.926 - * <li> If the argument is positive zero or negative zero, then the
140.927 - * result is the same as the argument.
140.928 - * </ul>
140.929 - *
140.930 - * @param d the floating-point value whose signum is to be returned
140.931 - * @return the signum function of the argument
140.932 - * @author Joseph D. Darcy
140.933 - * @since 1.5
140.934 - */
140.935 -// public static double signum(double d) {
140.936 -// return sun.misc.FpUtils.signum(d);
140.937 -// }
140.938 -
140.939 - /**
140.940 - * Returns the signum function of the argument; zero if the argument
140.941 - * is zero, 1.0f if the argument is greater than zero, -1.0f if the
140.942 - * argument is less than zero.
140.943 - *
140.944 - * <p>Special Cases:
140.945 - * <ul>
140.946 - * <li> If the argument is NaN, then the result is NaN.
140.947 - * <li> If the argument is positive zero or negative zero, then the
140.948 - * result is the same as the argument.
140.949 - * </ul>
140.950 - *
140.951 - * @param f the floating-point value whose signum is to be returned
140.952 - * @return the signum function of the argument
140.953 - * @author Joseph D. Darcy
140.954 - * @since 1.5
140.955 - */
140.956 -// public static float signum(float f) {
140.957 -// return sun.misc.FpUtils.signum(f);
140.958 -// }
140.959 -
140.960 - /**
140.961 - * Returns the first floating-point argument with the sign of the
140.962 - * second floating-point argument. Note that unlike the {@link
140.963 - * StrictMath#copySign(double, double) StrictMath.copySign}
140.964 - * method, this method does not require NaN {@code sign}
140.965 - * arguments to be treated as positive values; implementations are
140.966 - * permitted to treat some NaN arguments as positive and other NaN
140.967 - * arguments as negative to allow greater performance.
140.968 - *
140.969 - * @param magnitude the parameter providing the magnitude of the result
140.970 - * @param sign the parameter providing the sign of the result
140.971 - * @return a value with the magnitude of {@code magnitude}
140.972 - * and the sign of {@code sign}.
140.973 - * @since 1.6
140.974 - */
140.975 -// public static double copySign(double magnitude, double sign) {
140.976 -// return sun.misc.FpUtils.rawCopySign(magnitude, sign);
140.977 -// }
140.978 -
140.979 - /**
140.980 - * Returns the first floating-point argument with the sign of the
140.981 - * second floating-point argument. Note that unlike the {@link
140.982 - * StrictMath#copySign(float, float) StrictMath.copySign}
140.983 - * method, this method does not require NaN {@code sign}
140.984 - * arguments to be treated as positive values; implementations are
140.985 - * permitted to treat some NaN arguments as positive and other NaN
140.986 - * arguments as negative to allow greater performance.
140.987 - *
140.988 - * @param magnitude the parameter providing the magnitude of the result
140.989 - * @param sign the parameter providing the sign of the result
140.990 - * @return a value with the magnitude of {@code magnitude}
140.991 - * and the sign of {@code sign}.
140.992 - * @since 1.6
140.993 - */
140.994 -// public static float copySign(float magnitude, float sign) {
140.995 -// return sun.misc.FpUtils.rawCopySign(magnitude, sign);
140.996 -// }
140.997 -
140.998 - /**
140.999 - * Returns the unbiased exponent used in the representation of a
140.1000 - * {@code float}. Special cases:
140.1001 - *
140.1002 - * <ul>
140.1003 - * <li>If the argument is NaN or infinite, then the result is
140.1004 - * {@link Float#MAX_EXPONENT} + 1.
140.1005 - * <li>If the argument is zero or subnormal, then the result is
140.1006 - * {@link Float#MIN_EXPONENT} -1.
140.1007 - * </ul>
140.1008 - * @param f a {@code float} value
140.1009 - * @return the unbiased exponent of the argument
140.1010 - * @since 1.6
140.1011 - */
140.1012 -// public static int getExponent(float f) {
140.1013 -// return sun.misc.FpUtils.getExponent(f);
140.1014 -// }
140.1015 -
140.1016 - /**
140.1017 - * Returns the unbiased exponent used in the representation of a
140.1018 - * {@code double}. Special cases:
140.1019 - *
140.1020 - * <ul>
140.1021 - * <li>If the argument is NaN or infinite, then the result is
140.1022 - * {@link Double#MAX_EXPONENT} + 1.
140.1023 - * <li>If the argument is zero or subnormal, then the result is
140.1024 - * {@link Double#MIN_EXPONENT} -1.
140.1025 - * </ul>
140.1026 - * @param d a {@code double} value
140.1027 - * @return the unbiased exponent of the argument
140.1028 - * @since 1.6
140.1029 - */
140.1030 -// public static int getExponent(double d) {
140.1031 -// return sun.misc.FpUtils.getExponent(d);
140.1032 -// }
140.1033 -
140.1034 - /**
140.1035 - * Returns the floating-point number adjacent to the first
140.1036 - * argument in the direction of the second argument. If both
140.1037 - * arguments compare as equal the second argument is returned.
140.1038 - *
140.1039 - * <p>
140.1040 - * Special cases:
140.1041 - * <ul>
140.1042 - * <li> If either argument is a NaN, then NaN is returned.
140.1043 - *
140.1044 - * <li> If both arguments are signed zeros, {@code direction}
140.1045 - * is returned unchanged (as implied by the requirement of
140.1046 - * returning the second argument if the arguments compare as
140.1047 - * equal).
140.1048 - *
140.1049 - * <li> If {@code start} is
140.1050 - * ±{@link Double#MIN_VALUE} and {@code direction}
140.1051 - * has a value such that the result should have a smaller
140.1052 - * magnitude, then a zero with the same sign as {@code start}
140.1053 - * is returned.
140.1054 - *
140.1055 - * <li> If {@code start} is infinite and
140.1056 - * {@code direction} has a value such that the result should
140.1057 - * have a smaller magnitude, {@link Double#MAX_VALUE} with the
140.1058 - * same sign as {@code start} is returned.
140.1059 - *
140.1060 - * <li> If {@code start} is equal to ±
140.1061 - * {@link Double#MAX_VALUE} and {@code direction} has a
140.1062 - * value such that the result should have a larger magnitude, an
140.1063 - * infinity with same sign as {@code start} is returned.
140.1064 - * </ul>
140.1065 - *
140.1066 - * @param start starting floating-point value
140.1067 - * @param direction value indicating which of
140.1068 - * {@code start}'s neighbors or {@code start} should
140.1069 - * be returned
140.1070 - * @return The floating-point number adjacent to {@code start} in the
140.1071 - * direction of {@code direction}.
140.1072 - * @since 1.6
140.1073 - */
140.1074 -// public static double nextAfter(double start, double direction) {
140.1075 -// return sun.misc.FpUtils.nextAfter(start, direction);
140.1076 -// }
140.1077 -
140.1078 - /**
140.1079 - * Returns the floating-point number adjacent to the first
140.1080 - * argument in the direction of the second argument. If both
140.1081 - * arguments compare as equal a value equivalent to the second argument
140.1082 - * is returned.
140.1083 - *
140.1084 - * <p>
140.1085 - * Special cases:
140.1086 - * <ul>
140.1087 - * <li> If either argument is a NaN, then NaN is returned.
140.1088 - *
140.1089 - * <li> If both arguments are signed zeros, a value equivalent
140.1090 - * to {@code direction} is returned.
140.1091 - *
140.1092 - * <li> If {@code start} is
140.1093 - * ±{@link Float#MIN_VALUE} and {@code direction}
140.1094 - * has a value such that the result should have a smaller
140.1095 - * magnitude, then a zero with the same sign as {@code start}
140.1096 - * is returned.
140.1097 - *
140.1098 - * <li> If {@code start} is infinite and
140.1099 - * {@code direction} has a value such that the result should
140.1100 - * have a smaller magnitude, {@link Float#MAX_VALUE} with the
140.1101 - * same sign as {@code start} is returned.
140.1102 - *
140.1103 - * <li> If {@code start} is equal to ±
140.1104 - * {@link Float#MAX_VALUE} and {@code direction} has a
140.1105 - * value such that the result should have a larger magnitude, an
140.1106 - * infinity with same sign as {@code start} is returned.
140.1107 - * </ul>
140.1108 - *
140.1109 - * @param start starting floating-point value
140.1110 - * @param direction value indicating which of
140.1111 - * {@code start}'s neighbors or {@code start} should
140.1112 - * be returned
140.1113 - * @return The floating-point number adjacent to {@code start} in the
140.1114 - * direction of {@code direction}.
140.1115 - * @since 1.6
140.1116 - */
140.1117 -// public static float nextAfter(float start, double direction) {
140.1118 -// return sun.misc.FpUtils.nextAfter(start, direction);
140.1119 -// }
140.1120 -
140.1121 - /**
140.1122 - * Returns the floating-point value adjacent to {@code d} in
140.1123 - * the direction of positive infinity. This method is
140.1124 - * semantically equivalent to {@code nextAfter(d,
140.1125 - * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
140.1126 - * implementation may run faster than its equivalent
140.1127 - * {@code nextAfter} call.
140.1128 - *
140.1129 - * <p>Special Cases:
140.1130 - * <ul>
140.1131 - * <li> If the argument is NaN, the result is NaN.
140.1132 - *
140.1133 - * <li> If the argument is positive infinity, the result is
140.1134 - * positive infinity.
140.1135 - *
140.1136 - * <li> If the argument is zero, the result is
140.1137 - * {@link Double#MIN_VALUE}
140.1138 - *
140.1139 - * </ul>
140.1140 - *
140.1141 - * @param d starting floating-point value
140.1142 - * @return The adjacent floating-point value closer to positive
140.1143 - * infinity.
140.1144 - * @since 1.6
140.1145 - */
140.1146 -// public static double nextUp(double d) {
140.1147 -// return sun.misc.FpUtils.nextUp(d);
140.1148 -// }
140.1149 -
140.1150 - /**
140.1151 - * Returns the floating-point value adjacent to {@code f} in
140.1152 - * the direction of positive infinity. This method is
140.1153 - * semantically equivalent to {@code nextAfter(f,
140.1154 - * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
140.1155 - * implementation may run faster than its equivalent
140.1156 - * {@code nextAfter} call.
140.1157 - *
140.1158 - * <p>Special Cases:
140.1159 - * <ul>
140.1160 - * <li> If the argument is NaN, the result is NaN.
140.1161 - *
140.1162 - * <li> If the argument is positive infinity, the result is
140.1163 - * positive infinity.
140.1164 - *
140.1165 - * <li> If the argument is zero, the result is
140.1166 - * {@link Float#MIN_VALUE}
140.1167 - *
140.1168 - * </ul>
140.1169 - *
140.1170 - * @param f starting floating-point value
140.1171 - * @return The adjacent floating-point value closer to positive
140.1172 - * infinity.
140.1173 - * @since 1.6
140.1174 - */
140.1175 -// public static float nextUp(float f) {
140.1176 -// return sun.misc.FpUtils.nextUp(f);
140.1177 -// }
140.1178 -
140.1179 -
140.1180 - /**
140.1181 - * Return {@code d} ×
140.1182 - * 2<sup>{@code scaleFactor}</sup> rounded as if performed
140.1183 - * by a single correctly rounded floating-point multiply to a
140.1184 - * member of the double value set. See the Java
140.1185 - * Language Specification for a discussion of floating-point
140.1186 - * value sets. If the exponent of the result is between {@link
140.1187 - * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
140.1188 - * answer is calculated exactly. If the exponent of the result
140.1189 - * would be larger than {@code Double.MAX_EXPONENT}, an
140.1190 - * infinity is returned. Note that if the result is subnormal,
140.1191 - * precision may be lost; that is, when {@code scalb(x, n)}
140.1192 - * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
140.1193 - * <i>x</i>. When the result is non-NaN, the result has the same
140.1194 - * sign as {@code d}.
140.1195 - *
140.1196 - * <p>Special cases:
140.1197 - * <ul>
140.1198 - * <li> If the first argument is NaN, NaN is returned.
140.1199 - * <li> If the first argument is infinite, then an infinity of the
140.1200 - * same sign is returned.
140.1201 - * <li> If the first argument is zero, then a zero of the same
140.1202 - * sign is returned.
140.1203 - * </ul>
140.1204 - *
140.1205 - * @param d number to be scaled by a power of two.
140.1206 - * @param scaleFactor power of 2 used to scale {@code d}
140.1207 - * @return {@code d} × 2<sup>{@code scaleFactor}</sup>
140.1208 - * @since 1.6
140.1209 - */
140.1210 -// public static double scalb(double d, int scaleFactor) {
140.1211 -// return sun.misc.FpUtils.scalb(d, scaleFactor);
140.1212 -// }
140.1213 -
140.1214 - /**
140.1215 - * Return {@code f} ×
140.1216 - * 2<sup>{@code scaleFactor}</sup> rounded as if performed
140.1217 - * by a single correctly rounded floating-point multiply to a
140.1218 - * member of the float value set. See the Java
140.1219 - * Language Specification for a discussion of floating-point
140.1220 - * value sets. If the exponent of the result is between {@link
140.1221 - * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
140.1222 - * answer is calculated exactly. If the exponent of the result
140.1223 - * would be larger than {@code Float.MAX_EXPONENT}, an
140.1224 - * infinity is returned. Note that if the result is subnormal,
140.1225 - * precision may be lost; that is, when {@code scalb(x, n)}
140.1226 - * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
140.1227 - * <i>x</i>. When the result is non-NaN, the result has the same
140.1228 - * sign as {@code f}.
140.1229 - *
140.1230 - * <p>Special cases:
140.1231 - * <ul>
140.1232 - * <li> If the first argument is NaN, NaN is returned.
140.1233 - * <li> If the first argument is infinite, then an infinity of the
140.1234 - * same sign is returned.
140.1235 - * <li> If the first argument is zero, then a zero of the same
140.1236 - * sign is returned.
140.1237 - * </ul>
140.1238 - *
140.1239 - * @param f number to be scaled by a power of two.
140.1240 - * @param scaleFactor power of 2 used to scale {@code f}
140.1241 - * @return {@code f} × 2<sup>{@code scaleFactor}</sup>
140.1242 - * @since 1.6
140.1243 - */
140.1244 -// public static float scalb(float f, int scaleFactor) {
140.1245 -// return sun.misc.FpUtils.scalb(f, scaleFactor);
140.1246 -// }
140.1247 -}
141.1 --- a/emul/src/main/java/java/lang/NegativeArraySizeException.java Wed Jan 23 20:16:48 2013 +0100
141.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
141.3 @@ -1,55 +0,0 @@
141.4 -/*
141.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
141.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
141.7 - *
141.8 - * This code is free software; you can redistribute it and/or modify it
141.9 - * under the terms of the GNU General Public License version 2 only, as
141.10 - * published by the Free Software Foundation. Oracle designates this
141.11 - * particular file as subject to the "Classpath" exception as provided
141.12 - * by Oracle in the LICENSE file that accompanied this code.
141.13 - *
141.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
141.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
141.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
141.17 - * version 2 for more details (a copy is included in the LICENSE file that
141.18 - * accompanied this code).
141.19 - *
141.20 - * You should have received a copy of the GNU General Public License version
141.21 - * 2 along with this work; if not, write to the Free Software Foundation,
141.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
141.23 - *
141.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
141.25 - * or visit www.oracle.com if you need additional information or have any
141.26 - * questions.
141.27 - */
141.28 -
141.29 -package java.lang;
141.30 -
141.31 -/**
141.32 - * Thrown if an application tries to create an array with negative size.
141.33 - *
141.34 - * @author unascribed
141.35 - * @since JDK1.0
141.36 - */
141.37 -public
141.38 -class NegativeArraySizeException extends RuntimeException {
141.39 - private static final long serialVersionUID = -8960118058596991861L;
141.40 -
141.41 - /**
141.42 - * Constructs a <code>NegativeArraySizeException</code> with no
141.43 - * detail message.
141.44 - */
141.45 - public NegativeArraySizeException() {
141.46 - super();
141.47 - }
141.48 -
141.49 - /**
141.50 - * Constructs a <code>NegativeArraySizeException</code> with the
141.51 - * specified detail message.
141.52 - *
141.53 - * @param s the detail message.
141.54 - */
141.55 - public NegativeArraySizeException(String s) {
141.56 - super(s);
141.57 - }
141.58 -}
142.1 --- a/emul/src/main/java/java/lang/NoSuchMethodException.java Wed Jan 23 20:16:48 2013 +0100
142.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
142.3 @@ -1,53 +0,0 @@
142.4 -/*
142.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
142.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
142.7 - *
142.8 - * This code is free software; you can redistribute it and/or modify it
142.9 - * under the terms of the GNU General Public License version 2 only, as
142.10 - * published by the Free Software Foundation. Oracle designates this
142.11 - * particular file as subject to the "Classpath" exception as provided
142.12 - * by Oracle in the LICENSE file that accompanied this code.
142.13 - *
142.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
142.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
142.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
142.17 - * version 2 for more details (a copy is included in the LICENSE file that
142.18 - * accompanied this code).
142.19 - *
142.20 - * You should have received a copy of the GNU General Public License version
142.21 - * 2 along with this work; if not, write to the Free Software Foundation,
142.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
142.23 - *
142.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
142.25 - * or visit www.oracle.com if you need additional information or have any
142.26 - * questions.
142.27 - */
142.28 -
142.29 -package java.lang;
142.30 -
142.31 -/**
142.32 - * Thrown when a particular method cannot be found.
142.33 - *
142.34 - * @author unascribed
142.35 - * @since JDK1.0
142.36 - */
142.37 -public
142.38 -class NoSuchMethodException extends ReflectiveOperationException {
142.39 - private static final long serialVersionUID = 5034388446362600923L;
142.40 -
142.41 - /**
142.42 - * Constructs a <code>NoSuchMethodException</code> without a detail message.
142.43 - */
142.44 - public NoSuchMethodException() {
142.45 - super();
142.46 - }
142.47 -
142.48 - /**
142.49 - * Constructs a <code>NoSuchMethodException</code> with a detail message.
142.50 - *
142.51 - * @param s the detail message.
142.52 - */
142.53 - public NoSuchMethodException(String s) {
142.54 - super(s);
142.55 - }
142.56 -}
143.1 --- a/emul/src/main/java/java/lang/NullPointerException.java Wed Jan 23 20:16:48 2013 +0100
143.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
143.3 @@ -1,72 +0,0 @@
143.4 -/*
143.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
143.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
143.7 - *
143.8 - * This code is free software; you can redistribute it and/or modify it
143.9 - * under the terms of the GNU General Public License version 2 only, as
143.10 - * published by the Free Software Foundation. Oracle designates this
143.11 - * particular file as subject to the "Classpath" exception as provided
143.12 - * by Oracle in the LICENSE file that accompanied this code.
143.13 - *
143.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
143.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
143.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
143.17 - * version 2 for more details (a copy is included in the LICENSE file that
143.18 - * accompanied this code).
143.19 - *
143.20 - * You should have received a copy of the GNU General Public License version
143.21 - * 2 along with this work; if not, write to the Free Software Foundation,
143.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
143.23 - *
143.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
143.25 - * or visit www.oracle.com if you need additional information or have any
143.26 - * questions.
143.27 - */
143.28 -
143.29 -package java.lang;
143.30 -
143.31 -/**
143.32 - * Thrown when an application attempts to use {@code null} in a
143.33 - * case where an object is required. These include:
143.34 - * <ul>
143.35 - * <li>Calling the instance method of a {@code null} object.
143.36 - * <li>Accessing or modifying the field of a {@code null} object.
143.37 - * <li>Taking the length of {@code null} as if it were an array.
143.38 - * <li>Accessing or modifying the slots of {@code null} as if it
143.39 - * were an array.
143.40 - * <li>Throwing {@code null} as if it were a {@code Throwable}
143.41 - * value.
143.42 - * </ul>
143.43 - * <p>
143.44 - * Applications should throw instances of this class to indicate
143.45 - * other illegal uses of the {@code null} object.
143.46 - *
143.47 - * {@code NullPointerException} objects may be constructed by the
143.48 - * virtual machine as if {@linkplain Throwable#Throwable(String,
143.49 - * Throwable, boolean, boolean) suppression were disabled and/or the
143.50 - * stack trace was not writable}.
143.51 - *
143.52 - * @author unascribed
143.53 - * @since JDK1.0
143.54 - */
143.55 -public
143.56 -class NullPointerException extends RuntimeException {
143.57 - private static final long serialVersionUID = 5162710183389028792L;
143.58 -
143.59 - /**
143.60 - * Constructs a {@code NullPointerException} with no detail message.
143.61 - */
143.62 - public NullPointerException() {
143.63 - super();
143.64 - }
143.65 -
143.66 - /**
143.67 - * Constructs a {@code NullPointerException} with the specified
143.68 - * detail message.
143.69 - *
143.70 - * @param s the detail message.
143.71 - */
143.72 - public NullPointerException(String s) {
143.73 - super(s);
143.74 - }
143.75 -}
144.1 --- a/emul/src/main/java/java/lang/Number.java Wed Jan 23 20:16:48 2013 +0100
144.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
144.3 @@ -1,118 +0,0 @@
144.4 -/*
144.5 - * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
144.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
144.7 - *
144.8 - * This code is free software; you can redistribute it and/or modify it
144.9 - * under the terms of the GNU General Public License version 2 only, as
144.10 - * published by the Free Software Foundation. Oracle designates this
144.11 - * particular file as subject to the "Classpath" exception as provided
144.12 - * by Oracle in the LICENSE file that accompanied this code.
144.13 - *
144.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
144.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
144.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
144.17 - * version 2 for more details (a copy is included in the LICENSE file that
144.18 - * accompanied this code).
144.19 - *
144.20 - * You should have received a copy of the GNU General Public License version
144.21 - * 2 along with this work; if not, write to the Free Software Foundation,
144.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
144.23 - *
144.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
144.25 - * or visit www.oracle.com if you need additional information or have any
144.26 - * questions.
144.27 - */
144.28 -
144.29 -package java.lang;
144.30 -
144.31 -import org.apidesign.bck2brwsr.core.ExtraJavaScript;
144.32 -
144.33 -/**
144.34 - * The abstract class <code>Number</code> is the superclass of classes
144.35 - * <code>BigDecimal</code>, <code>BigInteger</code>,
144.36 - * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
144.37 - * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
144.38 - * <p>
144.39 - * Subclasses of <code>Number</code> must provide methods to convert
144.40 - * the represented numeric value to <code>byte</code>, <code>double</code>,
144.41 - * <code>float</code>, <code>int</code>, <code>long</code>, and
144.42 - * <code>short</code>.
144.43 - *
144.44 - * @author Lee Boynton
144.45 - * @author Arthur van Hoff
144.46 - * @see java.lang.Byte
144.47 - * @see java.lang.Double
144.48 - * @see java.lang.Float
144.49 - * @see java.lang.Integer
144.50 - * @see java.lang.Long
144.51 - * @see java.lang.Short
144.52 - * @since JDK1.0
144.53 - */
144.54 -@ExtraJavaScript(
144.55 - resource="/org/apidesign/vm4brwsr/emul/java_lang_Number.js",
144.56 - processByteCode=true
144.57 -)
144.58 -public abstract class Number implements java.io.Serializable {
144.59 - /**
144.60 - * Returns the value of the specified number as an <code>int</code>.
144.61 - * This may involve rounding or truncation.
144.62 - *
144.63 - * @return the numeric value represented by this object after conversion
144.64 - * to type <code>int</code>.
144.65 - */
144.66 - public abstract int intValue();
144.67 -
144.68 - /**
144.69 - * Returns the value of the specified number as a <code>long</code>.
144.70 - * This may involve rounding or truncation.
144.71 - *
144.72 - * @return the numeric value represented by this object after conversion
144.73 - * to type <code>long</code>.
144.74 - */
144.75 - public abstract long longValue();
144.76 -
144.77 - /**
144.78 - * Returns the value of the specified number as a <code>float</code>.
144.79 - * This may involve rounding.
144.80 - *
144.81 - * @return the numeric value represented by this object after conversion
144.82 - * to type <code>float</code>.
144.83 - */
144.84 - public abstract float floatValue();
144.85 -
144.86 - /**
144.87 - * Returns the value of the specified number as a <code>double</code>.
144.88 - * This may involve rounding.
144.89 - *
144.90 - * @return the numeric value represented by this object after conversion
144.91 - * to type <code>double</code>.
144.92 - */
144.93 - public abstract double doubleValue();
144.94 -
144.95 - /**
144.96 - * Returns the value of the specified number as a <code>byte</code>.
144.97 - * This may involve rounding or truncation.
144.98 - *
144.99 - * @return the numeric value represented by this object after conversion
144.100 - * to type <code>byte</code>.
144.101 - * @since JDK1.1
144.102 - */
144.103 - public byte byteValue() {
144.104 - return (byte)intValue();
144.105 - }
144.106 -
144.107 - /**
144.108 - * Returns the value of the specified number as a <code>short</code>.
144.109 - * This may involve rounding or truncation.
144.110 - *
144.111 - * @return the numeric value represented by this object after conversion
144.112 - * to type <code>short</code>.
144.113 - * @since JDK1.1
144.114 - */
144.115 - public short shortValue() {
144.116 - return (short)intValue();
144.117 - }
144.118 -
144.119 - /** use serialVersionUID from JDK 1.0.2 for interoperability */
144.120 - private static final long serialVersionUID = -8742448824652078965L;
144.121 -}
145.1 --- a/emul/src/main/java/java/lang/NumberFormatException.java Wed Jan 23 20:16:48 2013 +0100
145.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
145.3 @@ -1,67 +0,0 @@
145.4 -/*
145.5 - * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
145.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
145.7 - *
145.8 - * This code is free software; you can redistribute it and/or modify it
145.9 - * under the terms of the GNU General Public License version 2 only, as
145.10 - * published by the Free Software Foundation. Oracle designates this
145.11 - * particular file as subject to the "Classpath" exception as provided
145.12 - * by Oracle in the LICENSE file that accompanied this code.
145.13 - *
145.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
145.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
145.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
145.17 - * version 2 for more details (a copy is included in the LICENSE file that
145.18 - * accompanied this code).
145.19 - *
145.20 - * You should have received a copy of the GNU General Public License version
145.21 - * 2 along with this work; if not, write to the Free Software Foundation,
145.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
145.23 - *
145.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
145.25 - * or visit www.oracle.com if you need additional information or have any
145.26 - * questions.
145.27 - */
145.28 -
145.29 -package java.lang;
145.30 -
145.31 -/**
145.32 - * Thrown to indicate that the application has attempted to convert
145.33 - * a string to one of the numeric types, but that the string does not
145.34 - * have the appropriate format.
145.35 - *
145.36 - * @author unascribed
145.37 - * @see java.lang.Integer#toString()
145.38 - * @since JDK1.0
145.39 - */
145.40 -public
145.41 -class NumberFormatException extends IllegalArgumentException {
145.42 - static final long serialVersionUID = -2848938806368998894L;
145.43 -
145.44 - /**
145.45 - * Constructs a <code>NumberFormatException</code> with no detail message.
145.46 - */
145.47 - public NumberFormatException () {
145.48 - super();
145.49 - }
145.50 -
145.51 - /**
145.52 - * Constructs a <code>NumberFormatException</code> with the
145.53 - * specified detail message.
145.54 - *
145.55 - * @param s the detail message.
145.56 - */
145.57 - public NumberFormatException (String s) {
145.58 - super (s);
145.59 - }
145.60 -
145.61 - /**
145.62 - * Factory method for making a <code>NumberFormatException</code>
145.63 - * given the specified input which caused the error.
145.64 - *
145.65 - * @param s the input causing the error
145.66 - */
145.67 - static NumberFormatException forInputString(String s) {
145.68 - return new NumberFormatException("For input string: \"" + s + "\"");
145.69 - }
145.70 -}
146.1 --- a/emul/src/main/java/java/lang/Object.java Wed Jan 23 20:16:48 2013 +0100
146.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
146.3 @@ -1,595 +0,0 @@
146.4 -/*
146.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
146.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
146.7 - *
146.8 - * This code is free software; you can redistribute it and/or modify it
146.9 - * under the terms of the GNU General Public License version 2 only, as
146.10 - * published by the Free Software Foundation. Oracle designates this
146.11 - * particular file as subject to the "Classpath" exception as provided
146.12 - * by Oracle in the LICENSE file that accompanied this code.
146.13 - *
146.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
146.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
146.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
146.17 - * version 2 for more details (a copy is included in the LICENSE file that
146.18 - * accompanied this code).
146.19 - *
146.20 - * You should have received a copy of the GNU General Public License version
146.21 - * 2 along with this work; if not, write to the Free Software Foundation,
146.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
146.23 - *
146.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
146.25 - * or visit www.oracle.com if you need additional information or have any
146.26 - * questions.
146.27 - */
146.28 -
146.29 -package java.lang;
146.30 -
146.31 -import java.lang.reflect.Array;
146.32 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
146.33 -import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
146.34 -
146.35 -/**
146.36 - * Class {@code Object} is the root of the class hierarchy.
146.37 - * Every class has {@code Object} as a superclass. All objects,
146.38 - * including arrays, implement the methods of this class.
146.39 - *
146.40 - * @author unascribed
146.41 - * @see java.lang.Class
146.42 - * @since JDK1.0
146.43 - */
146.44 -@JavaScriptPrototype(container = "Object.prototype", prototype = "new Object")
146.45 -public class Object {
146.46 -
146.47 - private static void registerNatives() {
146.48 - try {
146.49 - Array.get(null, 0);
146.50 - } catch (Throwable ex) {
146.51 - // ignore
146.52 - }
146.53 - }
146.54 - static {
146.55 - registerNatives();
146.56 - }
146.57 -
146.58 - /**
146.59 - * Returns the runtime class of this {@code Object}. The returned
146.60 - * {@code Class} object is the object that is locked by {@code
146.61 - * static synchronized} methods of the represented class.
146.62 - *
146.63 - * <p><b>The actual result type is {@code Class<? extends |X|>}
146.64 - * where {@code |X|} is the erasure of the static type of the
146.65 - * expression on which {@code getClass} is called.</b> For
146.66 - * example, no cast is required in this code fragment:</p>
146.67 - *
146.68 - * <p>
146.69 - * {@code Number n = 0; }<br>
146.70 - * {@code Class<? extends Number> c = n.getClass(); }
146.71 - * </p>
146.72 - *
146.73 - * @return The {@code Class} object that represents the runtime
146.74 - * class of this object.
146.75 - * @see Class Literals, section 15.8.2 of
146.76 - * <cite>The Java™ Language Specification</cite>.
146.77 - */
146.78 - @JavaScriptBody(args={}, body="return this.constructor.$class;")
146.79 - public final native Class<?> getClass();
146.80 -
146.81 - /**
146.82 - * Returns a hash code value for the object. This method is
146.83 - * supported for the benefit of hash tables such as those provided by
146.84 - * {@link java.util.HashMap}.
146.85 - * <p>
146.86 - * The general contract of {@code hashCode} is:
146.87 - * <ul>
146.88 - * <li>Whenever it is invoked on the same object more than once during
146.89 - * an execution of a Java application, the {@code hashCode} method
146.90 - * must consistently return the same integer, provided no information
146.91 - * used in {@code equals} comparisons on the object is modified.
146.92 - * This integer need not remain consistent from one execution of an
146.93 - * application to another execution of the same application.
146.94 - * <li>If two objects are equal according to the {@code equals(Object)}
146.95 - * method, then calling the {@code hashCode} method on each of
146.96 - * the two objects must produce the same integer result.
146.97 - * <li>It is <em>not</em> required that if two objects are unequal
146.98 - * according to the {@link java.lang.Object#equals(java.lang.Object)}
146.99 - * method, then calling the {@code hashCode} method on each of the
146.100 - * two objects must produce distinct integer results. However, the
146.101 - * programmer should be aware that producing distinct integer results
146.102 - * for unequal objects may improve the performance of hash tables.
146.103 - * </ul>
146.104 - * <p>
146.105 - * As much as is reasonably practical, the hashCode method defined by
146.106 - * class {@code Object} does return distinct integers for distinct
146.107 - * objects. (This is typically implemented by converting the internal
146.108 - * address of the object into an integer, but this implementation
146.109 - * technique is not required by the
146.110 - * Java<font size="-2"><sup>TM</sup></font> programming language.)
146.111 - *
146.112 - * @return a hash code value for this object.
146.113 - * @see java.lang.Object#equals(java.lang.Object)
146.114 - * @see java.lang.System#identityHashCode
146.115 - */
146.116 - @JavaScriptBody(args = {}, body =
146.117 - "if (this.$hashCode) return this.$hashCode;\n"
146.118 - + "var h = this.computeHashCode__I();\n"
146.119 - + "return this.$hashCode = h & h;"
146.120 - )
146.121 - public native int hashCode();
146.122 -
146.123 - @JavaScriptBody(args = {}, body = "Math.random() * Math.pow(2, 32);")
146.124 - native int computeHashCode();
146.125 -
146.126 - /**
146.127 - * Indicates whether some other object is "equal to" this one.
146.128 - * <p>
146.129 - * The {@code equals} method implements an equivalence relation
146.130 - * on non-null object references:
146.131 - * <ul>
146.132 - * <li>It is <i>reflexive</i>: for any non-null reference value
146.133 - * {@code x}, {@code x.equals(x)} should return
146.134 - * {@code true}.
146.135 - * <li>It is <i>symmetric</i>: for any non-null reference values
146.136 - * {@code x} and {@code y}, {@code x.equals(y)}
146.137 - * should return {@code true} if and only if
146.138 - * {@code y.equals(x)} returns {@code true}.
146.139 - * <li>It is <i>transitive</i>: for any non-null reference values
146.140 - * {@code x}, {@code y}, and {@code z}, if
146.141 - * {@code x.equals(y)} returns {@code true} and
146.142 - * {@code y.equals(z)} returns {@code true}, then
146.143 - * {@code x.equals(z)} should return {@code true}.
146.144 - * <li>It is <i>consistent</i>: for any non-null reference values
146.145 - * {@code x} and {@code y}, multiple invocations of
146.146 - * {@code x.equals(y)} consistently return {@code true}
146.147 - * or consistently return {@code false}, provided no
146.148 - * information used in {@code equals} comparisons on the
146.149 - * objects is modified.
146.150 - * <li>For any non-null reference value {@code x},
146.151 - * {@code x.equals(null)} should return {@code false}.
146.152 - * </ul>
146.153 - * <p>
146.154 - * The {@code equals} method for class {@code Object} implements
146.155 - * the most discriminating possible equivalence relation on objects;
146.156 - * that is, for any non-null reference values {@code x} and
146.157 - * {@code y}, this method returns {@code true} if and only
146.158 - * if {@code x} and {@code y} refer to the same object
146.159 - * ({@code x == y} has the value {@code true}).
146.160 - * <p>
146.161 - * Note that it is generally necessary to override the {@code hashCode}
146.162 - * method whenever this method is overridden, so as to maintain the
146.163 - * general contract for the {@code hashCode} method, which states
146.164 - * that equal objects must have equal hash codes.
146.165 - *
146.166 - * @param obj the reference object with which to compare.
146.167 - * @return {@code true} if this object is the same as the obj
146.168 - * argument; {@code false} otherwise.
146.169 - * @see #hashCode()
146.170 - * @see java.util.HashMap
146.171 - */
146.172 - public boolean equals(Object obj) {
146.173 - return (this == obj);
146.174 - }
146.175 -
146.176 - /**
146.177 - * Creates and returns a copy of this object. The precise meaning
146.178 - * of "copy" may depend on the class of the object. The general
146.179 - * intent is that, for any object {@code x}, the expression:
146.180 - * <blockquote>
146.181 - * <pre>
146.182 - * x.clone() != x</pre></blockquote>
146.183 - * will be true, and that the expression:
146.184 - * <blockquote>
146.185 - * <pre>
146.186 - * x.clone().getClass() == x.getClass()</pre></blockquote>
146.187 - * will be {@code true}, but these are not absolute requirements.
146.188 - * While it is typically the case that:
146.189 - * <blockquote>
146.190 - * <pre>
146.191 - * x.clone().equals(x)</pre></blockquote>
146.192 - * will be {@code true}, this is not an absolute requirement.
146.193 - * <p>
146.194 - * By convention, the returned object should be obtained by calling
146.195 - * {@code super.clone}. If a class and all of its superclasses (except
146.196 - * {@code Object}) obey this convention, it will be the case that
146.197 - * {@code x.clone().getClass() == x.getClass()}.
146.198 - * <p>
146.199 - * By convention, the object returned by this method should be independent
146.200 - * of this object (which is being cloned). To achieve this independence,
146.201 - * it may be necessary to modify one or more fields of the object returned
146.202 - * by {@code super.clone} before returning it. Typically, this means
146.203 - * copying any mutable objects that comprise the internal "deep structure"
146.204 - * of the object being cloned and replacing the references to these
146.205 - * objects with references to the copies. If a class contains only
146.206 - * primitive fields or references to immutable objects, then it is usually
146.207 - * the case that no fields in the object returned by {@code super.clone}
146.208 - * need to be modified.
146.209 - * <p>
146.210 - * The method {@code clone} for class {@code Object} performs a
146.211 - * specific cloning operation. First, if the class of this object does
146.212 - * not implement the interface {@code Cloneable}, then a
146.213 - * {@code CloneNotSupportedException} is thrown. Note that all arrays
146.214 - * are considered to implement the interface {@code Cloneable} and that
146.215 - * the return type of the {@code clone} method of an array type {@code T[]}
146.216 - * is {@code T[]} where T is any reference or primitive type.
146.217 - * Otherwise, this method creates a new instance of the class of this
146.218 - * object and initializes all its fields with exactly the contents of
146.219 - * the corresponding fields of this object, as if by assignment; the
146.220 - * contents of the fields are not themselves cloned. Thus, this method
146.221 - * performs a "shallow copy" of this object, not a "deep copy" operation.
146.222 - * <p>
146.223 - * The class {@code Object} does not itself implement the interface
146.224 - * {@code Cloneable}, so calling the {@code clone} method on an object
146.225 - * whose class is {@code Object} will result in throwing an
146.226 - * exception at run time.
146.227 - *
146.228 - * @return a clone of this instance.
146.229 - * @exception CloneNotSupportedException if the object's class does not
146.230 - * support the {@code Cloneable} interface. Subclasses
146.231 - * that override the {@code clone} method can also
146.232 - * throw this exception to indicate that an instance cannot
146.233 - * be cloned.
146.234 - * @see java.lang.Cloneable
146.235 - */
146.236 - protected Object clone() throws CloneNotSupportedException {
146.237 - Object ret = clone(this);
146.238 - if (ret == null) {
146.239 - throw new CloneNotSupportedException(getClass().getName());
146.240 - }
146.241 - return ret;
146.242 - }
146.243 -
146.244 - @JavaScriptBody(args = "self", body =
146.245 - "\nif (!self.$instOf_java_lang_Cloneable) {"
146.246 - + "\n return null;"
146.247 - + "\n} else {"
146.248 - + "\n var clone = self.constructor(true);"
146.249 - + "\n var props = Object.getOwnPropertyNames(self);"
146.250 - + "\n for (var i = 0; i < props.length; i++) {"
146.251 - + "\n var p = props[i];"
146.252 - + "\n clone[p] = self[p];"
146.253 - + "\n };"
146.254 - + "\n return clone;"
146.255 - + "\n}"
146.256 - )
146.257 - private static native Object clone(Object self) throws CloneNotSupportedException;
146.258 -
146.259 - /**
146.260 - * Returns a string representation of the object. In general, the
146.261 - * {@code toString} method returns a string that
146.262 - * "textually represents" this object. The result should
146.263 - * be a concise but informative representation that is easy for a
146.264 - * person to read.
146.265 - * It is recommended that all subclasses override this method.
146.266 - * <p>
146.267 - * The {@code toString} method for class {@code Object}
146.268 - * returns a string consisting of the name of the class of which the
146.269 - * object is an instance, the at-sign character `{@code @}', and
146.270 - * the unsigned hexadecimal representation of the hash code of the
146.271 - * object. In other words, this method returns a string equal to the
146.272 - * value of:
146.273 - * <blockquote>
146.274 - * <pre>
146.275 - * getClass().getName() + '@' + Integer.toHexString(hashCode())
146.276 - * </pre></blockquote>
146.277 - *
146.278 - * @return a string representation of the object.
146.279 - */
146.280 - public String toString() {
146.281 - return getClass().getName() + "@" + Integer.toHexString(hashCode());
146.282 - }
146.283 -
146.284 - /**
146.285 - * Wakes up a single thread that is waiting on this object's
146.286 - * monitor. If any threads are waiting on this object, one of them
146.287 - * is chosen to be awakened. The choice is arbitrary and occurs at
146.288 - * the discretion of the implementation. A thread waits on an object's
146.289 - * monitor by calling one of the {@code wait} methods.
146.290 - * <p>
146.291 - * The awakened thread will not be able to proceed until the current
146.292 - * thread relinquishes the lock on this object. The awakened thread will
146.293 - * compete in the usual manner with any other threads that might be
146.294 - * actively competing to synchronize on this object; for example, the
146.295 - * awakened thread enjoys no reliable privilege or disadvantage in being
146.296 - * the next thread to lock this object.
146.297 - * <p>
146.298 - * This method should only be called by a thread that is the owner
146.299 - * of this object's monitor. A thread becomes the owner of the
146.300 - * object's monitor in one of three ways:
146.301 - * <ul>
146.302 - * <li>By executing a synchronized instance method of that object.
146.303 - * <li>By executing the body of a {@code synchronized} statement
146.304 - * that synchronizes on the object.
146.305 - * <li>For objects of type {@code Class,} by executing a
146.306 - * synchronized static method of that class.
146.307 - * </ul>
146.308 - * <p>
146.309 - * Only one thread at a time can own an object's monitor.
146.310 - *
146.311 - * @exception IllegalMonitorStateException if the current thread is not
146.312 - * the owner of this object's monitor.
146.313 - * @see java.lang.Object#notifyAll()
146.314 - * @see java.lang.Object#wait()
146.315 - */
146.316 - public final native void notify();
146.317 -
146.318 - /**
146.319 - * Wakes up all threads that are waiting on this object's monitor. A
146.320 - * thread waits on an object's monitor by calling one of the
146.321 - * {@code wait} methods.
146.322 - * <p>
146.323 - * The awakened threads will not be able to proceed until the current
146.324 - * thread relinquishes the lock on this object. The awakened threads
146.325 - * will compete in the usual manner with any other threads that might
146.326 - * be actively competing to synchronize on this object; for example,
146.327 - * the awakened threads enjoy no reliable privilege or disadvantage in
146.328 - * being the next thread to lock this object.
146.329 - * <p>
146.330 - * This method should only be called by a thread that is the owner
146.331 - * of this object's monitor. See the {@code notify} method for a
146.332 - * description of the ways in which a thread can become the owner of
146.333 - * a monitor.
146.334 - *
146.335 - * @exception IllegalMonitorStateException if the current thread is not
146.336 - * the owner of this object's monitor.
146.337 - * @see java.lang.Object#notify()
146.338 - * @see java.lang.Object#wait()
146.339 - */
146.340 - public final native void notifyAll();
146.341 -
146.342 - /**
146.343 - * Causes the current thread to wait until either another thread invokes the
146.344 - * {@link java.lang.Object#notify()} method or the
146.345 - * {@link java.lang.Object#notifyAll()} method for this object, or a
146.346 - * specified amount of time has elapsed.
146.347 - * <p>
146.348 - * The current thread must own this object's monitor.
146.349 - * <p>
146.350 - * This method causes the current thread (call it <var>T</var>) to
146.351 - * place itself in the wait set for this object and then to relinquish
146.352 - * any and all synchronization claims on this object. Thread <var>T</var>
146.353 - * becomes disabled for thread scheduling purposes and lies dormant
146.354 - * until one of four things happens:
146.355 - * <ul>
146.356 - * <li>Some other thread invokes the {@code notify} method for this
146.357 - * object and thread <var>T</var> happens to be arbitrarily chosen as
146.358 - * the thread to be awakened.
146.359 - * <li>Some other thread invokes the {@code notifyAll} method for this
146.360 - * object.
146.361 - * <li>Some other thread {@linkplain Thread#interrupt() interrupts}
146.362 - * thread <var>T</var>.
146.363 - * <li>The specified amount of real time has elapsed, more or less. If
146.364 - * {@code timeout} is zero, however, then real time is not taken into
146.365 - * consideration and the thread simply waits until notified.
146.366 - * </ul>
146.367 - * The thread <var>T</var> is then removed from the wait set for this
146.368 - * object and re-enabled for thread scheduling. It then competes in the
146.369 - * usual manner with other threads for the right to synchronize on the
146.370 - * object; once it has gained control of the object, all its
146.371 - * synchronization claims on the object are restored to the status quo
146.372 - * ante - that is, to the situation as of the time that the {@code wait}
146.373 - * method was invoked. Thread <var>T</var> then returns from the
146.374 - * invocation of the {@code wait} method. Thus, on return from the
146.375 - * {@code wait} method, the synchronization state of the object and of
146.376 - * thread {@code T} is exactly as it was when the {@code wait} method
146.377 - * was invoked.
146.378 - * <p>
146.379 - * A thread can also wake up without being notified, interrupted, or
146.380 - * timing out, a so-called <i>spurious wakeup</i>. While this will rarely
146.381 - * occur in practice, applications must guard against it by testing for
146.382 - * the condition that should have caused the thread to be awakened, and
146.383 - * continuing to wait if the condition is not satisfied. In other words,
146.384 - * waits should always occur in loops, like this one:
146.385 - * <pre>
146.386 - * synchronized (obj) {
146.387 - * while (<condition does not hold>)
146.388 - * obj.wait(timeout);
146.389 - * ... // Perform action appropriate to condition
146.390 - * }
146.391 - * </pre>
146.392 - * (For more information on this topic, see Section 3.2.3 in Doug Lea's
146.393 - * "Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
146.394 - * 2000), or Item 50 in Joshua Bloch's "Effective Java Programming
146.395 - * Language Guide" (Addison-Wesley, 2001).
146.396 - *
146.397 - * <p>If the current thread is {@linkplain java.lang.Thread#interrupt()
146.398 - * interrupted} by any thread before or while it is waiting, then an
146.399 - * {@code InterruptedException} is thrown. This exception is not
146.400 - * thrown until the lock status of this object has been restored as
146.401 - * described above.
146.402 - *
146.403 - * <p>
146.404 - * Note that the {@code wait} method, as it places the current thread
146.405 - * into the wait set for this object, unlocks only this object; any
146.406 - * other objects on which the current thread may be synchronized remain
146.407 - * locked while the thread waits.
146.408 - * <p>
146.409 - * This method should only be called by a thread that is the owner
146.410 - * of this object's monitor. See the {@code notify} method for a
146.411 - * description of the ways in which a thread can become the owner of
146.412 - * a monitor.
146.413 - *
146.414 - * @param timeout the maximum time to wait in milliseconds.
146.415 - * @exception IllegalArgumentException if the value of timeout is
146.416 - * negative.
146.417 - * @exception IllegalMonitorStateException if the current thread is not
146.418 - * the owner of the object's monitor.
146.419 - * @exception InterruptedException if any thread interrupted the
146.420 - * current thread before or while the current thread
146.421 - * was waiting for a notification. The <i>interrupted
146.422 - * status</i> of the current thread is cleared when
146.423 - * this exception is thrown.
146.424 - * @see java.lang.Object#notify()
146.425 - * @see java.lang.Object#notifyAll()
146.426 - */
146.427 - public final native void wait(long timeout) throws InterruptedException;
146.428 -
146.429 - /**
146.430 - * Causes the current thread to wait until another thread invokes the
146.431 - * {@link java.lang.Object#notify()} method or the
146.432 - * {@link java.lang.Object#notifyAll()} method for this object, or
146.433 - * some other thread interrupts the current thread, or a certain
146.434 - * amount of real time has elapsed.
146.435 - * <p>
146.436 - * This method is similar to the {@code wait} method of one
146.437 - * argument, but it allows finer control over the amount of time to
146.438 - * wait for a notification before giving up. The amount of real time,
146.439 - * measured in nanoseconds, is given by:
146.440 - * <blockquote>
146.441 - * <pre>
146.442 - * 1000000*timeout+nanos</pre></blockquote>
146.443 - * <p>
146.444 - * In all other respects, this method does the same thing as the
146.445 - * method {@link #wait(long)} of one argument. In particular,
146.446 - * {@code wait(0, 0)} means the same thing as {@code wait(0)}.
146.447 - * <p>
146.448 - * The current thread must own this object's monitor. The thread
146.449 - * releases ownership of this monitor and waits until either of the
146.450 - * following two conditions has occurred:
146.451 - * <ul>
146.452 - * <li>Another thread notifies threads waiting on this object's monitor
146.453 - * to wake up either through a call to the {@code notify} method
146.454 - * or the {@code notifyAll} method.
146.455 - * <li>The timeout period, specified by {@code timeout}
146.456 - * milliseconds plus {@code nanos} nanoseconds arguments, has
146.457 - * elapsed.
146.458 - * </ul>
146.459 - * <p>
146.460 - * The thread then waits until it can re-obtain ownership of the
146.461 - * monitor and resumes execution.
146.462 - * <p>
146.463 - * As in the one argument version, interrupts and spurious wakeups are
146.464 - * possible, and this method should always be used in a loop:
146.465 - * <pre>
146.466 - * synchronized (obj) {
146.467 - * while (<condition does not hold>)
146.468 - * obj.wait(timeout, nanos);
146.469 - * ... // Perform action appropriate to condition
146.470 - * }
146.471 - * </pre>
146.472 - * This method should only be called by a thread that is the owner
146.473 - * of this object's monitor. See the {@code notify} method for a
146.474 - * description of the ways in which a thread can become the owner of
146.475 - * a monitor.
146.476 - *
146.477 - * @param timeout the maximum time to wait in milliseconds.
146.478 - * @param nanos additional time, in nanoseconds range
146.479 - * 0-999999.
146.480 - * @exception IllegalArgumentException if the value of timeout is
146.481 - * negative or the value of nanos is
146.482 - * not in the range 0-999999.
146.483 - * @exception IllegalMonitorStateException if the current thread is not
146.484 - * the owner of this object's monitor.
146.485 - * @exception InterruptedException if any thread interrupted the
146.486 - * current thread before or while the current thread
146.487 - * was waiting for a notification. The <i>interrupted
146.488 - * status</i> of the current thread is cleared when
146.489 - * this exception is thrown.
146.490 - */
146.491 - public final void wait(long timeout, int nanos) throws InterruptedException {
146.492 - if (timeout < 0) {
146.493 - throw new IllegalArgumentException("timeout value is negative");
146.494 - }
146.495 -
146.496 - if (nanos < 0 || nanos > 999999) {
146.497 - throw new IllegalArgumentException(
146.498 - "nanosecond timeout value out of range");
146.499 - }
146.500 -
146.501 - if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
146.502 - timeout++;
146.503 - }
146.504 -
146.505 - wait(timeout);
146.506 - }
146.507 -
146.508 - /**
146.509 - * Causes the current thread to wait until another thread invokes the
146.510 - * {@link java.lang.Object#notify()} method or the
146.511 - * {@link java.lang.Object#notifyAll()} method for this object.
146.512 - * In other words, this method behaves exactly as if it simply
146.513 - * performs the call {@code wait(0)}.
146.514 - * <p>
146.515 - * The current thread must own this object's monitor. The thread
146.516 - * releases ownership of this monitor and waits until another thread
146.517 - * notifies threads waiting on this object's monitor to wake up
146.518 - * either through a call to the {@code notify} method or the
146.519 - * {@code notifyAll} method. The thread then waits until it can
146.520 - * re-obtain ownership of the monitor and resumes execution.
146.521 - * <p>
146.522 - * As in the one argument version, interrupts and spurious wakeups are
146.523 - * possible, and this method should always be used in a loop:
146.524 - * <pre>
146.525 - * synchronized (obj) {
146.526 - * while (<condition does not hold>)
146.527 - * obj.wait();
146.528 - * ... // Perform action appropriate to condition
146.529 - * }
146.530 - * </pre>
146.531 - * This method should only be called by a thread that is the owner
146.532 - * of this object's monitor. See the {@code notify} method for a
146.533 - * description of the ways in which a thread can become the owner of
146.534 - * a monitor.
146.535 - *
146.536 - * @exception IllegalMonitorStateException if the current thread is not
146.537 - * the owner of the object's monitor.
146.538 - * @exception InterruptedException if any thread interrupted the
146.539 - * current thread before or while the current thread
146.540 - * was waiting for a notification. The <i>interrupted
146.541 - * status</i> of the current thread is cleared when
146.542 - * this exception is thrown.
146.543 - * @see java.lang.Object#notify()
146.544 - * @see java.lang.Object#notifyAll()
146.545 - */
146.546 - public final void wait() throws InterruptedException {
146.547 - wait(0);
146.548 - }
146.549 -
146.550 - /**
146.551 - * Called by the garbage collector on an object when garbage collection
146.552 - * determines that there are no more references to the object.
146.553 - * A subclass overrides the {@code finalize} method to dispose of
146.554 - * system resources or to perform other cleanup.
146.555 - * <p>
146.556 - * The general contract of {@code finalize} is that it is invoked
146.557 - * if and when the Java<font size="-2"><sup>TM</sup></font> virtual
146.558 - * machine has determined that there is no longer any
146.559 - * means by which this object can be accessed by any thread that has
146.560 - * not yet died, except as a result of an action taken by the
146.561 - * finalization of some other object or class which is ready to be
146.562 - * finalized. The {@code finalize} method may take any action, including
146.563 - * making this object available again to other threads; the usual purpose
146.564 - * of {@code finalize}, however, is to perform cleanup actions before
146.565 - * the object is irrevocably discarded. For example, the finalize method
146.566 - * for an object that represents an input/output connection might perform
146.567 - * explicit I/O transactions to break the connection before the object is
146.568 - * permanently discarded.
146.569 - * <p>
146.570 - * The {@code finalize} method of class {@code Object} performs no
146.571 - * special action; it simply returns normally. Subclasses of
146.572 - * {@code Object} may override this definition.
146.573 - * <p>
146.574 - * The Java programming language does not guarantee which thread will
146.575 - * invoke the {@code finalize} method for any given object. It is
146.576 - * guaranteed, however, that the thread that invokes finalize will not
146.577 - * be holding any user-visible synchronization locks when finalize is
146.578 - * invoked. If an uncaught exception is thrown by the finalize method,
146.579 - * the exception is ignored and finalization of that object terminates.
146.580 - * <p>
146.581 - * After the {@code finalize} method has been invoked for an object, no
146.582 - * further action is taken until the Java virtual machine has again
146.583 - * determined that there is no longer any means by which this object can
146.584 - * be accessed by any thread that has not yet died, including possible
146.585 - * actions by other objects or classes which are ready to be finalized,
146.586 - * at which point the object may be discarded.
146.587 - * <p>
146.588 - * The {@code finalize} method is never invoked more than once by a Java
146.589 - * virtual machine for any given object.
146.590 - * <p>
146.591 - * Any exception thrown by the {@code finalize} method causes
146.592 - * the finalization of this object to be halted, but is otherwise
146.593 - * ignored.
146.594 - *
146.595 - * @throws Throwable the {@code Exception} raised by this method
146.596 - */
146.597 - protected void finalize() throws Throwable { }
146.598 -}
147.1 --- a/emul/src/main/java/java/lang/OutOfMemoryError.java Wed Jan 23 20:16:48 2013 +0100
147.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
147.3 @@ -1,60 +0,0 @@
147.4 -/*
147.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
147.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
147.7 - *
147.8 - * This code is free software; you can redistribute it and/or modify it
147.9 - * under the terms of the GNU General Public License version 2 only, as
147.10 - * published by the Free Software Foundation. Oracle designates this
147.11 - * particular file as subject to the "Classpath" exception as provided
147.12 - * by Oracle in the LICENSE file that accompanied this code.
147.13 - *
147.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
147.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
147.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
147.17 - * version 2 for more details (a copy is included in the LICENSE file that
147.18 - * accompanied this code).
147.19 - *
147.20 - * You should have received a copy of the GNU General Public License version
147.21 - * 2 along with this work; if not, write to the Free Software Foundation,
147.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
147.23 - *
147.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
147.25 - * or visit www.oracle.com if you need additional information or have any
147.26 - * questions.
147.27 - */
147.28 -
147.29 -package java.lang;
147.30 -
147.31 -/**
147.32 - * Thrown when the Java Virtual Machine cannot allocate an object
147.33 - * because it is out of memory, and no more memory could be made
147.34 - * available by the garbage collector.
147.35 - *
147.36 - * {@code OutOfMemoryError} objects may be constructed by the virtual
147.37 - * machine as if {@linkplain Throwable#Throwable(String, Throwable,
147.38 - * boolean, boolean) suppression were disabled and/or the stack trace was not
147.39 - * writable}.
147.40 - *
147.41 - * @author unascribed
147.42 - * @since JDK1.0
147.43 - */
147.44 -public class OutOfMemoryError extends VirtualMachineError {
147.45 - private static final long serialVersionUID = 8228564086184010517L;
147.46 -
147.47 - /**
147.48 - * Constructs an {@code OutOfMemoryError} with no detail message.
147.49 - */
147.50 - public OutOfMemoryError() {
147.51 - super();
147.52 - }
147.53 -
147.54 - /**
147.55 - * Constructs an {@code OutOfMemoryError} with the specified
147.56 - * detail message.
147.57 - *
147.58 - * @param s the detail message.
147.59 - */
147.60 - public OutOfMemoryError(String s) {
147.61 - super(s);
147.62 - }
147.63 -}
148.1 --- a/emul/src/main/java/java/lang/ReflectiveOperationException.java Wed Jan 23 20:16:48 2013 +0100
148.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
148.3 @@ -1,91 +0,0 @@
148.4 -/*
148.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
148.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
148.7 - *
148.8 - * This code is free software; you can redistribute it and/or modify it
148.9 - * under the terms of the GNU General Public License version 2 only, as
148.10 - * published by the Free Software Foundation. Oracle designates this
148.11 - * particular file as subject to the "Classpath" exception as provided
148.12 - * by Oracle in the LICENSE file that accompanied this code.
148.13 - *
148.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
148.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
148.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
148.17 - * version 2 for more details (a copy is included in the LICENSE file that
148.18 - * accompanied this code).
148.19 - *
148.20 - * You should have received a copy of the GNU General Public License version
148.21 - * 2 along with this work; if not, write to the Free Software Foundation,
148.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
148.23 - *
148.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
148.25 - * or visit www.oracle.com if you need additional information or have any
148.26 - * questions.
148.27 - */
148.28 -
148.29 -package java.lang;
148.30 -
148.31 -/**
148.32 - * Common superclass of exceptions thrown by reflective operations in
148.33 - * core reflection.
148.34 - *
148.35 - * @see LinkageError
148.36 - * @since 1.7
148.37 - */
148.38 -public class ReflectiveOperationException extends Exception {
148.39 - static final long serialVersionUID = 123456789L;
148.40 -
148.41 - /**
148.42 - * Constructs a new exception with {@code null} as its detail
148.43 - * message. The cause is not initialized, and may subsequently be
148.44 - * initialized by a call to {@link #initCause}.
148.45 - */
148.46 - public ReflectiveOperationException() {
148.47 - super();
148.48 - }
148.49 -
148.50 - /**
148.51 - * Constructs a new exception with the specified detail message.
148.52 - * The cause is not initialized, and may subsequently be
148.53 - * initialized by a call to {@link #initCause}.
148.54 - *
148.55 - * @param message the detail message. The detail message is saved for
148.56 - * later retrieval by the {@link #getMessage()} method.
148.57 - */
148.58 - public ReflectiveOperationException(String message) {
148.59 - super(message);
148.60 - }
148.61 -
148.62 - /**
148.63 - * Constructs a new exception with the specified detail message
148.64 - * and cause.
148.65 - *
148.66 - * <p>Note that the detail message associated with
148.67 - * {@code cause} is <em>not</em> automatically incorporated in
148.68 - * this exception's detail message.
148.69 - *
148.70 - * @param message the detail message (which is saved for later retrieval
148.71 - * by the {@link #getMessage()} method).
148.72 - * @param cause the cause (which is saved for later retrieval by the
148.73 - * {@link #getCause()} method). (A {@code null} value is
148.74 - * permitted, and indicates that the cause is nonexistent or
148.75 - * unknown.)
148.76 - */
148.77 - public ReflectiveOperationException(String message, Throwable cause) {
148.78 - super(message, cause);
148.79 - }
148.80 -
148.81 - /**
148.82 - * Constructs a new exception with the specified cause and a detail
148.83 - * message of {@code (cause==null ? null : cause.toString())} (which
148.84 - * typically contains the class and detail message of {@code cause}).
148.85 - *
148.86 - * @param cause the cause (which is saved for later retrieval by the
148.87 - * {@link #getCause()} method). (A {@code null} value is
148.88 - * permitted, and indicates that the cause is nonexistent or
148.89 - * unknown.)
148.90 - */
148.91 - public ReflectiveOperationException(Throwable cause) {
148.92 - super(cause);
148.93 - }
148.94 -}
149.1 --- a/emul/src/main/java/java/lang/Runnable.java Wed Jan 23 20:16:48 2013 +0100
149.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
149.3 @@ -1,69 +0,0 @@
149.4 -/*
149.5 - * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
149.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
149.7 - *
149.8 - * This code is free software; you can redistribute it and/or modify it
149.9 - * under the terms of the GNU General Public License version 2 only, as
149.10 - * published by the Free Software Foundation. Oracle designates this
149.11 - * particular file as subject to the "Classpath" exception as provided
149.12 - * by Oracle in the LICENSE file that accompanied this code.
149.13 - *
149.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
149.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
149.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
149.17 - * version 2 for more details (a copy is included in the LICENSE file that
149.18 - * accompanied this code).
149.19 - *
149.20 - * You should have received a copy of the GNU General Public License version
149.21 - * 2 along with this work; if not, write to the Free Software Foundation,
149.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
149.23 - *
149.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
149.25 - * or visit www.oracle.com if you need additional information or have any
149.26 - * questions.
149.27 - */
149.28 -
149.29 -package java.lang;
149.30 -
149.31 -/**
149.32 - * The <code>Runnable</code> interface should be implemented by any
149.33 - * class whose instances are intended to be executed by a thread. The
149.34 - * class must define a method of no arguments called <code>run</code>.
149.35 - * <p>
149.36 - * This interface is designed to provide a common protocol for objects that
149.37 - * wish to execute code while they are active. For example,
149.38 - * <code>Runnable</code> is implemented by class <code>Thread</code>.
149.39 - * Being active simply means that a thread has been started and has not
149.40 - * yet been stopped.
149.41 - * <p>
149.42 - * In addition, <code>Runnable</code> provides the means for a class to be
149.43 - * active while not subclassing <code>Thread</code>. A class that implements
149.44 - * <code>Runnable</code> can run without subclassing <code>Thread</code>
149.45 - * by instantiating a <code>Thread</code> instance and passing itself in
149.46 - * as the target. In most cases, the <code>Runnable</code> interface should
149.47 - * be used if you are only planning to override the <code>run()</code>
149.48 - * method and no other <code>Thread</code> methods.
149.49 - * This is important because classes should not be subclassed
149.50 - * unless the programmer intends on modifying or enhancing the fundamental
149.51 - * behavior of the class.
149.52 - *
149.53 - * @author Arthur van Hoff
149.54 - * @see java.lang.Thread
149.55 - * @see java.util.concurrent.Callable
149.56 - * @since JDK1.0
149.57 - */
149.58 -public
149.59 -interface Runnable {
149.60 - /**
149.61 - * When an object implementing interface <code>Runnable</code> is used
149.62 - * to create a thread, starting the thread causes the object's
149.63 - * <code>run</code> method to be called in that separately executing
149.64 - * thread.
149.65 - * <p>
149.66 - * The general contract of the method <code>run</code> is that it may
149.67 - * take any action whatsoever.
149.68 - *
149.69 - * @see java.lang.Thread#run()
149.70 - */
149.71 - public abstract void run();
149.72 -}
150.1 --- a/emul/src/main/java/java/lang/RuntimeException.java Wed Jan 23 20:16:48 2013 +0100
150.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
150.3 @@ -1,119 +0,0 @@
150.4 -/*
150.5 - * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
150.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
150.7 - *
150.8 - * This code is free software; you can redistribute it and/or modify it
150.9 - * under the terms of the GNU General Public License version 2 only, as
150.10 - * published by the Free Software Foundation. Oracle designates this
150.11 - * particular file as subject to the "Classpath" exception as provided
150.12 - * by Oracle in the LICENSE file that accompanied this code.
150.13 - *
150.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
150.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
150.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
150.17 - * version 2 for more details (a copy is included in the LICENSE file that
150.18 - * accompanied this code).
150.19 - *
150.20 - * You should have received a copy of the GNU General Public License version
150.21 - * 2 along with this work; if not, write to the Free Software Foundation,
150.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
150.23 - *
150.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
150.25 - * or visit www.oracle.com if you need additional information or have any
150.26 - * questions.
150.27 - */
150.28 -
150.29 -package java.lang;
150.30 -
150.31 -/**
150.32 - * {@code RuntimeException} is the superclass of those
150.33 - * exceptions that can be thrown during the normal operation of the
150.34 - * Java Virtual Machine.
150.35 - *
150.36 - * <p>{@code RuntimeException} and its subclasses are <em>unchecked
150.37 - * exceptions</em>. Unchecked exceptions do <em>not</em> need to be
150.38 - * declared in a method or constructor's {@code throws} clause if they
150.39 - * can be thrown by the execution of the method or constructor and
150.40 - * propagate outside the method or constructor boundary.
150.41 - *
150.42 - * @author Frank Yellin
150.43 - * @jls 11.2 Compile-Time Checking of Exceptions
150.44 - * @since JDK1.0
150.45 - */
150.46 -public class RuntimeException extends Exception {
150.47 - static final long serialVersionUID = -7034897190745766939L;
150.48 -
150.49 - /** Constructs a new runtime exception with {@code null} as its
150.50 - * detail message. The cause is not initialized, and may subsequently be
150.51 - * initialized by a call to {@link #initCause}.
150.52 - */
150.53 - public RuntimeException() {
150.54 - super();
150.55 - }
150.56 -
150.57 - /** Constructs a new runtime exception with the specified detail message.
150.58 - * The cause is not initialized, and may subsequently be initialized by a
150.59 - * call to {@link #initCause}.
150.60 - *
150.61 - * @param message the detail message. The detail message is saved for
150.62 - * later retrieval by the {@link #getMessage()} method.
150.63 - */
150.64 - public RuntimeException(String message) {
150.65 - super(message);
150.66 - }
150.67 -
150.68 - /**
150.69 - * Constructs a new runtime exception with the specified detail message and
150.70 - * cause. <p>Note that the detail message associated with
150.71 - * {@code cause} is <i>not</i> automatically incorporated in
150.72 - * this runtime exception's detail message.
150.73 - *
150.74 - * @param message the detail message (which is saved for later retrieval
150.75 - * by the {@link #getMessage()} method).
150.76 - * @param cause the cause (which is saved for later retrieval by the
150.77 - * {@link #getCause()} method). (A <tt>null</tt> value is
150.78 - * permitted, and indicates that the cause is nonexistent or
150.79 - * unknown.)
150.80 - * @since 1.4
150.81 - */
150.82 - public RuntimeException(String message, Throwable cause) {
150.83 - super(message, cause);
150.84 - }
150.85 -
150.86 - /** Constructs a new runtime exception with the specified cause and a
150.87 - * detail message of <tt>(cause==null ? null : cause.toString())</tt>
150.88 - * (which typically contains the class and detail message of
150.89 - * <tt>cause</tt>). This constructor is useful for runtime exceptions
150.90 - * that are little more than wrappers for other throwables.
150.91 - *
150.92 - * @param cause the cause (which is saved for later retrieval by the
150.93 - * {@link #getCause()} method). (A <tt>null</tt> value is
150.94 - * permitted, and indicates that the cause is nonexistent or
150.95 - * unknown.)
150.96 - * @since 1.4
150.97 - */
150.98 - public RuntimeException(Throwable cause) {
150.99 - super(cause);
150.100 - }
150.101 -
150.102 - /**
150.103 - * Constructs a new runtime exception with the specified detail
150.104 - * message, cause, suppression enabled or disabled, and writable
150.105 - * stack trace enabled or disabled.
150.106 - *
150.107 - * @param message the detail message.
150.108 - * @param cause the cause. (A {@code null} value is permitted,
150.109 - * and indicates that the cause is nonexistent or unknown.)
150.110 - * @param enableSuppression whether or not suppression is enabled
150.111 - * or disabled
150.112 - * @param writableStackTrace whether or not the stack trace should
150.113 - * be writable
150.114 - *
150.115 - * @since 1.7
150.116 - */
150.117 - protected RuntimeException(String message, Throwable cause,
150.118 - boolean enableSuppression,
150.119 - boolean writableStackTrace) {
150.120 - super(message, cause, enableSuppression, writableStackTrace);
150.121 - }
150.122 -}
151.1 --- a/emul/src/main/java/java/lang/SecurityException.java Wed Jan 23 20:16:48 2013 +0100
151.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
151.3 @@ -1,84 +0,0 @@
151.4 -/*
151.5 - * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
151.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
151.7 - *
151.8 - * This code is free software; you can redistribute it and/or modify it
151.9 - * under the terms of the GNU General Public License version 2 only, as
151.10 - * published by the Free Software Foundation. Oracle designates this
151.11 - * particular file as subject to the "Classpath" exception as provided
151.12 - * by Oracle in the LICENSE file that accompanied this code.
151.13 - *
151.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
151.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
151.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
151.17 - * version 2 for more details (a copy is included in the LICENSE file that
151.18 - * accompanied this code).
151.19 - *
151.20 - * You should have received a copy of the GNU General Public License version
151.21 - * 2 along with this work; if not, write to the Free Software Foundation,
151.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
151.23 - *
151.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
151.25 - * or visit www.oracle.com if you need additional information or have any
151.26 - * questions.
151.27 - */
151.28 -package java.lang;
151.29 -
151.30 -/**
151.31 - * Thrown by the security manager to indicate a security violation.
151.32 - *
151.33 - * @author unascribed
151.34 - * @see java.lang.SecurityManager
151.35 - * @since JDK1.0
151.36 - */
151.37 -public class SecurityException extends RuntimeException {
151.38 -
151.39 - private static final long serialVersionUID = 6878364983674394167L;
151.40 -
151.41 - /**
151.42 - * Constructs a <code>SecurityException</code> with no detail message.
151.43 - */
151.44 - public SecurityException() {
151.45 - super();
151.46 - }
151.47 -
151.48 - /**
151.49 - * Constructs a <code>SecurityException</code> with the specified
151.50 - * detail message.
151.51 - *
151.52 - * @param s the detail message.
151.53 - */
151.54 - public SecurityException(String s) {
151.55 - super(s);
151.56 - }
151.57 -
151.58 - /**
151.59 - * Creates a <code>SecurityException</code> with the specified
151.60 - * detail message and cause.
151.61 - *
151.62 - * @param message the detail message (which is saved for later retrieval
151.63 - * by the {@link #getMessage()} method).
151.64 - * @param cause the cause (which is saved for later retrieval by the
151.65 - * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
151.66 - * and indicates that the cause is nonexistent or unknown.)
151.67 - * @since 1.5
151.68 - */
151.69 - public SecurityException(String message, Throwable cause) {
151.70 - super(message, cause);
151.71 - }
151.72 -
151.73 - /**
151.74 - * Creates a <code>SecurityException</code> with the specified cause
151.75 - * and a detail message of <tt>(cause==null ? null : cause.toString())</tt>
151.76 - * (which typically contains the class and detail message of
151.77 - * <tt>cause</tt>).
151.78 - *
151.79 - * @param cause the cause (which is saved for later retrieval by the
151.80 - * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
151.81 - * and indicates that the cause is nonexistent or unknown.)
151.82 - * @since 1.5
151.83 - */
151.84 - public SecurityException(Throwable cause) {
151.85 - super(cause);
151.86 - }
151.87 -}
152.1 --- a/emul/src/main/java/java/lang/Short.java Wed Jan 23 20:16:48 2013 +0100
152.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
152.3 @@ -1,468 +0,0 @@
152.4 -/*
152.5 - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
152.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
152.7 - *
152.8 - * This code is free software; you can redistribute it and/or modify it
152.9 - * under the terms of the GNU General Public License version 2 only, as
152.10 - * published by the Free Software Foundation. Oracle designates this
152.11 - * particular file as subject to the "Classpath" exception as provided
152.12 - * by Oracle in the LICENSE file that accompanied this code.
152.13 - *
152.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
152.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
152.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
152.17 - * version 2 for more details (a copy is included in the LICENSE file that
152.18 - * accompanied this code).
152.19 - *
152.20 - * You should have received a copy of the GNU General Public License version
152.21 - * 2 along with this work; if not, write to the Free Software Foundation,
152.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
152.23 - *
152.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
152.25 - * or visit www.oracle.com if you need additional information or have any
152.26 - * questions.
152.27 - */
152.28 -
152.29 -package java.lang;
152.30 -
152.31 -/**
152.32 - * The {@code Short} class wraps a value of primitive type {@code
152.33 - * short} in an object. An object of type {@code Short} contains a
152.34 - * single field whose type is {@code short}.
152.35 - *
152.36 - * <p>In addition, this class provides several methods for converting
152.37 - * a {@code short} to a {@code String} and a {@code String} to a
152.38 - * {@code short}, as well as other constants and methods useful when
152.39 - * dealing with a {@code short}.
152.40 - *
152.41 - * @author Nakul Saraiya
152.42 - * @author Joseph D. Darcy
152.43 - * @see java.lang.Number
152.44 - * @since JDK1.1
152.45 - */
152.46 -public final class Short extends Number implements Comparable<Short> {
152.47 -
152.48 - /**
152.49 - * A constant holding the minimum value a {@code short} can
152.50 - * have, -2<sup>15</sup>.
152.51 - */
152.52 - public static final short MIN_VALUE = -32768;
152.53 -
152.54 - /**
152.55 - * A constant holding the maximum value a {@code short} can
152.56 - * have, 2<sup>15</sup>-1.
152.57 - */
152.58 - public static final short MAX_VALUE = 32767;
152.59 -
152.60 - /**
152.61 - * The {@code Class} instance representing the primitive type
152.62 - * {@code short}.
152.63 - */
152.64 - public static final Class<Short> TYPE = (Class<Short>) Class.getPrimitiveClass("short");
152.65 -
152.66 - /**
152.67 - * Returns a new {@code String} object representing the
152.68 - * specified {@code short}. The radix is assumed to be 10.
152.69 - *
152.70 - * @param s the {@code short} to be converted
152.71 - * @return the string representation of the specified {@code short}
152.72 - * @see java.lang.Integer#toString(int)
152.73 - */
152.74 - public static String toString(short s) {
152.75 - return Integer.toString((int)s, 10);
152.76 - }
152.77 -
152.78 - /**
152.79 - * Parses the string argument as a signed {@code short} in the
152.80 - * radix specified by the second argument. The characters in the
152.81 - * string must all be digits, of the specified radix (as
152.82 - * determined by whether {@link java.lang.Character#digit(char,
152.83 - * int)} returns a nonnegative value) except that the first
152.84 - * character may be an ASCII minus sign {@code '-'}
152.85 - * (<code>'\u002D'</code>) to indicate a negative value or an
152.86 - * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
152.87 - * indicate a positive value. The resulting {@code short} value
152.88 - * is returned.
152.89 - *
152.90 - * <p>An exception of type {@code NumberFormatException} is
152.91 - * thrown if any of the following situations occurs:
152.92 - * <ul>
152.93 - * <li> The first argument is {@code null} or is a string of
152.94 - * length zero.
152.95 - *
152.96 - * <li> The radix is either smaller than {@link
152.97 - * java.lang.Character#MIN_RADIX} or larger than {@link
152.98 - * java.lang.Character#MAX_RADIX}.
152.99 - *
152.100 - * <li> Any character of the string is not a digit of the
152.101 - * specified radix, except that the first character may be a minus
152.102 - * sign {@code '-'} (<code>'\u002D'</code>) or plus sign
152.103 - * {@code '+'} (<code>'\u002B'</code>) provided that the
152.104 - * string is longer than length 1.
152.105 - *
152.106 - * <li> The value represented by the string is not a value of type
152.107 - * {@code short}.
152.108 - * </ul>
152.109 - *
152.110 - * @param s the {@code String} containing the
152.111 - * {@code short} representation to be parsed
152.112 - * @param radix the radix to be used while parsing {@code s}
152.113 - * @return the {@code short} represented by the string
152.114 - * argument in the specified radix.
152.115 - * @throws NumberFormatException If the {@code String}
152.116 - * does not contain a parsable {@code short}.
152.117 - */
152.118 - public static short parseShort(String s, int radix)
152.119 - throws NumberFormatException {
152.120 - int i = Integer.parseInt(s, radix);
152.121 - if (i < MIN_VALUE || i > MAX_VALUE)
152.122 - throw new NumberFormatException(
152.123 - "Value out of range. Value:\"" + s + "\" Radix:" + radix);
152.124 - return (short)i;
152.125 - }
152.126 -
152.127 - /**
152.128 - * Parses the string argument as a signed decimal {@code
152.129 - * short}. The characters in the string must all be decimal
152.130 - * digits, except that the first character may be an ASCII minus
152.131 - * sign {@code '-'} (<code>'\u002D'</code>) to indicate a
152.132 - * negative value or an ASCII plus sign {@code '+'}
152.133 - * (<code>'\u002B'</code>) to indicate a positive value. The
152.134 - * resulting {@code short} value is returned, exactly as if the
152.135 - * argument and the radix 10 were given as arguments to the {@link
152.136 - * #parseShort(java.lang.String, int)} method.
152.137 - *
152.138 - * @param s a {@code String} containing the {@code short}
152.139 - * representation to be parsed
152.140 - * @return the {@code short} value represented by the
152.141 - * argument in decimal.
152.142 - * @throws NumberFormatException If the string does not
152.143 - * contain a parsable {@code short}.
152.144 - */
152.145 - public static short parseShort(String s) throws NumberFormatException {
152.146 - return parseShort(s, 10);
152.147 - }
152.148 -
152.149 - /**
152.150 - * Returns a {@code Short} object holding the value
152.151 - * extracted from the specified {@code String} when parsed
152.152 - * with the radix given by the second argument. The first argument
152.153 - * is interpreted as representing a signed {@code short} in
152.154 - * the radix specified by the second argument, exactly as if the
152.155 - * argument were given to the {@link #parseShort(java.lang.String,
152.156 - * int)} method. The result is a {@code Short} object that
152.157 - * represents the {@code short} value specified by the string.
152.158 - *
152.159 - * <p>In other words, this method returns a {@code Short} object
152.160 - * equal to the value of:
152.161 - *
152.162 - * <blockquote>
152.163 - * {@code new Short(Short.parseShort(s, radix))}
152.164 - * </blockquote>
152.165 - *
152.166 - * @param s the string to be parsed
152.167 - * @param radix the radix to be used in interpreting {@code s}
152.168 - * @return a {@code Short} object holding the value
152.169 - * represented by the string argument in the
152.170 - * specified radix.
152.171 - * @throws NumberFormatException If the {@code String} does
152.172 - * not contain a parsable {@code short}.
152.173 - */
152.174 - public static Short valueOf(String s, int radix)
152.175 - throws NumberFormatException {
152.176 - return valueOf(parseShort(s, radix));
152.177 - }
152.178 -
152.179 - /**
152.180 - * Returns a {@code Short} object holding the
152.181 - * value given by the specified {@code String}. The argument
152.182 - * is interpreted as representing a signed decimal
152.183 - * {@code short}, exactly as if the argument were given to
152.184 - * the {@link #parseShort(java.lang.String)} method. The result is
152.185 - * a {@code Short} object that represents the
152.186 - * {@code short} value specified by the string.
152.187 - *
152.188 - * <p>In other words, this method returns a {@code Short} object
152.189 - * equal to the value of:
152.190 - *
152.191 - * <blockquote>
152.192 - * {@code new Short(Short.parseShort(s))}
152.193 - * </blockquote>
152.194 - *
152.195 - * @param s the string to be parsed
152.196 - * @return a {@code Short} object holding the value
152.197 - * represented by the string argument
152.198 - * @throws NumberFormatException If the {@code String} does
152.199 - * not contain a parsable {@code short}.
152.200 - */
152.201 - public static Short valueOf(String s) throws NumberFormatException {
152.202 - return valueOf(s, 10);
152.203 - }
152.204 -
152.205 - private static class ShortCache {
152.206 - private ShortCache(){}
152.207 -
152.208 - static final Short cache[] = new Short[-(-128) + 127 + 1];
152.209 -
152.210 - static {
152.211 - for(int i = 0; i < cache.length; i++)
152.212 - cache[i] = new Short((short)(i - 128));
152.213 - }
152.214 - }
152.215 -
152.216 - /**
152.217 - * Returns a {@code Short} instance representing the specified
152.218 - * {@code short} value.
152.219 - * If a new {@code Short} instance is not required, this method
152.220 - * should generally be used in preference to the constructor
152.221 - * {@link #Short(short)}, as this method is likely to yield
152.222 - * significantly better space and time performance by caching
152.223 - * frequently requested values.
152.224 - *
152.225 - * This method will always cache values in the range -128 to 127,
152.226 - * inclusive, and may cache other values outside of this range.
152.227 - *
152.228 - * @param s a short value.
152.229 - * @return a {@code Short} instance representing {@code s}.
152.230 - * @since 1.5
152.231 - */
152.232 - public static Short valueOf(short s) {
152.233 - final int offset = 128;
152.234 - int sAsInt = s;
152.235 - if (sAsInt >= -128 && sAsInt <= 127) { // must cache
152.236 - return ShortCache.cache[sAsInt + offset];
152.237 - }
152.238 - return new Short(s);
152.239 - }
152.240 -
152.241 - /**
152.242 - * Decodes a {@code String} into a {@code Short}.
152.243 - * Accepts decimal, hexadecimal, and octal numbers given by
152.244 - * the following grammar:
152.245 - *
152.246 - * <blockquote>
152.247 - * <dl>
152.248 - * <dt><i>DecodableString:</i>
152.249 - * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
152.250 - * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
152.251 - * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
152.252 - * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
152.253 - * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
152.254 - * <p>
152.255 - * <dt><i>Sign:</i>
152.256 - * <dd>{@code -}
152.257 - * <dd>{@code +}
152.258 - * </dl>
152.259 - * </blockquote>
152.260 - *
152.261 - * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
152.262 - * are as defined in section 3.10.1 of
152.263 - * <cite>The Java™ Language Specification</cite>,
152.264 - * except that underscores are not accepted between digits.
152.265 - *
152.266 - * <p>The sequence of characters following an optional
152.267 - * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
152.268 - * "{@code #}", or leading zero) is parsed as by the {@code
152.269 - * Short.parseShort} method with the indicated radix (10, 16, or
152.270 - * 8). This sequence of characters must represent a positive
152.271 - * value or a {@link NumberFormatException} will be thrown. The
152.272 - * result is negated if first character of the specified {@code
152.273 - * String} is the minus sign. No whitespace characters are
152.274 - * permitted in the {@code String}.
152.275 - *
152.276 - * @param nm the {@code String} to decode.
152.277 - * @return a {@code Short} object holding the {@code short}
152.278 - * value represented by {@code nm}
152.279 - * @throws NumberFormatException if the {@code String} does not
152.280 - * contain a parsable {@code short}.
152.281 - * @see java.lang.Short#parseShort(java.lang.String, int)
152.282 - */
152.283 - public static Short decode(String nm) throws NumberFormatException {
152.284 - int i = Integer.decode(nm);
152.285 - if (i < MIN_VALUE || i > MAX_VALUE)
152.286 - throw new NumberFormatException(
152.287 - "Value " + i + " out of range from input " + nm);
152.288 - return valueOf((short)i);
152.289 - }
152.290 -
152.291 - /**
152.292 - * The value of the {@code Short}.
152.293 - *
152.294 - * @serial
152.295 - */
152.296 - private final short value;
152.297 -
152.298 - /**
152.299 - * Constructs a newly allocated {@code Short} object that
152.300 - * represents the specified {@code short} value.
152.301 - *
152.302 - * @param value the value to be represented by the
152.303 - * {@code Short}.
152.304 - */
152.305 - public Short(short value) {
152.306 - this.value = value;
152.307 - }
152.308 -
152.309 - /**
152.310 - * Constructs a newly allocated {@code Short} object that
152.311 - * represents the {@code short} value indicated by the
152.312 - * {@code String} parameter. The string is converted to a
152.313 - * {@code short} value in exactly the manner used by the
152.314 - * {@code parseShort} method for radix 10.
152.315 - *
152.316 - * @param s the {@code String} to be converted to a
152.317 - * {@code Short}
152.318 - * @throws NumberFormatException If the {@code String}
152.319 - * does not contain a parsable {@code short}.
152.320 - * @see java.lang.Short#parseShort(java.lang.String, int)
152.321 - */
152.322 - public Short(String s) throws NumberFormatException {
152.323 - this.value = parseShort(s, 10);
152.324 - }
152.325 -
152.326 - /**
152.327 - * Returns the value of this {@code Short} as a
152.328 - * {@code byte}.
152.329 - */
152.330 - public byte byteValue() {
152.331 - return (byte)value;
152.332 - }
152.333 -
152.334 - /**
152.335 - * Returns the value of this {@code Short} as a
152.336 - * {@code short}.
152.337 - */
152.338 - public short shortValue() {
152.339 - return value;
152.340 - }
152.341 -
152.342 - /**
152.343 - * Returns the value of this {@code Short} as an
152.344 - * {@code int}.
152.345 - */
152.346 - public int intValue() {
152.347 - return (int)value;
152.348 - }
152.349 -
152.350 - /**
152.351 - * Returns the value of this {@code Short} as a
152.352 - * {@code long}.
152.353 - */
152.354 - public long longValue() {
152.355 - return (long)value;
152.356 - }
152.357 -
152.358 - /**
152.359 - * Returns the value of this {@code Short} as a
152.360 - * {@code float}.
152.361 - */
152.362 - public float floatValue() {
152.363 - return (float)value;
152.364 - }
152.365 -
152.366 - /**
152.367 - * Returns the value of this {@code Short} as a
152.368 - * {@code double}.
152.369 - */
152.370 - public double doubleValue() {
152.371 - return (double)value;
152.372 - }
152.373 -
152.374 - /**
152.375 - * Returns a {@code String} object representing this
152.376 - * {@code Short}'s value. The value is converted to signed
152.377 - * decimal representation and returned as a string, exactly as if
152.378 - * the {@code short} value were given as an argument to the
152.379 - * {@link java.lang.Short#toString(short)} method.
152.380 - *
152.381 - * @return a string representation of the value of this object in
152.382 - * base 10.
152.383 - */
152.384 - public String toString() {
152.385 - return Integer.toString((int)value);
152.386 - }
152.387 -
152.388 - /**
152.389 - * Returns a hash code for this {@code Short}; equal to the result
152.390 - * of invoking {@code intValue()}.
152.391 - *
152.392 - * @return a hash code value for this {@code Short}
152.393 - */
152.394 - public int hashCode() {
152.395 - return (int)value;
152.396 - }
152.397 -
152.398 - /**
152.399 - * Compares this object to the specified object. The result is
152.400 - * {@code true} if and only if the argument is not
152.401 - * {@code null} and is a {@code Short} object that
152.402 - * contains the same {@code short} value as this object.
152.403 - *
152.404 - * @param obj the object to compare with
152.405 - * @return {@code true} if the objects are the same;
152.406 - * {@code false} otherwise.
152.407 - */
152.408 - public boolean equals(Object obj) {
152.409 - if (obj instanceof Short) {
152.410 - return value == ((Short)obj).shortValue();
152.411 - }
152.412 - return false;
152.413 - }
152.414 -
152.415 - /**
152.416 - * Compares two {@code Short} objects numerically.
152.417 - *
152.418 - * @param anotherShort the {@code Short} to be compared.
152.419 - * @return the value {@code 0} if this {@code Short} is
152.420 - * equal to the argument {@code Short}; a value less than
152.421 - * {@code 0} if this {@code Short} is numerically less
152.422 - * than the argument {@code Short}; and a value greater than
152.423 - * {@code 0} if this {@code Short} is numerically
152.424 - * greater than the argument {@code Short} (signed
152.425 - * comparison).
152.426 - * @since 1.2
152.427 - */
152.428 - public int compareTo(Short anotherShort) {
152.429 - return compare(this.value, anotherShort.value);
152.430 - }
152.431 -
152.432 - /**
152.433 - * Compares two {@code short} values numerically.
152.434 - * The value returned is identical to what would be returned by:
152.435 - * <pre>
152.436 - * Short.valueOf(x).compareTo(Short.valueOf(y))
152.437 - * </pre>
152.438 - *
152.439 - * @param x the first {@code short} to compare
152.440 - * @param y the second {@code short} to compare
152.441 - * @return the value {@code 0} if {@code x == y};
152.442 - * a value less than {@code 0} if {@code x < y}; and
152.443 - * a value greater than {@code 0} if {@code x > y}
152.444 - * @since 1.7
152.445 - */
152.446 - public static int compare(short x, short y) {
152.447 - return x - y;
152.448 - }
152.449 -
152.450 - /**
152.451 - * The number of bits used to represent a {@code short} value in two's
152.452 - * complement binary form.
152.453 - * @since 1.5
152.454 - */
152.455 - public static final int SIZE = 16;
152.456 -
152.457 - /**
152.458 - * Returns the value obtained by reversing the order of the bytes in the
152.459 - * two's complement representation of the specified {@code short} value.
152.460 - *
152.461 - * @return the value obtained by reversing (or, equivalently, swapping)
152.462 - * the bytes in the specified {@code short} value.
152.463 - * @since 1.5
152.464 - */
152.465 - public static short reverseBytes(short i) {
152.466 - return (short) (((i & 0xFF00) >> 8) | (i << 8));
152.467 - }
152.468 -
152.469 - /** use serialVersionUID from JDK 1.1. for interoperability */
152.470 - private static final long serialVersionUID = 7515723908773894738L;
152.471 -}
153.1 --- a/emul/src/main/java/java/lang/StackTraceElement.java Wed Jan 23 20:16:48 2013 +0100
153.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
153.3 @@ -1,223 +0,0 @@
153.4 -/*
153.5 - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
153.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
153.7 - *
153.8 - * This code is free software; you can redistribute it and/or modify it
153.9 - * under the terms of the GNU General Public License version 2 only, as
153.10 - * published by the Free Software Foundation. Oracle designates this
153.11 - * particular file as subject to the "Classpath" exception as provided
153.12 - * by Oracle in the LICENSE file that accompanied this code.
153.13 - *
153.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
153.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
153.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
153.17 - * version 2 for more details (a copy is included in the LICENSE file that
153.18 - * accompanied this code).
153.19 - *
153.20 - * You should have received a copy of the GNU General Public License version
153.21 - * 2 along with this work; if not, write to the Free Software Foundation,
153.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
153.23 - *
153.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
153.25 - * or visit www.oracle.com if you need additional information or have any
153.26 - * questions.
153.27 - */
153.28 -
153.29 -package java.lang;
153.30 -
153.31 -/**
153.32 - * An element in a stack trace, as returned by {@link
153.33 - * Throwable#getStackTrace()}. Each element represents a single stack frame.
153.34 - * All stack frames except for the one at the top of the stack represent
153.35 - * a method invocation. The frame at the top of the stack represents the
153.36 - * execution point at which the stack trace was generated. Typically,
153.37 - * this is the point at which the throwable corresponding to the stack trace
153.38 - * was created.
153.39 - *
153.40 - * @since 1.4
153.41 - * @author Josh Bloch
153.42 - */
153.43 -public final class StackTraceElement implements java.io.Serializable {
153.44 - // Normally initialized by VM (public constructor added in 1.5)
153.45 - private String declaringClass;
153.46 - private String methodName;
153.47 - private String fileName;
153.48 - private int lineNumber;
153.49 -
153.50 - /**
153.51 - * Creates a stack trace element representing the specified execution
153.52 - * point.
153.53 - *
153.54 - * @param declaringClass the fully qualified name of the class containing
153.55 - * the execution point represented by the stack trace element
153.56 - * @param methodName the name of the method containing the execution point
153.57 - * represented by the stack trace element
153.58 - * @param fileName the name of the file containing the execution point
153.59 - * represented by the stack trace element, or {@code null} if
153.60 - * this information is unavailable
153.61 - * @param lineNumber the line number of the source line containing the
153.62 - * execution point represented by this stack trace element, or
153.63 - * a negative number if this information is unavailable. A value
153.64 - * of -2 indicates that the method containing the execution point
153.65 - * is a native method
153.66 - * @throws NullPointerException if {@code declaringClass} or
153.67 - * {@code methodName} is null
153.68 - * @since 1.5
153.69 - */
153.70 - public StackTraceElement(String declaringClass, String methodName,
153.71 - String fileName, int lineNumber) {
153.72 - this.declaringClass = declaringClass;
153.73 - this.methodName = methodName;
153.74 - this.fileName = fileName;
153.75 - this.lineNumber = lineNumber;
153.76 - }
153.77 -
153.78 - /**
153.79 - * Returns the name of the source file containing the execution point
153.80 - * represented by this stack trace element. Generally, this corresponds
153.81 - * to the {@code SourceFile} attribute of the relevant {@code class}
153.82 - * file (as per <i>The Java Virtual Machine Specification</i>, Section
153.83 - * 4.7.7). In some systems, the name may refer to some source code unit
153.84 - * other than a file, such as an entry in source repository.
153.85 - *
153.86 - * @return the name of the file containing the execution point
153.87 - * represented by this stack trace element, or {@code null} if
153.88 - * this information is unavailable.
153.89 - */
153.90 - public String getFileName() {
153.91 - return fileName;
153.92 - }
153.93 -
153.94 - /**
153.95 - * Returns the line number of the source line containing the execution
153.96 - * point represented by this stack trace element. Generally, this is
153.97 - * derived from the {@code LineNumberTable} attribute of the relevant
153.98 - * {@code class} file (as per <i>The Java Virtual Machine
153.99 - * Specification</i>, Section 4.7.8).
153.100 - *
153.101 - * @return the line number of the source line containing the execution
153.102 - * point represented by this stack trace element, or a negative
153.103 - * number if this information is unavailable.
153.104 - */
153.105 - public int getLineNumber() {
153.106 - return lineNumber;
153.107 - }
153.108 -
153.109 - /**
153.110 - * Returns the fully qualified name of the class containing the
153.111 - * execution point represented by this stack trace element.
153.112 - *
153.113 - * @return the fully qualified name of the {@code Class} containing
153.114 - * the execution point represented by this stack trace element.
153.115 - */
153.116 - public String getClassName() {
153.117 - return declaringClass;
153.118 - }
153.119 -
153.120 - /**
153.121 - * Returns the name of the method containing the execution point
153.122 - * represented by this stack trace element. If the execution point is
153.123 - * contained in an instance or class initializer, this method will return
153.124 - * the appropriate <i>special method name</i>, {@code <init>} or
153.125 - * {@code <clinit>}, as per Section 3.9 of <i>The Java Virtual
153.126 - * Machine Specification</i>.
153.127 - *
153.128 - * @return the name of the method containing the execution point
153.129 - * represented by this stack trace element.
153.130 - */
153.131 - public String getMethodName() {
153.132 - return methodName;
153.133 - }
153.134 -
153.135 - /**
153.136 - * Returns true if the method containing the execution point
153.137 - * represented by this stack trace element is a native method.
153.138 - *
153.139 - * @return {@code true} if the method containing the execution point
153.140 - * represented by this stack trace element is a native method.
153.141 - */
153.142 - public boolean isNativeMethod() {
153.143 - return lineNumber == -2;
153.144 - }
153.145 -
153.146 - /**
153.147 - * Returns a string representation of this stack trace element. The
153.148 - * format of this string depends on the implementation, but the following
153.149 - * examples may be regarded as typical:
153.150 - * <ul>
153.151 - * <li>
153.152 - * {@code "MyClass.mash(MyClass.java:9)"} - Here, {@code "MyClass"}
153.153 - * is the <i>fully-qualified name</i> of the class containing the
153.154 - * execution point represented by this stack trace element,
153.155 - * {@code "mash"} is the name of the method containing the execution
153.156 - * point, {@code "MyClass.java"} is the source file containing the
153.157 - * execution point, and {@code "9"} is the line number of the source
153.158 - * line containing the execution point.
153.159 - * <li>
153.160 - * {@code "MyClass.mash(MyClass.java)"} - As above, but the line
153.161 - * number is unavailable.
153.162 - * <li>
153.163 - * {@code "MyClass.mash(Unknown Source)"} - As above, but neither
153.164 - * the file name nor the line number are available.
153.165 - * <li>
153.166 - * {@code "MyClass.mash(Native Method)"} - As above, but neither
153.167 - * the file name nor the line number are available, and the method
153.168 - * containing the execution point is known to be a native method.
153.169 - * </ul>
153.170 - * @see Throwable#printStackTrace()
153.171 - */
153.172 - public String toString() {
153.173 - return getClassName() + "." + methodName +
153.174 - (isNativeMethod() ? "(Native Method)" :
153.175 - (fileName != null && lineNumber >= 0 ?
153.176 - "(" + fileName + ":" + lineNumber + ")" :
153.177 - (fileName != null ? "("+fileName+")" : "(Unknown Source)")));
153.178 - }
153.179 -
153.180 - /**
153.181 - * Returns true if the specified object is another
153.182 - * {@code StackTraceElement} instance representing the same execution
153.183 - * point as this instance. Two stack trace elements {@code a} and
153.184 - * {@code b} are equal if and only if:
153.185 - * <pre>
153.186 - * equals(a.getFileName(), b.getFileName()) &&
153.187 - * a.getLineNumber() == b.getLineNumber()) &&
153.188 - * equals(a.getClassName(), b.getClassName()) &&
153.189 - * equals(a.getMethodName(), b.getMethodName())
153.190 - * </pre>
153.191 - * where {@code equals} has the semantics of {@link
153.192 - * java.util.Objects#equals(Object, Object) Objects.equals}.
153.193 - *
153.194 - * @param obj the object to be compared with this stack trace element.
153.195 - * @return true if the specified object is another
153.196 - * {@code StackTraceElement} instance representing the same
153.197 - * execution point as this instance.
153.198 - */
153.199 - public boolean equals(Object obj) {
153.200 - if (obj==this)
153.201 - return true;
153.202 - if (!(obj instanceof StackTraceElement))
153.203 - return false;
153.204 - StackTraceElement e = (StackTraceElement)obj;
153.205 - return e.declaringClass.equals(declaringClass) &&
153.206 - e.lineNumber == lineNumber &&
153.207 - equals(methodName, e.methodName) &&
153.208 - equals(fileName, e.fileName);
153.209 - }
153.210 -
153.211 - /**
153.212 - * Returns a hash code value for this stack trace element.
153.213 - */
153.214 - public int hashCode() {
153.215 - int result = 31*declaringClass.hashCode() + methodName.hashCode();
153.216 - result = 31*result + (fileName == null ? 0 : fileName.hashCode());
153.217 - result = 31*result + lineNumber;
153.218 - return result;
153.219 - }
153.220 -
153.221 - private static boolean equals(Object a, Object b) {
153.222 - return (a == b) || (a != null && a.equals(b));
153.223 - }
153.224 -
153.225 - private static final long serialVersionUID = 6992337162326171013L;
153.226 -}
154.1 --- a/emul/src/main/java/java/lang/String.java Wed Jan 23 20:16:48 2013 +0100
154.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
154.3 @@ -1,3009 +0,0 @@
154.4 -/*
154.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
154.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
154.7 - *
154.8 - * This code is free software; you can redistribute it and/or modify it
154.9 - * under the terms of the GNU General Public License version 2 only, as
154.10 - * published by the Free Software Foundation. Oracle designates this
154.11 - * particular file as subject to the "Classpath" exception as provided
154.12 - * by Oracle in the LICENSE file that accompanied this code.
154.13 - *
154.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
154.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
154.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
154.17 - * version 2 for more details (a copy is included in the LICENSE file that
154.18 - * accompanied this code).
154.19 - *
154.20 - * You should have received a copy of the GNU General Public License version
154.21 - * 2 along with this work; if not, write to the Free Software Foundation,
154.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
154.23 - *
154.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
154.25 - * or visit www.oracle.com if you need additional information or have any
154.26 - * questions.
154.27 - */
154.28 -
154.29 -package java.lang;
154.30 -
154.31 -import java.util.Comparator;
154.32 -import org.apidesign.bck2brwsr.core.ExtraJavaScript;
154.33 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
154.34 -import org.apidesign.bck2brwsr.core.JavaScriptOnly;
154.35 -import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
154.36 -
154.37 -/**
154.38 - * The <code>String</code> class represents character strings. All
154.39 - * string literals in Java programs, such as <code>"abc"</code>, are
154.40 - * implemented as instances of this class.
154.41 - * <p>
154.42 - * Strings are constant; their values cannot be changed after they
154.43 - * are created. String buffers support mutable strings.
154.44 - * Because String objects are immutable they can be shared. For example:
154.45 - * <p><blockquote><pre>
154.46 - * String str = "abc";
154.47 - * </pre></blockquote><p>
154.48 - * is equivalent to:
154.49 - * <p><blockquote><pre>
154.50 - * char data[] = {'a', 'b', 'c'};
154.51 - * String str = new String(data);
154.52 - * </pre></blockquote><p>
154.53 - * Here are some more examples of how strings can be used:
154.54 - * <p><blockquote><pre>
154.55 - * System.out.println("abc");
154.56 - * String cde = "cde";
154.57 - * System.out.println("abc" + cde);
154.58 - * String c = "abc".substring(2,3);
154.59 - * String d = cde.substring(1, 2);
154.60 - * </pre></blockquote>
154.61 - * <p>
154.62 - * The class <code>String</code> includes methods for examining
154.63 - * individual characters of the sequence, for comparing strings, for
154.64 - * searching strings, for extracting substrings, and for creating a
154.65 - * copy of a string with all characters translated to uppercase or to
154.66 - * lowercase. Case mapping is based on the Unicode Standard version
154.67 - * specified by the {@link java.lang.Character Character} class.
154.68 - * <p>
154.69 - * The Java language provides special support for the string
154.70 - * concatenation operator ( + ), and for conversion of
154.71 - * other objects to strings. String concatenation is implemented
154.72 - * through the <code>StringBuilder</code>(or <code>StringBuffer</code>)
154.73 - * class and its <code>append</code> method.
154.74 - * String conversions are implemented through the method
154.75 - * <code>toString</code>, defined by <code>Object</code> and
154.76 - * inherited by all classes in Java. For additional information on
154.77 - * string concatenation and conversion, see Gosling, Joy, and Steele,
154.78 - * <i>The Java Language Specification</i>.
154.79 - *
154.80 - * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
154.81 - * or method in this class will cause a {@link NullPointerException} to be
154.82 - * thrown.
154.83 - *
154.84 - * <p>A <code>String</code> represents a string in the UTF-16 format
154.85 - * in which <em>supplementary characters</em> are represented by <em>surrogate
154.86 - * pairs</em> (see the section <a href="Character.html#unicode">Unicode
154.87 - * Character Representations</a> in the <code>Character</code> class for
154.88 - * more information).
154.89 - * Index values refer to <code>char</code> code units, so a supplementary
154.90 - * character uses two positions in a <code>String</code>.
154.91 - * <p>The <code>String</code> class provides methods for dealing with
154.92 - * Unicode code points (i.e., characters), in addition to those for
154.93 - * dealing with Unicode code units (i.e., <code>char</code> values).
154.94 - *
154.95 - * @author Lee Boynton
154.96 - * @author Arthur van Hoff
154.97 - * @author Martin Buchholz
154.98 - * @author Ulf Zibis
154.99 - * @see java.lang.Object#toString()
154.100 - * @see java.lang.StringBuffer
154.101 - * @see java.lang.StringBuilder
154.102 - * @see java.nio.charset.Charset
154.103 - * @since JDK1.0
154.104 - */
154.105 -
154.106 -@ExtraJavaScript(
154.107 - resource="/org/apidesign/vm4brwsr/emul/java_lang_String.js",
154.108 - processByteCode=true
154.109 -)
154.110 -@JavaScriptPrototype(container = "String.prototype", prototype = "new String")
154.111 -public final class String
154.112 - implements java.io.Serializable, Comparable<String>, CharSequence
154.113 -{
154.114 - /** real string to delegate to */
154.115 - private Object r;
154.116 -
154.117 - /** use serialVersionUID from JDK 1.0.2 for interoperability */
154.118 - private static final long serialVersionUID = -6849794470754667710L;
154.119 -
154.120 - @JavaScriptOnly(name="toString", value="function() { return this.fld_r; }")
154.121 - private static void jsToString() {
154.122 - }
154.123 -
154.124 - @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
154.125 - private static void jsValudOf() {
154.126 - }
154.127 -
154.128 - /**
154.129 - * Class String is special cased within the Serialization Stream Protocol.
154.130 - *
154.131 - * A String instance is written initially into an ObjectOutputStream in the
154.132 - * following format:
154.133 - * <pre>
154.134 - * <code>TC_STRING</code> (utf String)
154.135 - * </pre>
154.136 - * The String is written by method <code>DataOutput.writeUTF</code>.
154.137 - * A new handle is generated to refer to all future references to the
154.138 - * string instance within the stream.
154.139 - */
154.140 -// private static final ObjectStreamField[] serialPersistentFields =
154.141 -// new ObjectStreamField[0];
154.142 -
154.143 - /**
154.144 - * Initializes a newly created {@code String} object so that it represents
154.145 - * an empty character sequence. Note that use of this constructor is
154.146 - * unnecessary since Strings are immutable.
154.147 - */
154.148 - public String() {
154.149 - this.r = "";
154.150 - }
154.151 -
154.152 - /**
154.153 - * Initializes a newly created {@code String} object so that it represents
154.154 - * the same sequence of characters as the argument; in other words, the
154.155 - * newly created string is a copy of the argument string. Unless an
154.156 - * explicit copy of {@code original} is needed, use of this constructor is
154.157 - * unnecessary since Strings are immutable.
154.158 - *
154.159 - * @param original
154.160 - * A {@code String}
154.161 - */
154.162 - public String(String original) {
154.163 - this.r = original.toString();
154.164 - }
154.165 -
154.166 - /**
154.167 - * Allocates a new {@code String} so that it represents the sequence of
154.168 - * characters currently contained in the character array argument. The
154.169 - * contents of the character array are copied; subsequent modification of
154.170 - * the character array does not affect the newly created string.
154.171 - *
154.172 - * @param value
154.173 - * The initial value of the string
154.174 - */
154.175 - @JavaScriptBody(args = { "charArr" }, body=
154.176 - "for (var i = 0; i < charArr.length; i++) {\n"
154.177 - + " if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n"
154.178 - + "}\n"
154.179 - + "this.fld_r = charArr.join('');\n"
154.180 - )
154.181 - public String(char value[]) {
154.182 - }
154.183 -
154.184 - /**
154.185 - * Allocates a new {@code String} that contains characters from a subarray
154.186 - * of the character array argument. The {@code offset} argument is the
154.187 - * index of the first character of the subarray and the {@code count}
154.188 - * argument specifies the length of the subarray. The contents of the
154.189 - * subarray are copied; subsequent modification of the character array does
154.190 - * not affect the newly created string.
154.191 - *
154.192 - * @param value
154.193 - * Array that is the source of characters
154.194 - *
154.195 - * @param offset
154.196 - * The initial offset
154.197 - *
154.198 - * @param count
154.199 - * The length
154.200 - *
154.201 - * @throws IndexOutOfBoundsException
154.202 - * If the {@code offset} and {@code count} arguments index
154.203 - * characters outside the bounds of the {@code value} array
154.204 - */
154.205 - @JavaScriptBody(args = { "charArr", "off", "cnt" }, body =
154.206 - "var up = off + cnt;\n" +
154.207 - "for (var i = off; i < up; i++) {\n" +
154.208 - " if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n" +
154.209 - "}\n" +
154.210 - "this.fld_r = charArr.slice(off, up).join(\"\");\n"
154.211 - )
154.212 - public String(char value[], int offset, int count) {
154.213 - }
154.214 -
154.215 - /**
154.216 - * Allocates a new {@code String} that contains characters from a subarray
154.217 - * of the <a href="Character.html#unicode">Unicode code point</a> array
154.218 - * argument. The {@code offset} argument is the index of the first code
154.219 - * point of the subarray and the {@code count} argument specifies the
154.220 - * length of the subarray. The contents of the subarray are converted to
154.221 - * {@code char}s; subsequent modification of the {@code int} array does not
154.222 - * affect the newly created string.
154.223 - *
154.224 - * @param codePoints
154.225 - * Array that is the source of Unicode code points
154.226 - *
154.227 - * @param offset
154.228 - * The initial offset
154.229 - *
154.230 - * @param count
154.231 - * The length
154.232 - *
154.233 - * @throws IllegalArgumentException
154.234 - * If any invalid Unicode code point is found in {@code
154.235 - * codePoints}
154.236 - *
154.237 - * @throws IndexOutOfBoundsException
154.238 - * If the {@code offset} and {@code count} arguments index
154.239 - * characters outside the bounds of the {@code codePoints} array
154.240 - *
154.241 - * @since 1.5
154.242 - */
154.243 - public String(int[] codePoints, int offset, int count) {
154.244 - if (offset < 0) {
154.245 - throw new StringIndexOutOfBoundsException(offset);
154.246 - }
154.247 - if (count < 0) {
154.248 - throw new StringIndexOutOfBoundsException(count);
154.249 - }
154.250 - // Note: offset or count might be near -1>>>1.
154.251 - if (offset > codePoints.length - count) {
154.252 - throw new StringIndexOutOfBoundsException(offset + count);
154.253 - }
154.254 -
154.255 - final int end = offset + count;
154.256 -
154.257 - // Pass 1: Compute precise size of char[]
154.258 - int n = count;
154.259 - for (int i = offset; i < end; i++) {
154.260 - int c = codePoints[i];
154.261 - if (Character.isBmpCodePoint(c))
154.262 - continue;
154.263 - else if (Character.isValidCodePoint(c))
154.264 - n++;
154.265 - else throw new IllegalArgumentException(Integer.toString(c));
154.266 - }
154.267 -
154.268 - // Pass 2: Allocate and fill in char[]
154.269 - final char[] v = new char[n];
154.270 -
154.271 - for (int i = offset, j = 0; i < end; i++, j++) {
154.272 - int c = codePoints[i];
154.273 - if (Character.isBmpCodePoint(c))
154.274 - v[j] = (char) c;
154.275 - else
154.276 - Character.toSurrogates(c, v, j++);
154.277 - }
154.278 -
154.279 - this.r = new String(v, 0, n);
154.280 - }
154.281 -
154.282 - /**
154.283 - * Allocates a new {@code String} constructed from a subarray of an array
154.284 - * of 8-bit integer values.
154.285 - *
154.286 - * <p> The {@code offset} argument is the index of the first byte of the
154.287 - * subarray, and the {@code count} argument specifies the length of the
154.288 - * subarray.
154.289 - *
154.290 - * <p> Each {@code byte} in the subarray is converted to a {@code char} as
154.291 - * specified in the method above.
154.292 - *
154.293 - * @deprecated This method does not properly convert bytes into characters.
154.294 - * As of JDK 1.1, the preferred way to do this is via the
154.295 - * {@code String} constructors that take a {@link
154.296 - * java.nio.charset.Charset}, charset name, or that use the platform's
154.297 - * default charset.
154.298 - *
154.299 - * @param ascii
154.300 - * The bytes to be converted to characters
154.301 - *
154.302 - * @param hibyte
154.303 - * The top 8 bits of each 16-bit Unicode code unit
154.304 - *
154.305 - * @param offset
154.306 - * The initial offset
154.307 - * @param count
154.308 - * The length
154.309 - *
154.310 - * @throws IndexOutOfBoundsException
154.311 - * If the {@code offset} or {@code count} argument is invalid
154.312 - *
154.313 - * @see #String(byte[], int)
154.314 - * @see #String(byte[], int, int, java.lang.String)
154.315 - * @see #String(byte[], int, int, java.nio.charset.Charset)
154.316 - * @see #String(byte[], int, int)
154.317 - * @see #String(byte[], java.lang.String)
154.318 - * @see #String(byte[], java.nio.charset.Charset)
154.319 - * @see #String(byte[])
154.320 - */
154.321 - @Deprecated
154.322 - public String(byte ascii[], int hibyte, int offset, int count) {
154.323 - checkBounds(ascii, offset, count);
154.324 - char value[] = new char[count];
154.325 -
154.326 - if (hibyte == 0) {
154.327 - for (int i = count ; i-- > 0 ;) {
154.328 - value[i] = (char) (ascii[i + offset] & 0xff);
154.329 - }
154.330 - } else {
154.331 - hibyte <<= 8;
154.332 - for (int i = count ; i-- > 0 ;) {
154.333 - value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
154.334 - }
154.335 - }
154.336 - this.r = new String(value, 0, count);
154.337 - }
154.338 -
154.339 - /**
154.340 - * Allocates a new {@code String} containing characters constructed from
154.341 - * an array of 8-bit integer values. Each character <i>c</i>in the
154.342 - * resulting string is constructed from the corresponding component
154.343 - * <i>b</i> in the byte array such that:
154.344 - *
154.345 - * <blockquote><pre>
154.346 - * <b><i>c</i></b> == (char)(((hibyte & 0xff) << 8)
154.347 - * | (<b><i>b</i></b> & 0xff))
154.348 - * </pre></blockquote>
154.349 - *
154.350 - * @deprecated This method does not properly convert bytes into
154.351 - * characters. As of JDK 1.1, the preferred way to do this is via the
154.352 - * {@code String} constructors that take a {@link
154.353 - * java.nio.charset.Charset}, charset name, or that use the platform's
154.354 - * default charset.
154.355 - *
154.356 - * @param ascii
154.357 - * The bytes to be converted to characters
154.358 - *
154.359 - * @param hibyte
154.360 - * The top 8 bits of each 16-bit Unicode code unit
154.361 - *
154.362 - * @see #String(byte[], int, int, java.lang.String)
154.363 - * @see #String(byte[], int, int, java.nio.charset.Charset)
154.364 - * @see #String(byte[], int, int)
154.365 - * @see #String(byte[], java.lang.String)
154.366 - * @see #String(byte[], java.nio.charset.Charset)
154.367 - * @see #String(byte[])
154.368 - */
154.369 - @Deprecated
154.370 - public String(byte ascii[], int hibyte) {
154.371 - this(ascii, hibyte, 0, ascii.length);
154.372 - }
154.373 -
154.374 - /* Common private utility method used to bounds check the byte array
154.375 - * and requested offset & length values used by the String(byte[],..)
154.376 - * constructors.
154.377 - */
154.378 - private static void checkBounds(byte[] bytes, int offset, int length) {
154.379 - if (length < 0)
154.380 - throw new StringIndexOutOfBoundsException(length);
154.381 - if (offset < 0)
154.382 - throw new StringIndexOutOfBoundsException(offset);
154.383 - if (offset > bytes.length - length)
154.384 - throw new StringIndexOutOfBoundsException(offset + length);
154.385 - }
154.386 -
154.387 - /**
154.388 - * Constructs a new {@code String} by decoding the specified subarray of
154.389 - * bytes using the specified charset. The length of the new {@code String}
154.390 - * is a function of the charset, and hence may not be equal to the length
154.391 - * of the subarray.
154.392 - *
154.393 - * <p> The behavior of this constructor when the given bytes are not valid
154.394 - * in the given charset is unspecified. The {@link
154.395 - * java.nio.charset.CharsetDecoder} class should be used when more control
154.396 - * over the decoding process is required.
154.397 - *
154.398 - * @param bytes
154.399 - * The bytes to be decoded into characters
154.400 - *
154.401 - * @param offset
154.402 - * The index of the first byte to decode
154.403 - *
154.404 - * @param length
154.405 - * The number of bytes to decode
154.406 -
154.407 - * @param charsetName
154.408 - * The name of a supported {@linkplain java.nio.charset.Charset
154.409 - * charset}
154.410 - *
154.411 - * @throws UnsupportedEncodingException
154.412 - * If the named charset is not supported
154.413 - *
154.414 - * @throws IndexOutOfBoundsException
154.415 - * If the {@code offset} and {@code length} arguments index
154.416 - * characters outside the bounds of the {@code bytes} array
154.417 - *
154.418 - * @since JDK1.1
154.419 - */
154.420 -// public String(byte bytes[], int offset, int length, String charsetName)
154.421 -// throws UnsupportedEncodingException
154.422 -// {
154.423 -// if (charsetName == null)
154.424 -// throw new NullPointerException("charsetName");
154.425 -// checkBounds(bytes, offset, length);
154.426 -// char[] v = StringCoding.decode(charsetName, bytes, offset, length);
154.427 -// this.offset = 0;
154.428 -// this.count = v.length;
154.429 -// this.value = v;
154.430 -// }
154.431 -
154.432 - /**
154.433 - * Constructs a new {@code String} by decoding the specified subarray of
154.434 - * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
154.435 - * The length of the new {@code String} is a function of the charset, and
154.436 - * hence may not be equal to the length of the subarray.
154.437 - *
154.438 - * <p> This method always replaces malformed-input and unmappable-character
154.439 - * sequences with this charset's default replacement string. The {@link
154.440 - * java.nio.charset.CharsetDecoder} class should be used when more control
154.441 - * over the decoding process is required.
154.442 - *
154.443 - * @param bytes
154.444 - * The bytes to be decoded into characters
154.445 - *
154.446 - * @param offset
154.447 - * The index of the first byte to decode
154.448 - *
154.449 - * @param length
154.450 - * The number of bytes to decode
154.451 - *
154.452 - * @param charset
154.453 - * The {@linkplain java.nio.charset.Charset charset} to be used to
154.454 - * decode the {@code bytes}
154.455 - *
154.456 - * @throws IndexOutOfBoundsException
154.457 - * If the {@code offset} and {@code length} arguments index
154.458 - * characters outside the bounds of the {@code bytes} array
154.459 - *
154.460 - * @since 1.6
154.461 - */
154.462 - /* don't want dependnecy on Charset
154.463 - public String(byte bytes[], int offset, int length, Charset charset) {
154.464 - if (charset == null)
154.465 - throw new NullPointerException("charset");
154.466 - checkBounds(bytes, offset, length);
154.467 - char[] v = StringCoding.decode(charset, bytes, offset, length);
154.468 - this.offset = 0;
154.469 - this.count = v.length;
154.470 - this.value = v;
154.471 - }
154.472 - */
154.473 -
154.474 - /**
154.475 - * Constructs a new {@code String} by decoding the specified array of bytes
154.476 - * using the specified {@linkplain java.nio.charset.Charset charset}. The
154.477 - * length of the new {@code String} is a function of the charset, and hence
154.478 - * may not be equal to the length of the byte array.
154.479 - *
154.480 - * <p> The behavior of this constructor when the given bytes are not valid
154.481 - * in the given charset is unspecified. The {@link
154.482 - * java.nio.charset.CharsetDecoder} class should be used when more control
154.483 - * over the decoding process is required.
154.484 - *
154.485 - * @param bytes
154.486 - * The bytes to be decoded into characters
154.487 - *
154.488 - * @param charsetName
154.489 - * The name of a supported {@linkplain java.nio.charset.Charset
154.490 - * charset}
154.491 - *
154.492 - * @throws UnsupportedEncodingException
154.493 - * If the named charset is not supported
154.494 - *
154.495 - * @since JDK1.1
154.496 - */
154.497 -// public String(byte bytes[], String charsetName)
154.498 -// throws UnsupportedEncodingException
154.499 -// {
154.500 -// this(bytes, 0, bytes.length, charsetName);
154.501 -// }
154.502 -
154.503 - /**
154.504 - * Constructs a new {@code String} by decoding the specified array of
154.505 - * bytes using the specified {@linkplain java.nio.charset.Charset charset}.
154.506 - * The length of the new {@code String} is a function of the charset, and
154.507 - * hence may not be equal to the length of the byte array.
154.508 - *
154.509 - * <p> This method always replaces malformed-input and unmappable-character
154.510 - * sequences with this charset's default replacement string. The {@link
154.511 - * java.nio.charset.CharsetDecoder} class should be used when more control
154.512 - * over the decoding process is required.
154.513 - *
154.514 - * @param bytes
154.515 - * The bytes to be decoded into characters
154.516 - *
154.517 - * @param charset
154.518 - * The {@linkplain java.nio.charset.Charset charset} to be used to
154.519 - * decode the {@code bytes}
154.520 - *
154.521 - * @since 1.6
154.522 - */
154.523 - /* don't want dep on Charset
154.524 - public String(byte bytes[], Charset charset) {
154.525 - this(bytes, 0, bytes.length, charset);
154.526 - }
154.527 - */
154.528 -
154.529 - /**
154.530 - * Constructs a new {@code String} by decoding the specified subarray of
154.531 - * bytes using the platform's default charset. The length of the new
154.532 - * {@code String} is a function of the charset, and hence may not be equal
154.533 - * to the length of the subarray.
154.534 - *
154.535 - * <p> The behavior of this constructor when the given bytes are not valid
154.536 - * in the default charset is unspecified. The {@link
154.537 - * java.nio.charset.CharsetDecoder} class should be used when more control
154.538 - * over the decoding process is required.
154.539 - *
154.540 - * @param bytes
154.541 - * The bytes to be decoded into characters
154.542 - *
154.543 - * @param offset
154.544 - * The index of the first byte to decode
154.545 - *
154.546 - * @param length
154.547 - * The number of bytes to decode
154.548 - *
154.549 - * @throws IndexOutOfBoundsException
154.550 - * If the {@code offset} and the {@code length} arguments index
154.551 - * characters outside the bounds of the {@code bytes} array
154.552 - *
154.553 - * @since JDK1.1
154.554 - */
154.555 - public String(byte bytes[], int offset, int length) {
154.556 - checkBounds(bytes, offset, length);
154.557 - char[] v = new char[length];
154.558 - for (int i = 0; i < length; i++) {
154.559 - v[i] = (char)bytes[offset++];
154.560 - }
154.561 - this.r = new String(v, 0, v.length);
154.562 - }
154.563 -
154.564 - /**
154.565 - * Constructs a new {@code String} by decoding the specified array of bytes
154.566 - * using the platform's default charset. The length of the new {@code
154.567 - * String} is a function of the charset, and hence may not be equal to the
154.568 - * length of the byte array.
154.569 - *
154.570 - * <p> The behavior of this constructor when the given bytes are not valid
154.571 - * in the default charset is unspecified. The {@link
154.572 - * java.nio.charset.CharsetDecoder} class should be used when more control
154.573 - * over the decoding process is required.
154.574 - *
154.575 - * @param bytes
154.576 - * The bytes to be decoded into characters
154.577 - *
154.578 - * @since JDK1.1
154.579 - */
154.580 - public String(byte bytes[]) {
154.581 - this(bytes, 0, bytes.length);
154.582 - }
154.583 -
154.584 - /**
154.585 - * Allocates a new string that contains the sequence of characters
154.586 - * currently contained in the string buffer argument. The contents of the
154.587 - * string buffer are copied; subsequent modification of the string buffer
154.588 - * does not affect the newly created string.
154.589 - *
154.590 - * @param buffer
154.591 - * A {@code StringBuffer}
154.592 - */
154.593 - public String(StringBuffer buffer) {
154.594 - this.r = buffer.toString();
154.595 - }
154.596 -
154.597 - /**
154.598 - * Allocates a new string that contains the sequence of characters
154.599 - * currently contained in the string builder argument. The contents of the
154.600 - * string builder are copied; subsequent modification of the string builder
154.601 - * does not affect the newly created string.
154.602 - *
154.603 - * <p> This constructor is provided to ease migration to {@code
154.604 - * StringBuilder}. Obtaining a string from a string builder via the {@code
154.605 - * toString} method is likely to run faster and is generally preferred.
154.606 - *
154.607 - * @param builder
154.608 - * A {@code StringBuilder}
154.609 - *
154.610 - * @since 1.5
154.611 - */
154.612 - public String(StringBuilder builder) {
154.613 - this.r = builder.toString();
154.614 - }
154.615 -
154.616 - /**
154.617 - * Returns the length of this string.
154.618 - * The length is equal to the number of <a href="Character.html#unicode">Unicode
154.619 - * code units</a> in the string.
154.620 - *
154.621 - * @return the length of the sequence of characters represented by this
154.622 - * object.
154.623 - */
154.624 - @JavaScriptBody(args = {}, body = "return this.toString().length;")
154.625 - public int length() {
154.626 - throw new UnsupportedOperationException();
154.627 - }
154.628 -
154.629 - /**
154.630 - * Returns <tt>true</tt> if, and only if, {@link #length()} is <tt>0</tt>.
154.631 - *
154.632 - * @return <tt>true</tt> if {@link #length()} is <tt>0</tt>, otherwise
154.633 - * <tt>false</tt>
154.634 - *
154.635 - * @since 1.6
154.636 - */
154.637 - @JavaScriptBody(args = {}, body="return this.toString().length === 0;")
154.638 - public boolean isEmpty() {
154.639 - return length() == 0;
154.640 - }
154.641 -
154.642 - /**
154.643 - * Returns the <code>char</code> value at the
154.644 - * specified index. An index ranges from <code>0</code> to
154.645 - * <code>length() - 1</code>. The first <code>char</code> value of the sequence
154.646 - * is at index <code>0</code>, the next at index <code>1</code>,
154.647 - * and so on, as for array indexing.
154.648 - *
154.649 - * <p>If the <code>char</code> value specified by the index is a
154.650 - * <a href="Character.html#unicode">surrogate</a>, the surrogate
154.651 - * value is returned.
154.652 - *
154.653 - * @param index the index of the <code>char</code> value.
154.654 - * @return the <code>char</code> value at the specified index of this string.
154.655 - * The first <code>char</code> value is at index <code>0</code>.
154.656 - * @exception IndexOutOfBoundsException if the <code>index</code>
154.657 - * argument is negative or not less than the length of this
154.658 - * string.
154.659 - */
154.660 - @JavaScriptBody(args = { "index" },
154.661 - body = "return this.toString().charCodeAt(index);"
154.662 - )
154.663 - public char charAt(int index) {
154.664 - throw new UnsupportedOperationException();
154.665 - }
154.666 -
154.667 - /**
154.668 - * Returns the character (Unicode code point) at the specified
154.669 - * index. The index refers to <code>char</code> values
154.670 - * (Unicode code units) and ranges from <code>0</code> to
154.671 - * {@link #length()}<code> - 1</code>.
154.672 - *
154.673 - * <p> If the <code>char</code> value specified at the given index
154.674 - * is in the high-surrogate range, the following index is less
154.675 - * than the length of this <code>String</code>, and the
154.676 - * <code>char</code> value at the following index is in the
154.677 - * low-surrogate range, then the supplementary code point
154.678 - * corresponding to this surrogate pair is returned. Otherwise,
154.679 - * the <code>char</code> value at the given index is returned.
154.680 - *
154.681 - * @param index the index to the <code>char</code> values
154.682 - * @return the code point value of the character at the
154.683 - * <code>index</code>
154.684 - * @exception IndexOutOfBoundsException if the <code>index</code>
154.685 - * argument is negative or not less than the length of this
154.686 - * string.
154.687 - * @since 1.5
154.688 - */
154.689 - public int codePointAt(int index) {
154.690 - if ((index < 0) || (index >= length())) {
154.691 - throw new StringIndexOutOfBoundsException(index);
154.692 - }
154.693 - return Character.codePointAtImpl(toCharArray(), offset() + index, offset() + length());
154.694 - }
154.695 -
154.696 - /**
154.697 - * Returns the character (Unicode code point) before the specified
154.698 - * index. The index refers to <code>char</code> values
154.699 - * (Unicode code units) and ranges from <code>1</code> to {@link
154.700 - * CharSequence#length() length}.
154.701 - *
154.702 - * <p> If the <code>char</code> value at <code>(index - 1)</code>
154.703 - * is in the low-surrogate range, <code>(index - 2)</code> is not
154.704 - * negative, and the <code>char</code> value at <code>(index -
154.705 - * 2)</code> is in the high-surrogate range, then the
154.706 - * supplementary code point value of the surrogate pair is
154.707 - * returned. If the <code>char</code> value at <code>index -
154.708 - * 1</code> is an unpaired low-surrogate or a high-surrogate, the
154.709 - * surrogate value is returned.
154.710 - *
154.711 - * @param index the index following the code point that should be returned
154.712 - * @return the Unicode code point value before the given index.
154.713 - * @exception IndexOutOfBoundsException if the <code>index</code>
154.714 - * argument is less than 1 or greater than the length
154.715 - * of this string.
154.716 - * @since 1.5
154.717 - */
154.718 - public int codePointBefore(int index) {
154.719 - int i = index - 1;
154.720 - if ((i < 0) || (i >= length())) {
154.721 - throw new StringIndexOutOfBoundsException(index);
154.722 - }
154.723 - return Character.codePointBeforeImpl(toCharArray(), offset() + index, offset());
154.724 - }
154.725 -
154.726 - /**
154.727 - * Returns the number of Unicode code points in the specified text
154.728 - * range of this <code>String</code>. The text range begins at the
154.729 - * specified <code>beginIndex</code> and extends to the
154.730 - * <code>char</code> at index <code>endIndex - 1</code>. Thus the
154.731 - * length (in <code>char</code>s) of the text range is
154.732 - * <code>endIndex-beginIndex</code>. Unpaired surrogates within
154.733 - * the text range count as one code point each.
154.734 - *
154.735 - * @param beginIndex the index to the first <code>char</code> of
154.736 - * the text range.
154.737 - * @param endIndex the index after the last <code>char</code> of
154.738 - * the text range.
154.739 - * @return the number of Unicode code points in the specified text
154.740 - * range
154.741 - * @exception IndexOutOfBoundsException if the
154.742 - * <code>beginIndex</code> is negative, or <code>endIndex</code>
154.743 - * is larger than the length of this <code>String</code>, or
154.744 - * <code>beginIndex</code> is larger than <code>endIndex</code>.
154.745 - * @since 1.5
154.746 - */
154.747 - public int codePointCount(int beginIndex, int endIndex) {
154.748 - if (beginIndex < 0 || endIndex > length() || beginIndex > endIndex) {
154.749 - throw new IndexOutOfBoundsException();
154.750 - }
154.751 - return Character.codePointCountImpl(toCharArray(), offset()+beginIndex, endIndex-beginIndex);
154.752 - }
154.753 -
154.754 - /**
154.755 - * Returns the index within this <code>String</code> that is
154.756 - * offset from the given <code>index</code> by
154.757 - * <code>codePointOffset</code> code points. Unpaired surrogates
154.758 - * within the text range given by <code>index</code> and
154.759 - * <code>codePointOffset</code> count as one code point each.
154.760 - *
154.761 - * @param index the index to be offset
154.762 - * @param codePointOffset the offset in code points
154.763 - * @return the index within this <code>String</code>
154.764 - * @exception IndexOutOfBoundsException if <code>index</code>
154.765 - * is negative or larger then the length of this
154.766 - * <code>String</code>, or if <code>codePointOffset</code> is positive
154.767 - * and the substring starting with <code>index</code> has fewer
154.768 - * than <code>codePointOffset</code> code points,
154.769 - * or if <code>codePointOffset</code> is negative and the substring
154.770 - * before <code>index</code> has fewer than the absolute value
154.771 - * of <code>codePointOffset</code> code points.
154.772 - * @since 1.5
154.773 - */
154.774 - public int offsetByCodePoints(int index, int codePointOffset) {
154.775 - if (index < 0 || index > length()) {
154.776 - throw new IndexOutOfBoundsException();
154.777 - }
154.778 - return Character.offsetByCodePointsImpl(toCharArray(), offset(), length(),
154.779 - offset()+index, codePointOffset) - offset();
154.780 - }
154.781 -
154.782 - /**
154.783 - * Copy characters from this string into dst starting at dstBegin.
154.784 - * This method doesn't perform any range checking.
154.785 - */
154.786 - @JavaScriptBody(args = { "arr", "to" }, body =
154.787 - "var s = this.toString();\n" +
154.788 - "for (var i = 0; i < s.length; i++) {\n" +
154.789 - " arr[to++] = s[i];\n" +
154.790 - "}"
154.791 - )
154.792 - void getChars(char dst[], int dstBegin) {
154.793 - AbstractStringBuilder.arraycopy(toCharArray(), offset(), dst, dstBegin, length());
154.794 - }
154.795 -
154.796 - /**
154.797 - * Copies characters from this string into the destination character
154.798 - * array.
154.799 - * <p>
154.800 - * The first character to be copied is at index <code>srcBegin</code>;
154.801 - * the last character to be copied is at index <code>srcEnd-1</code>
154.802 - * (thus the total number of characters to be copied is
154.803 - * <code>srcEnd-srcBegin</code>). The characters are copied into the
154.804 - * subarray of <code>dst</code> starting at index <code>dstBegin</code>
154.805 - * and ending at index:
154.806 - * <p><blockquote><pre>
154.807 - * dstbegin + (srcEnd-srcBegin) - 1
154.808 - * </pre></blockquote>
154.809 - *
154.810 - * @param srcBegin index of the first character in the string
154.811 - * to copy.
154.812 - * @param srcEnd index after the last character in the string
154.813 - * to copy.
154.814 - * @param dst the destination array.
154.815 - * @param dstBegin the start offset in the destination array.
154.816 - * @exception IndexOutOfBoundsException If any of the following
154.817 - * is true:
154.818 - * <ul><li><code>srcBegin</code> is negative.
154.819 - * <li><code>srcBegin</code> is greater than <code>srcEnd</code>
154.820 - * <li><code>srcEnd</code> is greater than the length of this
154.821 - * string
154.822 - * <li><code>dstBegin</code> is negative
154.823 - * <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
154.824 - * <code>dst.length</code></ul>
154.825 - */
154.826 - @JavaScriptBody(args = { "beg", "end", "arr", "dst" }, body=
154.827 - "var s = this.toString();\n" +
154.828 - "while (beg < end) {\n" +
154.829 - " arr[dst++] = s[beg++];\n" +
154.830 - "}\n"
154.831 - )
154.832 - public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
154.833 - if (srcBegin < 0) {
154.834 - throw new StringIndexOutOfBoundsException(srcBegin);
154.835 - }
154.836 - if (srcEnd > length()) {
154.837 - throw new StringIndexOutOfBoundsException(srcEnd);
154.838 - }
154.839 - if (srcBegin > srcEnd) {
154.840 - throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
154.841 - }
154.842 - AbstractStringBuilder.arraycopy(toCharArray(), offset() + srcBegin, dst, dstBegin,
154.843 - srcEnd - srcBegin);
154.844 - }
154.845 -
154.846 - /**
154.847 - * Copies characters from this string into the destination byte array. Each
154.848 - * byte receives the 8 low-order bits of the corresponding character. The
154.849 - * eight high-order bits of each character are not copied and do not
154.850 - * participate in the transfer in any way.
154.851 - *
154.852 - * <p> The first character to be copied is at index {@code srcBegin}; the
154.853 - * last character to be copied is at index {@code srcEnd-1}. The total
154.854 - * number of characters to be copied is {@code srcEnd-srcBegin}. The
154.855 - * characters, converted to bytes, are copied into the subarray of {@code
154.856 - * dst} starting at index {@code dstBegin} and ending at index:
154.857 - *
154.858 - * <blockquote><pre>
154.859 - * dstbegin + (srcEnd-srcBegin) - 1
154.860 - * </pre></blockquote>
154.861 - *
154.862 - * @deprecated This method does not properly convert characters into
154.863 - * bytes. As of JDK 1.1, the preferred way to do this is via the
154.864 - * {@link #getBytes()} method, which uses the platform's default charset.
154.865 - *
154.866 - * @param srcBegin
154.867 - * Index of the first character in the string to copy
154.868 - *
154.869 - * @param srcEnd
154.870 - * Index after the last character in the string to copy
154.871 - *
154.872 - * @param dst
154.873 - * The destination array
154.874 - *
154.875 - * @param dstBegin
154.876 - * The start offset in the destination array
154.877 - *
154.878 - * @throws IndexOutOfBoundsException
154.879 - * If any of the following is true:
154.880 - * <ul>
154.881 - * <li> {@code srcBegin} is negative
154.882 - * <li> {@code srcBegin} is greater than {@code srcEnd}
154.883 - * <li> {@code srcEnd} is greater than the length of this String
154.884 - * <li> {@code dstBegin} is negative
154.885 - * <li> {@code dstBegin+(srcEnd-srcBegin)} is larger than {@code
154.886 - * dst.length}
154.887 - * </ul>
154.888 - */
154.889 - @Deprecated
154.890 - public void getBytes(int srcBegin, int srcEnd, byte dst[], int dstBegin) {
154.891 - if (srcBegin < 0) {
154.892 - throw new StringIndexOutOfBoundsException(srcBegin);
154.893 - }
154.894 - if (srcEnd > length()) {
154.895 - throw new StringIndexOutOfBoundsException(srcEnd);
154.896 - }
154.897 - if (srcBegin > srcEnd) {
154.898 - throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
154.899 - }
154.900 - int j = dstBegin;
154.901 - int n = offset() + srcEnd;
154.902 - int i = offset() + srcBegin;
154.903 - char[] val = toCharArray(); /* avoid getfield opcode */
154.904 -
154.905 - while (i < n) {
154.906 - dst[j++] = (byte)val[i++];
154.907 - }
154.908 - }
154.909 -
154.910 - /**
154.911 - * Encodes this {@code String} into a sequence of bytes using the named
154.912 - * charset, storing the result into a new byte array.
154.913 - *
154.914 - * <p> The behavior of this method when this string cannot be encoded in
154.915 - * the given charset is unspecified. The {@link
154.916 - * java.nio.charset.CharsetEncoder} class should be used when more control
154.917 - * over the encoding process is required.
154.918 - *
154.919 - * @param charsetName
154.920 - * The name of a supported {@linkplain java.nio.charset.Charset
154.921 - * charset}
154.922 - *
154.923 - * @return The resultant byte array
154.924 - *
154.925 - * @throws UnsupportedEncodingException
154.926 - * If the named charset is not supported
154.927 - *
154.928 - * @since JDK1.1
154.929 - */
154.930 -// public byte[] getBytes(String charsetName)
154.931 -// throws UnsupportedEncodingException
154.932 -// {
154.933 -// if (charsetName == null) throw new NullPointerException();
154.934 -// return StringCoding.encode(charsetName, value, offset, count);
154.935 -// }
154.936 -
154.937 - /**
154.938 - * Encodes this {@code String} into a sequence of bytes using the given
154.939 - * {@linkplain java.nio.charset.Charset charset}, storing the result into a
154.940 - * new byte array.
154.941 - *
154.942 - * <p> This method always replaces malformed-input and unmappable-character
154.943 - * sequences with this charset's default replacement byte array. The
154.944 - * {@link java.nio.charset.CharsetEncoder} class should be used when more
154.945 - * control over the encoding process is required.
154.946 - *
154.947 - * @param charset
154.948 - * The {@linkplain java.nio.charset.Charset} to be used to encode
154.949 - * the {@code String}
154.950 - *
154.951 - * @return The resultant byte array
154.952 - *
154.953 - * @since 1.6
154.954 - */
154.955 - /* don't want dep on Charset
154.956 - public byte[] getBytes(Charset charset) {
154.957 - if (charset == null) throw new NullPointerException();
154.958 - return StringCoding.encode(charset, value, offset, count);
154.959 - }
154.960 - */
154.961 -
154.962 - /**
154.963 - * Encodes this {@code String} into a sequence of bytes using the
154.964 - * platform's default charset, storing the result into a new byte array.
154.965 - *
154.966 - * <p> The behavior of this method when this string cannot be encoded in
154.967 - * the default charset is unspecified. The {@link
154.968 - * java.nio.charset.CharsetEncoder} class should be used when more control
154.969 - * over the encoding process is required.
154.970 - *
154.971 - * @return The resultant byte array
154.972 - *
154.973 - * @since JDK1.1
154.974 - */
154.975 - public byte[] getBytes() {
154.976 - byte[] arr = new byte[length()];
154.977 - for (int i = 0; i < arr.length; i++) {
154.978 - final char v = charAt(i);
154.979 - arr[i] = (byte)v;
154.980 - }
154.981 - return arr;
154.982 - }
154.983 -
154.984 - /**
154.985 - * Compares this string to the specified object. The result is {@code
154.986 - * true} if and only if the argument is not {@code null} and is a {@code
154.987 - * String} object that represents the same sequence of characters as this
154.988 - * object.
154.989 - *
154.990 - * @param anObject
154.991 - * The object to compare this {@code String} against
154.992 - *
154.993 - * @return {@code true} if the given object represents a {@code String}
154.994 - * equivalent to this string, {@code false} otherwise
154.995 - *
154.996 - * @see #compareTo(String)
154.997 - * @see #equalsIgnoreCase(String)
154.998 - */
154.999 - @JavaScriptBody(args = { "obj" }, body =
154.1000 - "return obj != null && obj.$instOf_java_lang_String && "
154.1001 - + "this.toString() === obj.toString();"
154.1002 - )
154.1003 - public boolean equals(Object anObject) {
154.1004 - if (this == anObject) {
154.1005 - return true;
154.1006 - }
154.1007 - if (anObject instanceof String) {
154.1008 - String anotherString = (String)anObject;
154.1009 - int n = length();
154.1010 - if (n == anotherString.length()) {
154.1011 - char v1[] = toCharArray();
154.1012 - char v2[] = anotherString.toCharArray();
154.1013 - int i = offset();
154.1014 - int j = anotherString.offset();
154.1015 - while (n-- != 0) {
154.1016 - if (v1[i++] != v2[j++])
154.1017 - return false;
154.1018 - }
154.1019 - return true;
154.1020 - }
154.1021 - }
154.1022 - return false;
154.1023 - }
154.1024 -
154.1025 - /**
154.1026 - * Compares this string to the specified {@code StringBuffer}. The result
154.1027 - * is {@code true} if and only if this {@code String} represents the same
154.1028 - * sequence of characters as the specified {@code StringBuffer}.
154.1029 - *
154.1030 - * @param sb
154.1031 - * The {@code StringBuffer} to compare this {@code String} against
154.1032 - *
154.1033 - * @return {@code true} if this {@code String} represents the same
154.1034 - * sequence of characters as the specified {@code StringBuffer},
154.1035 - * {@code false} otherwise
154.1036 - *
154.1037 - * @since 1.4
154.1038 - */
154.1039 - public boolean contentEquals(StringBuffer sb) {
154.1040 - synchronized(sb) {
154.1041 - return contentEquals((CharSequence)sb);
154.1042 - }
154.1043 - }
154.1044 -
154.1045 - /**
154.1046 - * Compares this string to the specified {@code CharSequence}. The result
154.1047 - * is {@code true} if and only if this {@code String} represents the same
154.1048 - * sequence of char values as the specified sequence.
154.1049 - *
154.1050 - * @param cs
154.1051 - * The sequence to compare this {@code String} against
154.1052 - *
154.1053 - * @return {@code true} if this {@code String} represents the same
154.1054 - * sequence of char values as the specified sequence, {@code
154.1055 - * false} otherwise
154.1056 - *
154.1057 - * @since 1.5
154.1058 - */
154.1059 - public boolean contentEquals(CharSequence cs) {
154.1060 - if (length() != cs.length())
154.1061 - return false;
154.1062 - // Argument is a StringBuffer, StringBuilder
154.1063 - if (cs instanceof AbstractStringBuilder) {
154.1064 - char v1[] = toCharArray();
154.1065 - char v2[] = ((AbstractStringBuilder)cs).getValue();
154.1066 - int i = offset();
154.1067 - int j = 0;
154.1068 - int n = length();
154.1069 - while (n-- != 0) {
154.1070 - if (v1[i++] != v2[j++])
154.1071 - return false;
154.1072 - }
154.1073 - return true;
154.1074 - }
154.1075 - // Argument is a String
154.1076 - if (cs.equals(this))
154.1077 - return true;
154.1078 - // Argument is a generic CharSequence
154.1079 - char v1[] = toCharArray();
154.1080 - int i = offset();
154.1081 - int j = 0;
154.1082 - int n = length();
154.1083 - while (n-- != 0) {
154.1084 - if (v1[i++] != cs.charAt(j++))
154.1085 - return false;
154.1086 - }
154.1087 - return true;
154.1088 - }
154.1089 -
154.1090 - /**
154.1091 - * Compares this {@code String} to another {@code String}, ignoring case
154.1092 - * considerations. Two strings are considered equal ignoring case if they
154.1093 - * are of the same length and corresponding characters in the two strings
154.1094 - * are equal ignoring case.
154.1095 - *
154.1096 - * <p> Two characters {@code c1} and {@code c2} are considered the same
154.1097 - * ignoring case if at least one of the following is true:
154.1098 - * <ul>
154.1099 - * <li> The two characters are the same (as compared by the
154.1100 - * {@code ==} operator)
154.1101 - * <li> Applying the method {@link
154.1102 - * java.lang.Character#toUpperCase(char)} to each character
154.1103 - * produces the same result
154.1104 - * <li> Applying the method {@link
154.1105 - * java.lang.Character#toLowerCase(char)} to each character
154.1106 - * produces the same result
154.1107 - * </ul>
154.1108 - *
154.1109 - * @param anotherString
154.1110 - * The {@code String} to compare this {@code String} against
154.1111 - *
154.1112 - * @return {@code true} if the argument is not {@code null} and it
154.1113 - * represents an equivalent {@code String} ignoring case; {@code
154.1114 - * false} otherwise
154.1115 - *
154.1116 - * @see #equals(Object)
154.1117 - */
154.1118 - public boolean equalsIgnoreCase(String anotherString) {
154.1119 - return (this == anotherString) ? true :
154.1120 - (anotherString != null) && (anotherString.length() == length()) &&
154.1121 - regionMatches(true, 0, anotherString, 0, length());
154.1122 - }
154.1123 -
154.1124 - /**
154.1125 - * Compares two strings lexicographically.
154.1126 - * The comparison is based on the Unicode value of each character in
154.1127 - * the strings. The character sequence represented by this
154.1128 - * <code>String</code> object is compared lexicographically to the
154.1129 - * character sequence represented by the argument string. The result is
154.1130 - * a negative integer if this <code>String</code> object
154.1131 - * lexicographically precedes the argument string. The result is a
154.1132 - * positive integer if this <code>String</code> object lexicographically
154.1133 - * follows the argument string. The result is zero if the strings
154.1134 - * are equal; <code>compareTo</code> returns <code>0</code> exactly when
154.1135 - * the {@link #equals(Object)} method would return <code>true</code>.
154.1136 - * <p>
154.1137 - * This is the definition of lexicographic ordering. If two strings are
154.1138 - * different, then either they have different characters at some index
154.1139 - * that is a valid index for both strings, or their lengths are different,
154.1140 - * or both. If they have different characters at one or more index
154.1141 - * positions, let <i>k</i> be the smallest such index; then the string
154.1142 - * whose character at position <i>k</i> has the smaller value, as
154.1143 - * determined by using the < operator, lexicographically precedes the
154.1144 - * other string. In this case, <code>compareTo</code> returns the
154.1145 - * difference of the two character values at position <code>k</code> in
154.1146 - * the two string -- that is, the value:
154.1147 - * <blockquote><pre>
154.1148 - * this.charAt(k)-anotherString.charAt(k)
154.1149 - * </pre></blockquote>
154.1150 - * If there is no index position at which they differ, then the shorter
154.1151 - * string lexicographically precedes the longer string. In this case,
154.1152 - * <code>compareTo</code> returns the difference of the lengths of the
154.1153 - * strings -- that is, the value:
154.1154 - * <blockquote><pre>
154.1155 - * this.length()-anotherString.length()
154.1156 - * </pre></blockquote>
154.1157 - *
154.1158 - * @param anotherString the <code>String</code> to be compared.
154.1159 - * @return the value <code>0</code> if the argument string is equal to
154.1160 - * this string; a value less than <code>0</code> if this string
154.1161 - * is lexicographically less than the string argument; and a
154.1162 - * value greater than <code>0</code> if this string is
154.1163 - * lexicographically greater than the string argument.
154.1164 - */
154.1165 - public int compareTo(String anotherString) {
154.1166 - int len1 = length();
154.1167 - int len2 = anotherString.length();
154.1168 - int n = Math.min(len1, len2);
154.1169 - char v1[] = toCharArray();
154.1170 - char v2[] = anotherString.toCharArray();
154.1171 - int i = offset();
154.1172 - int j = anotherString.offset();
154.1173 -
154.1174 - if (i == j) {
154.1175 - int k = i;
154.1176 - int lim = n + i;
154.1177 - while (k < lim) {
154.1178 - char c1 = v1[k];
154.1179 - char c2 = v2[k];
154.1180 - if (c1 != c2) {
154.1181 - return c1 - c2;
154.1182 - }
154.1183 - k++;
154.1184 - }
154.1185 - } else {
154.1186 - while (n-- != 0) {
154.1187 - char c1 = v1[i++];
154.1188 - char c2 = v2[j++];
154.1189 - if (c1 != c2) {
154.1190 - return c1 - c2;
154.1191 - }
154.1192 - }
154.1193 - }
154.1194 - return len1 - len2;
154.1195 - }
154.1196 -
154.1197 - /**
154.1198 - * A Comparator that orders <code>String</code> objects as by
154.1199 - * <code>compareToIgnoreCase</code>. This comparator is serializable.
154.1200 - * <p>
154.1201 - * Note that this Comparator does <em>not</em> take locale into account,
154.1202 - * and will result in an unsatisfactory ordering for certain locales.
154.1203 - * The java.text package provides <em>Collators</em> to allow
154.1204 - * locale-sensitive ordering.
154.1205 - *
154.1206 - * @see java.text.Collator#compare(String, String)
154.1207 - * @since 1.2
154.1208 - */
154.1209 - public static final Comparator<String> CASE_INSENSITIVE_ORDER
154.1210 - = new CaseInsensitiveComparator();
154.1211 -
154.1212 - private static int offset() {
154.1213 - return 0;
154.1214 - }
154.1215 -
154.1216 - private static class CaseInsensitiveComparator
154.1217 - implements Comparator<String>, java.io.Serializable {
154.1218 - // use serialVersionUID from JDK 1.2.2 for interoperability
154.1219 - private static final long serialVersionUID = 8575799808933029326L;
154.1220 -
154.1221 - public int compare(String s1, String s2) {
154.1222 - int n1 = s1.length();
154.1223 - int n2 = s2.length();
154.1224 - int min = Math.min(n1, n2);
154.1225 - for (int i = 0; i < min; i++) {
154.1226 - char c1 = s1.charAt(i);
154.1227 - char c2 = s2.charAt(i);
154.1228 - if (c1 != c2) {
154.1229 - c1 = Character.toUpperCase(c1);
154.1230 - c2 = Character.toUpperCase(c2);
154.1231 - if (c1 != c2) {
154.1232 - c1 = Character.toLowerCase(c1);
154.1233 - c2 = Character.toLowerCase(c2);
154.1234 - if (c1 != c2) {
154.1235 - // No overflow because of numeric promotion
154.1236 - return c1 - c2;
154.1237 - }
154.1238 - }
154.1239 - }
154.1240 - }
154.1241 - return n1 - n2;
154.1242 - }
154.1243 - }
154.1244 -
154.1245 - /**
154.1246 - * Compares two strings lexicographically, ignoring case
154.1247 - * differences. This method returns an integer whose sign is that of
154.1248 - * calling <code>compareTo</code> with normalized versions of the strings
154.1249 - * where case differences have been eliminated by calling
154.1250 - * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
154.1251 - * each character.
154.1252 - * <p>
154.1253 - * Note that this method does <em>not</em> take locale into account,
154.1254 - * and will result in an unsatisfactory ordering for certain locales.
154.1255 - * The java.text package provides <em>collators</em> to allow
154.1256 - * locale-sensitive ordering.
154.1257 - *
154.1258 - * @param str the <code>String</code> to be compared.
154.1259 - * @return a negative integer, zero, or a positive integer as the
154.1260 - * specified String is greater than, equal to, or less
154.1261 - * than this String, ignoring case considerations.
154.1262 - * @see java.text.Collator#compare(String, String)
154.1263 - * @since 1.2
154.1264 - */
154.1265 - public int compareToIgnoreCase(String str) {
154.1266 - return CASE_INSENSITIVE_ORDER.compare(this, str);
154.1267 - }
154.1268 -
154.1269 - /**
154.1270 - * Tests if two string regions are equal.
154.1271 - * <p>
154.1272 - * A substring of this <tt>String</tt> object is compared to a substring
154.1273 - * of the argument other. The result is true if these substrings
154.1274 - * represent identical character sequences. The substring of this
154.1275 - * <tt>String</tt> object to be compared begins at index <tt>toffset</tt>
154.1276 - * and has length <tt>len</tt>. The substring of other to be compared
154.1277 - * begins at index <tt>ooffset</tt> and has length <tt>len</tt>. The
154.1278 - * result is <tt>false</tt> if and only if at least one of the following
154.1279 - * is true:
154.1280 - * <ul><li><tt>toffset</tt> is negative.
154.1281 - * <li><tt>ooffset</tt> is negative.
154.1282 - * <li><tt>toffset+len</tt> is greater than the length of this
154.1283 - * <tt>String</tt> object.
154.1284 - * <li><tt>ooffset+len</tt> is greater than the length of the other
154.1285 - * argument.
154.1286 - * <li>There is some nonnegative integer <i>k</i> less than <tt>len</tt>
154.1287 - * such that:
154.1288 - * <tt>this.charAt(toffset+<i>k</i>) != other.charAt(ooffset+<i>k</i>)</tt>
154.1289 - * </ul>
154.1290 - *
154.1291 - * @param toffset the starting offset of the subregion in this string.
154.1292 - * @param other the string argument.
154.1293 - * @param ooffset the starting offset of the subregion in the string
154.1294 - * argument.
154.1295 - * @param len the number of characters to compare.
154.1296 - * @return <code>true</code> if the specified subregion of this string
154.1297 - * exactly matches the specified subregion of the string argument;
154.1298 - * <code>false</code> otherwise.
154.1299 - */
154.1300 - public boolean regionMatches(int toffset, String other, int ooffset,
154.1301 - int len) {
154.1302 - char ta[] = toCharArray();
154.1303 - int to = offset() + toffset;
154.1304 - char pa[] = other.toCharArray();
154.1305 - int po = other.offset() + ooffset;
154.1306 - // Note: toffset, ooffset, or len might be near -1>>>1.
154.1307 - if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len)
154.1308 - || (ooffset > (long)other.length() - len)) {
154.1309 - return false;
154.1310 - }
154.1311 - while (len-- > 0) {
154.1312 - if (ta[to++] != pa[po++]) {
154.1313 - return false;
154.1314 - }
154.1315 - }
154.1316 - return true;
154.1317 - }
154.1318 -
154.1319 - /**
154.1320 - * Tests if two string regions are equal.
154.1321 - * <p>
154.1322 - * A substring of this <tt>String</tt> object is compared to a substring
154.1323 - * of the argument <tt>other</tt>. The result is <tt>true</tt> if these
154.1324 - * substrings represent character sequences that are the same, ignoring
154.1325 - * case if and only if <tt>ignoreCase</tt> is true. The substring of
154.1326 - * this <tt>String</tt> object to be compared begins at index
154.1327 - * <tt>toffset</tt> and has length <tt>len</tt>. The substring of
154.1328 - * <tt>other</tt> to be compared begins at index <tt>ooffset</tt> and
154.1329 - * has length <tt>len</tt>. The result is <tt>false</tt> if and only if
154.1330 - * at least one of the following is true:
154.1331 - * <ul><li><tt>toffset</tt> is negative.
154.1332 - * <li><tt>ooffset</tt> is negative.
154.1333 - * <li><tt>toffset+len</tt> is greater than the length of this
154.1334 - * <tt>String</tt> object.
154.1335 - * <li><tt>ooffset+len</tt> is greater than the length of the other
154.1336 - * argument.
154.1337 - * <li><tt>ignoreCase</tt> is <tt>false</tt> and there is some nonnegative
154.1338 - * integer <i>k</i> less than <tt>len</tt> such that:
154.1339 - * <blockquote><pre>
154.1340 - * this.charAt(toffset+k) != other.charAt(ooffset+k)
154.1341 - * </pre></blockquote>
154.1342 - * <li><tt>ignoreCase</tt> is <tt>true</tt> and there is some nonnegative
154.1343 - * integer <i>k</i> less than <tt>len</tt> such that:
154.1344 - * <blockquote><pre>
154.1345 - * Character.toLowerCase(this.charAt(toffset+k)) !=
154.1346 - Character.toLowerCase(other.charAt(ooffset+k))
154.1347 - * </pre></blockquote>
154.1348 - * and:
154.1349 - * <blockquote><pre>
154.1350 - * Character.toUpperCase(this.charAt(toffset+k)) !=
154.1351 - * Character.toUpperCase(other.charAt(ooffset+k))
154.1352 - * </pre></blockquote>
154.1353 - * </ul>
154.1354 - *
154.1355 - * @param ignoreCase if <code>true</code>, ignore case when comparing
154.1356 - * characters.
154.1357 - * @param toffset the starting offset of the subregion in this
154.1358 - * string.
154.1359 - * @param other the string argument.
154.1360 - * @param ooffset the starting offset of the subregion in the string
154.1361 - * argument.
154.1362 - * @param len the number of characters to compare.
154.1363 - * @return <code>true</code> if the specified subregion of this string
154.1364 - * matches the specified subregion of the string argument;
154.1365 - * <code>false</code> otherwise. Whether the matching is exact
154.1366 - * or case insensitive depends on the <code>ignoreCase</code>
154.1367 - * argument.
154.1368 - */
154.1369 - public boolean regionMatches(boolean ignoreCase, int toffset,
154.1370 - String other, int ooffset, int len) {
154.1371 - char ta[] = toCharArray();
154.1372 - int to = offset() + toffset;
154.1373 - char pa[] = other.toCharArray();
154.1374 - int po = other.offset() + ooffset;
154.1375 - // Note: toffset, ooffset, or len might be near -1>>>1.
154.1376 - if ((ooffset < 0) || (toffset < 0) || (toffset > (long)length() - len) ||
154.1377 - (ooffset > (long)other.length() - len)) {
154.1378 - return false;
154.1379 - }
154.1380 - while (len-- > 0) {
154.1381 - char c1 = ta[to++];
154.1382 - char c2 = pa[po++];
154.1383 - if (c1 == c2) {
154.1384 - continue;
154.1385 - }
154.1386 - if (ignoreCase) {
154.1387 - // If characters don't match but case may be ignored,
154.1388 - // try converting both characters to uppercase.
154.1389 - // If the results match, then the comparison scan should
154.1390 - // continue.
154.1391 - char u1 = Character.toUpperCase(c1);
154.1392 - char u2 = Character.toUpperCase(c2);
154.1393 - if (u1 == u2) {
154.1394 - continue;
154.1395 - }
154.1396 - // Unfortunately, conversion to uppercase does not work properly
154.1397 - // for the Georgian alphabet, which has strange rules about case
154.1398 - // conversion. So we need to make one last check before
154.1399 - // exiting.
154.1400 - if (Character.toLowerCase(u1) == Character.toLowerCase(u2)) {
154.1401 - continue;
154.1402 - }
154.1403 - }
154.1404 - return false;
154.1405 - }
154.1406 - return true;
154.1407 - }
154.1408 -
154.1409 - /**
154.1410 - * Tests if the substring of this string beginning at the
154.1411 - * specified index starts with the specified prefix.
154.1412 - *
154.1413 - * @param prefix the prefix.
154.1414 - * @param toffset where to begin looking in this string.
154.1415 - * @return <code>true</code> if the character sequence represented by the
154.1416 - * argument is a prefix of the substring of this object starting
154.1417 - * at index <code>toffset</code>; <code>false</code> otherwise.
154.1418 - * The result is <code>false</code> if <code>toffset</code> is
154.1419 - * negative or greater than the length of this
154.1420 - * <code>String</code> object; otherwise the result is the same
154.1421 - * as the result of the expression
154.1422 - * <pre>
154.1423 - * this.substring(toffset).startsWith(prefix)
154.1424 - * </pre>
154.1425 - */
154.1426 - @JavaScriptBody(args = { "find", "from" }, body=
154.1427 - "find = find.toString();\n" +
154.1428 - "return this.toString().substring(from, from + find.length) === find;\n"
154.1429 - )
154.1430 - public boolean startsWith(String prefix, int toffset) {
154.1431 - char ta[] = toCharArray();
154.1432 - int to = offset() + toffset;
154.1433 - char pa[] = prefix.toCharArray();
154.1434 - int po = prefix.offset();
154.1435 - int pc = prefix.length();
154.1436 - // Note: toffset might be near -1>>>1.
154.1437 - if ((toffset < 0) || (toffset > length() - pc)) {
154.1438 - return false;
154.1439 - }
154.1440 - while (--pc >= 0) {
154.1441 - if (ta[to++] != pa[po++]) {
154.1442 - return false;
154.1443 - }
154.1444 - }
154.1445 - return true;
154.1446 - }
154.1447 -
154.1448 - /**
154.1449 - * Tests if this string starts with the specified prefix.
154.1450 - *
154.1451 - * @param prefix the prefix.
154.1452 - * @return <code>true</code> if the character sequence represented by the
154.1453 - * argument is a prefix of the character sequence represented by
154.1454 - * this string; <code>false</code> otherwise.
154.1455 - * Note also that <code>true</code> will be returned if the
154.1456 - * argument is an empty string or is equal to this
154.1457 - * <code>String</code> object as determined by the
154.1458 - * {@link #equals(Object)} method.
154.1459 - * @since 1. 0
154.1460 - */
154.1461 - public boolean startsWith(String prefix) {
154.1462 - return startsWith(prefix, 0);
154.1463 - }
154.1464 -
154.1465 - /**
154.1466 - * Tests if this string ends with the specified suffix.
154.1467 - *
154.1468 - * @param suffix the suffix.
154.1469 - * @return <code>true</code> if the character sequence represented by the
154.1470 - * argument is a suffix of the character sequence represented by
154.1471 - * this object; <code>false</code> otherwise. Note that the
154.1472 - * result will be <code>true</code> if the argument is the
154.1473 - * empty string or is equal to this <code>String</code> object
154.1474 - * as determined by the {@link #equals(Object)} method.
154.1475 - */
154.1476 - public boolean endsWith(String suffix) {
154.1477 - return startsWith(suffix, length() - suffix.length());
154.1478 - }
154.1479 -
154.1480 - /**
154.1481 - * Returns a hash code for this string. The hash code for a
154.1482 - * <code>String</code> object is computed as
154.1483 - * <blockquote><pre>
154.1484 - * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
154.1485 - * </pre></blockquote>
154.1486 - * using <code>int</code> arithmetic, where <code>s[i]</code> is the
154.1487 - * <i>i</i>th character of the string, <code>n</code> is the length of
154.1488 - * the string, and <code>^</code> indicates exponentiation.
154.1489 - * (The hash value of the empty string is zero.)
154.1490 - *
154.1491 - * @return a hash code value for this object.
154.1492 - */
154.1493 - public int hashCode() {
154.1494 - return super.hashCode();
154.1495 - }
154.1496 - int computeHashCode() {
154.1497 - int h = 0;
154.1498 - if (h == 0 && length() > 0) {
154.1499 - int off = offset();
154.1500 - int len = length();
154.1501 -
154.1502 - for (int i = 0; i < len; i++) {
154.1503 - h = 31*h + charAt(off++);
154.1504 - }
154.1505 - }
154.1506 - return h;
154.1507 - }
154.1508 -
154.1509 - /**
154.1510 - * Returns the index within this string of the first occurrence of
154.1511 - * the specified character. If a character with value
154.1512 - * <code>ch</code> occurs in the character sequence represented by
154.1513 - * this <code>String</code> object, then the index (in Unicode
154.1514 - * code units) of the first such occurrence is returned. For
154.1515 - * values of <code>ch</code> in the range from 0 to 0xFFFF
154.1516 - * (inclusive), this is the smallest value <i>k</i> such that:
154.1517 - * <blockquote><pre>
154.1518 - * this.charAt(<i>k</i>) == ch
154.1519 - * </pre></blockquote>
154.1520 - * is true. For other values of <code>ch</code>, it is the
154.1521 - * smallest value <i>k</i> such that:
154.1522 - * <blockquote><pre>
154.1523 - * this.codePointAt(<i>k</i>) == ch
154.1524 - * </pre></blockquote>
154.1525 - * is true. In either case, if no such character occurs in this
154.1526 - * string, then <code>-1</code> is returned.
154.1527 - *
154.1528 - * @param ch a character (Unicode code point).
154.1529 - * @return the index of the first occurrence of the character in the
154.1530 - * character sequence represented by this object, or
154.1531 - * <code>-1</code> if the character does not occur.
154.1532 - */
154.1533 - public int indexOf(int ch) {
154.1534 - return indexOf(ch, 0);
154.1535 - }
154.1536 -
154.1537 - /**
154.1538 - * Returns the index within this string of the first occurrence of the
154.1539 - * specified character, starting the search at the specified index.
154.1540 - * <p>
154.1541 - * If a character with value <code>ch</code> occurs in the
154.1542 - * character sequence represented by this <code>String</code>
154.1543 - * object at an index no smaller than <code>fromIndex</code>, then
154.1544 - * the index of the first such occurrence is returned. For values
154.1545 - * of <code>ch</code> in the range from 0 to 0xFFFF (inclusive),
154.1546 - * this is the smallest value <i>k</i> such that:
154.1547 - * <blockquote><pre>
154.1548 - * (this.charAt(<i>k</i>) == ch) && (<i>k</i> >= fromIndex)
154.1549 - * </pre></blockquote>
154.1550 - * is true. For other values of <code>ch</code>, it is the
154.1551 - * smallest value <i>k</i> such that:
154.1552 - * <blockquote><pre>
154.1553 - * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> >= fromIndex)
154.1554 - * </pre></blockquote>
154.1555 - * is true. In either case, if no such character occurs in this
154.1556 - * string at or after position <code>fromIndex</code>, then
154.1557 - * <code>-1</code> is returned.
154.1558 - *
154.1559 - * <p>
154.1560 - * There is no restriction on the value of <code>fromIndex</code>. If it
154.1561 - * is negative, it has the same effect as if it were zero: this entire
154.1562 - * string may be searched. If it is greater than the length of this
154.1563 - * string, it has the same effect as if it were equal to the length of
154.1564 - * this string: <code>-1</code> is returned.
154.1565 - *
154.1566 - * <p>All indices are specified in <code>char</code> values
154.1567 - * (Unicode code units).
154.1568 - *
154.1569 - * @param ch a character (Unicode code point).
154.1570 - * @param fromIndex the index to start the search from.
154.1571 - * @return the index of the first occurrence of the character in the
154.1572 - * character sequence represented by this object that is greater
154.1573 - * than or equal to <code>fromIndex</code>, or <code>-1</code>
154.1574 - * if the character does not occur.
154.1575 - */
154.1576 - @JavaScriptBody(args = { "ch", "from" }, body =
154.1577 - "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
154.1578 - "return this.toString().indexOf(ch, from);\n"
154.1579 - )
154.1580 - public int indexOf(int ch, int fromIndex) {
154.1581 - if (fromIndex < 0) {
154.1582 - fromIndex = 0;
154.1583 - } else if (fromIndex >= length()) {
154.1584 - // Note: fromIndex might be near -1>>>1.
154.1585 - return -1;
154.1586 - }
154.1587 -
154.1588 - if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
154.1589 - // handle most cases here (ch is a BMP code point or a
154.1590 - // negative value (invalid code point))
154.1591 - final char[] value = this.toCharArray();
154.1592 - final int offset = this.offset();
154.1593 - final int max = offset + length();
154.1594 - for (int i = offset + fromIndex; i < max ; i++) {
154.1595 - if (value[i] == ch) {
154.1596 - return i - offset;
154.1597 - }
154.1598 - }
154.1599 - return -1;
154.1600 - } else {
154.1601 - return indexOfSupplementary(ch, fromIndex);
154.1602 - }
154.1603 - }
154.1604 -
154.1605 - /**
154.1606 - * Handles (rare) calls of indexOf with a supplementary character.
154.1607 - */
154.1608 - private int indexOfSupplementary(int ch, int fromIndex) {
154.1609 - if (Character.isValidCodePoint(ch)) {
154.1610 - final char[] value = this.toCharArray();
154.1611 - final int offset = this.offset();
154.1612 - final char hi = Character.highSurrogate(ch);
154.1613 - final char lo = Character.lowSurrogate(ch);
154.1614 - final int max = offset + length() - 1;
154.1615 - for (int i = offset + fromIndex; i < max; i++) {
154.1616 - if (value[i] == hi && value[i+1] == lo) {
154.1617 - return i - offset;
154.1618 - }
154.1619 - }
154.1620 - }
154.1621 - return -1;
154.1622 - }
154.1623 -
154.1624 - /**
154.1625 - * Returns the index within this string of the last occurrence of
154.1626 - * the specified character. For values of <code>ch</code> in the
154.1627 - * range from 0 to 0xFFFF (inclusive), the index (in Unicode code
154.1628 - * units) returned is the largest value <i>k</i> such that:
154.1629 - * <blockquote><pre>
154.1630 - * this.charAt(<i>k</i>) == ch
154.1631 - * </pre></blockquote>
154.1632 - * is true. For other values of <code>ch</code>, it is the
154.1633 - * largest value <i>k</i> such that:
154.1634 - * <blockquote><pre>
154.1635 - * this.codePointAt(<i>k</i>) == ch
154.1636 - * </pre></blockquote>
154.1637 - * is true. In either case, if no such character occurs in this
154.1638 - * string, then <code>-1</code> is returned. The
154.1639 - * <code>String</code> is searched backwards starting at the last
154.1640 - * character.
154.1641 - *
154.1642 - * @param ch a character (Unicode code point).
154.1643 - * @return the index of the last occurrence of the character in the
154.1644 - * character sequence represented by this object, or
154.1645 - * <code>-1</code> if the character does not occur.
154.1646 - */
154.1647 - public int lastIndexOf(int ch) {
154.1648 - return lastIndexOf(ch, length() - 1);
154.1649 - }
154.1650 -
154.1651 - /**
154.1652 - * Returns the index within this string of the last occurrence of
154.1653 - * the specified character, searching backward starting at the
154.1654 - * specified index. For values of <code>ch</code> in the range
154.1655 - * from 0 to 0xFFFF (inclusive), the index returned is the largest
154.1656 - * value <i>k</i> such that:
154.1657 - * <blockquote><pre>
154.1658 - * (this.charAt(<i>k</i>) == ch) && (<i>k</i> <= fromIndex)
154.1659 - * </pre></blockquote>
154.1660 - * is true. For other values of <code>ch</code>, it is the
154.1661 - * largest value <i>k</i> such that:
154.1662 - * <blockquote><pre>
154.1663 - * (this.codePointAt(<i>k</i>) == ch) && (<i>k</i> <= fromIndex)
154.1664 - * </pre></blockquote>
154.1665 - * is true. In either case, if no such character occurs in this
154.1666 - * string at or before position <code>fromIndex</code>, then
154.1667 - * <code>-1</code> is returned.
154.1668 - *
154.1669 - * <p>All indices are specified in <code>char</code> values
154.1670 - * (Unicode code units).
154.1671 - *
154.1672 - * @param ch a character (Unicode code point).
154.1673 - * @param fromIndex the index to start the search from. There is no
154.1674 - * restriction on the value of <code>fromIndex</code>. If it is
154.1675 - * greater than or equal to the length of this string, it has
154.1676 - * the same effect as if it were equal to one less than the
154.1677 - * length of this string: this entire string may be searched.
154.1678 - * If it is negative, it has the same effect as if it were -1:
154.1679 - * -1 is returned.
154.1680 - * @return the index of the last occurrence of the character in the
154.1681 - * character sequence represented by this object that is less
154.1682 - * than or equal to <code>fromIndex</code>, or <code>-1</code>
154.1683 - * if the character does not occur before that point.
154.1684 - */
154.1685 - @JavaScriptBody(args = { "ch", "from" }, body =
154.1686 - "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
154.1687 - "return this.toString().lastIndexOf(ch, from);"
154.1688 - )
154.1689 - public int lastIndexOf(int ch, int fromIndex) {
154.1690 - if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
154.1691 - // handle most cases here (ch is a BMP code point or a
154.1692 - // negative value (invalid code point))
154.1693 - final char[] value = this.toCharArray();
154.1694 - final int offset = this.offset();
154.1695 - int i = offset + Math.min(fromIndex, length() - 1);
154.1696 - for (; i >= offset ; i--) {
154.1697 - if (value[i] == ch) {
154.1698 - return i - offset;
154.1699 - }
154.1700 - }
154.1701 - return -1;
154.1702 - } else {
154.1703 - return lastIndexOfSupplementary(ch, fromIndex);
154.1704 - }
154.1705 - }
154.1706 -
154.1707 - /**
154.1708 - * Handles (rare) calls of lastIndexOf with a supplementary character.
154.1709 - */
154.1710 - private int lastIndexOfSupplementary(int ch, int fromIndex) {
154.1711 - if (Character.isValidCodePoint(ch)) {
154.1712 - final char[] value = this.toCharArray();
154.1713 - final int offset = this.offset();
154.1714 - char hi = Character.highSurrogate(ch);
154.1715 - char lo = Character.lowSurrogate(ch);
154.1716 - int i = offset + Math.min(fromIndex, length() - 2);
154.1717 - for (; i >= offset; i--) {
154.1718 - if (value[i] == hi && value[i+1] == lo) {
154.1719 - return i - offset;
154.1720 - }
154.1721 - }
154.1722 - }
154.1723 - return -1;
154.1724 - }
154.1725 -
154.1726 - /**
154.1727 - * Returns the index within this string of the first occurrence of the
154.1728 - * specified substring.
154.1729 - *
154.1730 - * <p>The returned index is the smallest value <i>k</i> for which:
154.1731 - * <blockquote><pre>
154.1732 - * this.startsWith(str, <i>k</i>)
154.1733 - * </pre></blockquote>
154.1734 - * If no such value of <i>k</i> exists, then {@code -1} is returned.
154.1735 - *
154.1736 - * @param str the substring to search for.
154.1737 - * @return the index of the first occurrence of the specified substring,
154.1738 - * or {@code -1} if there is no such occurrence.
154.1739 - */
154.1740 - public int indexOf(String str) {
154.1741 - return indexOf(str, 0);
154.1742 - }
154.1743 -
154.1744 - /**
154.1745 - * Returns the index within this string of the first occurrence of the
154.1746 - * specified substring, starting at the specified index.
154.1747 - *
154.1748 - * <p>The returned index is the smallest value <i>k</i> for which:
154.1749 - * <blockquote><pre>
154.1750 - * <i>k</i> >= fromIndex && this.startsWith(str, <i>k</i>)
154.1751 - * </pre></blockquote>
154.1752 - * If no such value of <i>k</i> exists, then {@code -1} is returned.
154.1753 - *
154.1754 - * @param str the substring to search for.
154.1755 - * @param fromIndex the index from which to start the search.
154.1756 - * @return the index of the first occurrence of the specified substring,
154.1757 - * starting at the specified index,
154.1758 - * or {@code -1} if there is no such occurrence.
154.1759 - */
154.1760 - @JavaScriptBody(args = { "str", "fromIndex" }, body =
154.1761 - "return this.toString().indexOf(str.toString(), fromIndex);"
154.1762 - )
154.1763 - public native int indexOf(String str, int fromIndex);
154.1764 -
154.1765 - /**
154.1766 - * Returns the index within this string of the last occurrence of the
154.1767 - * specified substring. The last occurrence of the empty string ""
154.1768 - * is considered to occur at the index value {@code this.length()}.
154.1769 - *
154.1770 - * <p>The returned index is the largest value <i>k</i> for which:
154.1771 - * <blockquote><pre>
154.1772 - * this.startsWith(str, <i>k</i>)
154.1773 - * </pre></blockquote>
154.1774 - * If no such value of <i>k</i> exists, then {@code -1} is returned.
154.1775 - *
154.1776 - * @param str the substring to search for.
154.1777 - * @return the index of the last occurrence of the specified substring,
154.1778 - * or {@code -1} if there is no such occurrence.
154.1779 - */
154.1780 - public int lastIndexOf(String str) {
154.1781 - return lastIndexOf(str, length());
154.1782 - }
154.1783 -
154.1784 - /**
154.1785 - * Returns the index within this string of the last occurrence of the
154.1786 - * specified substring, searching backward starting at the specified index.
154.1787 - *
154.1788 - * <p>The returned index is the largest value <i>k</i> for which:
154.1789 - * <blockquote><pre>
154.1790 - * <i>k</i> <= fromIndex && this.startsWith(str, <i>k</i>)
154.1791 - * </pre></blockquote>
154.1792 - * If no such value of <i>k</i> exists, then {@code -1} is returned.
154.1793 - *
154.1794 - * @param str the substring to search for.
154.1795 - * @param fromIndex the index to start the search from.
154.1796 - * @return the index of the last occurrence of the specified substring,
154.1797 - * searching backward from the specified index,
154.1798 - * or {@code -1} if there is no such occurrence.
154.1799 - */
154.1800 - @JavaScriptBody(args = { "s", "from" }, body =
154.1801 - "return this.toString().lastIndexOf(s.toString(), from);"
154.1802 - )
154.1803 - public int lastIndexOf(String str, int fromIndex) {
154.1804 - return lastIndexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
154.1805 - }
154.1806 -
154.1807 - /**
154.1808 - * Code shared by String and StringBuffer to do searches. The
154.1809 - * source is the character array being searched, and the target
154.1810 - * is the string being searched for.
154.1811 - *
154.1812 - * @param source the characters being searched.
154.1813 - * @param sourceOffset offset of the source string.
154.1814 - * @param sourceCount count of the source string.
154.1815 - * @param target the characters being searched for.
154.1816 - * @param targetOffset offset of the target string.
154.1817 - * @param targetCount count of the target string.
154.1818 - * @param fromIndex the index to begin searching from.
154.1819 - */
154.1820 - static int lastIndexOf(char[] source, int sourceOffset, int sourceCount,
154.1821 - char[] target, int targetOffset, int targetCount,
154.1822 - int fromIndex) {
154.1823 - /*
154.1824 - * Check arguments; return immediately where possible. For
154.1825 - * consistency, don't check for null str.
154.1826 - */
154.1827 - int rightIndex = sourceCount - targetCount;
154.1828 - if (fromIndex < 0) {
154.1829 - return -1;
154.1830 - }
154.1831 - if (fromIndex > rightIndex) {
154.1832 - fromIndex = rightIndex;
154.1833 - }
154.1834 - /* Empty string always matches. */
154.1835 - if (targetCount == 0) {
154.1836 - return fromIndex;
154.1837 - }
154.1838 -
154.1839 - int strLastIndex = targetOffset + targetCount - 1;
154.1840 - char strLastChar = target[strLastIndex];
154.1841 - int min = sourceOffset + targetCount - 1;
154.1842 - int i = min + fromIndex;
154.1843 -
154.1844 - startSearchForLastChar:
154.1845 - while (true) {
154.1846 - while (i >= min && source[i] != strLastChar) {
154.1847 - i--;
154.1848 - }
154.1849 - if (i < min) {
154.1850 - return -1;
154.1851 - }
154.1852 - int j = i - 1;
154.1853 - int start = j - (targetCount - 1);
154.1854 - int k = strLastIndex - 1;
154.1855 -
154.1856 - while (j > start) {
154.1857 - if (source[j--] != target[k--]) {
154.1858 - i--;
154.1859 - continue startSearchForLastChar;
154.1860 - }
154.1861 - }
154.1862 - return start - sourceOffset + 1;
154.1863 - }
154.1864 - }
154.1865 -
154.1866 - /**
154.1867 - * Returns a new string that is a substring of this string. The
154.1868 - * substring begins with the character at the specified index and
154.1869 - * extends to the end of this string. <p>
154.1870 - * Examples:
154.1871 - * <blockquote><pre>
154.1872 - * "unhappy".substring(2) returns "happy"
154.1873 - * "Harbison".substring(3) returns "bison"
154.1874 - * "emptiness".substring(9) returns "" (an empty string)
154.1875 - * </pre></blockquote>
154.1876 - *
154.1877 - * @param beginIndex the beginning index, inclusive.
154.1878 - * @return the specified substring.
154.1879 - * @exception IndexOutOfBoundsException if
154.1880 - * <code>beginIndex</code> is negative or larger than the
154.1881 - * length of this <code>String</code> object.
154.1882 - */
154.1883 - public String substring(int beginIndex) {
154.1884 - return substring(beginIndex, length());
154.1885 - }
154.1886 -
154.1887 - /**
154.1888 - * Returns a new string that is a substring of this string. The
154.1889 - * substring begins at the specified <code>beginIndex</code> and
154.1890 - * extends to the character at index <code>endIndex - 1</code>.
154.1891 - * Thus the length of the substring is <code>endIndex-beginIndex</code>.
154.1892 - * <p>
154.1893 - * Examples:
154.1894 - * <blockquote><pre>
154.1895 - * "hamburger".substring(4, 8) returns "urge"
154.1896 - * "smiles".substring(1, 5) returns "mile"
154.1897 - * </pre></blockquote>
154.1898 - *
154.1899 - * @param beginIndex the beginning index, inclusive.
154.1900 - * @param endIndex the ending index, exclusive.
154.1901 - * @return the specified substring.
154.1902 - * @exception IndexOutOfBoundsException if the
154.1903 - * <code>beginIndex</code> is negative, or
154.1904 - * <code>endIndex</code> is larger than the length of
154.1905 - * this <code>String</code> object, or
154.1906 - * <code>beginIndex</code> is larger than
154.1907 - * <code>endIndex</code>.
154.1908 - */
154.1909 - @JavaScriptBody(args = { "beginIndex", "endIndex" }, body =
154.1910 - "return this.toString().substring(beginIndex, endIndex);"
154.1911 - )
154.1912 - public String substring(int beginIndex, int endIndex) {
154.1913 - if (beginIndex < 0) {
154.1914 - throw new StringIndexOutOfBoundsException(beginIndex);
154.1915 - }
154.1916 - if (endIndex > length()) {
154.1917 - throw new StringIndexOutOfBoundsException(endIndex);
154.1918 - }
154.1919 - if (beginIndex > endIndex) {
154.1920 - throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
154.1921 - }
154.1922 - return ((beginIndex == 0) && (endIndex == length())) ? this :
154.1923 - new String(toCharArray(), offset() + beginIndex, endIndex - beginIndex);
154.1924 - }
154.1925 -
154.1926 - /**
154.1927 - * Returns a new character sequence that is a subsequence of this sequence.
154.1928 - *
154.1929 - * <p> An invocation of this method of the form
154.1930 - *
154.1931 - * <blockquote><pre>
154.1932 - * str.subSequence(begin, end)</pre></blockquote>
154.1933 - *
154.1934 - * behaves in exactly the same way as the invocation
154.1935 - *
154.1936 - * <blockquote><pre>
154.1937 - * str.substring(begin, end)</pre></blockquote>
154.1938 - *
154.1939 - * This method is defined so that the <tt>String</tt> class can implement
154.1940 - * the {@link CharSequence} interface. </p>
154.1941 - *
154.1942 - * @param beginIndex the begin index, inclusive.
154.1943 - * @param endIndex the end index, exclusive.
154.1944 - * @return the specified subsequence.
154.1945 - *
154.1946 - * @throws IndexOutOfBoundsException
154.1947 - * if <tt>beginIndex</tt> or <tt>endIndex</tt> are negative,
154.1948 - * if <tt>endIndex</tt> is greater than <tt>length()</tt>,
154.1949 - * or if <tt>beginIndex</tt> is greater than <tt>startIndex</tt>
154.1950 - *
154.1951 - * @since 1.4
154.1952 - * @spec JSR-51
154.1953 - */
154.1954 - public CharSequence subSequence(int beginIndex, int endIndex) {
154.1955 - return this.substring(beginIndex, endIndex);
154.1956 - }
154.1957 -
154.1958 - /**
154.1959 - * Concatenates the specified string to the end of this string.
154.1960 - * <p>
154.1961 - * If the length of the argument string is <code>0</code>, then this
154.1962 - * <code>String</code> object is returned. Otherwise, a new
154.1963 - * <code>String</code> object is created, representing a character
154.1964 - * sequence that is the concatenation of the character sequence
154.1965 - * represented by this <code>String</code> object and the character
154.1966 - * sequence represented by the argument string.<p>
154.1967 - * Examples:
154.1968 - * <blockquote><pre>
154.1969 - * "cares".concat("s") returns "caress"
154.1970 - * "to".concat("get").concat("her") returns "together"
154.1971 - * </pre></blockquote>
154.1972 - *
154.1973 - * @param str the <code>String</code> that is concatenated to the end
154.1974 - * of this <code>String</code>.
154.1975 - * @return a string that represents the concatenation of this object's
154.1976 - * characters followed by the string argument's characters.
154.1977 - */
154.1978 - public String concat(String str) {
154.1979 - int otherLen = str.length();
154.1980 - if (otherLen == 0) {
154.1981 - return this;
154.1982 - }
154.1983 - char buf[] = new char[length() + otherLen];
154.1984 - getChars(0, length(), buf, 0);
154.1985 - str.getChars(0, otherLen, buf, length());
154.1986 - return new String(buf, 0, length() + otherLen);
154.1987 - }
154.1988 -
154.1989 - /**
154.1990 - * Returns a new string resulting from replacing all occurrences of
154.1991 - * <code>oldChar</code> in this string with <code>newChar</code>.
154.1992 - * <p>
154.1993 - * If the character <code>oldChar</code> does not occur in the
154.1994 - * character sequence represented by this <code>String</code> object,
154.1995 - * then a reference to this <code>String</code> object is returned.
154.1996 - * Otherwise, a new <code>String</code> object is created that
154.1997 - * represents a character sequence identical to the character sequence
154.1998 - * represented by this <code>String</code> object, except that every
154.1999 - * occurrence of <code>oldChar</code> is replaced by an occurrence
154.2000 - * of <code>newChar</code>.
154.2001 - * <p>
154.2002 - * Examples:
154.2003 - * <blockquote><pre>
154.2004 - * "mesquite in your cellar".replace('e', 'o')
154.2005 - * returns "mosquito in your collar"
154.2006 - * "the war of baronets".replace('r', 'y')
154.2007 - * returns "the way of bayonets"
154.2008 - * "sparring with a purple porpoise".replace('p', 't')
154.2009 - * returns "starring with a turtle tortoise"
154.2010 - * "JonL".replace('q', 'x') returns "JonL" (no change)
154.2011 - * </pre></blockquote>
154.2012 - *
154.2013 - * @param oldChar the old character.
154.2014 - * @param newChar the new character.
154.2015 - * @return a string derived from this string by replacing every
154.2016 - * occurrence of <code>oldChar</code> with <code>newChar</code>.
154.2017 - */
154.2018 - @JavaScriptBody(args = { "arg1", "arg2" }, body =
154.2019 - "if (typeof arg1 === 'number') arg1 = String.fromCharCode(arg1);\n" +
154.2020 - "if (typeof arg2 === 'number') arg2 = String.fromCharCode(arg2);\n" +
154.2021 - "var s = this.toString();\n" +
154.2022 - "for (;;) {\n" +
154.2023 - " var ret = s.replace(arg1, arg2);\n" +
154.2024 - " if (ret === s) {\n" +
154.2025 - " return ret;\n" +
154.2026 - " }\n" +
154.2027 - " s = ret;\n" +
154.2028 - "}"
154.2029 - )
154.2030 - public String replace(char oldChar, char newChar) {
154.2031 - if (oldChar != newChar) {
154.2032 - int len = length();
154.2033 - int i = -1;
154.2034 - char[] val = toCharArray(); /* avoid getfield opcode */
154.2035 - int off = offset(); /* avoid getfield opcode */
154.2036 -
154.2037 - while (++i < len) {
154.2038 - if (val[off + i] == oldChar) {
154.2039 - break;
154.2040 - }
154.2041 - }
154.2042 - if (i < len) {
154.2043 - char buf[] = new char[len];
154.2044 - for (int j = 0 ; j < i ; j++) {
154.2045 - buf[j] = val[off+j];
154.2046 - }
154.2047 - while (i < len) {
154.2048 - char c = val[off + i];
154.2049 - buf[i] = (c == oldChar) ? newChar : c;
154.2050 - i++;
154.2051 - }
154.2052 - return new String(buf, 0, len);
154.2053 - }
154.2054 - }
154.2055 - return this;
154.2056 - }
154.2057 -
154.2058 - /**
154.2059 - * Tells whether or not this string matches the given <a
154.2060 - * href="../util/regex/Pattern.html#sum">regular expression</a>.
154.2061 - *
154.2062 - * <p> An invocation of this method of the form
154.2063 - * <i>str</i><tt>.matches(</tt><i>regex</i><tt>)</tt> yields exactly the
154.2064 - * same result as the expression
154.2065 - *
154.2066 - * <blockquote><tt> {@link java.util.regex.Pattern}.{@link
154.2067 - * java.util.regex.Pattern#matches(String,CharSequence)
154.2068 - * matches}(</tt><i>regex</i><tt>,</tt> <i>str</i><tt>)</tt></blockquote>
154.2069 - *
154.2070 - * @param regex
154.2071 - * the regular expression to which this string is to be matched
154.2072 - *
154.2073 - * @return <tt>true</tt> if, and only if, this string matches the
154.2074 - * given regular expression
154.2075 - *
154.2076 - * @throws PatternSyntaxException
154.2077 - * if the regular expression's syntax is invalid
154.2078 - *
154.2079 - * @see java.util.regex.Pattern
154.2080 - *
154.2081 - * @since 1.4
154.2082 - * @spec JSR-51
154.2083 - */
154.2084 - @JavaScriptBody(args = { "regex" }, body =
154.2085 - "var self = this.toString();\n"
154.2086 - + "var re = new RegExp(regex.toString());\n"
154.2087 - + "var r = re.exec(self);\n"
154.2088 - + "return r != null && r.length > 0 && self.length == r[0].length;"
154.2089 - )
154.2090 - public boolean matches(String regex) {
154.2091 - throw new UnsupportedOperationException();
154.2092 - }
154.2093 -
154.2094 - /**
154.2095 - * Returns true if and only if this string contains the specified
154.2096 - * sequence of char values.
154.2097 - *
154.2098 - * @param s the sequence to search for
154.2099 - * @return true if this string contains <code>s</code>, false otherwise
154.2100 - * @throws NullPointerException if <code>s</code> is <code>null</code>
154.2101 - * @since 1.5
154.2102 - */
154.2103 - public boolean contains(CharSequence s) {
154.2104 - return indexOf(s.toString()) > -1;
154.2105 - }
154.2106 -
154.2107 - /**
154.2108 - * Replaces the first substring of this string that matches the given <a
154.2109 - * href="../util/regex/Pattern.html#sum">regular expression</a> with the
154.2110 - * given replacement.
154.2111 - *
154.2112 - * <p> An invocation of this method of the form
154.2113 - * <i>str</i><tt>.replaceFirst(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
154.2114 - * yields exactly the same result as the expression
154.2115 - *
154.2116 - * <blockquote><tt>
154.2117 - * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
154.2118 - * compile}(</tt><i>regex</i><tt>).{@link
154.2119 - * java.util.regex.Pattern#matcher(java.lang.CharSequence)
154.2120 - * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceFirst
154.2121 - * replaceFirst}(</tt><i>repl</i><tt>)</tt></blockquote>
154.2122 - *
154.2123 - *<p>
154.2124 - * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
154.2125 - * replacement string may cause the results to be different than if it were
154.2126 - * being treated as a literal replacement string; see
154.2127 - * {@link java.util.regex.Matcher#replaceFirst}.
154.2128 - * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
154.2129 - * meaning of these characters, if desired.
154.2130 - *
154.2131 - * @param regex
154.2132 - * the regular expression to which this string is to be matched
154.2133 - * @param replacement
154.2134 - * the string to be substituted for the first match
154.2135 - *
154.2136 - * @return The resulting <tt>String</tt>
154.2137 - *
154.2138 - * @throws PatternSyntaxException
154.2139 - * if the regular expression's syntax is invalid
154.2140 - *
154.2141 - * @see java.util.regex.Pattern
154.2142 - *
154.2143 - * @since 1.4
154.2144 - * @spec JSR-51
154.2145 - */
154.2146 - public String replaceFirst(String regex, String replacement) {
154.2147 - throw new UnsupportedOperationException();
154.2148 - }
154.2149 -
154.2150 - /**
154.2151 - * Replaces each substring of this string that matches the given <a
154.2152 - * href="../util/regex/Pattern.html#sum">regular expression</a> with the
154.2153 - * given replacement.
154.2154 - *
154.2155 - * <p> An invocation of this method of the form
154.2156 - * <i>str</i><tt>.replaceAll(</tt><i>regex</i><tt>,</tt> <i>repl</i><tt>)</tt>
154.2157 - * yields exactly the same result as the expression
154.2158 - *
154.2159 - * <blockquote><tt>
154.2160 - * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
154.2161 - * compile}(</tt><i>regex</i><tt>).{@link
154.2162 - * java.util.regex.Pattern#matcher(java.lang.CharSequence)
154.2163 - * matcher}(</tt><i>str</i><tt>).{@link java.util.regex.Matcher#replaceAll
154.2164 - * replaceAll}(</tt><i>repl</i><tt>)</tt></blockquote>
154.2165 - *
154.2166 - *<p>
154.2167 - * Note that backslashes (<tt>\</tt>) and dollar signs (<tt>$</tt>) in the
154.2168 - * replacement string may cause the results to be different than if it were
154.2169 - * being treated as a literal replacement string; see
154.2170 - * {@link java.util.regex.Matcher#replaceAll Matcher.replaceAll}.
154.2171 - * Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
154.2172 - * meaning of these characters, if desired.
154.2173 - *
154.2174 - * @param regex
154.2175 - * the regular expression to which this string is to be matched
154.2176 - * @param replacement
154.2177 - * the string to be substituted for each match
154.2178 - *
154.2179 - * @return The resulting <tt>String</tt>
154.2180 - *
154.2181 - * @throws PatternSyntaxException
154.2182 - * if the regular expression's syntax is invalid
154.2183 - *
154.2184 - * @see java.util.regex.Pattern
154.2185 - *
154.2186 - * @since 1.4
154.2187 - * @spec JSR-51
154.2188 - */
154.2189 - public String replaceAll(String regex, String replacement) {
154.2190 - throw new UnsupportedOperationException();
154.2191 - }
154.2192 -
154.2193 - /**
154.2194 - * Replaces each substring of this string that matches the literal target
154.2195 - * sequence with the specified literal replacement sequence. The
154.2196 - * replacement proceeds from the beginning of the string to the end, for
154.2197 - * example, replacing "aa" with "b" in the string "aaa" will result in
154.2198 - * "ba" rather than "ab".
154.2199 - *
154.2200 - * @param target The sequence of char values to be replaced
154.2201 - * @param replacement The replacement sequence of char values
154.2202 - * @return The resulting string
154.2203 - * @throws NullPointerException if <code>target</code> or
154.2204 - * <code>replacement</code> is <code>null</code>.
154.2205 - * @since 1.5
154.2206 - */
154.2207 - public String replace(CharSequence target, CharSequence replacement) {
154.2208 - throw new UnsupportedOperationException("This one should be supported, but without dep on rest of regexp");
154.2209 - }
154.2210 -
154.2211 - /**
154.2212 - * Splits this string around matches of the given
154.2213 - * <a href="../util/regex/Pattern.html#sum">regular expression</a>.
154.2214 - *
154.2215 - * <p> The array returned by this method contains each substring of this
154.2216 - * string that is terminated by another substring that matches the given
154.2217 - * expression or is terminated by the end of the string. The substrings in
154.2218 - * the array are in the order in which they occur in this string. If the
154.2219 - * expression does not match any part of the input then the resulting array
154.2220 - * has just one element, namely this string.
154.2221 - *
154.2222 - * <p> The <tt>limit</tt> parameter controls the number of times the
154.2223 - * pattern is applied and therefore affects the length of the resulting
154.2224 - * array. If the limit <i>n</i> is greater than zero then the pattern
154.2225 - * will be applied at most <i>n</i> - 1 times, the array's
154.2226 - * length will be no greater than <i>n</i>, and the array's last entry
154.2227 - * will contain all input beyond the last matched delimiter. If <i>n</i>
154.2228 - * is non-positive then the pattern will be applied as many times as
154.2229 - * possible and the array can have any length. If <i>n</i> is zero then
154.2230 - * the pattern will be applied as many times as possible, the array can
154.2231 - * have any length, and trailing empty strings will be discarded.
154.2232 - *
154.2233 - * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the
154.2234 - * following results with these parameters:
154.2235 - *
154.2236 - * <blockquote><table cellpadding=1 cellspacing=0 summary="Split example showing regex, limit, and result">
154.2237 - * <tr>
154.2238 - * <th>Regex</th>
154.2239 - * <th>Limit</th>
154.2240 - * <th>Result</th>
154.2241 - * </tr>
154.2242 - * <tr><td align=center>:</td>
154.2243 - * <td align=center>2</td>
154.2244 - * <td><tt>{ "boo", "and:foo" }</tt></td></tr>
154.2245 - * <tr><td align=center>:</td>
154.2246 - * <td align=center>5</td>
154.2247 - * <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
154.2248 - * <tr><td align=center>:</td>
154.2249 - * <td align=center>-2</td>
154.2250 - * <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
154.2251 - * <tr><td align=center>o</td>
154.2252 - * <td align=center>5</td>
154.2253 - * <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
154.2254 - * <tr><td align=center>o</td>
154.2255 - * <td align=center>-2</td>
154.2256 - * <td><tt>{ "b", "", ":and:f", "", "" }</tt></td></tr>
154.2257 - * <tr><td align=center>o</td>
154.2258 - * <td align=center>0</td>
154.2259 - * <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
154.2260 - * </table></blockquote>
154.2261 - *
154.2262 - * <p> An invocation of this method of the form
154.2263 - * <i>str.</i><tt>split(</tt><i>regex</i><tt>,</tt> <i>n</i><tt>)</tt>
154.2264 - * yields the same result as the expression
154.2265 - *
154.2266 - * <blockquote>
154.2267 - * {@link java.util.regex.Pattern}.{@link java.util.regex.Pattern#compile
154.2268 - * compile}<tt>(</tt><i>regex</i><tt>)</tt>.{@link
154.2269 - * java.util.regex.Pattern#split(java.lang.CharSequence,int)
154.2270 - * split}<tt>(</tt><i>str</i><tt>,</tt> <i>n</i><tt>)</tt>
154.2271 - * </blockquote>
154.2272 - *
154.2273 - *
154.2274 - * @param regex
154.2275 - * the delimiting regular expression
154.2276 - *
154.2277 - * @param limit
154.2278 - * the result threshold, as described above
154.2279 - *
154.2280 - * @return the array of strings computed by splitting this string
154.2281 - * around matches of the given regular expression
154.2282 - *
154.2283 - * @throws PatternSyntaxException
154.2284 - * if the regular expression's syntax is invalid
154.2285 - *
154.2286 - * @see java.util.regex.Pattern
154.2287 - *
154.2288 - * @since 1.4
154.2289 - * @spec JSR-51
154.2290 - */
154.2291 - public String[] split(String regex, int limit) {
154.2292 - throw new UnsupportedOperationException("Needs regexp");
154.2293 - }
154.2294 -
154.2295 - /**
154.2296 - * Splits this string around matches of the given <a
154.2297 - * href="../util/regex/Pattern.html#sum">regular expression</a>.
154.2298 - *
154.2299 - * <p> This method works as if by invoking the two-argument {@link
154.2300 - * #split(String, int) split} method with the given expression and a limit
154.2301 - * argument of zero. Trailing empty strings are therefore not included in
154.2302 - * the resulting array.
154.2303 - *
154.2304 - * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the following
154.2305 - * results with these expressions:
154.2306 - *
154.2307 - * <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
154.2308 - * <tr>
154.2309 - * <th>Regex</th>
154.2310 - * <th>Result</th>
154.2311 - * </tr>
154.2312 - * <tr><td align=center>:</td>
154.2313 - * <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
154.2314 - * <tr><td align=center>o</td>
154.2315 - * <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
154.2316 - * </table></blockquote>
154.2317 - *
154.2318 - *
154.2319 - * @param regex
154.2320 - * the delimiting regular expression
154.2321 - *
154.2322 - * @return the array of strings computed by splitting this string
154.2323 - * around matches of the given regular expression
154.2324 - *
154.2325 - * @throws PatternSyntaxException
154.2326 - * if the regular expression's syntax is invalid
154.2327 - *
154.2328 - * @see java.util.regex.Pattern
154.2329 - *
154.2330 - * @since 1.4
154.2331 - * @spec JSR-51
154.2332 - */
154.2333 - public String[] split(String regex) {
154.2334 - return split(regex, 0);
154.2335 - }
154.2336 -
154.2337 - /**
154.2338 - * Converts all of the characters in this <code>String</code> to lower
154.2339 - * case using the rules of the given <code>Locale</code>. Case mapping is based
154.2340 - * on the Unicode Standard version specified by the {@link java.lang.Character Character}
154.2341 - * class. Since case mappings are not always 1:1 char mappings, the resulting
154.2342 - * <code>String</code> may be a different length than the original <code>String</code>.
154.2343 - * <p>
154.2344 - * Examples of lowercase mappings are in the following table:
154.2345 - * <table border="1" summary="Lowercase mapping examples showing language code of locale, upper case, lower case, and description">
154.2346 - * <tr>
154.2347 - * <th>Language Code of Locale</th>
154.2348 - * <th>Upper Case</th>
154.2349 - * <th>Lower Case</th>
154.2350 - * <th>Description</th>
154.2351 - * </tr>
154.2352 - * <tr>
154.2353 - * <td>tr (Turkish)</td>
154.2354 - * <td>\u0130</td>
154.2355 - * <td>\u0069</td>
154.2356 - * <td>capital letter I with dot above -> small letter i</td>
154.2357 - * </tr>
154.2358 - * <tr>
154.2359 - * <td>tr (Turkish)</td>
154.2360 - * <td>\u0049</td>
154.2361 - * <td>\u0131</td>
154.2362 - * <td>capital letter I -> small letter dotless i </td>
154.2363 - * </tr>
154.2364 - * <tr>
154.2365 - * <td>(all)</td>
154.2366 - * <td>French Fries</td>
154.2367 - * <td>french fries</td>
154.2368 - * <td>lowercased all chars in String</td>
154.2369 - * </tr>
154.2370 - * <tr>
154.2371 - * <td>(all)</td>
154.2372 - * <td><img src="doc-files/capiota.gif" alt="capiota"><img src="doc-files/capchi.gif" alt="capchi">
154.2373 - * <img src="doc-files/captheta.gif" alt="captheta"><img src="doc-files/capupsil.gif" alt="capupsil">
154.2374 - * <img src="doc-files/capsigma.gif" alt="capsigma"></td>
154.2375 - * <td><img src="doc-files/iota.gif" alt="iota"><img src="doc-files/chi.gif" alt="chi">
154.2376 - * <img src="doc-files/theta.gif" alt="theta"><img src="doc-files/upsilon.gif" alt="upsilon">
154.2377 - * <img src="doc-files/sigma1.gif" alt="sigma"></td>
154.2378 - * <td>lowercased all chars in String</td>
154.2379 - * </tr>
154.2380 - * </table>
154.2381 - *
154.2382 - * @param locale use the case transformation rules for this locale
154.2383 - * @return the <code>String</code>, converted to lowercase.
154.2384 - * @see java.lang.String#toLowerCase()
154.2385 - * @see java.lang.String#toUpperCase()
154.2386 - * @see java.lang.String#toUpperCase(Locale)
154.2387 - * @since 1.1
154.2388 - */
154.2389 -// public String toLowerCase(Locale locale) {
154.2390 -// if (locale == null) {
154.2391 -// throw new NullPointerException();
154.2392 -// }
154.2393 -//
154.2394 -// int firstUpper;
154.2395 -//
154.2396 -// /* Now check if there are any characters that need to be changed. */
154.2397 -// scan: {
154.2398 -// for (firstUpper = 0 ; firstUpper < count; ) {
154.2399 -// char c = value[offset+firstUpper];
154.2400 -// if ((c >= Character.MIN_HIGH_SURROGATE) &&
154.2401 -// (c <= Character.MAX_HIGH_SURROGATE)) {
154.2402 -// int supplChar = codePointAt(firstUpper);
154.2403 -// if (supplChar != Character.toLowerCase(supplChar)) {
154.2404 -// break scan;
154.2405 -// }
154.2406 -// firstUpper += Character.charCount(supplChar);
154.2407 -// } else {
154.2408 -// if (c != Character.toLowerCase(c)) {
154.2409 -// break scan;
154.2410 -// }
154.2411 -// firstUpper++;
154.2412 -// }
154.2413 -// }
154.2414 -// return this;
154.2415 -// }
154.2416 -//
154.2417 -// char[] result = new char[count];
154.2418 -// int resultOffset = 0; /* result may grow, so i+resultOffset
154.2419 -// * is the write location in result */
154.2420 -//
154.2421 -// /* Just copy the first few lowerCase characters. */
154.2422 -// arraycopy(value, offset, result, 0, firstUpper);
154.2423 -//
154.2424 -// String lang = locale.getLanguage();
154.2425 -// boolean localeDependent =
154.2426 -// (lang == "tr" || lang == "az" || lang == "lt");
154.2427 -// char[] lowerCharArray;
154.2428 -// int lowerChar;
154.2429 -// int srcChar;
154.2430 -// int srcCount;
154.2431 -// for (int i = firstUpper; i < count; i += srcCount) {
154.2432 -// srcChar = (int)value[offset+i];
154.2433 -// if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
154.2434 -// (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
154.2435 -// srcChar = codePointAt(i);
154.2436 -// srcCount = Character.charCount(srcChar);
154.2437 -// } else {
154.2438 -// srcCount = 1;
154.2439 -// }
154.2440 -// if (localeDependent || srcChar == '\u03A3') { // GREEK CAPITAL LETTER SIGMA
154.2441 -// lowerChar = ConditionalSpecialCasing.toLowerCaseEx(this, i, locale);
154.2442 -// } else if (srcChar == '\u0130') { // LATIN CAPITAL LETTER I DOT
154.2443 -// lowerChar = Character.ERROR;
154.2444 -// } else {
154.2445 -// lowerChar = Character.toLowerCase(srcChar);
154.2446 -// }
154.2447 -// if ((lowerChar == Character.ERROR) ||
154.2448 -// (lowerChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
154.2449 -// if (lowerChar == Character.ERROR) {
154.2450 -// if (!localeDependent && srcChar == '\u0130') {
154.2451 -// lowerCharArray =
154.2452 -// ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH);
154.2453 -// } else {
154.2454 -// lowerCharArray =
154.2455 -// ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale);
154.2456 -// }
154.2457 -// } else if (srcCount == 2) {
154.2458 -// resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount;
154.2459 -// continue;
154.2460 -// } else {
154.2461 -// lowerCharArray = Character.toChars(lowerChar);
154.2462 -// }
154.2463 -//
154.2464 -// /* Grow result if needed */
154.2465 -// int mapLen = lowerCharArray.length;
154.2466 -// if (mapLen > srcCount) {
154.2467 -// char[] result2 = new char[result.length + mapLen - srcCount];
154.2468 -// arraycopy(result, 0, result2, 0,
154.2469 -// i + resultOffset);
154.2470 -// result = result2;
154.2471 -// }
154.2472 -// for (int x=0; x<mapLen; ++x) {
154.2473 -// result[i+resultOffset+x] = lowerCharArray[x];
154.2474 -// }
154.2475 -// resultOffset += (mapLen - srcCount);
154.2476 -// } else {
154.2477 -// result[i+resultOffset] = (char)lowerChar;
154.2478 -// }
154.2479 -// }
154.2480 -// return new String(0, count+resultOffset, result);
154.2481 -// }
154.2482 -
154.2483 - /**
154.2484 - * Converts all of the characters in this <code>String</code> to lower
154.2485 - * case using the rules of the default locale. This is equivalent to calling
154.2486 - * <code>toLowerCase(Locale.getDefault())</code>.
154.2487 - * <p>
154.2488 - * <b>Note:</b> This method is locale sensitive, and may produce unexpected
154.2489 - * results if used for strings that are intended to be interpreted locale
154.2490 - * independently.
154.2491 - * Examples are programming language identifiers, protocol keys, and HTML
154.2492 - * tags.
154.2493 - * For instance, <code>"TITLE".toLowerCase()</code> in a Turkish locale
154.2494 - * returns <code>"t\u005Cu0131tle"</code>, where '\u005Cu0131' is the
154.2495 - * LATIN SMALL LETTER DOTLESS I character.
154.2496 - * To obtain correct results for locale insensitive strings, use
154.2497 - * <code>toLowerCase(Locale.ENGLISH)</code>.
154.2498 - * <p>
154.2499 - * @return the <code>String</code>, converted to lowercase.
154.2500 - * @see java.lang.String#toLowerCase(Locale)
154.2501 - */
154.2502 - @JavaScriptBody(args = {}, body = "return this.toLowerCase();")
154.2503 - public String toLowerCase() {
154.2504 - throw new UnsupportedOperationException("Should be supported but without connection to locale");
154.2505 - }
154.2506 -
154.2507 - /**
154.2508 - * Converts all of the characters in this <code>String</code> to upper
154.2509 - * case using the rules of the given <code>Locale</code>. Case mapping is based
154.2510 - * on the Unicode Standard version specified by the {@link java.lang.Character Character}
154.2511 - * class. Since case mappings are not always 1:1 char mappings, the resulting
154.2512 - * <code>String</code> may be a different length than the original <code>String</code>.
154.2513 - * <p>
154.2514 - * Examples of locale-sensitive and 1:M case mappings are in the following table.
154.2515 - * <p>
154.2516 - * <table border="1" summary="Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description.">
154.2517 - * <tr>
154.2518 - * <th>Language Code of Locale</th>
154.2519 - * <th>Lower Case</th>
154.2520 - * <th>Upper Case</th>
154.2521 - * <th>Description</th>
154.2522 - * </tr>
154.2523 - * <tr>
154.2524 - * <td>tr (Turkish)</td>
154.2525 - * <td>\u0069</td>
154.2526 - * <td>\u0130</td>
154.2527 - * <td>small letter i -> capital letter I with dot above</td>
154.2528 - * </tr>
154.2529 - * <tr>
154.2530 - * <td>tr (Turkish)</td>
154.2531 - * <td>\u0131</td>
154.2532 - * <td>\u0049</td>
154.2533 - * <td>small letter dotless i -> capital letter I</td>
154.2534 - * </tr>
154.2535 - * <tr>
154.2536 - * <td>(all)</td>
154.2537 - * <td>\u00df</td>
154.2538 - * <td>\u0053 \u0053</td>
154.2539 - * <td>small letter sharp s -> two letters: SS</td>
154.2540 - * </tr>
154.2541 - * <tr>
154.2542 - * <td>(all)</td>
154.2543 - * <td>Fahrvergnügen</td>
154.2544 - * <td>FAHRVERGNÜGEN</td>
154.2545 - * <td></td>
154.2546 - * </tr>
154.2547 - * </table>
154.2548 - * @param locale use the case transformation rules for this locale
154.2549 - * @return the <code>String</code>, converted to uppercase.
154.2550 - * @see java.lang.String#toUpperCase()
154.2551 - * @see java.lang.String#toLowerCase()
154.2552 - * @see java.lang.String#toLowerCase(Locale)
154.2553 - * @since 1.1
154.2554 - */
154.2555 - /* not for javascript
154.2556 - public String toUpperCase(Locale locale) {
154.2557 - if (locale == null) {
154.2558 - throw new NullPointerException();
154.2559 - }
154.2560 -
154.2561 - int firstLower;
154.2562 -
154.2563 - // Now check if there are any characters that need to be changed.
154.2564 - scan: {
154.2565 - for (firstLower = 0 ; firstLower < count; ) {
154.2566 - int c = (int)value[offset+firstLower];
154.2567 - int srcCount;
154.2568 - if ((c >= Character.MIN_HIGH_SURROGATE) &&
154.2569 - (c <= Character.MAX_HIGH_SURROGATE)) {
154.2570 - c = codePointAt(firstLower);
154.2571 - srcCount = Character.charCount(c);
154.2572 - } else {
154.2573 - srcCount = 1;
154.2574 - }
154.2575 - int upperCaseChar = Character.toUpperCaseEx(c);
154.2576 - if ((upperCaseChar == Character.ERROR) ||
154.2577 - (c != upperCaseChar)) {
154.2578 - break scan;
154.2579 - }
154.2580 - firstLower += srcCount;
154.2581 - }
154.2582 - return this;
154.2583 - }
154.2584 -
154.2585 - char[] result = new char[count]; /* may grow *
154.2586 - int resultOffset = 0; /* result may grow, so i+resultOffset
154.2587 - * is the write location in result *
154.2588 -
154.2589 - /* Just copy the first few upperCase characters. *
154.2590 - arraycopy(value, offset, result, 0, firstLower);
154.2591 -
154.2592 - String lang = locale.getLanguage();
154.2593 - boolean localeDependent =
154.2594 - (lang == "tr" || lang == "az" || lang == "lt");
154.2595 - char[] upperCharArray;
154.2596 - int upperChar;
154.2597 - int srcChar;
154.2598 - int srcCount;
154.2599 - for (int i = firstLower; i < count; i += srcCount) {
154.2600 - srcChar = (int)value[offset+i];
154.2601 - if ((char)srcChar >= Character.MIN_HIGH_SURROGATE &&
154.2602 - (char)srcChar <= Character.MAX_HIGH_SURROGATE) {
154.2603 - srcChar = codePointAt(i);
154.2604 - srcCount = Character.charCount(srcChar);
154.2605 - } else {
154.2606 - srcCount = 1;
154.2607 - }
154.2608 - if (localeDependent) {
154.2609 - upperChar = ConditionalSpecialCasing.toUpperCaseEx(this, i, locale);
154.2610 - } else {
154.2611 - upperChar = Character.toUpperCaseEx(srcChar);
154.2612 - }
154.2613 - if ((upperChar == Character.ERROR) ||
154.2614 - (upperChar >= Character.MIN_SUPPLEMENTARY_CODE_POINT)) {
154.2615 - if (upperChar == Character.ERROR) {
154.2616 - if (localeDependent) {
154.2617 - upperCharArray =
154.2618 - ConditionalSpecialCasing.toUpperCaseCharArray(this, i, locale);
154.2619 - } else {
154.2620 - upperCharArray = Character.toUpperCaseCharArray(srcChar);
154.2621 - }
154.2622 - } else if (srcCount == 2) {
154.2623 - resultOffset += Character.toChars(upperChar, result, i + resultOffset) - srcCount;
154.2624 - continue;
154.2625 - } else {
154.2626 - upperCharArray = Character.toChars(upperChar);
154.2627 - }
154.2628 -
154.2629 - /* Grow result if needed *
154.2630 - int mapLen = upperCharArray.length;
154.2631 - if (mapLen > srcCount) {
154.2632 - char[] result2 = new char[result.length + mapLen - srcCount];
154.2633 - arraycopy(result, 0, result2, 0,
154.2634 - i + resultOffset);
154.2635 - result = result2;
154.2636 - }
154.2637 - for (int x=0; x<mapLen; ++x) {
154.2638 - result[i+resultOffset+x] = upperCharArray[x];
154.2639 - }
154.2640 - resultOffset += (mapLen - srcCount);
154.2641 - } else {
154.2642 - result[i+resultOffset] = (char)upperChar;
154.2643 - }
154.2644 - }
154.2645 - return new String(0, count+resultOffset, result);
154.2646 - }
154.2647 - */
154.2648 -
154.2649 - /**
154.2650 - * Converts all of the characters in this <code>String</code> to upper
154.2651 - * case using the rules of the default locale. This method is equivalent to
154.2652 - * <code>toUpperCase(Locale.getDefault())</code>.
154.2653 - * <p>
154.2654 - * <b>Note:</b> This method is locale sensitive, and may produce unexpected
154.2655 - * results if used for strings that are intended to be interpreted locale
154.2656 - * independently.
154.2657 - * Examples are programming language identifiers, protocol keys, and HTML
154.2658 - * tags.
154.2659 - * For instance, <code>"title".toUpperCase()</code> in a Turkish locale
154.2660 - * returns <code>"T\u005Cu0130TLE"</code>, where '\u005Cu0130' is the
154.2661 - * LATIN CAPITAL LETTER I WITH DOT ABOVE character.
154.2662 - * To obtain correct results for locale insensitive strings, use
154.2663 - * <code>toUpperCase(Locale.ENGLISH)</code>.
154.2664 - * <p>
154.2665 - * @return the <code>String</code>, converted to uppercase.
154.2666 - * @see java.lang.String#toUpperCase(Locale)
154.2667 - */
154.2668 - @JavaScriptBody(args = {}, body = "return this.toUpperCase();")
154.2669 - public String toUpperCase() {
154.2670 - throw new UnsupportedOperationException();
154.2671 - }
154.2672 -
154.2673 - /**
154.2674 - * Returns a copy of the string, with leading and trailing whitespace
154.2675 - * omitted.
154.2676 - * <p>
154.2677 - * If this <code>String</code> object represents an empty character
154.2678 - * sequence, or the first and last characters of character sequence
154.2679 - * represented by this <code>String</code> object both have codes
154.2680 - * greater than <code>'\u0020'</code> (the space character), then a
154.2681 - * reference to this <code>String</code> object is returned.
154.2682 - * <p>
154.2683 - * Otherwise, if there is no character with a code greater than
154.2684 - * <code>'\u0020'</code> in the string, then a new
154.2685 - * <code>String</code> object representing an empty string is created
154.2686 - * and returned.
154.2687 - * <p>
154.2688 - * Otherwise, let <i>k</i> be the index of the first character in the
154.2689 - * string whose code is greater than <code>'\u0020'</code>, and let
154.2690 - * <i>m</i> be the index of the last character in the string whose code
154.2691 - * is greater than <code>'\u0020'</code>. A new <code>String</code>
154.2692 - * object is created, representing the substring of this string that
154.2693 - * begins with the character at index <i>k</i> and ends with the
154.2694 - * character at index <i>m</i>-that is, the result of
154.2695 - * <code>this.substring(<i>k</i>, <i>m</i>+1)</code>.
154.2696 - * <p>
154.2697 - * This method may be used to trim whitespace (as defined above) from
154.2698 - * the beginning and end of a string.
154.2699 - *
154.2700 - * @return A copy of this string with leading and trailing white
154.2701 - * space removed, or this string if it has no leading or
154.2702 - * trailing white space.
154.2703 - */
154.2704 - public String trim() {
154.2705 - int len = length();
154.2706 - int st = 0;
154.2707 - int off = offset(); /* avoid getfield opcode */
154.2708 - char[] val = toCharArray(); /* avoid getfield opcode */
154.2709 -
154.2710 - while ((st < len) && (val[off + st] <= ' ')) {
154.2711 - st++;
154.2712 - }
154.2713 - while ((st < len) && (val[off + len - 1] <= ' ')) {
154.2714 - len--;
154.2715 - }
154.2716 - return ((st > 0) || (len < length())) ? substring(st, len) : this;
154.2717 - }
154.2718 -
154.2719 - /**
154.2720 - * This object (which is already a string!) is itself returned.
154.2721 - *
154.2722 - * @return the string itself.
154.2723 - */
154.2724 - @JavaScriptBody(args = {}, body = "return this.toString();")
154.2725 - public String toString() {
154.2726 - return this;
154.2727 - }
154.2728 -
154.2729 - /**
154.2730 - * Converts this string to a new character array.
154.2731 - *
154.2732 - * @return a newly allocated character array whose length is the length
154.2733 - * of this string and whose contents are initialized to contain
154.2734 - * the character sequence represented by this string.
154.2735 - */
154.2736 - public char[] toCharArray() {
154.2737 - char result[] = new char[length()];
154.2738 - getChars(0, length(), result, 0);
154.2739 - return result;
154.2740 - }
154.2741 -
154.2742 - /**
154.2743 - * Returns a formatted string using the specified format string and
154.2744 - * arguments.
154.2745 - *
154.2746 - * <p> The locale always used is the one returned by {@link
154.2747 - * java.util.Locale#getDefault() Locale.getDefault()}.
154.2748 - *
154.2749 - * @param format
154.2750 - * A <a href="../util/Formatter.html#syntax">format string</a>
154.2751 - *
154.2752 - * @param args
154.2753 - * Arguments referenced by the format specifiers in the format
154.2754 - * string. If there are more arguments than format specifiers, the
154.2755 - * extra arguments are ignored. The number of arguments is
154.2756 - * variable and may be zero. The maximum number of arguments is
154.2757 - * limited by the maximum dimension of a Java array as defined by
154.2758 - * <cite>The Java™ Virtual Machine Specification</cite>.
154.2759 - * The behaviour on a
154.2760 - * <tt>null</tt> argument depends on the <a
154.2761 - * href="../util/Formatter.html#syntax">conversion</a>.
154.2762 - *
154.2763 - * @throws IllegalFormatException
154.2764 - * If a format string contains an illegal syntax, a format
154.2765 - * specifier that is incompatible with the given arguments,
154.2766 - * insufficient arguments given the format string, or other
154.2767 - * illegal conditions. For specification of all possible
154.2768 - * formatting errors, see the <a
154.2769 - * href="../util/Formatter.html#detail">Details</a> section of the
154.2770 - * formatter class specification.
154.2771 - *
154.2772 - * @throws NullPointerException
154.2773 - * If the <tt>format</tt> is <tt>null</tt>
154.2774 - *
154.2775 - * @return A formatted string
154.2776 - *
154.2777 - * @see java.util.Formatter
154.2778 - * @since 1.5
154.2779 - */
154.2780 - public static String format(String format, Object ... args) {
154.2781 - throw new UnsupportedOperationException();
154.2782 - }
154.2783 -
154.2784 - /**
154.2785 - * Returns a formatted string using the specified locale, format string,
154.2786 - * and arguments.
154.2787 - *
154.2788 - * @param l
154.2789 - * The {@linkplain java.util.Locale locale} to apply during
154.2790 - * formatting. If <tt>l</tt> is <tt>null</tt> then no localization
154.2791 - * is applied.
154.2792 - *
154.2793 - * @param format
154.2794 - * A <a href="../util/Formatter.html#syntax">format string</a>
154.2795 - *
154.2796 - * @param args
154.2797 - * Arguments referenced by the format specifiers in the format
154.2798 - * string. If there are more arguments than format specifiers, the
154.2799 - * extra arguments are ignored. The number of arguments is
154.2800 - * variable and may be zero. The maximum number of arguments is
154.2801 - * limited by the maximum dimension of a Java array as defined by
154.2802 - * <cite>The Java™ Virtual Machine Specification</cite>.
154.2803 - * The behaviour on a
154.2804 - * <tt>null</tt> argument depends on the <a
154.2805 - * href="../util/Formatter.html#syntax">conversion</a>.
154.2806 - *
154.2807 - * @throws IllegalFormatException
154.2808 - * If a format string contains an illegal syntax, a format
154.2809 - * specifier that is incompatible with the given arguments,
154.2810 - * insufficient arguments given the format string, or other
154.2811 - * illegal conditions. For specification of all possible
154.2812 - * formatting errors, see the <a
154.2813 - * href="../util/Formatter.html#detail">Details</a> section of the
154.2814 - * formatter class specification
154.2815 - *
154.2816 - * @throws NullPointerException
154.2817 - * If the <tt>format</tt> is <tt>null</tt>
154.2818 - *
154.2819 - * @return A formatted string
154.2820 - *
154.2821 - * @see java.util.Formatter
154.2822 - * @since 1.5
154.2823 - */
154.2824 -// public static String format(Locale l, String format, Object ... args) {
154.2825 -// return new Formatter(l).format(format, args).toString();
154.2826 -// }
154.2827 -
154.2828 - /**
154.2829 - * Returns the string representation of the <code>Object</code> argument.
154.2830 - *
154.2831 - * @param obj an <code>Object</code>.
154.2832 - * @return if the argument is <code>null</code>, then a string equal to
154.2833 - * <code>"null"</code>; otherwise, the value of
154.2834 - * <code>obj.toString()</code> is returned.
154.2835 - * @see java.lang.Object#toString()
154.2836 - */
154.2837 - public static String valueOf(Object obj) {
154.2838 - return (obj == null) ? "null" : obj.toString();
154.2839 - }
154.2840 -
154.2841 - /**
154.2842 - * Returns the string representation of the <code>char</code> array
154.2843 - * argument. The contents of the character array are copied; subsequent
154.2844 - * modification of the character array does not affect the newly
154.2845 - * created string.
154.2846 - *
154.2847 - * @param data a <code>char</code> array.
154.2848 - * @return a newly allocated string representing the same sequence of
154.2849 - * characters contained in the character array argument.
154.2850 - */
154.2851 - public static String valueOf(char data[]) {
154.2852 - return new String(data);
154.2853 - }
154.2854 -
154.2855 - /**
154.2856 - * Returns the string representation of a specific subarray of the
154.2857 - * <code>char</code> array argument.
154.2858 - * <p>
154.2859 - * The <code>offset</code> argument is the index of the first
154.2860 - * character of the subarray. The <code>count</code> argument
154.2861 - * specifies the length of the subarray. The contents of the subarray
154.2862 - * are copied; subsequent modification of the character array does not
154.2863 - * affect the newly created string.
154.2864 - *
154.2865 - * @param data the character array.
154.2866 - * @param offset the initial offset into the value of the
154.2867 - * <code>String</code>.
154.2868 - * @param count the length of the value of the <code>String</code>.
154.2869 - * @return a string representing the sequence of characters contained
154.2870 - * in the subarray of the character array argument.
154.2871 - * @exception IndexOutOfBoundsException if <code>offset</code> is
154.2872 - * negative, or <code>count</code> is negative, or
154.2873 - * <code>offset+count</code> is larger than
154.2874 - * <code>data.length</code>.
154.2875 - */
154.2876 - public static String valueOf(char data[], int offset, int count) {
154.2877 - return new String(data, offset, count);
154.2878 - }
154.2879 -
154.2880 - /**
154.2881 - * Returns a String that represents the character sequence in the
154.2882 - * array specified.
154.2883 - *
154.2884 - * @param data the character array.
154.2885 - * @param offset initial offset of the subarray.
154.2886 - * @param count length of the subarray.
154.2887 - * @return a <code>String</code> that contains the characters of the
154.2888 - * specified subarray of the character array.
154.2889 - */
154.2890 - public static String copyValueOf(char data[], int offset, int count) {
154.2891 - // All public String constructors now copy the data.
154.2892 - return new String(data, offset, count);
154.2893 - }
154.2894 -
154.2895 - /**
154.2896 - * Returns a String that represents the character sequence in the
154.2897 - * array specified.
154.2898 - *
154.2899 - * @param data the character array.
154.2900 - * @return a <code>String</code> that contains the characters of the
154.2901 - * character array.
154.2902 - */
154.2903 - public static String copyValueOf(char data[]) {
154.2904 - return copyValueOf(data, 0, data.length);
154.2905 - }
154.2906 -
154.2907 - /**
154.2908 - * Returns the string representation of the <code>boolean</code> argument.
154.2909 - *
154.2910 - * @param b a <code>boolean</code>.
154.2911 - * @return if the argument is <code>true</code>, a string equal to
154.2912 - * <code>"true"</code> is returned; otherwise, a string equal to
154.2913 - * <code>"false"</code> is returned.
154.2914 - */
154.2915 - public static String valueOf(boolean b) {
154.2916 - return b ? "true" : "false";
154.2917 - }
154.2918 -
154.2919 - /**
154.2920 - * Returns the string representation of the <code>char</code>
154.2921 - * argument.
154.2922 - *
154.2923 - * @param c a <code>char</code>.
154.2924 - * @return a string of length <code>1</code> containing
154.2925 - * as its single character the argument <code>c</code>.
154.2926 - */
154.2927 - public static String valueOf(char c) {
154.2928 - char data[] = {c};
154.2929 - return new String(data, 0, 1);
154.2930 - }
154.2931 -
154.2932 - /**
154.2933 - * Returns the string representation of the <code>int</code> argument.
154.2934 - * <p>
154.2935 - * The representation is exactly the one returned by the
154.2936 - * <code>Integer.toString</code> method of one argument.
154.2937 - *
154.2938 - * @param i an <code>int</code>.
154.2939 - * @return a string representation of the <code>int</code> argument.
154.2940 - * @see java.lang.Integer#toString(int, int)
154.2941 - */
154.2942 - public static String valueOf(int i) {
154.2943 - return Integer.toString(i);
154.2944 - }
154.2945 -
154.2946 - /**
154.2947 - * Returns the string representation of the <code>long</code> argument.
154.2948 - * <p>
154.2949 - * The representation is exactly the one returned by the
154.2950 - * <code>Long.toString</code> method of one argument.
154.2951 - *
154.2952 - * @param l a <code>long</code>.
154.2953 - * @return a string representation of the <code>long</code> argument.
154.2954 - * @see java.lang.Long#toString(long)
154.2955 - */
154.2956 - public static String valueOf(long l) {
154.2957 - return Long.toString(l);
154.2958 - }
154.2959 -
154.2960 - /**
154.2961 - * Returns the string representation of the <code>float</code> argument.
154.2962 - * <p>
154.2963 - * The representation is exactly the one returned by the
154.2964 - * <code>Float.toString</code> method of one argument.
154.2965 - *
154.2966 - * @param f a <code>float</code>.
154.2967 - * @return a string representation of the <code>float</code> argument.
154.2968 - * @see java.lang.Float#toString(float)
154.2969 - */
154.2970 - public static String valueOf(float f) {
154.2971 - return Float.toString(f);
154.2972 - }
154.2973 -
154.2974 - /**
154.2975 - * Returns the string representation of the <code>double</code> argument.
154.2976 - * <p>
154.2977 - * The representation is exactly the one returned by the
154.2978 - * <code>Double.toString</code> method of one argument.
154.2979 - *
154.2980 - * @param d a <code>double</code>.
154.2981 - * @return a string representation of the <code>double</code> argument.
154.2982 - * @see java.lang.Double#toString(double)
154.2983 - */
154.2984 - public static String valueOf(double d) {
154.2985 - return Double.toString(d);
154.2986 - }
154.2987 -
154.2988 - /**
154.2989 - * Returns a canonical representation for the string object.
154.2990 - * <p>
154.2991 - * A pool of strings, initially empty, is maintained privately by the
154.2992 - * class <code>String</code>.
154.2993 - * <p>
154.2994 - * When the intern method is invoked, if the pool already contains a
154.2995 - * string equal to this <code>String</code> object as determined by
154.2996 - * the {@link #equals(Object)} method, then the string from the pool is
154.2997 - * returned. Otherwise, this <code>String</code> object is added to the
154.2998 - * pool and a reference to this <code>String</code> object is returned.
154.2999 - * <p>
154.3000 - * It follows that for any two strings <code>s</code> and <code>t</code>,
154.3001 - * <code>s.intern() == t.intern()</code> is <code>true</code>
154.3002 - * if and only if <code>s.equals(t)</code> is <code>true</code>.
154.3003 - * <p>
154.3004 - * All literal strings and string-valued constant expressions are
154.3005 - * interned. String literals are defined in section 3.10.5 of the
154.3006 - * <cite>The Java™ Language Specification</cite>.
154.3007 - *
154.3008 - * @return a string that has the same contents as this string, but is
154.3009 - * guaranteed to be from a pool of unique strings.
154.3010 - */
154.3011 - public native String intern();
154.3012 -}
155.1 --- a/emul/src/main/java/java/lang/StringBuffer.java Wed Jan 23 20:16:48 2013 +0100
155.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
155.3 @@ -1,604 +0,0 @@
155.4 -/*
155.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
155.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
155.7 - *
155.8 - * This code is free software; you can redistribute it and/or modify it
155.9 - * under the terms of the GNU General Public License version 2 only, as
155.10 - * published by the Free Software Foundation. Oracle designates this
155.11 - * particular file as subject to the "Classpath" exception as provided
155.12 - * by Oracle in the LICENSE file that accompanied this code.
155.13 - *
155.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
155.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
155.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
155.17 - * version 2 for more details (a copy is included in the LICENSE file that
155.18 - * accompanied this code).
155.19 - *
155.20 - * You should have received a copy of the GNU General Public License version
155.21 - * 2 along with this work; if not, write to the Free Software Foundation,
155.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
155.23 - *
155.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
155.25 - * or visit www.oracle.com if you need additional information or have any
155.26 - * questions.
155.27 - */
155.28 -
155.29 -package java.lang;
155.30 -
155.31 -
155.32 -/**
155.33 - * A thread-safe, mutable sequence of characters.
155.34 - * A string buffer is like a {@link String}, but can be modified. At any
155.35 - * point in time it contains some particular sequence of characters, but
155.36 - * the length and content of the sequence can be changed through certain
155.37 - * method calls.
155.38 - * <p>
155.39 - * String buffers are safe for use by multiple threads. The methods
155.40 - * are synchronized where necessary so that all the operations on any
155.41 - * particular instance behave as if they occur in some serial order
155.42 - * that is consistent with the order of the method calls made by each of
155.43 - * the individual threads involved.
155.44 - * <p>
155.45 - * The principal operations on a <code>StringBuffer</code> are the
155.46 - * <code>append</code> and <code>insert</code> methods, which are
155.47 - * overloaded so as to accept data of any type. Each effectively
155.48 - * converts a given datum to a string and then appends or inserts the
155.49 - * characters of that string to the string buffer. The
155.50 - * <code>append</code> method always adds these characters at the end
155.51 - * of the buffer; the <code>insert</code> method adds the characters at
155.52 - * a specified point.
155.53 - * <p>
155.54 - * For example, if <code>z</code> refers to a string buffer object
155.55 - * whose current contents are "<code>start</code>", then
155.56 - * the method call <code>z.append("le")</code> would cause the string
155.57 - * buffer to contain "<code>startle</code>", whereas
155.58 - * <code>z.insert(4, "le")</code> would alter the string buffer to
155.59 - * contain "<code>starlet</code>".
155.60 - * <p>
155.61 - * In general, if sb refers to an instance of a <code>StringBuffer</code>,
155.62 - * then <code>sb.append(x)</code> has the same effect as
155.63 - * <code>sb.insert(sb.length(), x)</code>.
155.64 - * <p>
155.65 - * Whenever an operation occurs involving a source sequence (such as
155.66 - * appending or inserting from a source sequence) this class synchronizes
155.67 - * only on the string buffer performing the operation, not on the source.
155.68 - * <p>
155.69 - * Every string buffer has a capacity. As long as the length of the
155.70 - * character sequence contained in the string buffer does not exceed
155.71 - * the capacity, it is not necessary to allocate a new internal
155.72 - * buffer array. If the internal buffer overflows, it is
155.73 - * automatically made larger.
155.74 - *
155.75 - * As of release JDK 5, this class has been supplemented with an equivalent
155.76 - * class designed for use by a single thread, {@link StringBuilder}. The
155.77 - * <tt>StringBuilder</tt> class should generally be used in preference to
155.78 - * this one, as it supports all of the same operations but it is faster, as
155.79 - * it performs no synchronization.
155.80 - *
155.81 - * @author Arthur van Hoff
155.82 - * @see java.lang.StringBuilder
155.83 - * @see java.lang.String
155.84 - * @since JDK1.0
155.85 - */
155.86 - public final class StringBuffer
155.87 - extends AbstractStringBuilder
155.88 - implements java.io.Serializable, CharSequence
155.89 -{
155.90 -
155.91 - /** use serialVersionUID from JDK 1.0.2 for interoperability */
155.92 - static final long serialVersionUID = 3388685877147921107L;
155.93 -
155.94 - /**
155.95 - * Constructs a string buffer with no characters in it and an
155.96 - * initial capacity of 16 characters.
155.97 - */
155.98 - public StringBuffer() {
155.99 - super(16);
155.100 - }
155.101 -
155.102 - /**
155.103 - * Constructs a string buffer with no characters in it and
155.104 - * the specified initial capacity.
155.105 - *
155.106 - * @param capacity the initial capacity.
155.107 - * @exception NegativeArraySizeException if the <code>capacity</code>
155.108 - * argument is less than <code>0</code>.
155.109 - */
155.110 - public StringBuffer(int capacity) {
155.111 - super(capacity);
155.112 - }
155.113 -
155.114 - /**
155.115 - * Constructs a string buffer initialized to the contents of the
155.116 - * specified string. The initial capacity of the string buffer is
155.117 - * <code>16</code> plus the length of the string argument.
155.118 - *
155.119 - * @param str the initial contents of the buffer.
155.120 - * @exception NullPointerException if <code>str</code> is <code>null</code>
155.121 - */
155.122 - public StringBuffer(String str) {
155.123 - super(str.length() + 16);
155.124 - append(str);
155.125 - }
155.126 -
155.127 - /**
155.128 - * Constructs a string buffer that contains the same characters
155.129 - * as the specified <code>CharSequence</code>. The initial capacity of
155.130 - * the string buffer is <code>16</code> plus the length of the
155.131 - * <code>CharSequence</code> argument.
155.132 - * <p>
155.133 - * If the length of the specified <code>CharSequence</code> is
155.134 - * less than or equal to zero, then an empty buffer of capacity
155.135 - * <code>16</code> is returned.
155.136 - *
155.137 - * @param seq the sequence to copy.
155.138 - * @exception NullPointerException if <code>seq</code> is <code>null</code>
155.139 - * @since 1.5
155.140 - */
155.141 - public StringBuffer(CharSequence seq) {
155.142 - this(seq.length() + 16);
155.143 - append(seq);
155.144 - }
155.145 -
155.146 - public synchronized int length() {
155.147 - return count;
155.148 - }
155.149 -
155.150 - public synchronized int capacity() {
155.151 - return value.length;
155.152 - }
155.153 -
155.154 -
155.155 - public synchronized void ensureCapacity(int minimumCapacity) {
155.156 - if (minimumCapacity > value.length) {
155.157 - expandCapacity(minimumCapacity);
155.158 - }
155.159 - }
155.160 -
155.161 - /**
155.162 - * @since 1.5
155.163 - */
155.164 - public synchronized void trimToSize() {
155.165 - super.trimToSize();
155.166 - }
155.167 -
155.168 - /**
155.169 - * @throws IndexOutOfBoundsException {@inheritDoc}
155.170 - * @see #length()
155.171 - */
155.172 - public synchronized void setLength(int newLength) {
155.173 - super.setLength(newLength);
155.174 - }
155.175 -
155.176 - /**
155.177 - * @throws IndexOutOfBoundsException {@inheritDoc}
155.178 - * @see #length()
155.179 - */
155.180 - public synchronized char charAt(int index) {
155.181 - if ((index < 0) || (index >= count))
155.182 - throw new StringIndexOutOfBoundsException(index);
155.183 - return value[index];
155.184 - }
155.185 -
155.186 - /**
155.187 - * @since 1.5
155.188 - */
155.189 - public synchronized int codePointAt(int index) {
155.190 - return super.codePointAt(index);
155.191 - }
155.192 -
155.193 - /**
155.194 - * @since 1.5
155.195 - */
155.196 - public synchronized int codePointBefore(int index) {
155.197 - return super.codePointBefore(index);
155.198 - }
155.199 -
155.200 - /**
155.201 - * @since 1.5
155.202 - */
155.203 - public synchronized int codePointCount(int beginIndex, int endIndex) {
155.204 - return super.codePointCount(beginIndex, endIndex);
155.205 - }
155.206 -
155.207 - /**
155.208 - * @since 1.5
155.209 - */
155.210 - public synchronized int offsetByCodePoints(int index, int codePointOffset) {
155.211 - return super.offsetByCodePoints(index, codePointOffset);
155.212 - }
155.213 -
155.214 - /**
155.215 - * @throws NullPointerException {@inheritDoc}
155.216 - * @throws IndexOutOfBoundsException {@inheritDoc}
155.217 - */
155.218 - public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
155.219 - int dstBegin)
155.220 - {
155.221 - super.getChars(srcBegin, srcEnd, dst, dstBegin);
155.222 - }
155.223 -
155.224 - /**
155.225 - * @throws IndexOutOfBoundsException {@inheritDoc}
155.226 - * @see #length()
155.227 - */
155.228 - public synchronized void setCharAt(int index, char ch) {
155.229 - if ((index < 0) || (index >= count))
155.230 - throw new StringIndexOutOfBoundsException(index);
155.231 - value[index] = ch;
155.232 - }
155.233 -
155.234 - public synchronized StringBuffer append(Object obj) {
155.235 - super.append(String.valueOf(obj));
155.236 - return this;
155.237 - }
155.238 -
155.239 - public synchronized StringBuffer append(String str) {
155.240 - super.append(str);
155.241 - return this;
155.242 - }
155.243 -
155.244 - /**
155.245 - * Appends the specified <tt>StringBuffer</tt> to this sequence.
155.246 - * <p>
155.247 - * The characters of the <tt>StringBuffer</tt> argument are appended,
155.248 - * in order, to the contents of this <tt>StringBuffer</tt>, increasing the
155.249 - * length of this <tt>StringBuffer</tt> by the length of the argument.
155.250 - * If <tt>sb</tt> is <tt>null</tt>, then the four characters
155.251 - * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
155.252 - * <p>
155.253 - * Let <i>n</i> be the length of the old character sequence, the one
155.254 - * contained in the <tt>StringBuffer</tt> just prior to execution of the
155.255 - * <tt>append</tt> method. Then the character at index <i>k</i> in
155.256 - * the new character sequence is equal to the character at index <i>k</i>
155.257 - * in the old character sequence, if <i>k</i> is less than <i>n</i>;
155.258 - * otherwise, it is equal to the character at index <i>k-n</i> in the
155.259 - * argument <code>sb</code>.
155.260 - * <p>
155.261 - * This method synchronizes on <code>this</code> (the destination)
155.262 - * object but does not synchronize on the source (<code>sb</code>).
155.263 - *
155.264 - * @param sb the <tt>StringBuffer</tt> to append.
155.265 - * @return a reference to this object.
155.266 - * @since 1.4
155.267 - */
155.268 - public synchronized StringBuffer append(StringBuffer sb) {
155.269 - super.append(sb);
155.270 - return this;
155.271 - }
155.272 -
155.273 -
155.274 - /**
155.275 - * Appends the specified <code>CharSequence</code> to this
155.276 - * sequence.
155.277 - * <p>
155.278 - * The characters of the <code>CharSequence</code> argument are appended,
155.279 - * in order, increasing the length of this sequence by the length of the
155.280 - * argument.
155.281 - *
155.282 - * <p>The result of this method is exactly the same as if it were an
155.283 - * invocation of this.append(s, 0, s.length());
155.284 - *
155.285 - * <p>This method synchronizes on this (the destination)
155.286 - * object but does not synchronize on the source (<code>s</code>).
155.287 - *
155.288 - * <p>If <code>s</code> is <code>null</code>, then the four characters
155.289 - * <code>"null"</code> are appended.
155.290 - *
155.291 - * @param s the <code>CharSequence</code> to append.
155.292 - * @return a reference to this object.
155.293 - * @since 1.5
155.294 - */
155.295 - public StringBuffer append(CharSequence s) {
155.296 - // Note, synchronization achieved via other invocations
155.297 - if (s == null)
155.298 - s = "null";
155.299 - if (s instanceof String)
155.300 - return this.append((String)s);
155.301 - if (s instanceof StringBuffer)
155.302 - return this.append((StringBuffer)s);
155.303 - return this.append(s, 0, s.length());
155.304 - }
155.305 -
155.306 - /**
155.307 - * @throws IndexOutOfBoundsException {@inheritDoc}
155.308 - * @since 1.5
155.309 - */
155.310 - public synchronized StringBuffer append(CharSequence s, int start, int end)
155.311 - {
155.312 - super.append(s, start, end);
155.313 - return this;
155.314 - }
155.315 -
155.316 - public synchronized StringBuffer append(char[] str) {
155.317 - super.append(str);
155.318 - return this;
155.319 - }
155.320 -
155.321 - /**
155.322 - * @throws IndexOutOfBoundsException {@inheritDoc}
155.323 - */
155.324 - public synchronized StringBuffer append(char[] str, int offset, int len) {
155.325 - super.append(str, offset, len);
155.326 - return this;
155.327 - }
155.328 -
155.329 - public synchronized StringBuffer append(boolean b) {
155.330 - super.append(b);
155.331 - return this;
155.332 - }
155.333 -
155.334 - public synchronized StringBuffer append(char c) {
155.335 - super.append(c);
155.336 - return this;
155.337 - }
155.338 -
155.339 - public synchronized StringBuffer append(int i) {
155.340 - super.append(i);
155.341 - return this;
155.342 - }
155.343 -
155.344 - /**
155.345 - * @since 1.5
155.346 - */
155.347 - public synchronized StringBuffer appendCodePoint(int codePoint) {
155.348 - super.appendCodePoint(codePoint);
155.349 - return this;
155.350 - }
155.351 -
155.352 - public synchronized StringBuffer append(long lng) {
155.353 - super.append(lng);
155.354 - return this;
155.355 - }
155.356 -
155.357 - public synchronized StringBuffer append(float f) {
155.358 - super.append(f);
155.359 - return this;
155.360 - }
155.361 -
155.362 - public synchronized StringBuffer append(double d) {
155.363 - super.append(d);
155.364 - return this;
155.365 - }
155.366 -
155.367 - /**
155.368 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.369 - * @since 1.2
155.370 - */
155.371 - public synchronized StringBuffer delete(int start, int end) {
155.372 - super.delete(start, end);
155.373 - return this;
155.374 - }
155.375 -
155.376 - /**
155.377 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.378 - * @since 1.2
155.379 - */
155.380 - public synchronized StringBuffer deleteCharAt(int index) {
155.381 - super.deleteCharAt(index);
155.382 - return this;
155.383 - }
155.384 -
155.385 - /**
155.386 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.387 - * @since 1.2
155.388 - */
155.389 - public synchronized StringBuffer replace(int start, int end, String str) {
155.390 - super.replace(start, end, str);
155.391 - return this;
155.392 - }
155.393 -
155.394 - /**
155.395 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.396 - * @since 1.2
155.397 - */
155.398 - public synchronized String substring(int start) {
155.399 - return substring(start, count);
155.400 - }
155.401 -
155.402 - /**
155.403 - * @throws IndexOutOfBoundsException {@inheritDoc}
155.404 - * @since 1.4
155.405 - */
155.406 - public synchronized CharSequence subSequence(int start, int end) {
155.407 - return super.substring(start, end);
155.408 - }
155.409 -
155.410 - /**
155.411 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.412 - * @since 1.2
155.413 - */
155.414 - public synchronized String substring(int start, int end) {
155.415 - return super.substring(start, end);
155.416 - }
155.417 -
155.418 - /**
155.419 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.420 - * @since 1.2
155.421 - */
155.422 - public synchronized StringBuffer insert(int index, char[] str, int offset,
155.423 - int len)
155.424 - {
155.425 - super.insert(index, str, offset, len);
155.426 - return this;
155.427 - }
155.428 -
155.429 - /**
155.430 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.431 - */
155.432 - public synchronized StringBuffer insert(int offset, Object obj) {
155.433 - super.insert(offset, String.valueOf(obj));
155.434 - return this;
155.435 - }
155.436 -
155.437 - /**
155.438 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.439 - */
155.440 - public synchronized StringBuffer insert(int offset, String str) {
155.441 - super.insert(offset, str);
155.442 - return this;
155.443 - }
155.444 -
155.445 - /**
155.446 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.447 - */
155.448 - public synchronized StringBuffer insert(int offset, char[] str) {
155.449 - super.insert(offset, str);
155.450 - return this;
155.451 - }
155.452 -
155.453 - /**
155.454 - * @throws IndexOutOfBoundsException {@inheritDoc}
155.455 - * @since 1.5
155.456 - */
155.457 - public StringBuffer insert(int dstOffset, CharSequence s) {
155.458 - // Note, synchronization achieved via other invocations
155.459 - if (s == null)
155.460 - s = "null";
155.461 - if (s instanceof String)
155.462 - return this.insert(dstOffset, (String)s);
155.463 - return this.insert(dstOffset, s, 0, s.length());
155.464 - }
155.465 -
155.466 - /**
155.467 - * @throws IndexOutOfBoundsException {@inheritDoc}
155.468 - * @since 1.5
155.469 - */
155.470 - public synchronized StringBuffer insert(int dstOffset, CharSequence s,
155.471 - int start, int end)
155.472 - {
155.473 - super.insert(dstOffset, s, start, end);
155.474 - return this;
155.475 - }
155.476 -
155.477 - /**
155.478 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.479 - */
155.480 - public StringBuffer insert(int offset, boolean b) {
155.481 - return insert(offset, String.valueOf(b));
155.482 - }
155.483 -
155.484 - /**
155.485 - * @throws IndexOutOfBoundsException {@inheritDoc}
155.486 - */
155.487 - public synchronized StringBuffer insert(int offset, char c) {
155.488 - super.insert(offset, c);
155.489 - return this;
155.490 - }
155.491 -
155.492 - /**
155.493 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.494 - */
155.495 - public StringBuffer insert(int offset, int i) {
155.496 - return insert(offset, String.valueOf(i));
155.497 - }
155.498 -
155.499 - /**
155.500 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.501 - */
155.502 - public StringBuffer insert(int offset, long l) {
155.503 - return insert(offset, String.valueOf(l));
155.504 - }
155.505 -
155.506 - /**
155.507 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.508 - */
155.509 - public StringBuffer insert(int offset, float f) {
155.510 - return insert(offset, String.valueOf(f));
155.511 - }
155.512 -
155.513 - /**
155.514 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
155.515 - */
155.516 - public StringBuffer insert(int offset, double d) {
155.517 - return insert(offset, String.valueOf(d));
155.518 - }
155.519 -
155.520 - /**
155.521 - * @throws NullPointerException {@inheritDoc}
155.522 - * @since 1.4
155.523 - */
155.524 - public int indexOf(String str) {
155.525 - return indexOf(str, 0);
155.526 - }
155.527 -
155.528 - /**
155.529 - * @throws NullPointerException {@inheritDoc}
155.530 - * @since 1.4
155.531 - */
155.532 - public synchronized int indexOf(String str, int fromIndex) {
155.533 - return super.indexOf(str, fromIndex);
155.534 - }
155.535 -
155.536 - /**
155.537 - * @throws NullPointerException {@inheritDoc}
155.538 - * @since 1.4
155.539 - */
155.540 - public int lastIndexOf(String str) {
155.541 - // Note, synchronization achieved via other invocations
155.542 - return lastIndexOf(str, count);
155.543 - }
155.544 -
155.545 - /**
155.546 - * @throws NullPointerException {@inheritDoc}
155.547 - * @since 1.4
155.548 - */
155.549 - public synchronized int lastIndexOf(String str, int fromIndex) {
155.550 - return String.lastIndexOf(value, 0, count,
155.551 - str.toCharArray(), 0, str.length(), fromIndex);
155.552 - }
155.553 -
155.554 - /**
155.555 - * @since JDK1.0.2
155.556 - */
155.557 - public synchronized StringBuffer reverse() {
155.558 - super.reverse();
155.559 - return this;
155.560 - }
155.561 -
155.562 - public synchronized String toString() {
155.563 - return new String(value, 0, count);
155.564 - }
155.565 -
155.566 -// /**
155.567 -// * Serializable fields for StringBuffer.
155.568 -// *
155.569 -// * @serialField value char[]
155.570 -// * The backing character array of this StringBuffer.
155.571 -// * @serialField count int
155.572 -// * The number of characters in this StringBuffer.
155.573 -// * @serialField shared boolean
155.574 -// * A flag indicating whether the backing array is shared.
155.575 -// * The value is ignored upon deserialization.
155.576 -// */
155.577 -// private static final java.io.ObjectStreamField[] serialPersistentFields =
155.578 -// {
155.579 -// new java.io.ObjectStreamField("value", char[].class),
155.580 -// new java.io.ObjectStreamField("count", Integer.TYPE),
155.581 -// new java.io.ObjectStreamField("shared", Boolean.TYPE),
155.582 -// };
155.583 -//
155.584 -// /**
155.585 -// * readObject is called to restore the state of the StringBuffer from
155.586 -// * a stream.
155.587 -// */
155.588 -// private synchronized void writeObject(java.io.ObjectOutputStream s)
155.589 -// throws java.io.IOException {
155.590 -// java.io.ObjectOutputStream.PutField fields = s.putFields();
155.591 -// fields.put("value", value);
155.592 -// fields.put("count", count);
155.593 -// fields.put("shared", false);
155.594 -// s.writeFields();
155.595 -// }
155.596 -//
155.597 -// /**
155.598 -// * readObject is called to restore the state of the StringBuffer from
155.599 -// * a stream.
155.600 -// */
155.601 -// private void readObject(java.io.ObjectInputStream s)
155.602 -// throws java.io.IOException, ClassNotFoundException {
155.603 -// java.io.ObjectInputStream.GetField fields = s.readFields();
155.604 -// value = (char[])fields.get("value", null);
155.605 -// count = fields.get("count", 0);
155.606 -// }
155.607 -}
156.1 --- a/emul/src/main/java/java/lang/StringBuilder.java Wed Jan 23 20:16:48 2013 +0100
156.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
156.3 @@ -1,436 +0,0 @@
156.4 -/*
156.5 - * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
156.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
156.7 - *
156.8 - * This code is free software; you can redistribute it and/or modify it
156.9 - * under the terms of the GNU General Public License version 2 only, as
156.10 - * published by the Free Software Foundation. Oracle designates this
156.11 - * particular file as subject to the "Classpath" exception as provided
156.12 - * by Oracle in the LICENSE file that accompanied this code.
156.13 - *
156.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
156.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
156.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
156.17 - * version 2 for more details (a copy is included in the LICENSE file that
156.18 - * accompanied this code).
156.19 - *
156.20 - * You should have received a copy of the GNU General Public License version
156.21 - * 2 along with this work; if not, write to the Free Software Foundation,
156.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
156.23 - *
156.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
156.25 - * or visit www.oracle.com if you need additional information or have any
156.26 - * questions.
156.27 - */
156.28 -
156.29 -package java.lang;
156.30 -
156.31 -
156.32 -/**
156.33 - * A mutable sequence of characters. This class provides an API compatible
156.34 - * with <code>StringBuffer</code>, but with no guarantee of synchronization.
156.35 - * This class is designed for use as a drop-in replacement for
156.36 - * <code>StringBuffer</code> in places where the string buffer was being
156.37 - * used by a single thread (as is generally the case). Where possible,
156.38 - * it is recommended that this class be used in preference to
156.39 - * <code>StringBuffer</code> as it will be faster under most implementations.
156.40 - *
156.41 - * <p>The principal operations on a <code>StringBuilder</code> are the
156.42 - * <code>append</code> and <code>insert</code> methods, which are
156.43 - * overloaded so as to accept data of any type. Each effectively
156.44 - * converts a given datum to a string and then appends or inserts the
156.45 - * characters of that string to the string builder. The
156.46 - * <code>append</code> method always adds these characters at the end
156.47 - * of the builder; the <code>insert</code> method adds the characters at
156.48 - * a specified point.
156.49 - * <p>
156.50 - * For example, if <code>z</code> refers to a string builder object
156.51 - * whose current contents are "<code>start</code>", then
156.52 - * the method call <code>z.append("le")</code> would cause the string
156.53 - * builder to contain "<code>startle</code>", whereas
156.54 - * <code>z.insert(4, "le")</code> would alter the string builder to
156.55 - * contain "<code>starlet</code>".
156.56 - * <p>
156.57 - * In general, if sb refers to an instance of a <code>StringBuilder</code>,
156.58 - * then <code>sb.append(x)</code> has the same effect as
156.59 - * <code>sb.insert(sb.length(), x)</code>.
156.60 - *
156.61 - * Every string builder has a capacity. As long as the length of the
156.62 - * character sequence contained in the string builder does not exceed
156.63 - * the capacity, it is not necessary to allocate a new internal
156.64 - * buffer. If the internal buffer overflows, it is automatically made larger.
156.65 - *
156.66 - * <p>Instances of <code>StringBuilder</code> are not safe for
156.67 - * use by multiple threads. If such synchronization is required then it is
156.68 - * recommended that {@link java.lang.StringBuffer} be used.
156.69 - *
156.70 - * @author Michael McCloskey
156.71 - * @see java.lang.StringBuffer
156.72 - * @see java.lang.String
156.73 - * @since 1.5
156.74 - */
156.75 -public final class StringBuilder
156.76 - extends AbstractStringBuilder
156.77 - implements java.io.Serializable, CharSequence
156.78 -{
156.79 -
156.80 - /** use serialVersionUID for interoperability */
156.81 - static final long serialVersionUID = 4383685877147921099L;
156.82 -
156.83 - /**
156.84 - * Constructs a string builder with no characters in it and an
156.85 - * initial capacity of 16 characters.
156.86 - */
156.87 - public StringBuilder() {
156.88 - super(16);
156.89 - }
156.90 -
156.91 - /**
156.92 - * Constructs a string builder with no characters in it and an
156.93 - * initial capacity specified by the <code>capacity</code> argument.
156.94 - *
156.95 - * @param capacity the initial capacity.
156.96 - * @throws NegativeArraySizeException if the <code>capacity</code>
156.97 - * argument is less than <code>0</code>.
156.98 - */
156.99 - public StringBuilder(int capacity) {
156.100 - super(capacity);
156.101 - }
156.102 -
156.103 - /**
156.104 - * Constructs a string builder initialized to the contents of the
156.105 - * specified string. The initial capacity of the string builder is
156.106 - * <code>16</code> plus the length of the string argument.
156.107 - *
156.108 - * @param str the initial contents of the buffer.
156.109 - * @throws NullPointerException if <code>str</code> is <code>null</code>
156.110 - */
156.111 - public StringBuilder(String str) {
156.112 - super(str.length() + 16);
156.113 - append(str);
156.114 - }
156.115 -
156.116 - /**
156.117 - * Constructs a string builder that contains the same characters
156.118 - * as the specified <code>CharSequence</code>. The initial capacity of
156.119 - * the string builder is <code>16</code> plus the length of the
156.120 - * <code>CharSequence</code> argument.
156.121 - *
156.122 - * @param seq the sequence to copy.
156.123 - * @throws NullPointerException if <code>seq</code> is <code>null</code>
156.124 - */
156.125 - public StringBuilder(CharSequence seq) {
156.126 - this(seq.length() + 16);
156.127 - append(seq);
156.128 - }
156.129 -
156.130 - public StringBuilder append(Object obj) {
156.131 - return append(String.valueOf(obj));
156.132 - }
156.133 -
156.134 - public StringBuilder append(String str) {
156.135 - super.append(str);
156.136 - return this;
156.137 - }
156.138 -
156.139 - // Appends the specified string builder to this sequence.
156.140 - private StringBuilder append(StringBuilder sb) {
156.141 - if (sb == null)
156.142 - return append("null");
156.143 - int len = sb.length();
156.144 - int newcount = count + len;
156.145 - if (newcount > value.length)
156.146 - expandCapacity(newcount);
156.147 - sb.getChars(0, len, value, count);
156.148 - count = newcount;
156.149 - return this;
156.150 - }
156.151 -
156.152 - /**
156.153 - * Appends the specified <tt>StringBuffer</tt> to this sequence.
156.154 - * <p>
156.155 - * The characters of the <tt>StringBuffer</tt> argument are appended,
156.156 - * in order, to this sequence, increasing the
156.157 - * length of this sequence by the length of the argument.
156.158 - * If <tt>sb</tt> is <tt>null</tt>, then the four characters
156.159 - * <tt>"null"</tt> are appended to this sequence.
156.160 - * <p>
156.161 - * Let <i>n</i> be the length of this character sequence just prior to
156.162 - * execution of the <tt>append</tt> method. Then the character at index
156.163 - * <i>k</i> in the new character sequence is equal to the character at
156.164 - * index <i>k</i> in the old character sequence, if <i>k</i> is less than
156.165 - * <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i>
156.166 - * in the argument <code>sb</code>.
156.167 - *
156.168 - * @param sb the <tt>StringBuffer</tt> to append.
156.169 - * @return a reference to this object.
156.170 - */
156.171 - public StringBuilder append(StringBuffer sb) {
156.172 - super.append(sb);
156.173 - return this;
156.174 - }
156.175 -
156.176 - /**
156.177 - */
156.178 - public StringBuilder append(CharSequence s) {
156.179 - if (s == null)
156.180 - s = "null";
156.181 - if (s instanceof String)
156.182 - return this.append((String)s);
156.183 - if (s instanceof StringBuffer)
156.184 - return this.append((StringBuffer)s);
156.185 - if (s instanceof StringBuilder)
156.186 - return this.append((StringBuilder)s);
156.187 - return this.append(s, 0, s.length());
156.188 - }
156.189 -
156.190 - /**
156.191 - * @throws IndexOutOfBoundsException {@inheritDoc}
156.192 - */
156.193 - public StringBuilder append(CharSequence s, int start, int end) {
156.194 - super.append(s, start, end);
156.195 - return this;
156.196 - }
156.197 -
156.198 - public StringBuilder append(char[] str) {
156.199 - super.append(str);
156.200 - return this;
156.201 - }
156.202 -
156.203 - /**
156.204 - * @throws IndexOutOfBoundsException {@inheritDoc}
156.205 - */
156.206 - public StringBuilder append(char[] str, int offset, int len) {
156.207 - super.append(str, offset, len);
156.208 - return this;
156.209 - }
156.210 -
156.211 - public StringBuilder append(boolean b) {
156.212 - super.append(b);
156.213 - return this;
156.214 - }
156.215 -
156.216 - public StringBuilder append(char c) {
156.217 - super.append(c);
156.218 - return this;
156.219 - }
156.220 -
156.221 - public StringBuilder append(int i) {
156.222 - super.append(i);
156.223 - return this;
156.224 - }
156.225 -
156.226 - public StringBuilder append(long lng) {
156.227 - super.append(lng);
156.228 - return this;
156.229 - }
156.230 -
156.231 - public StringBuilder append(float f) {
156.232 - super.append(f);
156.233 - return this;
156.234 - }
156.235 -
156.236 - public StringBuilder append(double d) {
156.237 - super.append(d);
156.238 - return this;
156.239 - }
156.240 -
156.241 - /**
156.242 - * @since 1.5
156.243 - */
156.244 - public StringBuilder appendCodePoint(int codePoint) {
156.245 - super.appendCodePoint(codePoint);
156.246 - return this;
156.247 - }
156.248 -
156.249 - /**
156.250 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.251 - */
156.252 - public StringBuilder delete(int start, int end) {
156.253 - super.delete(start, end);
156.254 - return this;
156.255 - }
156.256 -
156.257 - /**
156.258 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.259 - */
156.260 - public StringBuilder deleteCharAt(int index) {
156.261 - super.deleteCharAt(index);
156.262 - return this;
156.263 - }
156.264 -
156.265 - /**
156.266 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.267 - */
156.268 - public StringBuilder replace(int start, int end, String str) {
156.269 - super.replace(start, end, str);
156.270 - return this;
156.271 - }
156.272 -
156.273 - /**
156.274 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.275 - */
156.276 - public StringBuilder insert(int index, char[] str, int offset,
156.277 - int len)
156.278 - {
156.279 - super.insert(index, str, offset, len);
156.280 - return this;
156.281 - }
156.282 -
156.283 - /**
156.284 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.285 - */
156.286 - public StringBuilder insert(int offset, Object obj) {
156.287 - return insert(offset, String.valueOf(obj));
156.288 - }
156.289 -
156.290 - /**
156.291 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.292 - */
156.293 - public StringBuilder insert(int offset, String str) {
156.294 - super.insert(offset, str);
156.295 - return this;
156.296 - }
156.297 -
156.298 - /**
156.299 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.300 - */
156.301 - public StringBuilder insert(int offset, char[] str) {
156.302 - super.insert(offset, str);
156.303 - return this;
156.304 - }
156.305 -
156.306 - /**
156.307 - * @throws IndexOutOfBoundsException {@inheritDoc}
156.308 - */
156.309 - public StringBuilder insert(int dstOffset, CharSequence s) {
156.310 - if (s == null)
156.311 - s = "null";
156.312 - if (s instanceof String)
156.313 - return this.insert(dstOffset, (String)s);
156.314 - return this.insert(dstOffset, s, 0, s.length());
156.315 - }
156.316 -
156.317 - /**
156.318 - * @throws IndexOutOfBoundsException {@inheritDoc}
156.319 - */
156.320 - public StringBuilder insert(int dstOffset, CharSequence s,
156.321 - int start, int end)
156.322 - {
156.323 - super.insert(dstOffset, s, start, end);
156.324 - return this;
156.325 - }
156.326 -
156.327 - /**
156.328 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.329 - */
156.330 - public StringBuilder insert(int offset, boolean b) {
156.331 - super.insert(offset, b);
156.332 - return this;
156.333 - }
156.334 -
156.335 - /**
156.336 - * @throws IndexOutOfBoundsException {@inheritDoc}
156.337 - */
156.338 - public StringBuilder insert(int offset, char c) {
156.339 - super.insert(offset, c);
156.340 - return this;
156.341 - }
156.342 -
156.343 - /**
156.344 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.345 - */
156.346 - public StringBuilder insert(int offset, int i) {
156.347 - return insert(offset, String.valueOf(i));
156.348 - }
156.349 -
156.350 - /**
156.351 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.352 - */
156.353 - public StringBuilder insert(int offset, long l) {
156.354 - return insert(offset, String.valueOf(l));
156.355 - }
156.356 -
156.357 - /**
156.358 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.359 - */
156.360 - public StringBuilder insert(int offset, float f) {
156.361 - return insert(offset, String.valueOf(f));
156.362 - }
156.363 -
156.364 - /**
156.365 - * @throws StringIndexOutOfBoundsException {@inheritDoc}
156.366 - */
156.367 - public StringBuilder insert(int offset, double d) {
156.368 - return insert(offset, String.valueOf(d));
156.369 - }
156.370 -
156.371 - /**
156.372 - * @throws NullPointerException {@inheritDoc}
156.373 - */
156.374 - public int indexOf(String str) {
156.375 - return indexOf(str, 0);
156.376 - }
156.377 -
156.378 - /**
156.379 - * @throws NullPointerException {@inheritDoc}
156.380 - */
156.381 - public int indexOf(String str, int fromIndex) {
156.382 - return super.indexOf(str, fromIndex);
156.383 - }
156.384 -
156.385 - /**
156.386 - * @throws NullPointerException {@inheritDoc}
156.387 - */
156.388 - public int lastIndexOf(String str) {
156.389 - return lastIndexOf(str, count);
156.390 - }
156.391 -
156.392 - /**
156.393 - * @throws NullPointerException {@inheritDoc}
156.394 - */
156.395 - public int lastIndexOf(String str, int fromIndex) {
156.396 - return String.lastIndexOf(value, 0, count,
156.397 - str.toCharArray(), 0, str.length(), fromIndex);
156.398 - }
156.399 -
156.400 - public StringBuilder reverse() {
156.401 - super.reverse();
156.402 - return this;
156.403 - }
156.404 -
156.405 - public String toString() {
156.406 - // Create a copy, don't share the array
156.407 - return new String(value, 0, count);
156.408 - }
156.409 -
156.410 - /**
156.411 - * Save the state of the <tt>StringBuilder</tt> instance to a stream
156.412 - * (that is, serialize it).
156.413 - *
156.414 - * @serialData the number of characters currently stored in the string
156.415 - * builder (<tt>int</tt>), followed by the characters in the
156.416 - * string builder (<tt>char[]</tt>). The length of the
156.417 - * <tt>char</tt> array may be greater than the number of
156.418 - * characters currently stored in the string builder, in which
156.419 - * case extra characters are ignored.
156.420 - */
156.421 -// private void writeObject(java.io.ObjectOutputStream s)
156.422 -// throws java.io.IOException {
156.423 -// s.defaultWriteObject();
156.424 -// s.writeInt(count);
156.425 -// s.writeObject(value);
156.426 -// }
156.427 -
156.428 - /**
156.429 - * readObject is called to restore the state of the StringBuffer from
156.430 - * a stream.
156.431 - */
156.432 -// private void readObject(java.io.ObjectInputStream s)
156.433 -// throws java.io.IOException, ClassNotFoundException {
156.434 -// s.defaultReadObject();
156.435 -// count = s.readInt();
156.436 -// value = (char[]) s.readObject();
156.437 -// }
156.438 -
156.439 -}
157.1 --- a/emul/src/main/java/java/lang/StringIndexOutOfBoundsException.java Wed Jan 23 20:16:48 2013 +0100
157.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
157.3 @@ -1,71 +0,0 @@
157.4 -/*
157.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
157.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
157.7 - *
157.8 - * This code is free software; you can redistribute it and/or modify it
157.9 - * under the terms of the GNU General Public License version 2 only, as
157.10 - * published by the Free Software Foundation. Oracle designates this
157.11 - * particular file as subject to the "Classpath" exception as provided
157.12 - * by Oracle in the LICENSE file that accompanied this code.
157.13 - *
157.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
157.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
157.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
157.17 - * version 2 for more details (a copy is included in the LICENSE file that
157.18 - * accompanied this code).
157.19 - *
157.20 - * You should have received a copy of the GNU General Public License version
157.21 - * 2 along with this work; if not, write to the Free Software Foundation,
157.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
157.23 - *
157.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
157.25 - * or visit www.oracle.com if you need additional information or have any
157.26 - * questions.
157.27 - */
157.28 -
157.29 -package java.lang;
157.30 -
157.31 -/**
157.32 - * Thrown by <code>String</code> methods to indicate that an index
157.33 - * is either negative or greater than the size of the string. For
157.34 - * some methods such as the charAt method, this exception also is
157.35 - * thrown when the index is equal to the size of the string.
157.36 - *
157.37 - * @author unascribed
157.38 - * @see java.lang.String#charAt(int)
157.39 - * @since JDK1.0
157.40 - */
157.41 -public
157.42 -class StringIndexOutOfBoundsException extends IndexOutOfBoundsException {
157.43 - private static final long serialVersionUID = -6762910422159637258L;
157.44 -
157.45 - /**
157.46 - * Constructs a <code>StringIndexOutOfBoundsException</code> with no
157.47 - * detail message.
157.48 - *
157.49 - * @since JDK1.0.
157.50 - */
157.51 - public StringIndexOutOfBoundsException() {
157.52 - super();
157.53 - }
157.54 -
157.55 - /**
157.56 - * Constructs a <code>StringIndexOutOfBoundsException</code> with
157.57 - * the specified detail message.
157.58 - *
157.59 - * @param s the detail message.
157.60 - */
157.61 - public StringIndexOutOfBoundsException(String s) {
157.62 - super(s);
157.63 - }
157.64 -
157.65 - /**
157.66 - * Constructs a new <code>StringIndexOutOfBoundsException</code>
157.67 - * class with an argument indicating the illegal index.
157.68 - *
157.69 - * @param index the illegal index.
157.70 - */
157.71 - public StringIndexOutOfBoundsException(int index) {
157.72 - super("String index out of range: " + index);
157.73 - }
157.74 -}
158.1 --- a/emul/src/main/java/java/lang/Throwable.java Wed Jan 23 20:16:48 2013 +0100
158.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
158.3 @@ -1,1088 +0,0 @@
158.4 -/*
158.5 - * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
158.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
158.7 - *
158.8 - * This code is free software; you can redistribute it and/or modify it
158.9 - * under the terms of the GNU General Public License version 2 only, as
158.10 - * published by the Free Software Foundation. Oracle designates this
158.11 - * particular file as subject to the "Classpath" exception as provided
158.12 - * by Oracle in the LICENSE file that accompanied this code.
158.13 - *
158.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
158.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
158.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
158.17 - * version 2 for more details (a copy is included in the LICENSE file that
158.18 - * accompanied this code).
158.19 - *
158.20 - * You should have received a copy of the GNU General Public License version
158.21 - * 2 along with this work; if not, write to the Free Software Foundation,
158.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
158.23 - *
158.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
158.25 - * or visit www.oracle.com if you need additional information or have any
158.26 - * questions.
158.27 - */
158.28 -
158.29 -package java.lang;
158.30 -import java.io.*;
158.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
158.32 -import org.apidesign.bck2brwsr.core.JavaScriptOnly;
158.33 -
158.34 -/**
158.35 - * The {@code Throwable} class is the superclass of all errors and
158.36 - * exceptions in the Java language. Only objects that are instances of this
158.37 - * class (or one of its subclasses) are thrown by the Java Virtual Machine or
158.38 - * can be thrown by the Java {@code throw} statement. Similarly, only
158.39 - * this class or one of its subclasses can be the argument type in a
158.40 - * {@code catch} clause.
158.41 - *
158.42 - * For the purposes of compile-time checking of exceptions, {@code
158.43 - * Throwable} and any subclass of {@code Throwable} that is not also a
158.44 - * subclass of either {@link RuntimeException} or {@link Error} are
158.45 - * regarded as checked exceptions.
158.46 - *
158.47 - * <p>Instances of two subclasses, {@link java.lang.Error} and
158.48 - * {@link java.lang.Exception}, are conventionally used to indicate
158.49 - * that exceptional situations have occurred. Typically, these instances
158.50 - * are freshly created in the context of the exceptional situation so
158.51 - * as to include relevant information (such as stack trace data).
158.52 - *
158.53 - * <p>A throwable contains a snapshot of the execution stack of its
158.54 - * thread at the time it was created. It can also contain a message
158.55 - * string that gives more information about the error. Over time, a
158.56 - * throwable can {@linkplain Throwable#addSuppressed suppress} other
158.57 - * throwables from being propagated. Finally, the throwable can also
158.58 - * contain a <i>cause</i>: another throwable that caused this
158.59 - * throwable to be constructed. The recording of this causal information
158.60 - * is referred to as the <i>chained exception</i> facility, as the
158.61 - * cause can, itself, have a cause, and so on, leading to a "chain" of
158.62 - * exceptions, each caused by another.
158.63 - *
158.64 - * <p>One reason that a throwable may have a cause is that the class that
158.65 - * throws it is built atop a lower layered abstraction, and an operation on
158.66 - * the upper layer fails due to a failure in the lower layer. It would be bad
158.67 - * design to let the throwable thrown by the lower layer propagate outward, as
158.68 - * it is generally unrelated to the abstraction provided by the upper layer.
158.69 - * Further, doing so would tie the API of the upper layer to the details of
158.70 - * its implementation, assuming the lower layer's exception was a checked
158.71 - * exception. Throwing a "wrapped exception" (i.e., an exception containing a
158.72 - * cause) allows the upper layer to communicate the details of the failure to
158.73 - * its caller without incurring either of these shortcomings. It preserves
158.74 - * the flexibility to change the implementation of the upper layer without
158.75 - * changing its API (in particular, the set of exceptions thrown by its
158.76 - * methods).
158.77 - *
158.78 - * <p>A second reason that a throwable may have a cause is that the method
158.79 - * that throws it must conform to a general-purpose interface that does not
158.80 - * permit the method to throw the cause directly. For example, suppose
158.81 - * a persistent collection conforms to the {@link java.util.Collection
158.82 - * Collection} interface, and that its persistence is implemented atop
158.83 - * {@code java.io}. Suppose the internals of the {@code add} method
158.84 - * can throw an {@link java.io.IOException IOException}. The implementation
158.85 - * can communicate the details of the {@code IOException} to its caller
158.86 - * while conforming to the {@code Collection} interface by wrapping the
158.87 - * {@code IOException} in an appropriate unchecked exception. (The
158.88 - * specification for the persistent collection should indicate that it is
158.89 - * capable of throwing such exceptions.)
158.90 - *
158.91 - * <p>A cause can be associated with a throwable in two ways: via a
158.92 - * constructor that takes the cause as an argument, or via the
158.93 - * {@link #initCause(Throwable)} method. New throwable classes that
158.94 - * wish to allow causes to be associated with them should provide constructors
158.95 - * that take a cause and delegate (perhaps indirectly) to one of the
158.96 - * {@code Throwable} constructors that takes a cause.
158.97 - *
158.98 - * Because the {@code initCause} method is public, it allows a cause to be
158.99 - * associated with any throwable, even a "legacy throwable" whose
158.100 - * implementation predates the addition of the exception chaining mechanism to
158.101 - * {@code Throwable}.
158.102 - *
158.103 - * <p>By convention, class {@code Throwable} and its subclasses have two
158.104 - * constructors, one that takes no arguments and one that takes a
158.105 - * {@code String} argument that can be used to produce a detail message.
158.106 - * Further, those subclasses that might likely have a cause associated with
158.107 - * them should have two more constructors, one that takes a
158.108 - * {@code Throwable} (the cause), and one that takes a
158.109 - * {@code String} (the detail message) and a {@code Throwable} (the
158.110 - * cause).
158.111 - *
158.112 - * @author unascribed
158.113 - * @author Josh Bloch (Added exception chaining and programmatic access to
158.114 - * stack trace in 1.4.)
158.115 - * @jls 11.2 Compile-Time Checking of Exceptions
158.116 - * @since JDK1.0
158.117 - */
158.118 -public class Throwable implements Serializable {
158.119 - /** use serialVersionUID from JDK 1.0.2 for interoperability */
158.120 - private static final long serialVersionUID = -3042686055658047285L;
158.121 -
158.122 - /**
158.123 - * Native code saves some indication of the stack backtrace in this slot.
158.124 - */
158.125 - private transient Object backtrace;
158.126 -
158.127 - /**
158.128 - * Specific details about the Throwable. For example, for
158.129 - * {@code FileNotFoundException}, this contains the name of
158.130 - * the file that could not be found.
158.131 - *
158.132 - * @serial
158.133 - */
158.134 - private String detailMessage;
158.135 -
158.136 -
158.137 - /**
158.138 - * Holder class to defer initializing sentinel objects only used
158.139 - * for serialization.
158.140 - */
158.141 - private static class SentinelHolder {
158.142 - /**
158.143 - * {@linkplain #setStackTrace(StackTraceElement[]) Setting the
158.144 - * stack trace} to a one-element array containing this sentinel
158.145 - * value indicates future attempts to set the stack trace will be
158.146 - * ignored. The sentinal is equal to the result of calling:<br>
158.147 - * {@code new StackTraceElement("", "", null, Integer.MIN_VALUE)}
158.148 - */
158.149 - public static final StackTraceElement STACK_TRACE_ELEMENT_SENTINEL =
158.150 - new StackTraceElement("", "", null, Integer.MIN_VALUE);
158.151 -
158.152 - /**
158.153 - * Sentinel value used in the serial form to indicate an immutable
158.154 - * stack trace.
158.155 - */
158.156 - public static final StackTraceElement[] STACK_TRACE_SENTINEL =
158.157 - new StackTraceElement[] {STACK_TRACE_ELEMENT_SENTINEL};
158.158 - }
158.159 -
158.160 - /**
158.161 - * A shared value for an empty stack.
158.162 - */
158.163 - private static final StackTraceElement[] UNASSIGNED_STACK = new StackTraceElement[0];
158.164 -
158.165 - /*
158.166 - * To allow Throwable objects to be made immutable and safely
158.167 - * reused by the JVM, such as OutOfMemoryErrors, fields of
158.168 - * Throwable that are writable in response to user actions, cause,
158.169 - * stackTrace, and suppressedExceptions obey the following
158.170 - * protocol:
158.171 - *
158.172 - * 1) The fields are initialized to a non-null sentinel value
158.173 - * which indicates the value has logically not been set.
158.174 - *
158.175 - * 2) Writing a null to the field indicates further writes
158.176 - * are forbidden
158.177 - *
158.178 - * 3) The sentinel value may be replaced with another non-null
158.179 - * value.
158.180 - *
158.181 - * For example, implementations of the HotSpot JVM have
158.182 - * preallocated OutOfMemoryError objects to provide for better
158.183 - * diagnosability of that situation. These objects are created
158.184 - * without calling the constructor for that class and the fields
158.185 - * in question are initialized to null. To support this
158.186 - * capability, any new fields added to Throwable that require
158.187 - * being initialized to a non-null value require a coordinated JVM
158.188 - * change.
158.189 - */
158.190 -
158.191 - /**
158.192 - * The throwable that caused this throwable to get thrown, or null if this
158.193 - * throwable was not caused by another throwable, or if the causative
158.194 - * throwable is unknown. If this field is equal to this throwable itself,
158.195 - * it indicates that the cause of this throwable has not yet been
158.196 - * initialized.
158.197 - *
158.198 - * @serial
158.199 - * @since 1.4
158.200 - */
158.201 - private Throwable cause = this;
158.202 -
158.203 - /**
158.204 - * The stack trace, as returned by {@link #getStackTrace()}.
158.205 - *
158.206 - * The field is initialized to a zero-length array. A {@code
158.207 - * null} value of this field indicates subsequent calls to {@link
158.208 - * #setStackTrace(StackTraceElement[])} and {@link
158.209 - * #fillInStackTrace()} will be be no-ops.
158.210 - *
158.211 - * @serial
158.212 - * @since 1.4
158.213 - */
158.214 - private StackTraceElement[] stackTrace = UNASSIGNED_STACK;
158.215 -
158.216 - // Setting this static field introduces an acceptable
158.217 - // initialization dependency on a few java.util classes.
158.218 -// I don't think this dependency is acceptable
158.219 -// private static final List<Throwable> SUPPRESSED_SENTINEL =
158.220 -// Collections.unmodifiableList(new ArrayList<Throwable>(0));
158.221 -
158.222 - /**
158.223 - * The list of suppressed exceptions, as returned by {@link
158.224 - * #getSuppressed()}. The list is initialized to a zero-element
158.225 - * unmodifiable sentinel list. When a serialized Throwable is
158.226 - * read in, if the {@code suppressedExceptions} field points to a
158.227 - * zero-element list, the field is reset to the sentinel value.
158.228 - *
158.229 - * @serial
158.230 - * @since 1.7
158.231 - */
158.232 -// private List<Throwable> suppressedExceptions = SUPPRESSED_SENTINEL;
158.233 -
158.234 - /** Message for trying to suppress a null exception. */
158.235 - private static final String NULL_CAUSE_MESSAGE = "Cannot suppress a null exception.";
158.236 -
158.237 - /** Message for trying to suppress oneself. */
158.238 - private static final String SELF_SUPPRESSION_MESSAGE = "Self-suppression not permitted";
158.239 -
158.240 - /** Caption for labeling causative exception stack traces */
158.241 - @JavaScriptOnly(name="toString", value="function() { return this.toString__Ljava_lang_String_2().toString(); }")
158.242 - private static void jsToString() {
158.243 - }
158.244 -
158.245 - @JavaScriptOnly(name="valueOf", value="function() { return this.toString().valueOf(); }")
158.246 - private static void jsValudOf() {
158.247 - }
158.248 - private static final String CAUSE_CAPTION = "Caused by: ";
158.249 -
158.250 - /** Caption for labeling suppressed exception stack traces */
158.251 - private static final String SUPPRESSED_CAPTION = "Suppressed: ";
158.252 -
158.253 - /**
158.254 - * Constructs a new throwable with {@code null} as its detail message.
158.255 - * The cause is not initialized, and may subsequently be initialized by a
158.256 - * call to {@link #initCause}.
158.257 - *
158.258 - * <p>The {@link #fillInStackTrace()} method is called to initialize
158.259 - * the stack trace data in the newly created throwable.
158.260 - */
158.261 - public Throwable() {
158.262 - fillInStackTrace();
158.263 - }
158.264 -
158.265 - /**
158.266 - * Constructs a new throwable with the specified detail message. The
158.267 - * cause is not initialized, and may subsequently be initialized by
158.268 - * a call to {@link #initCause}.
158.269 - *
158.270 - * <p>The {@link #fillInStackTrace()} method is called to initialize
158.271 - * the stack trace data in the newly created throwable.
158.272 - *
158.273 - * @param message the detail message. The detail message is saved for
158.274 - * later retrieval by the {@link #getMessage()} method.
158.275 - */
158.276 - public Throwable(String message) {
158.277 - fillInStackTrace();
158.278 - detailMessage = message;
158.279 - }
158.280 -
158.281 - /**
158.282 - * Constructs a new throwable with the specified detail message and
158.283 - * cause. <p>Note that the detail message associated with
158.284 - * {@code cause} is <i>not</i> automatically incorporated in
158.285 - * this throwable's detail message.
158.286 - *
158.287 - * <p>The {@link #fillInStackTrace()} method is called to initialize
158.288 - * the stack trace data in the newly created throwable.
158.289 - *
158.290 - * @param message the detail message (which is saved for later retrieval
158.291 - * by the {@link #getMessage()} method).
158.292 - * @param cause the cause (which is saved for later retrieval by the
158.293 - * {@link #getCause()} method). (A {@code null} value is
158.294 - * permitted, and indicates that the cause is nonexistent or
158.295 - * unknown.)
158.296 - * @since 1.4
158.297 - */
158.298 - public Throwable(String message, Throwable cause) {
158.299 - fillInStackTrace();
158.300 - detailMessage = message;
158.301 - this.cause = cause;
158.302 - }
158.303 -
158.304 - /**
158.305 - * Constructs a new throwable with the specified cause and a detail
158.306 - * message of {@code (cause==null ? null : cause.toString())} (which
158.307 - * typically contains the class and detail message of {@code cause}).
158.308 - * This constructor is useful for throwables that are little more than
158.309 - * wrappers for other throwables (for example, {@link
158.310 - * java.security.PrivilegedActionException}).
158.311 - *
158.312 - * <p>The {@link #fillInStackTrace()} method is called to initialize
158.313 - * the stack trace data in the newly created throwable.
158.314 - *
158.315 - * @param cause the cause (which is saved for later retrieval by the
158.316 - * {@link #getCause()} method). (A {@code null} value is
158.317 - * permitted, and indicates that the cause is nonexistent or
158.318 - * unknown.)
158.319 - * @since 1.4
158.320 - */
158.321 - public Throwable(Throwable cause) {
158.322 - fillInStackTrace();
158.323 - detailMessage = (cause==null ? null : cause.toString());
158.324 - this.cause = cause;
158.325 - }
158.326 -
158.327 - /**
158.328 - * Constructs a new throwable with the specified detail message,
158.329 - * cause, {@linkplain #addSuppressed suppression} enabled or
158.330 - * disabled, and writable stack trace enabled or disabled. If
158.331 - * suppression is disabled, {@link #getSuppressed} for this object
158.332 - * will return a zero-length array and calls to {@link
158.333 - * #addSuppressed} that would otherwise append an exception to the
158.334 - * suppressed list will have no effect. If the writable stack
158.335 - * trace is false, this constructor will not call {@link
158.336 - * #fillInStackTrace()}, a {@code null} will be written to the
158.337 - * {@code stackTrace} field, and subsequent calls to {@code
158.338 - * fillInStackTrace} and {@link
158.339 - * #setStackTrace(StackTraceElement[])} will not set the stack
158.340 - * trace. If the writable stack trace is false, {@link
158.341 - * #getStackTrace} will return a zero length array.
158.342 - *
158.343 - * <p>Note that the other constructors of {@code Throwable} treat
158.344 - * suppression as being enabled and the stack trace as being
158.345 - * writable. Subclasses of {@code Throwable} should document any
158.346 - * conditions under which suppression is disabled and document
158.347 - * conditions under which the stack trace is not writable.
158.348 - * Disabling of suppression should only occur in exceptional
158.349 - * circumstances where special requirements exist, such as a
158.350 - * virtual machine reusing exception objects under low-memory
158.351 - * situations. Circumstances where a given exception object is
158.352 - * repeatedly caught and rethrown, such as to implement control
158.353 - * flow between two sub-systems, is another situation where
158.354 - * immutable throwable objects would be appropriate.
158.355 - *
158.356 - * @param message the detail message.
158.357 - * @param cause the cause. (A {@code null} value is permitted,
158.358 - * and indicates that the cause is nonexistent or unknown.)
158.359 - * @param enableSuppression whether or not suppression is enabled or disabled
158.360 - * @param writableStackTrace whether or not the stack trace should be
158.361 - * writable
158.362 - *
158.363 - * @see OutOfMemoryError
158.364 - * @see NullPointerException
158.365 - * @see ArithmeticException
158.366 - * @since 1.7
158.367 - */
158.368 - protected Throwable(String message, Throwable cause,
158.369 - boolean enableSuppression,
158.370 - boolean writableStackTrace) {
158.371 - if (writableStackTrace) {
158.372 - fillInStackTrace();
158.373 - } else {
158.374 - stackTrace = null;
158.375 - }
158.376 - detailMessage = message;
158.377 - this.cause = cause;
158.378 -// if (!enableSuppression)
158.379 -// suppressedExceptions = null;
158.380 - }
158.381 -
158.382 - /**
158.383 - * Returns the detail message string of this throwable.
158.384 - *
158.385 - * @return the detail message string of this {@code Throwable} instance
158.386 - * (which may be {@code null}).
158.387 - */
158.388 - public String getMessage() {
158.389 - return detailMessage;
158.390 - }
158.391 -
158.392 - /**
158.393 - * Creates a localized description of this throwable.
158.394 - * Subclasses may override this method in order to produce a
158.395 - * locale-specific message. For subclasses that do not override this
158.396 - * method, the default implementation returns the same result as
158.397 - * {@code getMessage()}.
158.398 - *
158.399 - * @return The localized description of this throwable.
158.400 - * @since JDK1.1
158.401 - */
158.402 - public String getLocalizedMessage() {
158.403 - return getMessage();
158.404 - }
158.405 -
158.406 - /**
158.407 - * Returns the cause of this throwable or {@code null} if the
158.408 - * cause is nonexistent or unknown. (The cause is the throwable that
158.409 - * caused this throwable to get thrown.)
158.410 - *
158.411 - * <p>This implementation returns the cause that was supplied via one of
158.412 - * the constructors requiring a {@code Throwable}, or that was set after
158.413 - * creation with the {@link #initCause(Throwable)} method. While it is
158.414 - * typically unnecessary to override this method, a subclass can override
158.415 - * it to return a cause set by some other means. This is appropriate for
158.416 - * a "legacy chained throwable" that predates the addition of chained
158.417 - * exceptions to {@code Throwable}. Note that it is <i>not</i>
158.418 - * necessary to override any of the {@code PrintStackTrace} methods,
158.419 - * all of which invoke the {@code getCause} method to determine the
158.420 - * cause of a throwable.
158.421 - *
158.422 - * @return the cause of this throwable or {@code null} if the
158.423 - * cause is nonexistent or unknown.
158.424 - * @since 1.4
158.425 - */
158.426 - public synchronized Throwable getCause() {
158.427 - return (cause==this ? null : cause);
158.428 - }
158.429 -
158.430 - /**
158.431 - * Initializes the <i>cause</i> of this throwable to the specified value.
158.432 - * (The cause is the throwable that caused this throwable to get thrown.)
158.433 - *
158.434 - * <p>This method can be called at most once. It is generally called from
158.435 - * within the constructor, or immediately after creating the
158.436 - * throwable. If this throwable was created
158.437 - * with {@link #Throwable(Throwable)} or
158.438 - * {@link #Throwable(String,Throwable)}, this method cannot be called
158.439 - * even once.
158.440 - *
158.441 - * <p>An example of using this method on a legacy throwable type
158.442 - * without other support for setting the cause is:
158.443 - *
158.444 - * <pre>
158.445 - * try {
158.446 - * lowLevelOp();
158.447 - * } catch (LowLevelException le) {
158.448 - * throw (HighLevelException)
158.449 - * new HighLevelException().initCause(le); // Legacy constructor
158.450 - * }
158.451 - * </pre>
158.452 - *
158.453 - * @param cause the cause (which is saved for later retrieval by the
158.454 - * {@link #getCause()} method). (A {@code null} value is
158.455 - * permitted, and indicates that the cause is nonexistent or
158.456 - * unknown.)
158.457 - * @return a reference to this {@code Throwable} instance.
158.458 - * @throws IllegalArgumentException if {@code cause} is this
158.459 - * throwable. (A throwable cannot be its own cause.)
158.460 - * @throws IllegalStateException if this throwable was
158.461 - * created with {@link #Throwable(Throwable)} or
158.462 - * {@link #Throwable(String,Throwable)}, or this method has already
158.463 - * been called on this throwable.
158.464 - * @since 1.4
158.465 - */
158.466 - public synchronized Throwable initCause(Throwable cause) {
158.467 - if (this.cause != this)
158.468 - throw new IllegalStateException("Can't overwrite cause");
158.469 - if (cause == this)
158.470 - throw new IllegalArgumentException("Self-causation not permitted");
158.471 - this.cause = cause;
158.472 - return this;
158.473 - }
158.474 -
158.475 - /**
158.476 - * Returns a short description of this throwable.
158.477 - * The result is the concatenation of:
158.478 - * <ul>
158.479 - * <li> the {@linkplain Class#getName() name} of the class of this object
158.480 - * <li> ": " (a colon and a space)
158.481 - * <li> the result of invoking this object's {@link #getLocalizedMessage}
158.482 - * method
158.483 - * </ul>
158.484 - * If {@code getLocalizedMessage} returns {@code null}, then just
158.485 - * the class name is returned.
158.486 - *
158.487 - * @return a string representation of this throwable.
158.488 - */
158.489 - public String toString() {
158.490 - String s = getClass().getName();
158.491 - String message = getLocalizedMessage();
158.492 - return (message != null) ? (s + ": " + message) : s;
158.493 - }
158.494 -
158.495 - /**
158.496 - * Prints this throwable and its backtrace to the
158.497 - * standard error stream. This method prints a stack trace for this
158.498 - * {@code Throwable} object on the error output stream that is
158.499 - * the value of the field {@code System.err}. The first line of
158.500 - * output contains the result of the {@link #toString()} method for
158.501 - * this object. Remaining lines represent data previously recorded by
158.502 - * the method {@link #fillInStackTrace()}. The format of this
158.503 - * information depends on the implementation, but the following
158.504 - * example may be regarded as typical:
158.505 - * <blockquote><pre>
158.506 - * java.lang.NullPointerException
158.507 - * at MyClass.mash(MyClass.java:9)
158.508 - * at MyClass.crunch(MyClass.java:6)
158.509 - * at MyClass.main(MyClass.java:3)
158.510 - * </pre></blockquote>
158.511 - * This example was produced by running the program:
158.512 - * <pre>
158.513 - * class MyClass {
158.514 - * public static void main(String[] args) {
158.515 - * crunch(null);
158.516 - * }
158.517 - * static void crunch(int[] a) {
158.518 - * mash(a);
158.519 - * }
158.520 - * static void mash(int[] b) {
158.521 - * System.out.println(b[0]);
158.522 - * }
158.523 - * }
158.524 - * </pre>
158.525 - * The backtrace for a throwable with an initialized, non-null cause
158.526 - * should generally include the backtrace for the cause. The format
158.527 - * of this information depends on the implementation, but the following
158.528 - * example may be regarded as typical:
158.529 - * <pre>
158.530 - * HighLevelException: MidLevelException: LowLevelException
158.531 - * at Junk.a(Junk.java:13)
158.532 - * at Junk.main(Junk.java:4)
158.533 - * Caused by: MidLevelException: LowLevelException
158.534 - * at Junk.c(Junk.java:23)
158.535 - * at Junk.b(Junk.java:17)
158.536 - * at Junk.a(Junk.java:11)
158.537 - * ... 1 more
158.538 - * Caused by: LowLevelException
158.539 - * at Junk.e(Junk.java:30)
158.540 - * at Junk.d(Junk.java:27)
158.541 - * at Junk.c(Junk.java:21)
158.542 - * ... 3 more
158.543 - * </pre>
158.544 - * Note the presence of lines containing the characters {@code "..."}.
158.545 - * These lines indicate that the remainder of the stack trace for this
158.546 - * exception matches the indicated number of frames from the bottom of the
158.547 - * stack trace of the exception that was caused by this exception (the
158.548 - * "enclosing" exception). This shorthand can greatly reduce the length
158.549 - * of the output in the common case where a wrapped exception is thrown
158.550 - * from same method as the "causative exception" is caught. The above
158.551 - * example was produced by running the program:
158.552 - * <pre>
158.553 - * public class Junk {
158.554 - * public static void main(String args[]) {
158.555 - * try {
158.556 - * a();
158.557 - * } catch(HighLevelException e) {
158.558 - * e.printStackTrace();
158.559 - * }
158.560 - * }
158.561 - * static void a() throws HighLevelException {
158.562 - * try {
158.563 - * b();
158.564 - * } catch(MidLevelException e) {
158.565 - * throw new HighLevelException(e);
158.566 - * }
158.567 - * }
158.568 - * static void b() throws MidLevelException {
158.569 - * c();
158.570 - * }
158.571 - * static void c() throws MidLevelException {
158.572 - * try {
158.573 - * d();
158.574 - * } catch(LowLevelException e) {
158.575 - * throw new MidLevelException(e);
158.576 - * }
158.577 - * }
158.578 - * static void d() throws LowLevelException {
158.579 - * e();
158.580 - * }
158.581 - * static void e() throws LowLevelException {
158.582 - * throw new LowLevelException();
158.583 - * }
158.584 - * }
158.585 - *
158.586 - * class HighLevelException extends Exception {
158.587 - * HighLevelException(Throwable cause) { super(cause); }
158.588 - * }
158.589 - *
158.590 - * class MidLevelException extends Exception {
158.591 - * MidLevelException(Throwable cause) { super(cause); }
158.592 - * }
158.593 - *
158.594 - * class LowLevelException extends Exception {
158.595 - * }
158.596 - * </pre>
158.597 - * As of release 7, the platform supports the notion of
158.598 - * <i>suppressed exceptions</i> (in conjunction with the {@code
158.599 - * try}-with-resources statement). Any exceptions that were
158.600 - * suppressed in order to deliver an exception are printed out
158.601 - * beneath the stack trace. The format of this information
158.602 - * depends on the implementation, but the following example may be
158.603 - * regarded as typical:
158.604 - *
158.605 - * <pre>
158.606 - * Exception in thread "main" java.lang.Exception: Something happened
158.607 - * at Foo.bar(Foo.java:10)
158.608 - * at Foo.main(Foo.java:5)
158.609 - * Suppressed: Resource$CloseFailException: Resource ID = 0
158.610 - * at Resource.close(Resource.java:26)
158.611 - * at Foo.bar(Foo.java:9)
158.612 - * ... 1 more
158.613 - * </pre>
158.614 - * Note that the "... n more" notation is used on suppressed exceptions
158.615 - * just at it is used on causes. Unlike causes, suppressed exceptions are
158.616 - * indented beyond their "containing exceptions."
158.617 - *
158.618 - * <p>An exception can have both a cause and one or more suppressed
158.619 - * exceptions:
158.620 - * <pre>
158.621 - * Exception in thread "main" java.lang.Exception: Main block
158.622 - * at Foo3.main(Foo3.java:7)
158.623 - * Suppressed: Resource$CloseFailException: Resource ID = 2
158.624 - * at Resource.close(Resource.java:26)
158.625 - * at Foo3.main(Foo3.java:5)
158.626 - * Suppressed: Resource$CloseFailException: Resource ID = 1
158.627 - * at Resource.close(Resource.java:26)
158.628 - * at Foo3.main(Foo3.java:5)
158.629 - * Caused by: java.lang.Exception: I did it
158.630 - * at Foo3.main(Foo3.java:8)
158.631 - * </pre>
158.632 - * Likewise, a suppressed exception can have a cause:
158.633 - * <pre>
158.634 - * Exception in thread "main" java.lang.Exception: Main block
158.635 - * at Foo4.main(Foo4.java:6)
158.636 - * Suppressed: Resource2$CloseFailException: Resource ID = 1
158.637 - * at Resource2.close(Resource2.java:20)
158.638 - * at Foo4.main(Foo4.java:5)
158.639 - * Caused by: java.lang.Exception: Rats, you caught me
158.640 - * at Resource2$CloseFailException.<init>(Resource2.java:45)
158.641 - * ... 2 more
158.642 - * </pre>
158.643 - */
158.644 -// public void printStackTrace() {
158.645 -// printStackTrace(System.err);
158.646 -// }
158.647 -//
158.648 -// /**
158.649 -// * Prints this throwable and its backtrace to the specified print stream.
158.650 -// *
158.651 -// * @param s {@code PrintStream} to use for output
158.652 -// */
158.653 -// public void printStackTrace(PrintStream s) {
158.654 -// printStackTrace(new WrappedPrintStream(s));
158.655 -// }
158.656 -//
158.657 -// private void printStackTrace(PrintStreamOrWriter s) {
158.658 -// // Guard against malicious overrides of Throwable.equals by
158.659 -// // using a Set with identity equality semantics.
158.660 -//// Set<Throwable> dejaVu =
158.661 -//// Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
158.662 -//// dejaVu.add(this);
158.663 -//
158.664 -// synchronized (s.lock()) {
158.665 -// // Print our stack trace
158.666 -// s.println(this);
158.667 -// StackTraceElement[] trace = getOurStackTrace();
158.668 -// for (StackTraceElement traceElement : trace)
158.669 -// s.println("\tat " + traceElement);
158.670 -//
158.671 -// // Print suppressed exceptions, if any
158.672 -//// for (Throwable se : getSuppressed())
158.673 -//// se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu);
158.674 -//
158.675 -// // Print cause, if any
158.676 -// Throwable ourCause = getCause();
158.677 -//// if (ourCause != null)
158.678 -//// ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu);
158.679 -// }
158.680 -// }
158.681 -//
158.682 -// /**
158.683 -// * Print our stack trace as an enclosed exception for the specified
158.684 -// * stack trace.
158.685 -// */
158.686 -// private void printEnclosedStackTrace(PrintStreamOrWriter s,
158.687 -// StackTraceElement[] enclosingTrace,
158.688 -// String caption,
158.689 -// String prefix,
158.690 -// Object dejaVu) {
158.691 -// assert Thread.holdsLock(s.lock());
158.692 -// {
158.693 -// // Compute number of frames in common between this and enclosing trace
158.694 -// StackTraceElement[] trace = getOurStackTrace();
158.695 -// int m = trace.length - 1;
158.696 -// int n = enclosingTrace.length - 1;
158.697 -// while (m >= 0 && n >=0 && trace[m].equals(enclosingTrace[n])) {
158.698 -// m--; n--;
158.699 -// }
158.700 -// int framesInCommon = trace.length - 1 - m;
158.701 -//
158.702 -// // Print our stack trace
158.703 -// s.println(prefix + caption + this);
158.704 -// for (int i = 0; i <= m; i++)
158.705 -// s.println(prefix + "\tat " + trace[i]);
158.706 -// if (framesInCommon != 0)
158.707 -// s.println(prefix + "\t... " + framesInCommon + " more");
158.708 -//
158.709 -// // Print suppressed exceptions, if any
158.710 -// for (Throwable se : getSuppressed())
158.711 -// se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION,
158.712 -// prefix +"\t", dejaVu);
158.713 -//
158.714 -// // Print cause, if any
158.715 -// Throwable ourCause = getCause();
158.716 -// if (ourCause != null)
158.717 -// ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, prefix, dejaVu);
158.718 -// }
158.719 -// }
158.720 -//
158.721 -// /**
158.722 -// * Prints this throwable and its backtrace to the specified
158.723 -// * print writer.
158.724 -// *
158.725 -// * @param s {@code PrintWriter} to use for output
158.726 -// * @since JDK1.1
158.727 -// */
158.728 -// public void printStackTrace(PrintWriter s) {
158.729 -// printStackTrace(new WrappedPrintWriter(s));
158.730 -// }
158.731 -//
158.732 -// /**
158.733 -// * Wrapper class for PrintStream and PrintWriter to enable a single
158.734 -// * implementation of printStackTrace.
158.735 -// */
158.736 -// private abstract static class PrintStreamOrWriter {
158.737 -// /** Returns the object to be locked when using this StreamOrWriter */
158.738 -// abstract Object lock();
158.739 -//
158.740 -// /** Prints the specified string as a line on this StreamOrWriter */
158.741 -// abstract void println(Object o);
158.742 -// }
158.743 -//
158.744 -// private static class WrappedPrintStream extends PrintStreamOrWriter {
158.745 -// private final PrintStream printStream;
158.746 -//
158.747 -// WrappedPrintStream(PrintStream printStream) {
158.748 -// this.printStream = printStream;
158.749 -// }
158.750 -//
158.751 -// Object lock() {
158.752 -// return printStream;
158.753 -// }
158.754 -//
158.755 -// void println(Object o) {
158.756 -// printStream.println(o);
158.757 -// }
158.758 -// }
158.759 -//
158.760 -// private static class WrappedPrintWriter extends PrintStreamOrWriter {
158.761 -// private final PrintWriter printWriter;
158.762 -//
158.763 -// WrappedPrintWriter(PrintWriter printWriter) {
158.764 -// this.printWriter = printWriter;
158.765 -// }
158.766 -//
158.767 -// Object lock() {
158.768 -// return printWriter;
158.769 -// }
158.770 -//
158.771 -// void println(Object o) {
158.772 -// printWriter.println(o);
158.773 -// }
158.774 -// }
158.775 -
158.776 - /**
158.777 - * Fills in the execution stack trace. This method records within this
158.778 - * {@code Throwable} object information about the current state of
158.779 - * the stack frames for the current thread.
158.780 - *
158.781 - * <p>If the stack trace of this {@code Throwable} {@linkplain
158.782 - * Throwable#Throwable(String, Throwable, boolean, boolean) is not
158.783 - * writable}, calling this method has no effect.
158.784 - *
158.785 - * @return a reference to this {@code Throwable} instance.
158.786 - * @see java.lang.Throwable#printStackTrace()
158.787 - */
158.788 - public synchronized Throwable fillInStackTrace() {
158.789 - if (stackTrace != null ||
158.790 - backtrace != null /* Out of protocol state */ ) {
158.791 - fillInStackTrace(0);
158.792 - stackTrace = UNASSIGNED_STACK;
158.793 - }
158.794 - return this;
158.795 - }
158.796 -
158.797 - @JavaScriptBody(args = { "dummy" }, body = "")
158.798 - private native Throwable fillInStackTrace(int dummy);
158.799 -
158.800 - /**
158.801 - * Provides programmatic access to the stack trace information printed by
158.802 - * {@link #printStackTrace()}. Returns an array of stack trace elements,
158.803 - * each representing one stack frame. The zeroth element of the array
158.804 - * (assuming the array's length is non-zero) represents the top of the
158.805 - * stack, which is the last method invocation in the sequence. Typically,
158.806 - * this is the point at which this throwable was created and thrown.
158.807 - * The last element of the array (assuming the array's length is non-zero)
158.808 - * represents the bottom of the stack, which is the first method invocation
158.809 - * in the sequence.
158.810 - *
158.811 - * <p>Some virtual machines may, under some circumstances, omit one
158.812 - * or more stack frames from the stack trace. In the extreme case,
158.813 - * a virtual machine that has no stack trace information concerning
158.814 - * this throwable is permitted to return a zero-length array from this
158.815 - * method. Generally speaking, the array returned by this method will
158.816 - * contain one element for every frame that would be printed by
158.817 - * {@code printStackTrace}. Writes to the returned array do not
158.818 - * affect future calls to this method.
158.819 - *
158.820 - * @return an array of stack trace elements representing the stack trace
158.821 - * pertaining to this throwable.
158.822 - * @since 1.4
158.823 - */
158.824 - public StackTraceElement[] getStackTrace() {
158.825 - return getOurStackTrace().clone();
158.826 - }
158.827 -
158.828 - private synchronized StackTraceElement[] getOurStackTrace() {
158.829 - // Initialize stack trace field with information from
158.830 - // backtrace if this is the first call to this method
158.831 - if (stackTrace == UNASSIGNED_STACK ||
158.832 - (stackTrace == null && backtrace != null) /* Out of protocol state */) {
158.833 - int depth = getStackTraceDepth();
158.834 - stackTrace = new StackTraceElement[depth];
158.835 - for (int i=0; i < depth; i++)
158.836 - stackTrace[i] = getStackTraceElement(i);
158.837 - } else if (stackTrace == null) {
158.838 - return UNASSIGNED_STACK;
158.839 - }
158.840 - return stackTrace;
158.841 - }
158.842 -
158.843 - /**
158.844 - * Sets the stack trace elements that will be returned by
158.845 - * {@link #getStackTrace()} and printed by {@link #printStackTrace()}
158.846 - * and related methods.
158.847 - *
158.848 - * This method, which is designed for use by RPC frameworks and other
158.849 - * advanced systems, allows the client to override the default
158.850 - * stack trace that is either generated by {@link #fillInStackTrace()}
158.851 - * when a throwable is constructed or deserialized when a throwable is
158.852 - * read from a serialization stream.
158.853 - *
158.854 - * <p>If the stack trace of this {@code Throwable} {@linkplain
158.855 - * Throwable#Throwable(String, Throwable, boolean, boolean) is not
158.856 - * writable}, calling this method has no effect other than
158.857 - * validating its argument.
158.858 - *
158.859 - * @param stackTrace the stack trace elements to be associated with
158.860 - * this {@code Throwable}. The specified array is copied by this
158.861 - * call; changes in the specified array after the method invocation
158.862 - * returns will have no affect on this {@code Throwable}'s stack
158.863 - * trace.
158.864 - *
158.865 - * @throws NullPointerException if {@code stackTrace} is
158.866 - * {@code null} or if any of the elements of
158.867 - * {@code stackTrace} are {@code null}
158.868 - *
158.869 - * @since 1.4
158.870 - */
158.871 - public void setStackTrace(StackTraceElement[] stackTrace) {
158.872 - // Validate argument
158.873 - StackTraceElement[] defensiveCopy = stackTrace.clone();
158.874 - for (int i = 0; i < defensiveCopy.length; i++) {
158.875 - if (defensiveCopy[i] == null)
158.876 - throw new NullPointerException("stackTrace[" + i + "]");
158.877 - }
158.878 -
158.879 - synchronized (this) {
158.880 - if (this.stackTrace == null && // Immutable stack
158.881 - backtrace == null) // Test for out of protocol state
158.882 - return;
158.883 - this.stackTrace = defensiveCopy;
158.884 - }
158.885 - }
158.886 -
158.887 - /**
158.888 - * Returns the number of elements in the stack trace (or 0 if the stack
158.889 - * trace is unavailable).
158.890 - *
158.891 - * package-protection for use by SharedSecrets.
158.892 - */
158.893 - native int getStackTraceDepth();
158.894 -
158.895 - /**
158.896 - * Returns the specified element of the stack trace.
158.897 - *
158.898 - * package-protection for use by SharedSecrets.
158.899 - *
158.900 - * @param index index of the element to return.
158.901 - * @throws IndexOutOfBoundsException if {@code index < 0 ||
158.902 - * index >= getStackTraceDepth() }
158.903 - */
158.904 - native StackTraceElement getStackTraceElement(int index);
158.905 -
158.906 - /**
158.907 - * Reads a {@code Throwable} from a stream, enforcing
158.908 - * well-formedness constraints on fields. Null entries and
158.909 - * self-pointers are not allowed in the list of {@code
158.910 - * suppressedExceptions}. Null entries are not allowed for stack
158.911 - * trace elements. A null stack trace in the serial form results
158.912 - * in a zero-length stack element array. A single-element stack
158.913 - * trace whose entry is equal to {@code new StackTraceElement("",
158.914 - * "", null, Integer.MIN_VALUE)} results in a {@code null} {@code
158.915 - * stackTrace} field.
158.916 - *
158.917 - * Note that there are no constraints on the value the {@code
158.918 - * cause} field can hold; both {@code null} and {@code this} are
158.919 - * valid values for the field.
158.920 - */
158.921 -// private void readObject(ObjectInputStream s)
158.922 -// throws IOException, ClassNotFoundException {
158.923 -// s.defaultReadObject(); // read in all fields
158.924 -// if (suppressedExceptions != null) {
158.925 -// List<Throwable> suppressed = null;
158.926 -// if (suppressedExceptions.isEmpty()) {
158.927 -// // Use the sentinel for a zero-length list
158.928 -// suppressed = SUPPRESSED_SENTINEL;
158.929 -// } else { // Copy Throwables to new list
158.930 -// suppressed = new ArrayList<Throwable>(1);
158.931 -// for (Throwable t : suppressedExceptions) {
158.932 -// // Enforce constraints on suppressed exceptions in
158.933 -// // case of corrupt or malicious stream.
158.934 -// if (t == null)
158.935 -// throw new NullPointerException(NULL_CAUSE_MESSAGE);
158.936 -// if (t == this)
158.937 -// throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
158.938 -// suppressed.add(t);
158.939 -// }
158.940 -// }
158.941 -// suppressedExceptions = suppressed;
158.942 -// } // else a null suppressedExceptions field remains null
158.943 -//
158.944 -// /*
158.945 -// * For zero-length stack traces, use a clone of
158.946 -// * UNASSIGNED_STACK rather than UNASSIGNED_STACK itself to
158.947 -// * allow identity comparison against UNASSIGNED_STACK in
158.948 -// * getOurStackTrace. The identity of UNASSIGNED_STACK in
158.949 -// * stackTrace indicates to the getOurStackTrace method that
158.950 -// * the stackTrace needs to be constructed from the information
158.951 -// * in backtrace.
158.952 -// */
158.953 -// if (stackTrace != null) {
158.954 -// if (stackTrace.length == 0) {
158.955 -// stackTrace = UNASSIGNED_STACK.clone();
158.956 -// } else if (stackTrace.length == 1 &&
158.957 -// // Check for the marker of an immutable stack trace
158.958 -// SentinelHolder.STACK_TRACE_ELEMENT_SENTINEL.equals(stackTrace[0])) {
158.959 -// stackTrace = null;
158.960 -// } else { // Verify stack trace elements are non-null.
158.961 -// for(StackTraceElement ste : stackTrace) {
158.962 -// if (ste == null)
158.963 -// throw new NullPointerException("null StackTraceElement in serial stream. ");
158.964 -// }
158.965 -// }
158.966 -// } else {
158.967 -// // A null stackTrace field in the serial form can result
158.968 -// // from an exception serialized without that field in
158.969 -// // older JDK releases; treat such exceptions as having
158.970 -// // empty stack traces.
158.971 -// stackTrace = UNASSIGNED_STACK.clone();
158.972 -// }
158.973 -// }
158.974 -
158.975 - /**
158.976 - * Write a {@code Throwable} object to a stream.
158.977 - *
158.978 - * A {@code null} stack trace field is represented in the serial
158.979 - * form as a one-element array whose element is equal to {@code
158.980 - * new StackTraceElement("", "", null, Integer.MIN_VALUE)}.
158.981 - */
158.982 -// private synchronized void writeObject(ObjectOutputStream s)
158.983 -// throws IOException {
158.984 -// // Ensure that the stackTrace field is initialized to a
158.985 -// // non-null value, if appropriate. As of JDK 7, a null stack
158.986 -// // trace field is a valid value indicating the stack trace
158.987 -// // should not be set.
158.988 -// getOurStackTrace();
158.989 -//
158.990 -// StackTraceElement[] oldStackTrace = stackTrace;
158.991 -// try {
158.992 -// if (stackTrace == null)
158.993 -// stackTrace = SentinelHolder.STACK_TRACE_SENTINEL;
158.994 -// s.defaultWriteObject();
158.995 -// } finally {
158.996 -// stackTrace = oldStackTrace;
158.997 -// }
158.998 -// }
158.999 -
158.1000 - /**
158.1001 - * Appends the specified exception to the exceptions that were
158.1002 - * suppressed in order to deliver this exception. This method is
158.1003 - * thread-safe and typically called (automatically and implicitly)
158.1004 - * by the {@code try}-with-resources statement.
158.1005 - *
158.1006 - * <p>The suppression behavior is enabled <em>unless</em> disabled
158.1007 - * {@linkplain #Throwable(String, Throwable, boolean, boolean) via
158.1008 - * a constructor}. When suppression is disabled, this method does
158.1009 - * nothing other than to validate its argument.
158.1010 - *
158.1011 - * <p>Note that when one exception {@linkplain
158.1012 - * #initCause(Throwable) causes} another exception, the first
158.1013 - * exception is usually caught and then the second exception is
158.1014 - * thrown in response. In other words, there is a causal
158.1015 - * connection between the two exceptions.
158.1016 - *
158.1017 - * In contrast, there are situations where two independent
158.1018 - * exceptions can be thrown in sibling code blocks, in particular
158.1019 - * in the {@code try} block of a {@code try}-with-resources
158.1020 - * statement and the compiler-generated {@code finally} block
158.1021 - * which closes the resource.
158.1022 - *
158.1023 - * In these situations, only one of the thrown exceptions can be
158.1024 - * propagated. In the {@code try}-with-resources statement, when
158.1025 - * there are two such exceptions, the exception originating from
158.1026 - * the {@code try} block is propagated and the exception from the
158.1027 - * {@code finally} block is added to the list of exceptions
158.1028 - * suppressed by the exception from the {@code try} block. As an
158.1029 - * exception unwinds the stack, it can accumulate multiple
158.1030 - * suppressed exceptions.
158.1031 - *
158.1032 - * <p>An exception may have suppressed exceptions while also being
158.1033 - * caused by another exception. Whether or not an exception has a
158.1034 - * cause is semantically known at the time of its creation, unlike
158.1035 - * whether or not an exception will suppress other exceptions
158.1036 - * which is typically only determined after an exception is
158.1037 - * thrown.
158.1038 - *
158.1039 - * <p>Note that programmer written code is also able to take
158.1040 - * advantage of calling this method in situations where there are
158.1041 - * multiple sibling exceptions and only one can be propagated.
158.1042 - *
158.1043 - * @param exception the exception to be added to the list of
158.1044 - * suppressed exceptions
158.1045 - * @throws IllegalArgumentException if {@code exception} is this
158.1046 - * throwable; a throwable cannot suppress itself.
158.1047 - * @throws NullPointerException if {@code exception} is {@code null}
158.1048 - * @since 1.7
158.1049 - */
158.1050 - public final synchronized void addSuppressed(Throwable exception) {
158.1051 - if (exception == this)
158.1052 - throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
158.1053 -
158.1054 - if (exception == null)
158.1055 - throw new NullPointerException(NULL_CAUSE_MESSAGE);
158.1056 -
158.1057 -// if (suppressedExceptions == null) // Suppressed exceptions not recorded
158.1058 -// return;
158.1059 -//
158.1060 -// if (suppressedExceptions == SUPPRESSED_SENTINEL)
158.1061 -// suppressedExceptions = new ArrayList<Throwable>(1);
158.1062 -//
158.1063 -// suppressedExceptions.add(exception);
158.1064 - }
158.1065 -
158.1066 - private static final Throwable[] EMPTY_THROWABLE_ARRAY = new Throwable[0];
158.1067 -
158.1068 - /**
158.1069 - * Returns an array containing all of the exceptions that were
158.1070 - * suppressed, typically by the {@code try}-with-resources
158.1071 - * statement, in order to deliver this exception.
158.1072 - *
158.1073 - * If no exceptions were suppressed or {@linkplain
158.1074 - * #Throwable(String, Throwable, boolean, boolean) suppression is
158.1075 - * disabled}, an empty array is returned. This method is
158.1076 - * thread-safe. Writes to the returned array do not affect future
158.1077 - * calls to this method.
158.1078 - *
158.1079 - * @return an array containing all of the exceptions that were
158.1080 - * suppressed to deliver this exception.
158.1081 - * @since 1.7
158.1082 - */
158.1083 - public final synchronized Throwable[] getSuppressed() {
158.1084 - return new Throwable[0];
158.1085 -// if (suppressedExceptions == SUPPRESSED_SENTINEL ||
158.1086 -// suppressedExceptions == null)
158.1087 -// return EMPTY_THROWABLE_ARRAY;
158.1088 -// else
158.1089 -// return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY);
158.1090 - }
158.1091 -}
159.1 --- a/emul/src/main/java/java/lang/VirtualMachineError.java Wed Jan 23 20:16:48 2013 +0100
159.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
159.3 @@ -1,54 +0,0 @@
159.4 -/*
159.5 - * Copyright (c) 1995, 1997, Oracle and/or its affiliates. All rights reserved.
159.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
159.7 - *
159.8 - * This code is free software; you can redistribute it and/or modify it
159.9 - * under the terms of the GNU General Public License version 2 only, as
159.10 - * published by the Free Software Foundation. Oracle designates this
159.11 - * particular file as subject to the "Classpath" exception as provided
159.12 - * by Oracle in the LICENSE file that accompanied this code.
159.13 - *
159.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
159.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
159.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
159.17 - * version 2 for more details (a copy is included in the LICENSE file that
159.18 - * accompanied this code).
159.19 - *
159.20 - * You should have received a copy of the GNU General Public License version
159.21 - * 2 along with this work; if not, write to the Free Software Foundation,
159.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
159.23 - *
159.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
159.25 - * or visit www.oracle.com if you need additional information or have any
159.26 - * questions.
159.27 - */
159.28 -
159.29 -package java.lang;
159.30 -
159.31 -/**
159.32 - * Thrown to indicate that the Java Virtual Machine is broken or has
159.33 - * run out of resources necessary for it to continue operating.
159.34 - *
159.35 - *
159.36 - * @author Frank Yellin
159.37 - * @since JDK1.0
159.38 - */
159.39 -abstract public
159.40 -class VirtualMachineError extends Error {
159.41 - /**
159.42 - * Constructs a <code>VirtualMachineError</code> with no detail message.
159.43 - */
159.44 - public VirtualMachineError() {
159.45 - super();
159.46 - }
159.47 -
159.48 - /**
159.49 - * Constructs a <code>VirtualMachineError</code> with the specified
159.50 - * detail message.
159.51 - *
159.52 - * @param s the detail message.
159.53 - */
159.54 - public VirtualMachineError(String s) {
159.55 - super(s);
159.56 - }
159.57 -}
160.1 --- a/emul/src/main/java/java/lang/Void.java Wed Jan 23 20:16:48 2013 +0100
160.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
160.3 @@ -1,49 +0,0 @@
160.4 -/*
160.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
160.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
160.7 - *
160.8 - * This code is free software; you can redistribute it and/or modify it
160.9 - * under the terms of the GNU General Public License version 2 only, as
160.10 - * published by the Free Software Foundation. Oracle designates this
160.11 - * particular file as subject to the "Classpath" exception as provided
160.12 - * by Oracle in the LICENSE file that accompanied this code.
160.13 - *
160.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
160.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
160.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
160.17 - * version 2 for more details (a copy is included in the LICENSE file that
160.18 - * accompanied this code).
160.19 - *
160.20 - * You should have received a copy of the GNU General Public License version
160.21 - * 2 along with this work; if not, write to the Free Software Foundation,
160.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
160.23 - *
160.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
160.25 - * or visit www.oracle.com if you need additional information or have any
160.26 - * questions.
160.27 - */
160.28 -
160.29 -package java.lang;
160.30 -
160.31 -/**
160.32 - * The {@code Void} class is an uninstantiable placeholder class to hold a
160.33 - * reference to the {@code Class} object representing the Java keyword
160.34 - * void.
160.35 - *
160.36 - * @author unascribed
160.37 - * @since JDK1.1
160.38 - */
160.39 -public final
160.40 -class Void {
160.41 -
160.42 - /**
160.43 - * The {@code Class} object representing the pseudo-type corresponding to
160.44 - * the keyword {@code void}.
160.45 - */
160.46 - public static final Class<Void> TYPE = Class.getPrimitiveClass("void");
160.47 -
160.48 - /*
160.49 - * The Void class cannot be instantiated.
160.50 - */
160.51 - private Void() {}
160.52 -}
161.1 --- a/emul/src/main/java/java/lang/annotation/Annotation.java Wed Jan 23 20:16:48 2013 +0100
161.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
161.3 @@ -1,131 +0,0 @@
161.4 -/*
161.5 - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
161.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
161.7 - *
161.8 - * This code is free software; you can redistribute it and/or modify it
161.9 - * under the terms of the GNU General Public License version 2 only, as
161.10 - * published by the Free Software Foundation. Oracle designates this
161.11 - * particular file as subject to the "Classpath" exception as provided
161.12 - * by Oracle in the LICENSE file that accompanied this code.
161.13 - *
161.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
161.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
161.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
161.17 - * version 2 for more details (a copy is included in the LICENSE file that
161.18 - * accompanied this code).
161.19 - *
161.20 - * You should have received a copy of the GNU General Public License version
161.21 - * 2 along with this work; if not, write to the Free Software Foundation,
161.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
161.23 - *
161.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
161.25 - * or visit www.oracle.com if you need additional information or have any
161.26 - * questions.
161.27 - */
161.28 -
161.29 -package java.lang.annotation;
161.30 -
161.31 -/**
161.32 - * The common interface extended by all annotation types. Note that an
161.33 - * interface that manually extends this one does <i>not</i> define
161.34 - * an annotation type. Also note that this interface does not itself
161.35 - * define an annotation type.
161.36 - *
161.37 - * More information about annotation types can be found in section 9.6 of
161.38 - * <cite>The Java™ Language Specification</cite>.
161.39 - *
161.40 - * @author Josh Bloch
161.41 - * @since 1.5
161.42 - */
161.43 -public interface Annotation {
161.44 - /**
161.45 - * Returns true if the specified object represents an annotation
161.46 - * that is logically equivalent to this one. In other words,
161.47 - * returns true if the specified object is an instance of the same
161.48 - * annotation type as this instance, all of whose members are equal
161.49 - * to the corresponding member of this annotation, as defined below:
161.50 - * <ul>
161.51 - * <li>Two corresponding primitive typed members whose values are
161.52 - * <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
161.53 - * unless their type is <tt>float</tt> or <tt>double</tt>.
161.54 - *
161.55 - * <li>Two corresponding <tt>float</tt> members whose values
161.56 - * are <tt>x</tt> and <tt>y</tt> are considered equal if
161.57 - * <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
161.58 - * (Unlike the <tt>==</tt> operator, NaN is considered equal
161.59 - * to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
161.60 - *
161.61 - * <li>Two corresponding <tt>double</tt> members whose values
161.62 - * are <tt>x</tt> and <tt>y</tt> are considered equal if
161.63 - * <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
161.64 - * (Unlike the <tt>==</tt> operator, NaN is considered equal
161.65 - * to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
161.66 - *
161.67 - * <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
161.68 - * annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
161.69 - * are considered equal if <tt>x.equals(y)</tt>. (Note that this
161.70 - * definition is recursive for annotation typed members.)
161.71 - *
161.72 - * <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
161.73 - * are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
161.74 - * appropriate overloading of {@link java.util.Arrays#equals}.
161.75 - * </ul>
161.76 - *
161.77 - * @return true if the specified object represents an annotation
161.78 - * that is logically equivalent to this one, otherwise false
161.79 - */
161.80 - boolean equals(Object obj);
161.81 -
161.82 - /**
161.83 - * Returns the hash code of this annotation, as defined below:
161.84 - *
161.85 - * <p>The hash code of an annotation is the sum of the hash codes
161.86 - * of its members (including those with default values), as defined
161.87 - * below:
161.88 - *
161.89 - * The hash code of an annotation member is (127 times the hash code
161.90 - * of the member-name as computed by {@link String#hashCode()}) XOR
161.91 - * the hash code of the member-value, as defined below:
161.92 - *
161.93 - * <p>The hash code of a member-value depends on its type:
161.94 - * <ul>
161.95 - * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
161.96 - * <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
161.97 - * <tt><i>WrapperType</i></tt> is the wrapper type corresponding
161.98 - * to the primitive type of <tt><i>v</i></tt> ({@link Byte},
161.99 - * {@link Character}, {@link Double}, {@link Float}, {@link Integer},
161.100 - * {@link Long}, {@link Short}, or {@link Boolean}).
161.101 - *
161.102 - * <li>The hash code of a string, enum, class, or annotation member-value
161.103 - I <tt><i>v</i></tt> is computed as by calling
161.104 - * <tt><i>v</i>.hashCode()</tt>. (In the case of annotation
161.105 - * member values, this is a recursive definition.)
161.106 - *
161.107 - * <li>The hash code of an array member-value is computed by calling
161.108 - * the appropriate overloading of
161.109 - * {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
161.110 - * on the value. (There is one overloading for each primitive
161.111 - * type, and one for object reference types.)
161.112 - * </ul>
161.113 - *
161.114 - * @return the hash code of this annotation
161.115 - */
161.116 - int hashCode();
161.117 -
161.118 - /**
161.119 - * Returns a string representation of this annotation. The details
161.120 - * of the representation are implementation-dependent, but the following
161.121 - * may be regarded as typical:
161.122 - * <pre>
161.123 - * @com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
161.124 - * </pre>
161.125 - *
161.126 - * @return a string representation of this annotation
161.127 - */
161.128 - String toString();
161.129 -
161.130 - /**
161.131 - * Returns the annotation type of this annotation.
161.132 - */
161.133 - Class<? extends Annotation> annotationType();
161.134 -}
162.1 --- a/emul/src/main/java/java/lang/annotation/Documented.java Wed Jan 23 20:16:48 2013 +0100
162.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
162.3 @@ -1,43 +0,0 @@
162.4 -/*
162.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
162.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
162.7 - *
162.8 - * This code is free software; you can redistribute it and/or modify it
162.9 - * under the terms of the GNU General Public License version 2 only, as
162.10 - * published by the Free Software Foundation. Oracle designates this
162.11 - * particular file as subject to the "Classpath" exception as provided
162.12 - * by Oracle in the LICENSE file that accompanied this code.
162.13 - *
162.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
162.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
162.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
162.17 - * version 2 for more details (a copy is included in the LICENSE file that
162.18 - * accompanied this code).
162.19 - *
162.20 - * You should have received a copy of the GNU General Public License version
162.21 - * 2 along with this work; if not, write to the Free Software Foundation,
162.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
162.23 - *
162.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
162.25 - * or visit www.oracle.com if you need additional information or have any
162.26 - * questions.
162.27 - */
162.28 -
162.29 -package java.lang.annotation;
162.30 -
162.31 -/**
162.32 - * Indicates that annotations with a type are to be documented by javadoc
162.33 - * and similar tools by default. This type should be used to annotate the
162.34 - * declarations of types whose annotations affect the use of annotated
162.35 - * elements by their clients. If a type declaration is annotated with
162.36 - * Documented, its annotations become part of the public API
162.37 - * of the annotated elements.
162.38 - *
162.39 - * @author Joshua Bloch
162.40 - * @since 1.5
162.41 - */
162.42 -@Documented
162.43 -@Retention(RetentionPolicy.RUNTIME)
162.44 -@Target(ElementType.ANNOTATION_TYPE)
162.45 -public @interface Documented {
162.46 -}
163.1 --- a/emul/src/main/java/java/lang/annotation/ElementType.java Wed Jan 23 20:16:48 2013 +0100
163.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
163.3 @@ -1,63 +0,0 @@
163.4 -/*
163.5 - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
163.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
163.7 - *
163.8 - * This code is free software; you can redistribute it and/or modify it
163.9 - * under the terms of the GNU General Public License version 2 only, as
163.10 - * published by the Free Software Foundation. Oracle designates this
163.11 - * particular file as subject to the "Classpath" exception as provided
163.12 - * by Oracle in the LICENSE file that accompanied this code.
163.13 - *
163.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
163.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
163.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
163.17 - * version 2 for more details (a copy is included in the LICENSE file that
163.18 - * accompanied this code).
163.19 - *
163.20 - * You should have received a copy of the GNU General Public License version
163.21 - * 2 along with this work; if not, write to the Free Software Foundation,
163.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
163.23 - *
163.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
163.25 - * or visit www.oracle.com if you need additional information or have any
163.26 - * questions.
163.27 - */
163.28 -
163.29 -package java.lang.annotation;
163.30 -
163.31 -/**
163.32 - * A program element type. The constants of this enumerated type
163.33 - * provide a simple classification of the declared elements in a
163.34 - * Java program.
163.35 - *
163.36 - * <p>These constants are used with the {@link Target} meta-annotation type
163.37 - * to specify where it is legal to use an annotation type.
163.38 - *
163.39 - * @author Joshua Bloch
163.40 - * @since 1.5
163.41 - */
163.42 -public enum ElementType {
163.43 - /** Class, interface (including annotation type), or enum declaration */
163.44 - TYPE,
163.45 -
163.46 - /** Field declaration (includes enum constants) */
163.47 - FIELD,
163.48 -
163.49 - /** Method declaration */
163.50 - METHOD,
163.51 -
163.52 - /** Parameter declaration */
163.53 - PARAMETER,
163.54 -
163.55 - /** Constructor declaration */
163.56 - CONSTRUCTOR,
163.57 -
163.58 - /** Local variable declaration */
163.59 - LOCAL_VARIABLE,
163.60 -
163.61 - /** Annotation type declaration */
163.62 - ANNOTATION_TYPE,
163.63 -
163.64 - /** Package declaration */
163.65 - PACKAGE
163.66 -}
164.1 --- a/emul/src/main/java/java/lang/annotation/Retention.java Wed Jan 23 20:16:48 2013 +0100
164.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
164.3 @@ -1,47 +0,0 @@
164.4 -/*
164.5 - * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
164.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
164.7 - *
164.8 - * This code is free software; you can redistribute it and/or modify it
164.9 - * under the terms of the GNU General Public License version 2 only, as
164.10 - * published by the Free Software Foundation. Oracle designates this
164.11 - * particular file as subject to the "Classpath" exception as provided
164.12 - * by Oracle in the LICENSE file that accompanied this code.
164.13 - *
164.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
164.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
164.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
164.17 - * version 2 for more details (a copy is included in the LICENSE file that
164.18 - * accompanied this code).
164.19 - *
164.20 - * You should have received a copy of the GNU General Public License version
164.21 - * 2 along with this work; if not, write to the Free Software Foundation,
164.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
164.23 - *
164.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
164.25 - * or visit www.oracle.com if you need additional information or have any
164.26 - * questions.
164.27 - */
164.28 -
164.29 -package java.lang.annotation;
164.30 -
164.31 -/**
164.32 - * Indicates how long annotations with the annotated type are to
164.33 - * be retained. If no Retention annotation is present on
164.34 - * an annotation type declaration, the retention policy defaults to
164.35 - * {@code RetentionPolicy.CLASS}.
164.36 - *
164.37 - * <p>A Retention meta-annotation has effect only if the
164.38 - * meta-annotated type is used directly for annotation. It has no
164.39 - * effect if the meta-annotated type is used as a member type in
164.40 - * another annotation type.
164.41 - *
164.42 - * @author Joshua Bloch
164.43 - * @since 1.5
164.44 - */
164.45 -@Documented
164.46 -@Retention(RetentionPolicy.RUNTIME)
164.47 -@Target(ElementType.ANNOTATION_TYPE)
164.48 -public @interface Retention {
164.49 - RetentionPolicy value();
164.50 -}
165.1 --- a/emul/src/main/java/java/lang/annotation/RetentionPolicy.java Wed Jan 23 20:16:48 2013 +0100
165.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
165.3 @@ -1,57 +0,0 @@
165.4 -/*
165.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
165.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
165.7 - *
165.8 - * This code is free software; you can redistribute it and/or modify it
165.9 - * under the terms of the GNU General Public License version 2 only, as
165.10 - * published by the Free Software Foundation. Oracle designates this
165.11 - * particular file as subject to the "Classpath" exception as provided
165.12 - * by Oracle in the LICENSE file that accompanied this code.
165.13 - *
165.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
165.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
165.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
165.17 - * version 2 for more details (a copy is included in the LICENSE file that
165.18 - * accompanied this code).
165.19 - *
165.20 - * You should have received a copy of the GNU General Public License version
165.21 - * 2 along with this work; if not, write to the Free Software Foundation,
165.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
165.23 - *
165.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
165.25 - * or visit www.oracle.com if you need additional information or have any
165.26 - * questions.
165.27 - */
165.28 -
165.29 -package java.lang.annotation;
165.30 -
165.31 -/**
165.32 - * Annotation retention policy. The constants of this enumerated type
165.33 - * describe the various policies for retaining annotations. They are used
165.34 - * in conjunction with the {@link Retention} meta-annotation type to specify
165.35 - * how long annotations are to be retained.
165.36 - *
165.37 - * @author Joshua Bloch
165.38 - * @since 1.5
165.39 - */
165.40 -public enum RetentionPolicy {
165.41 - /**
165.42 - * Annotations are to be discarded by the compiler.
165.43 - */
165.44 - SOURCE,
165.45 -
165.46 - /**
165.47 - * Annotations are to be recorded in the class file by the compiler
165.48 - * but need not be retained by the VM at run time. This is the default
165.49 - * behavior.
165.50 - */
165.51 - CLASS,
165.52 -
165.53 - /**
165.54 - * Annotations are to be recorded in the class file by the compiler and
165.55 - * retained by the VM at run time, so they may be read reflectively.
165.56 - *
165.57 - * @see java.lang.reflect.AnnotatedElement
165.58 - */
165.59 - RUNTIME
165.60 -}
166.1 --- a/emul/src/main/java/java/lang/annotation/Target.java Wed Jan 23 20:16:48 2013 +0100
166.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
166.3 @@ -1,68 +0,0 @@
166.4 -/*
166.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
166.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
166.7 - *
166.8 - * This code is free software; you can redistribute it and/or modify it
166.9 - * under the terms of the GNU General Public License version 2 only, as
166.10 - * published by the Free Software Foundation. Oracle designates this
166.11 - * particular file as subject to the "Classpath" exception as provided
166.12 - * by Oracle in the LICENSE file that accompanied this code.
166.13 - *
166.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
166.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
166.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
166.17 - * version 2 for more details (a copy is included in the LICENSE file that
166.18 - * accompanied this code).
166.19 - *
166.20 - * You should have received a copy of the GNU General Public License version
166.21 - * 2 along with this work; if not, write to the Free Software Foundation,
166.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
166.23 - *
166.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
166.25 - * or visit www.oracle.com if you need additional information or have any
166.26 - * questions.
166.27 - */
166.28 -
166.29 -package java.lang.annotation;
166.30 -
166.31 -/**
166.32 - * Indicates the kinds of program element to which an annotation type
166.33 - * is applicable. If a Target meta-annotation is not present on an
166.34 - * annotation type declaration, the declared type may be used on any
166.35 - * program element. If such a meta-annotation is present, the compiler
166.36 - * will enforce the specified usage restriction.
166.37 - *
166.38 - * For example, this meta-annotation indicates that the declared type is
166.39 - * itself a meta-annotation type. It can only be used on annotation type
166.40 - * declarations:
166.41 - * <pre>
166.42 - * @Target(ElementType.ANNOTATION_TYPE)
166.43 - * public @interface MetaAnnotationType {
166.44 - * ...
166.45 - * }
166.46 - * </pre>
166.47 - * This meta-annotation indicates that the declared type is intended solely
166.48 - * for use as a member type in complex annotation type declarations. It
166.49 - * cannot be used to annotate anything directly:
166.50 - * <pre>
166.51 - * @Target({})
166.52 - * public @interface MemberType {
166.53 - * ...
166.54 - * }
166.55 - * </pre>
166.56 - * It is a compile-time error for a single ElementType constant to
166.57 - * appear more than once in a Target annotation. For example, the
166.58 - * following meta-annotation is illegal:
166.59 - * <pre>
166.60 - * @Target({ElementType.FIELD, ElementType.METHOD, ElementType.FIELD})
166.61 - * public @interface Bogus {
166.62 - * ...
166.63 - * }
166.64 - * </pre>
166.65 - */
166.66 -@Documented
166.67 -@Retention(RetentionPolicy.RUNTIME)
166.68 -@Target(ElementType.ANNOTATION_TYPE)
166.69 -public @interface Target {
166.70 - ElementType[] value();
166.71 -}
167.1 --- a/emul/src/main/java/java/lang/annotation/UnsupportedOperationException.java Wed Jan 23 20:16:48 2013 +0100
167.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
167.3 @@ -1,94 +0,0 @@
167.4 -/*
167.5 - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
167.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
167.7 - *
167.8 - * This code is free software; you can redistribute it and/or modify it
167.9 - * under the terms of the GNU General Public License version 2 only, as
167.10 - * published by the Free Software Foundation. Oracle designates this
167.11 - * particular file as subject to the "Classpath" exception as provided
167.12 - * by Oracle in the LICENSE file that accompanied this code.
167.13 - *
167.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
167.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
167.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
167.17 - * version 2 for more details (a copy is included in the LICENSE file that
167.18 - * accompanied this code).
167.19 - *
167.20 - * You should have received a copy of the GNU General Public License version
167.21 - * 2 along with this work; if not, write to the Free Software Foundation,
167.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
167.23 - *
167.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
167.25 - * or visit www.oracle.com if you need additional information or have any
167.26 - * questions.
167.27 - */
167.28 -
167.29 -package java.lang;
167.30 -
167.31 -/**
167.32 - * Thrown to indicate that the requested operation is not supported.<p>
167.33 - *
167.34 - * This class is a member of the
167.35 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
167.36 - * Java Collections Framework</a>.
167.37 - *
167.38 - * @author Josh Bloch
167.39 - * @since 1.2
167.40 - */
167.41 -public class UnsupportedOperationException extends RuntimeException {
167.42 - /**
167.43 - * Constructs an UnsupportedOperationException with no detail message.
167.44 - */
167.45 - public UnsupportedOperationException() {
167.46 - }
167.47 -
167.48 - /**
167.49 - * Constructs an UnsupportedOperationException with the specified
167.50 - * detail message.
167.51 - *
167.52 - * @param message the detail message
167.53 - */
167.54 - public UnsupportedOperationException(String message) {
167.55 - super(message);
167.56 - }
167.57 -
167.58 - /**
167.59 - * Constructs a new exception with the specified detail message and
167.60 - * cause.
167.61 - *
167.62 - * <p>Note that the detail message associated with <code>cause</code> is
167.63 - * <i>not</i> automatically incorporated in this exception's detail
167.64 - * message.
167.65 - *
167.66 - * @param message the detail message (which is saved for later retrieval
167.67 - * by the {@link Throwable#getMessage()} method).
167.68 - * @param cause the cause (which is saved for later retrieval by the
167.69 - * {@link Throwable#getCause()} method). (A <tt>null</tt> value
167.70 - * is permitted, and indicates that the cause is nonexistent or
167.71 - * unknown.)
167.72 - * @since 1.5
167.73 - */
167.74 - public UnsupportedOperationException(String message, Throwable cause) {
167.75 - super(message, cause);
167.76 - }
167.77 -
167.78 - /**
167.79 - * Constructs a new exception with the specified cause and a detail
167.80 - * message of <tt>(cause==null ? null : cause.toString())</tt> (which
167.81 - * typically contains the class and detail message of <tt>cause</tt>).
167.82 - * This constructor is useful for exceptions that are little more than
167.83 - * wrappers for other throwables (for example, {@link
167.84 - * java.security.PrivilegedActionException}).
167.85 - *
167.86 - * @param cause the cause (which is saved for later retrieval by the
167.87 - * {@link Throwable#getCause()} method). (A <tt>null</tt> value is
167.88 - * permitted, and indicates that the cause is nonexistent or
167.89 - * unknown.)
167.90 - * @since 1.5
167.91 - */
167.92 - public UnsupportedOperationException(Throwable cause) {
167.93 - super(cause);
167.94 - }
167.95 -
167.96 - static final long serialVersionUID = -1242599979055084673L;
167.97 -}
168.1 --- a/emul/src/main/java/java/lang/reflect/AccessibleObject.java Wed Jan 23 20:16:48 2013 +0100
168.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
168.3 @@ -1,167 +0,0 @@
168.4 -/*
168.5 - * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
168.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
168.7 - *
168.8 - * This code is free software; you can redistribute it and/or modify it
168.9 - * under the terms of the GNU General Public License version 2 only, as
168.10 - * published by the Free Software Foundation. Oracle designates this
168.11 - * particular file as subject to the "Classpath" exception as provided
168.12 - * by Oracle in the LICENSE file that accompanied this code.
168.13 - *
168.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
168.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
168.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
168.17 - * version 2 for more details (a copy is included in the LICENSE file that
168.18 - * accompanied this code).
168.19 - *
168.20 - * You should have received a copy of the GNU General Public License version
168.21 - * 2 along with this work; if not, write to the Free Software Foundation,
168.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
168.23 - *
168.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
168.25 - * or visit www.oracle.com if you need additional information or have any
168.26 - * questions.
168.27 - */
168.28 -
168.29 -package java.lang.reflect;
168.30 -
168.31 -import java.lang.annotation.Annotation;
168.32 -
168.33 -/**
168.34 - * The AccessibleObject class is the base class for Field, Method and
168.35 - * Constructor objects. It provides the ability to flag a reflected
168.36 - * object as suppressing default Java language access control checks
168.37 - * when it is used. The access checks--for public, default (package)
168.38 - * access, protected, and private members--are performed when Fields,
168.39 - * Methods or Constructors are used to set or get fields, to invoke
168.40 - * methods, or to create and initialize new instances of classes,
168.41 - * respectively.
168.42 - *
168.43 - * <p>Setting the {@code accessible} flag in a reflected object
168.44 - * permits sophisticated applications with sufficient privilege, such
168.45 - * as Java Object Serialization or other persistence mechanisms, to
168.46 - * manipulate objects in a manner that would normally be prohibited.
168.47 - *
168.48 - * <p>By default, a reflected object is <em>not</em> accessible.
168.49 - *
168.50 - * @see Field
168.51 - * @see Method
168.52 - * @see Constructor
168.53 - * @see ReflectPermission
168.54 - *
168.55 - * @since 1.2
168.56 - */
168.57 -public class AccessibleObject implements AnnotatedElement {
168.58 -
168.59 - /**
168.60 - * Convenience method to set the {@code accessible} flag for an
168.61 - * array of objects with a single security check (for efficiency).
168.62 - *
168.63 - * <p>First, if there is a security manager, its
168.64 - * {@code checkPermission} method is called with a
168.65 - * {@code ReflectPermission("suppressAccessChecks")} permission.
168.66 - *
168.67 - * <p>A {@code SecurityException} is raised if {@code flag} is
168.68 - * {@code true} but accessibility of any of the elements of the input
168.69 - * {@code array} may not be changed (for example, if the element
168.70 - * object is a {@link Constructor} object for the class {@link
168.71 - * java.lang.Class}). In the event of such a SecurityException, the
168.72 - * accessibility of objects is set to {@code flag} for array elements
168.73 - * upto (and excluding) the element for which the exception occurred; the
168.74 - * accessibility of elements beyond (and including) the element for which
168.75 - * the exception occurred is unchanged.
168.76 - *
168.77 - * @param array the array of AccessibleObjects
168.78 - * @param flag the new value for the {@code accessible} flag
168.79 - * in each object
168.80 - * @throws SecurityException if the request is denied.
168.81 - * @see SecurityManager#checkPermission
168.82 - * @see java.lang.RuntimePermission
168.83 - */
168.84 - public static void setAccessible(AccessibleObject[] array, boolean flag)
168.85 - throws SecurityException {
168.86 - throw new SecurityException();
168.87 - }
168.88 -
168.89 - /**
168.90 - * Set the {@code accessible} flag for this object to
168.91 - * the indicated boolean value. A value of {@code true} indicates that
168.92 - * the reflected object should suppress Java language access
168.93 - * checking when it is used. A value of {@code false} indicates
168.94 - * that the reflected object should enforce Java language access checks.
168.95 - *
168.96 - * <p>First, if there is a security manager, its
168.97 - * {@code checkPermission} method is called with a
168.98 - * {@code ReflectPermission("suppressAccessChecks")} permission.
168.99 - *
168.100 - * <p>A {@code SecurityException} is raised if {@code flag} is
168.101 - * {@code true} but accessibility of this object may not be changed
168.102 - * (for example, if this element object is a {@link Constructor} object for
168.103 - * the class {@link java.lang.Class}).
168.104 - *
168.105 - * <p>A {@code SecurityException} is raised if this object is a {@link
168.106 - * java.lang.reflect.Constructor} object for the class
168.107 - * {@code java.lang.Class}, and {@code flag} is true.
168.108 - *
168.109 - * @param flag the new value for the {@code accessible} flag
168.110 - * @throws SecurityException if the request is denied.
168.111 - * @see SecurityManager#checkPermission
168.112 - * @see java.lang.RuntimePermission
168.113 - */
168.114 - public void setAccessible(boolean flag) throws SecurityException {
168.115 - throw new SecurityException();
168.116 - }
168.117 -
168.118 - /**
168.119 - * Get the value of the {@code accessible} flag for this object.
168.120 - *
168.121 - * @return the value of the object's {@code accessible} flag
168.122 - */
168.123 - public boolean isAccessible() {
168.124 - return override;
168.125 - }
168.126 -
168.127 - /**
168.128 - * Constructor: only used by the Java Virtual Machine.
168.129 - */
168.130 - protected AccessibleObject() {}
168.131 -
168.132 - // Indicates whether language-level access checks are overridden
168.133 - // by this object. Initializes to "false". This field is used by
168.134 - // Field, Method, and Constructor.
168.135 - //
168.136 - // NOTE: for security purposes, this field must not be visible
168.137 - // outside this package.
168.138 - boolean override;
168.139 -
168.140 - /**
168.141 - * @throws NullPointerException {@inheritDoc}
168.142 - * @since 1.5
168.143 - */
168.144 - public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
168.145 - throw new AssertionError("All subclasses should override this method");
168.146 - }
168.147 -
168.148 - /**
168.149 - * @throws NullPointerException {@inheritDoc}
168.150 - * @since 1.5
168.151 - */
168.152 - public boolean isAnnotationPresent(
168.153 - Class<? extends Annotation> annotationClass) {
168.154 - return getAnnotation(annotationClass) != null;
168.155 - }
168.156 -
168.157 - /**
168.158 - * @since 1.5
168.159 - */
168.160 - public Annotation[] getAnnotations() {
168.161 - return getDeclaredAnnotations();
168.162 - }
168.163 -
168.164 - /**
168.165 - * @since 1.5
168.166 - */
168.167 - public Annotation[] getDeclaredAnnotations() {
168.168 - throw new AssertionError("All subclasses should override this method");
168.169 - }
168.170 -}
169.1 --- a/emul/src/main/java/java/lang/reflect/AnnotatedElement.java Wed Jan 23 20:16:48 2013 +0100
169.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
169.3 @@ -1,112 +0,0 @@
169.4 -/*
169.5 - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
169.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
169.7 - *
169.8 - * This code is free software; you can redistribute it and/or modify it
169.9 - * under the terms of the GNU General Public License version 2 only, as
169.10 - * published by the Free Software Foundation. Oracle designates this
169.11 - * particular file as subject to the "Classpath" exception as provided
169.12 - * by Oracle in the LICENSE file that accompanied this code.
169.13 - *
169.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
169.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
169.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
169.17 - * version 2 for more details (a copy is included in the LICENSE file that
169.18 - * accompanied this code).
169.19 - *
169.20 - * You should have received a copy of the GNU General Public License version
169.21 - * 2 along with this work; if not, write to the Free Software Foundation,
169.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
169.23 - *
169.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
169.25 - * or visit www.oracle.com if you need additional information or have any
169.26 - * questions.
169.27 - */
169.28 -
169.29 -package java.lang.reflect;
169.30 -
169.31 -import java.lang.annotation.Annotation;
169.32 -
169.33 -/**
169.34 - * Represents an annotated element of the program currently running in this
169.35 - * VM. This interface allows annotations to be read reflectively. All
169.36 - * annotations returned by methods in this interface are immutable and
169.37 - * serializable. It is permissible for the caller to modify the
169.38 - * arrays returned by accessors for array-valued enum members; it will
169.39 - * have no affect on the arrays returned to other callers.
169.40 - *
169.41 - * <p>If an annotation returned by a method in this interface contains
169.42 - * (directly or indirectly) a {@link Class}-valued member referring to
169.43 - * a class that is not accessible in this VM, attempting to read the class
169.44 - * by calling the relevant Class-returning method on the returned annotation
169.45 - * will result in a {@link TypeNotPresentException}.
169.46 - *
169.47 - * <p>Similarly, attempting to read an enum-valued member will result in
169.48 - * a {@link EnumConstantNotPresentException} if the enum constant in the
169.49 - * annotation is no longer present in the enum type.
169.50 - *
169.51 - * <p>Finally, Attempting to read a member whose definition has evolved
169.52 - * incompatibly will result in a {@link
169.53 - * java.lang.annotation.AnnotationTypeMismatchException} or an
169.54 - * {@link java.lang.annotation.IncompleteAnnotationException}.
169.55 - *
169.56 - * @see java.lang.EnumConstantNotPresentException
169.57 - * @see java.lang.TypeNotPresentException
169.58 - * @see java.lang.annotation.AnnotationFormatError
169.59 - * @see java.lang.annotation.AnnotationTypeMismatchException
169.60 - * @see java.lang.annotation.IncompleteAnnotationException
169.61 - * @since 1.5
169.62 - * @author Josh Bloch
169.63 - */
169.64 -public interface AnnotatedElement {
169.65 - /**
169.66 - * Returns true if an annotation for the specified type
169.67 - * is present on this element, else false. This method
169.68 - * is designed primarily for convenient access to marker annotations.
169.69 - *
169.70 - * @param annotationClass the Class object corresponding to the
169.71 - * annotation type
169.72 - * @return true if an annotation for the specified annotation
169.73 - * type is present on this element, else false
169.74 - * @throws NullPointerException if the given annotation class is null
169.75 - * @since 1.5
169.76 - */
169.77 - boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
169.78 -
169.79 - /**
169.80 - * Returns this element's annotation for the specified type if
169.81 - * such an annotation is present, else null.
169.82 - *
169.83 - * @param annotationClass the Class object corresponding to the
169.84 - * annotation type
169.85 - * @return this element's annotation for the specified annotation type if
169.86 - * present on this element, else null
169.87 - * @throws NullPointerException if the given annotation class is null
169.88 - * @since 1.5
169.89 - */
169.90 - <T extends Annotation> T getAnnotation(Class<T> annotationClass);
169.91 -
169.92 - /**
169.93 - * Returns all annotations present on this element. (Returns an array
169.94 - * of length zero if this element has no annotations.) The caller of
169.95 - * this method is free to modify the returned array; it will have no
169.96 - * effect on the arrays returned to other callers.
169.97 - *
169.98 - * @return all annotations present on this element
169.99 - * @since 1.5
169.100 - */
169.101 - Annotation[] getAnnotations();
169.102 -
169.103 - /**
169.104 - * Returns all annotations that are directly present on this
169.105 - * element. Unlike the other methods in this interface, this method
169.106 - * ignores inherited annotations. (Returns an array of length zero if
169.107 - * no annotations are directly present on this element.) The caller of
169.108 - * this method is free to modify the returned array; it will have no
169.109 - * effect on the arrays returned to other callers.
169.110 - *
169.111 - * @return All annotations directly present on this element
169.112 - * @since 1.5
169.113 - */
169.114 - Annotation[] getDeclaredAnnotations();
169.115 -}
170.1 --- a/emul/src/main/java/java/lang/reflect/Array.java Wed Jan 23 20:16:48 2013 +0100
170.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
170.3 @@ -1,659 +0,0 @@
170.4 -/*
170.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
170.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
170.7 - *
170.8 - * This code is free software; you can redistribute it and/or modify it
170.9 - * under the terms of the GNU General Public License version 2 only, as
170.10 - * published by the Free Software Foundation. Oracle designates this
170.11 - * particular file as subject to the "Classpath" exception as provided
170.12 - * by Oracle in the LICENSE file that accompanied this code.
170.13 - *
170.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
170.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
170.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
170.17 - * version 2 for more details (a copy is included in the LICENSE file that
170.18 - * accompanied this code).
170.19 - *
170.20 - * You should have received a copy of the GNU General Public License version
170.21 - * 2 along with this work; if not, write to the Free Software Foundation,
170.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
170.23 - *
170.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
170.25 - * or visit www.oracle.com if you need additional information or have any
170.26 - * questions.
170.27 - */
170.28 -
170.29 -package java.lang.reflect;
170.30 -
170.31 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
170.32 -import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
170.33 -
170.34 -/**
170.35 - * The {@code Array} class provides static methods to dynamically create and
170.36 - * access Java arrays.
170.37 - *
170.38 - * <p>{@code Array} permits widening conversions to occur during a get or set
170.39 - * operation, but throws an {@code IllegalArgumentException} if a narrowing
170.40 - * conversion would occur.
170.41 - *
170.42 - * @author Nakul Saraiya
170.43 - */
170.44 -@JavaScriptPrototype(prototype = "new Array", container = "Array.prototype")
170.45 -public final
170.46 -class Array {
170.47 -
170.48 - /**
170.49 - * Constructor. Class Array is not instantiable.
170.50 - */
170.51 - private Array() {}
170.52 -
170.53 - /**
170.54 - * Creates a new array with the specified component type and
170.55 - * length.
170.56 - * Invoking this method is equivalent to creating an array
170.57 - * as follows:
170.58 - * <blockquote>
170.59 - * <pre>
170.60 - * int[] x = {length};
170.61 - * Array.newInstance(componentType, x);
170.62 - * </pre>
170.63 - * </blockquote>
170.64 - *
170.65 - * @param componentType the {@code Class} object representing the
170.66 - * component type of the new array
170.67 - * @param length the length of the new array
170.68 - * @return the new array
170.69 - * @exception NullPointerException if the specified
170.70 - * {@code componentType} parameter is null
170.71 - * @exception IllegalArgumentException if componentType is {@link Void#TYPE}
170.72 - * @exception NegativeArraySizeException if the specified {@code length}
170.73 - * is negative
170.74 - */
170.75 - public static Object newInstance(Class<?> componentType, int length)
170.76 - throws NegativeArraySizeException {
170.77 - if (length < 0) {
170.78 - throw new NegativeArraySizeException();
170.79 - }
170.80 - String sig = findSignature(componentType);
170.81 - return newArray(componentType.isPrimitive(), sig, length);
170.82 - }
170.83 -
170.84 - private static String findSignature(Class<?> type) {
170.85 - if (type == Integer.TYPE) {
170.86 - return "[I";
170.87 - }
170.88 - if (type == Long.TYPE) {
170.89 - return "[J";
170.90 - }
170.91 - if (type == Double.TYPE) {
170.92 - return "[D";
170.93 - }
170.94 - if (type == Float.TYPE) {
170.95 - return "[F";
170.96 - }
170.97 - if (type == Byte.TYPE) {
170.98 - return "[B";
170.99 - }
170.100 - if (type == Boolean.TYPE) {
170.101 - return "[Z";
170.102 - }
170.103 - if (type == Short.TYPE) {
170.104 - return "[S";
170.105 - }
170.106 - if (type == Character.TYPE) {
170.107 - return "[C";
170.108 - }
170.109 - if (type.getName().equals("void")) {
170.110 - throw new IllegalStateException("Can't create array for " + type);
170.111 - }
170.112 - return "[L" + type.getName() + ";";
170.113 - }
170.114 - /**
170.115 - * Creates a new array
170.116 - * with the specified component type and dimensions.
170.117 - * If {@code componentType}
170.118 - * represents a non-array class or interface, the new array
170.119 - * has {@code dimensions.length} dimensions and
170.120 - * {@code componentType} as its component type. If
170.121 - * {@code componentType} represents an array class, the
170.122 - * number of dimensions of the new array is equal to the sum
170.123 - * of {@code dimensions.length} and the number of
170.124 - * dimensions of {@code componentType}. In this case, the
170.125 - * component type of the new array is the component type of
170.126 - * {@code componentType}.
170.127 - *
170.128 - * <p>The number of dimensions of the new array must not
170.129 - * exceed the number of array dimensions supported by the
170.130 - * implementation (typically 255).
170.131 - *
170.132 - * @param componentType the {@code Class} object representing the component
170.133 - * type of the new array
170.134 - * @param dimensions an array of {@code int} representing the dimensions of
170.135 - * the new array
170.136 - * @return the new array
170.137 - * @exception NullPointerException if the specified
170.138 - * {@code componentType} argument is null
170.139 - * @exception IllegalArgumentException if the specified {@code dimensions}
170.140 - * argument is a zero-dimensional array, or if the number of
170.141 - * requested dimensions exceeds the limit on the number of array dimensions
170.142 - * supported by the implementation (typically 255), or if componentType
170.143 - * is {@link Void#TYPE}.
170.144 - * @exception NegativeArraySizeException if any of the components in
170.145 - * the specified {@code dimensions} argument is negative.
170.146 - */
170.147 - public static Object newInstance(Class<?> componentType, int... dimensions)
170.148 - throws IllegalArgumentException, NegativeArraySizeException {
170.149 - StringBuilder sig = new StringBuilder();
170.150 - for (int i = 1; i < dimensions.length; i++) {
170.151 - sig.append('[');
170.152 - }
170.153 - sig.append(findSignature(componentType));
170.154 - return multiNewArray(sig.toString(), dimensions, 0);
170.155 - }
170.156 -
170.157 - /**
170.158 - * Returns the length of the specified array object, as an {@code int}.
170.159 - *
170.160 - * @param array the array
170.161 - * @return the length of the array
170.162 - * @exception IllegalArgumentException if the object argument is not
170.163 - * an array
170.164 - */
170.165 - public static int getLength(Object array)
170.166 - throws IllegalArgumentException {
170.167 - if (!array.getClass().isArray()) {
170.168 - throw new IllegalArgumentException("Argument is not an array");
170.169 - }
170.170 - return length(array);
170.171 - }
170.172 -
170.173 - @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
170.174 - private static native int length(Object arr);
170.175 -
170.176 - /**
170.177 - * Returns the value of the indexed component in the specified
170.178 - * array object. The value is automatically wrapped in an object
170.179 - * if it has a primitive type.
170.180 - *
170.181 - * @param array the array
170.182 - * @param index the index
170.183 - * @return the (possibly wrapped) value of the indexed component in
170.184 - * the specified array
170.185 - * @exception NullPointerException If the specified object is null
170.186 - * @exception IllegalArgumentException If the specified object is not
170.187 - * an array
170.188 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.189 - * argument is negative, or if it is greater than or equal to the
170.190 - * length of the specified array
170.191 - */
170.192 - public static Object get(Object array, int index)
170.193 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.194 - final Class<?> t = array.getClass().getComponentType();
170.195 - if (t.isPrimitive()) {
170.196 - return Array.fromPrimitive(t, array, index);
170.197 - } else {
170.198 - return ((Object[])array)[index];
170.199 - }
170.200 - }
170.201 -
170.202 - /**
170.203 - * Returns the value of the indexed component in the specified
170.204 - * array object, as a {@code boolean}.
170.205 - *
170.206 - * @param array the array
170.207 - * @param index the index
170.208 - * @return the value of the indexed component in the specified array
170.209 - * @exception NullPointerException If the specified object is null
170.210 - * @exception IllegalArgumentException If the specified object is not
170.211 - * an array, or if the indexed element cannot be converted to the
170.212 - * return type by an identity or widening conversion
170.213 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.214 - * argument is negative, or if it is greater than or equal to the
170.215 - * length of the specified array
170.216 - * @see Array#get
170.217 - */
170.218 - public static native boolean getBoolean(Object array, int index)
170.219 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
170.220 -
170.221 - /**
170.222 - * Returns the value of the indexed component in the specified
170.223 - * array object, as a {@code byte}.
170.224 - *
170.225 - * @param array the array
170.226 - * @param index the index
170.227 - * @return the value of the indexed component in the specified array
170.228 - * @exception NullPointerException If the specified object is null
170.229 - * @exception IllegalArgumentException If the specified object is not
170.230 - * an array, or if the indexed element cannot be converted to the
170.231 - * return type by an identity or widening conversion
170.232 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.233 - * argument is negative, or if it is greater than or equal to the
170.234 - * length of the specified array
170.235 - * @see Array#get
170.236 - */
170.237 - public static byte getByte(Object array, int index)
170.238 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.239 - if (array.getClass().getComponentType() != Byte.TYPE) {
170.240 - throw new IllegalArgumentException();
170.241 - }
170.242 - byte[] arr = (byte[]) array;
170.243 - return arr[index];
170.244 - }
170.245 -
170.246 - /**
170.247 - * Returns the value of the indexed component in the specified
170.248 - * array object, as a {@code char}.
170.249 - *
170.250 - * @param array the array
170.251 - * @param index the index
170.252 - * @return the value of the indexed component in the specified array
170.253 - * @exception NullPointerException If the specified object is null
170.254 - * @exception IllegalArgumentException If the specified object is not
170.255 - * an array, or if the indexed element cannot be converted to the
170.256 - * return type by an identity or widening conversion
170.257 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.258 - * argument is negative, or if it is greater than or equal to the
170.259 - * length of the specified array
170.260 - * @see Array#get
170.261 - */
170.262 - public static native char getChar(Object array, int index)
170.263 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
170.264 -
170.265 - /**
170.266 - * Returns the value of the indexed component in the specified
170.267 - * array object, as a {@code short}.
170.268 - *
170.269 - * @param array the array
170.270 - * @param index the index
170.271 - * @return the value of the indexed component in the specified array
170.272 - * @exception NullPointerException If the specified object is null
170.273 - * @exception IllegalArgumentException If the specified object is not
170.274 - * an array, or if the indexed element cannot be converted to the
170.275 - * return type by an identity or widening conversion
170.276 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.277 - * argument is negative, or if it is greater than or equal to the
170.278 - * length of the specified array
170.279 - * @see Array#get
170.280 - */
170.281 - public static short getShort(Object array, int index)
170.282 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.283 - final Class<?> t = array.getClass().getComponentType();
170.284 - if (t == Short.TYPE) {
170.285 - short[] arr = (short[]) array;
170.286 - return arr[index];
170.287 - }
170.288 - return getByte(array, index);
170.289 - }
170.290 -
170.291 - /**
170.292 - * Returns the value of the indexed component in the specified
170.293 - * array object, as an {@code int}.
170.294 - *
170.295 - * @param array the array
170.296 - * @param index the index
170.297 - * @return the value of the indexed component in the specified array
170.298 - * @exception NullPointerException If the specified object is null
170.299 - * @exception IllegalArgumentException If the specified object is not
170.300 - * an array, or if the indexed element cannot be converted to the
170.301 - * return type by an identity or widening conversion
170.302 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.303 - * argument is negative, or if it is greater than or equal to the
170.304 - * length of the specified array
170.305 - * @see Array#get
170.306 - */
170.307 - public static int getInt(Object array, int index)
170.308 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.309 - final Class<?> t = array.getClass().getComponentType();
170.310 - if (t == Integer.TYPE) {
170.311 - int[] arr = (int[]) array;
170.312 - return arr[index];
170.313 - }
170.314 - return getShort(array, index);
170.315 - }
170.316 -
170.317 - /**
170.318 - * Returns the value of the indexed component in the specified
170.319 - * array object, as a {@code long}.
170.320 - *
170.321 - * @param array the array
170.322 - * @param index the index
170.323 - * @return the value of the indexed component in the specified array
170.324 - * @exception NullPointerException If the specified object is null
170.325 - * @exception IllegalArgumentException If the specified object is not
170.326 - * an array, or if the indexed element cannot be converted to the
170.327 - * return type by an identity or widening conversion
170.328 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.329 - * argument is negative, or if it is greater than or equal to the
170.330 - * length of the specified array
170.331 - * @see Array#get
170.332 - */
170.333 - public static long getLong(Object array, int index)
170.334 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.335 - final Class<?> t = array.getClass().getComponentType();
170.336 - if (t == Long.TYPE) {
170.337 - long[] arr = (long[]) array;
170.338 - return arr[index];
170.339 - }
170.340 - return getInt(array, index);
170.341 - }
170.342 -
170.343 - /**
170.344 - * Returns the value of the indexed component in the specified
170.345 - * array object, as a {@code float}.
170.346 - *
170.347 - * @param array the array
170.348 - * @param index the index
170.349 - * @return the value of the indexed component in the specified array
170.350 - * @exception NullPointerException If the specified object is null
170.351 - * @exception IllegalArgumentException If the specified object is not
170.352 - * an array, or if the indexed element cannot be converted to the
170.353 - * return type by an identity or widening conversion
170.354 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.355 - * argument is negative, or if it is greater than or equal to the
170.356 - * length of the specified array
170.357 - * @see Array#get
170.358 - */
170.359 - public static float getFloat(Object array, int index)
170.360 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.361 - final Class<?> t = array.getClass().getComponentType();
170.362 - if (t == Float.TYPE) {
170.363 - float[] arr = (float[]) array;
170.364 - return arr[index];
170.365 - }
170.366 - return getLong(array, index);
170.367 - }
170.368 -
170.369 - /**
170.370 - * Returns the value of the indexed component in the specified
170.371 - * array object, as a {@code double}.
170.372 - *
170.373 - * @param array the array
170.374 - * @param index the index
170.375 - * @return the value of the indexed component in the specified array
170.376 - * @exception NullPointerException If the specified object is null
170.377 - * @exception IllegalArgumentException If the specified object is not
170.378 - * an array, or if the indexed element cannot be converted to the
170.379 - * return type by an identity or widening conversion
170.380 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.381 - * argument is negative, or if it is greater than or equal to the
170.382 - * length of the specified array
170.383 - * @see Array#get
170.384 - */
170.385 - public static double getDouble(Object array, int index)
170.386 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.387 - final Class<?> t = array.getClass().getComponentType();
170.388 - if (t == Double.TYPE) {
170.389 - double[] arr = (double[]) array;
170.390 - return arr[index];
170.391 - }
170.392 - return getFloat(array, index);
170.393 - }
170.394 -
170.395 - /**
170.396 - * Sets the value of the indexed component of the specified array
170.397 - * object to the specified new value. The new value is first
170.398 - * automatically unwrapped if the array has a primitive component
170.399 - * type.
170.400 - * @param array the array
170.401 - * @param index the index into the array
170.402 - * @param value the new value of the indexed component
170.403 - * @exception NullPointerException If the specified object argument
170.404 - * is null
170.405 - * @exception IllegalArgumentException If the specified object argument
170.406 - * is not an array, or if the array component type is primitive and
170.407 - * an unwrapping conversion fails
170.408 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.409 - * argument is negative, or if it is greater than or equal to
170.410 - * the length of the specified array
170.411 - */
170.412 - public static void set(Object array, int index, Object value)
170.413 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.414 - if (array.getClass().getComponentType().isPrimitive()) {
170.415 - throw new IllegalArgumentException();
170.416 - } else {
170.417 - Object[] arr = (Object[])array;
170.418 - arr[index] = value;
170.419 - }
170.420 - }
170.421 -
170.422 - /**
170.423 - * Sets the value of the indexed component of the specified array
170.424 - * object to the specified {@code boolean} value.
170.425 - * @param array the array
170.426 - * @param index the index into the array
170.427 - * @param z the new value of the indexed component
170.428 - * @exception NullPointerException If the specified object argument
170.429 - * is null
170.430 - * @exception IllegalArgumentException If the specified object argument
170.431 - * is not an array, or if the specified value cannot be converted
170.432 - * to the underlying array's component type by an identity or a
170.433 - * primitive widening conversion
170.434 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.435 - * argument is negative, or if it is greater than or equal to
170.436 - * the length of the specified array
170.437 - * @see Array#set
170.438 - */
170.439 - public static native void setBoolean(Object array, int index, boolean z)
170.440 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
170.441 -
170.442 - /**
170.443 - * Sets the value of the indexed component of the specified array
170.444 - * object to the specified {@code byte} value.
170.445 - * @param array the array
170.446 - * @param index the index into the array
170.447 - * @param b the new value of the indexed component
170.448 - * @exception NullPointerException If the specified object argument
170.449 - * is null
170.450 - * @exception IllegalArgumentException If the specified object argument
170.451 - * is not an array, or if the specified value cannot be converted
170.452 - * to the underlying array's component type by an identity or a
170.453 - * primitive widening conversion
170.454 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.455 - * argument is negative, or if it is greater than or equal to
170.456 - * the length of the specified array
170.457 - * @see Array#set
170.458 - */
170.459 - public static void setByte(Object array, int index, byte b)
170.460 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.461 - Class<?> t = array.getClass().getComponentType();
170.462 - if (t == Byte.TYPE) {
170.463 - byte[] arr = (byte[]) array;
170.464 - arr[index] = b;
170.465 - } else {
170.466 - setShort(array, index, b);
170.467 - }
170.468 - }
170.469 -
170.470 - /**
170.471 - * Sets the value of the indexed component of the specified array
170.472 - * object to the specified {@code char} value.
170.473 - * @param array the array
170.474 - * @param index the index into the array
170.475 - * @param c the new value of the indexed component
170.476 - * @exception NullPointerException If the specified object argument
170.477 - * is null
170.478 - * @exception IllegalArgumentException If the specified object argument
170.479 - * is not an array, or if the specified value cannot be converted
170.480 - * to the underlying array's component type by an identity or a
170.481 - * primitive widening conversion
170.482 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.483 - * argument is negative, or if it is greater than or equal to
170.484 - * the length of the specified array
170.485 - * @see Array#set
170.486 - */
170.487 - public static native void setChar(Object array, int index, char c)
170.488 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
170.489 -
170.490 - /**
170.491 - * Sets the value of the indexed component of the specified array
170.492 - * object to the specified {@code short} value.
170.493 - * @param array the array
170.494 - * @param index the index into the array
170.495 - * @param s the new value of the indexed component
170.496 - * @exception NullPointerException If the specified object argument
170.497 - * is null
170.498 - * @exception IllegalArgumentException If the specified object argument
170.499 - * is not an array, or if the specified value cannot be converted
170.500 - * to the underlying array's component type by an identity or a
170.501 - * primitive widening conversion
170.502 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.503 - * argument is negative, or if it is greater than or equal to
170.504 - * the length of the specified array
170.505 - * @see Array#set
170.506 - */
170.507 - public static void setShort(Object array, int index, short s)
170.508 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.509 - Class<?> t = array.getClass().getComponentType();
170.510 - if (t == Short.TYPE) {
170.511 - short[] arr = (short[]) array;
170.512 - arr[index] = s;
170.513 - } else {
170.514 - setInt(array, index, s);
170.515 - }
170.516 -
170.517 - }
170.518 -
170.519 - /**
170.520 - * Sets the value of the indexed component of the specified array
170.521 - * object to the specified {@code int} value.
170.522 - * @param array the array
170.523 - * @param index the index into the array
170.524 - * @param i the new value of the indexed component
170.525 - * @exception NullPointerException If the specified object argument
170.526 - * is null
170.527 - * @exception IllegalArgumentException If the specified object argument
170.528 - * is not an array, or if the specified value cannot be converted
170.529 - * to the underlying array's component type by an identity or a
170.530 - * primitive widening conversion
170.531 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.532 - * argument is negative, or if it is greater than or equal to
170.533 - * the length of the specified array
170.534 - * @see Array#set
170.535 - */
170.536 - public static void setInt(Object array, int index, int i)
170.537 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.538 - Class<?> t = array.getClass().getComponentType();
170.539 - if (t == Integer.TYPE) {
170.540 - long[] arr = (long[]) array;
170.541 - arr[index] = i;
170.542 - } else {
170.543 - setLong(array, index, i);
170.544 - }
170.545 - }
170.546 -
170.547 - /**
170.548 - * Sets the value of the indexed component of the specified array
170.549 - * object to the specified {@code long} value.
170.550 - * @param array the array
170.551 - * @param index the index into the array
170.552 - * @param l the new value of the indexed component
170.553 - * @exception NullPointerException If the specified object argument
170.554 - * is null
170.555 - * @exception IllegalArgumentException If the specified object argument
170.556 - * is not an array, or if the specified value cannot be converted
170.557 - * to the underlying array's component type by an identity or a
170.558 - * primitive widening conversion
170.559 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.560 - * argument is negative, or if it is greater than or equal to
170.561 - * the length of the specified array
170.562 - * @see Array#set
170.563 - */
170.564 - public static void setLong(Object array, int index, long l)
170.565 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.566 - Class<?> t = array.getClass().getComponentType();
170.567 - if (t == Long.TYPE) {
170.568 - long[] arr = (long[]) array;
170.569 - arr[index] = l;
170.570 - } else {
170.571 - setFloat(array, index, l);
170.572 - }
170.573 - }
170.574 -
170.575 - /**
170.576 - * Sets the value of the indexed component of the specified array
170.577 - * object to the specified {@code float} value.
170.578 - * @param array the array
170.579 - * @param index the index into the array
170.580 - * @param f the new value of the indexed component
170.581 - * @exception NullPointerException If the specified object argument
170.582 - * is null
170.583 - * @exception IllegalArgumentException If the specified object argument
170.584 - * is not an array, or if the specified value cannot be converted
170.585 - * to the underlying array's component type by an identity or a
170.586 - * primitive widening conversion
170.587 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.588 - * argument is negative, or if it is greater than or equal to
170.589 - * the length of the specified array
170.590 - * @see Array#set
170.591 - */
170.592 - public static void setFloat(Object array, int index, float f)
170.593 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.594 - Class<?> t = array.getClass().getComponentType();
170.595 - if (t == Float.TYPE) {
170.596 - float[] arr = (float[])array;
170.597 - arr[index] = f;
170.598 - } else {
170.599 - setDouble(array, index, f);
170.600 - }
170.601 - }
170.602 -
170.603 - /**
170.604 - * Sets the value of the indexed component of the specified array
170.605 - * object to the specified {@code double} value.
170.606 - * @param array the array
170.607 - * @param index the index into the array
170.608 - * @param d the new value of the indexed component
170.609 - * @exception NullPointerException If the specified object argument
170.610 - * is null
170.611 - * @exception IllegalArgumentException If the specified object argument
170.612 - * is not an array, or if the specified value cannot be converted
170.613 - * to the underlying array's component type by an identity or a
170.614 - * primitive widening conversion
170.615 - * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
170.616 - * argument is negative, or if it is greater than or equal to
170.617 - * the length of the specified array
170.618 - * @see Array#set
170.619 - */
170.620 - public static void setDouble(Object array, int index, double d)
170.621 - throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
170.622 - Class<?> t = array.getClass().getComponentType();
170.623 - if (t == Double.TYPE) {
170.624 - double[] arr = (double[])array;
170.625 - arr[index] = d;
170.626 - } else {
170.627 - throw new IllegalArgumentException("argument type mismatch");
170.628 - }
170.629 - }
170.630 -
170.631 - /*
170.632 - * Private
170.633 - */
170.634 -
170.635 - @JavaScriptBody(args = { "primitive", "sig", "length" }, body =
170.636 - "var arr = new Array(length);\n"
170.637 - + "var value = primitive ? 0 : null;\n"
170.638 - + "for(var i = 0; i < length; i++) arr[i] = value;\n"
170.639 - + "arr.jvmName = sig;\n"
170.640 - + "return arr;"
170.641 - )
170.642 - private static native Object newArray(boolean primitive, String sig, int length);
170.643 -
170.644 - private static Object multiNewArray(String sig, int[] dims, int index)
170.645 - throws IllegalArgumentException, NegativeArraySizeException {
170.646 - if (dims.length == index + 1) {
170.647 - return newArray(sig.length() == 2, sig, dims[index]);
170.648 - }
170.649 - Object[] arr = (Object[]) newArray(false, sig, dims[index]);
170.650 - String compsig = sig.substring(1);
170.651 - for (int i = 0; i < arr.length; i++) {
170.652 - arr[i] = multiNewArray(compsig, dims, index + 1);
170.653 - }
170.654 - return arr;
170.655 - }
170.656 - private static Object fromPrimitive(Class<?> t, Object array, int index) {
170.657 - return Method.fromPrimitive(t, atArray(array, index));
170.658 - }
170.659 -
170.660 - @JavaScriptBody(args = { "array", "index" }, body = "return array[index]")
170.661 - private static native Object atArray(Object array, int index);
170.662 -}
171.1 --- a/emul/src/main/java/java/lang/reflect/Field.java Wed Jan 23 20:16:48 2013 +0100
171.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
171.3 @@ -1,953 +0,0 @@
171.4 -/*
171.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
171.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
171.7 - *
171.8 - * This code is free software; you can redistribute it and/or modify it
171.9 - * under the terms of the GNU General Public License version 2 only, as
171.10 - * published by the Free Software Foundation. Oracle designates this
171.11 - * particular file as subject to the "Classpath" exception as provided
171.12 - * by Oracle in the LICENSE file that accompanied this code.
171.13 - *
171.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
171.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
171.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
171.17 - * version 2 for more details (a copy is included in the LICENSE file that
171.18 - * accompanied this code).
171.19 - *
171.20 - * You should have received a copy of the GNU General Public License version
171.21 - * 2 along with this work; if not, write to the Free Software Foundation,
171.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
171.23 - *
171.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
171.25 - * or visit www.oracle.com if you need additional information or have any
171.26 - * questions.
171.27 - */
171.28 -
171.29 -package java.lang.reflect;
171.30 -
171.31 -import java.lang.annotation.Annotation;
171.32 -
171.33 -
171.34 -/**
171.35 - * A {@code Field} provides information about, and dynamic access to, a
171.36 - * single field of a class or an interface. The reflected field may
171.37 - * be a class (static) field or an instance field.
171.38 - *
171.39 - * <p>A {@code Field} permits widening conversions to occur during a get or
171.40 - * set access operation, but throws an {@code IllegalArgumentException} if a
171.41 - * narrowing conversion would occur.
171.42 - *
171.43 - * @see Member
171.44 - * @see java.lang.Class
171.45 - * @see java.lang.Class#getFields()
171.46 - * @see java.lang.Class#getField(String)
171.47 - * @see java.lang.Class#getDeclaredFields()
171.48 - * @see java.lang.Class#getDeclaredField(String)
171.49 - *
171.50 - * @author Kenneth Russell
171.51 - * @author Nakul Saraiya
171.52 - */
171.53 -public final
171.54 -class Field extends AccessibleObject implements Member {
171.55 -
171.56 - private Class<?> clazz;
171.57 - private int slot;
171.58 - // This is guaranteed to be interned by the VM in the 1.4
171.59 - // reflection implementation
171.60 - private String name;
171.61 - private Class<?> type;
171.62 - private int modifiers;
171.63 - // Generics and annotations support
171.64 - private transient String signature;
171.65 - private byte[] annotations;
171.66 - // For sharing of FieldAccessors. This branching structure is
171.67 - // currently only two levels deep (i.e., one root Field and
171.68 - // potentially many Field objects pointing to it.)
171.69 - private Field root;
171.70 -
171.71 - // Generics infrastructure
171.72 -
171.73 - private String getGenericSignature() {return signature;}
171.74 -
171.75 -
171.76 - /**
171.77 - * Package-private constructor used by ReflectAccess to enable
171.78 - * instantiation of these objects in Java code from the java.lang
171.79 - * package via sun.reflect.LangReflectAccess.
171.80 - */
171.81 - Field(Class<?> declaringClass,
171.82 - String name,
171.83 - Class<?> type,
171.84 - int modifiers,
171.85 - int slot,
171.86 - String signature,
171.87 - byte[] annotations)
171.88 - {
171.89 - this.clazz = declaringClass;
171.90 - this.name = name;
171.91 - this.type = type;
171.92 - this.modifiers = modifiers;
171.93 - this.slot = slot;
171.94 - this.signature = signature;
171.95 - this.annotations = annotations;
171.96 - }
171.97 -
171.98 - /**
171.99 - * Package-private routine (exposed to java.lang.Class via
171.100 - * ReflectAccess) which returns a copy of this Field. The copy's
171.101 - * "root" field points to this Field.
171.102 - */
171.103 - Field copy() {
171.104 - // This routine enables sharing of FieldAccessor objects
171.105 - // among Field objects which refer to the same underlying
171.106 - // method in the VM. (All of this contortion is only necessary
171.107 - // because of the "accessibility" bit in AccessibleObject,
171.108 - // which implicitly requires that new java.lang.reflect
171.109 - // objects be fabricated for each reflective call on Class
171.110 - // objects.)
171.111 - Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
171.112 - res.root = this;
171.113 - return res;
171.114 - }
171.115 -
171.116 - /**
171.117 - * Returns the {@code Class} object representing the class or interface
171.118 - * that declares the field represented by this {@code Field} object.
171.119 - */
171.120 - public Class<?> getDeclaringClass() {
171.121 - return clazz;
171.122 - }
171.123 -
171.124 - /**
171.125 - * Returns the name of the field represented by this {@code Field} object.
171.126 - */
171.127 - public String getName() {
171.128 - return name;
171.129 - }
171.130 -
171.131 - /**
171.132 - * Returns the Java language modifiers for the field represented
171.133 - * by this {@code Field} object, as an integer. The {@code Modifier} class should
171.134 - * be used to decode the modifiers.
171.135 - *
171.136 - * @see Modifier
171.137 - */
171.138 - public int getModifiers() {
171.139 - return modifiers;
171.140 - }
171.141 -
171.142 - /**
171.143 - * Returns {@code true} if this field represents an element of
171.144 - * an enumerated type; returns {@code false} otherwise.
171.145 - *
171.146 - * @return {@code true} if and only if this field represents an element of
171.147 - * an enumerated type.
171.148 - * @since 1.5
171.149 - */
171.150 - public boolean isEnumConstant() {
171.151 - return (getModifiers() & Modifier.ENUM) != 0;
171.152 - }
171.153 -
171.154 - /**
171.155 - * Returns {@code true} if this field is a synthetic
171.156 - * field; returns {@code false} otherwise.
171.157 - *
171.158 - * @return true if and only if this field is a synthetic
171.159 - * field as defined by the Java Language Specification.
171.160 - * @since 1.5
171.161 - */
171.162 - public boolean isSynthetic() {
171.163 - return Modifier.isSynthetic(getModifiers());
171.164 - }
171.165 -
171.166 - /**
171.167 - * Returns a {@code Class} object that identifies the
171.168 - * declared type for the field represented by this
171.169 - * {@code Field} object.
171.170 - *
171.171 - * @return a {@code Class} object identifying the declared
171.172 - * type of the field represented by this object
171.173 - */
171.174 - public Class<?> getType() {
171.175 - return type;
171.176 - }
171.177 -
171.178 - /**
171.179 - * Returns a {@code Type} object that represents the declared type for
171.180 - * the field represented by this {@code Field} object.
171.181 - *
171.182 - * <p>If the {@code Type} is a parameterized type, the
171.183 - * {@code Type} object returned must accurately reflect the
171.184 - * actual type parameters used in the source code.
171.185 - *
171.186 - * <p>If the type of the underlying field is a type variable or a
171.187 - * parameterized type, it is created. Otherwise, it is resolved.
171.188 - *
171.189 - * @return a {@code Type} object that represents the declared type for
171.190 - * the field represented by this {@code Field} object
171.191 - * @throws GenericSignatureFormatError if the generic field
171.192 - * signature does not conform to the format specified in
171.193 - * <cite>The Java™ Virtual Machine Specification</cite>
171.194 - * @throws TypeNotPresentException if the generic type
171.195 - * signature of the underlying field refers to a non-existent
171.196 - * type declaration
171.197 - * @throws MalformedParameterizedTypeException if the generic
171.198 - * signature of the underlying field refers to a parameterized type
171.199 - * that cannot be instantiated for any reason
171.200 - * @since 1.5
171.201 - */
171.202 - public Type getGenericType() {
171.203 - throw new UnsupportedOperationException();
171.204 - }
171.205 -
171.206 -
171.207 - /**
171.208 - * Compares this {@code Field} against the specified object. Returns
171.209 - * true if the objects are the same. Two {@code Field} objects are the same if
171.210 - * they were declared by the same class and have the same name
171.211 - * and type.
171.212 - */
171.213 - public boolean equals(Object obj) {
171.214 - if (obj != null && obj instanceof Field) {
171.215 - Field other = (Field)obj;
171.216 - return (getDeclaringClass() == other.getDeclaringClass())
171.217 - && (getName() == other.getName())
171.218 - && (getType() == other.getType());
171.219 - }
171.220 - return false;
171.221 - }
171.222 -
171.223 - /**
171.224 - * Returns a hashcode for this {@code Field}. This is computed as the
171.225 - * exclusive-or of the hashcodes for the underlying field's
171.226 - * declaring class name and its name.
171.227 - */
171.228 - public int hashCode() {
171.229 - return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
171.230 - }
171.231 -
171.232 - /**
171.233 - * Returns a string describing this {@code Field}. The format is
171.234 - * the access modifiers for the field, if any, followed
171.235 - * by the field type, followed by a space, followed by
171.236 - * the fully-qualified name of the class declaring the field,
171.237 - * followed by a period, followed by the name of the field.
171.238 - * For example:
171.239 - * <pre>
171.240 - * public static final int java.lang.Thread.MIN_PRIORITY
171.241 - * private int java.io.FileDescriptor.fd
171.242 - * </pre>
171.243 - *
171.244 - * <p>The modifiers are placed in canonical order as specified by
171.245 - * "The Java Language Specification". This is {@code public},
171.246 - * {@code protected} or {@code private} first, and then other
171.247 - * modifiers in the following order: {@code static}, {@code final},
171.248 - * {@code transient}, {@code volatile}.
171.249 - */
171.250 - public String toString() {
171.251 - int mod = getModifiers();
171.252 - return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
171.253 - + getTypeName(getType()) + " "
171.254 - + getTypeName(getDeclaringClass()) + "."
171.255 - + getName());
171.256 - }
171.257 -
171.258 - /**
171.259 - * Returns a string describing this {@code Field}, including
171.260 - * its generic type. The format is the access modifiers for the
171.261 - * field, if any, followed by the generic field type, followed by
171.262 - * a space, followed by the fully-qualified name of the class
171.263 - * declaring the field, followed by a period, followed by the name
171.264 - * of the field.
171.265 - *
171.266 - * <p>The modifiers are placed in canonical order as specified by
171.267 - * "The Java Language Specification". This is {@code public},
171.268 - * {@code protected} or {@code private} first, and then other
171.269 - * modifiers in the following order: {@code static}, {@code final},
171.270 - * {@code transient}, {@code volatile}.
171.271 - *
171.272 - * @return a string describing this {@code Field}, including
171.273 - * its generic type
171.274 - *
171.275 - * @since 1.5
171.276 - */
171.277 - public String toGenericString() {
171.278 - int mod = getModifiers();
171.279 - Type fieldType = getGenericType();
171.280 - return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
171.281 - + ((fieldType instanceof Class) ?
171.282 - getTypeName((Class)fieldType): fieldType.toString())+ " "
171.283 - + getTypeName(getDeclaringClass()) + "."
171.284 - + getName());
171.285 - }
171.286 -
171.287 - /**
171.288 - * Returns the value of the field represented by this {@code Field}, on
171.289 - * the specified object. The value is automatically wrapped in an
171.290 - * object if it has a primitive type.
171.291 - *
171.292 - * <p>The underlying field's value is obtained as follows:
171.293 - *
171.294 - * <p>If the underlying field is a static field, the {@code obj} argument
171.295 - * is ignored; it may be null.
171.296 - *
171.297 - * <p>Otherwise, the underlying field is an instance field. If the
171.298 - * specified {@code obj} argument is null, the method throws a
171.299 - * {@code NullPointerException}. If the specified object is not an
171.300 - * instance of the class or interface declaring the underlying
171.301 - * field, the method throws an {@code IllegalArgumentException}.
171.302 - *
171.303 - * <p>If this {@code Field} object is enforcing Java language access control, and
171.304 - * the underlying field is inaccessible, the method throws an
171.305 - * {@code IllegalAccessException}.
171.306 - * If the underlying field is static, the class that declared the
171.307 - * field is initialized if it has not already been initialized.
171.308 - *
171.309 - * <p>Otherwise, the value is retrieved from the underlying instance
171.310 - * or static field. If the field has a primitive type, the value
171.311 - * is wrapped in an object before being returned, otherwise it is
171.312 - * returned as is.
171.313 - *
171.314 - * <p>If the field is hidden in the type of {@code obj},
171.315 - * the field's value is obtained according to the preceding rules.
171.316 - *
171.317 - * @param obj object from which the represented field's value is
171.318 - * to be extracted
171.319 - * @return the value of the represented field in object
171.320 - * {@code obj}; primitive values are wrapped in an appropriate
171.321 - * object before being returned
171.322 - *
171.323 - * @exception IllegalAccessException if this {@code Field} object
171.324 - * is enforcing Java language access control and the underlying
171.325 - * field is inaccessible.
171.326 - * @exception IllegalArgumentException if the specified object is not an
171.327 - * instance of the class or interface declaring the underlying
171.328 - * field (or a subclass or implementor thereof).
171.329 - * @exception NullPointerException if the specified object is null
171.330 - * and the field is an instance field.
171.331 - * @exception ExceptionInInitializerError if the initialization provoked
171.332 - * by this method fails.
171.333 - */
171.334 - public Object get(Object obj)
171.335 - throws IllegalArgumentException, IllegalAccessException
171.336 - {
171.337 - return getFieldAccessor(obj).get(obj);
171.338 - }
171.339 -
171.340 - /**
171.341 - * Gets the value of a static or instance {@code boolean} field.
171.342 - *
171.343 - * @param obj the object to extract the {@code boolean} value
171.344 - * from
171.345 - * @return the value of the {@code boolean} field
171.346 - *
171.347 - * @exception IllegalAccessException if this {@code Field} object
171.348 - * is enforcing Java language access control and the underlying
171.349 - * field is inaccessible.
171.350 - * @exception IllegalArgumentException if the specified object is not
171.351 - * an instance of the class or interface declaring the
171.352 - * underlying field (or a subclass or implementor
171.353 - * thereof), or if the field value cannot be
171.354 - * converted to the type {@code boolean} by a
171.355 - * widening conversion.
171.356 - * @exception NullPointerException if the specified object is null
171.357 - * and the field is an instance field.
171.358 - * @exception ExceptionInInitializerError if the initialization provoked
171.359 - * by this method fails.
171.360 - * @see Field#get
171.361 - */
171.362 - public boolean getBoolean(Object obj)
171.363 - throws IllegalArgumentException, IllegalAccessException
171.364 - {
171.365 - return getFieldAccessor(obj).getBoolean(obj);
171.366 - }
171.367 -
171.368 - /**
171.369 - * Gets the value of a static or instance {@code byte} field.
171.370 - *
171.371 - * @param obj the object to extract the {@code byte} value
171.372 - * from
171.373 - * @return the value of the {@code byte} field
171.374 - *
171.375 - * @exception IllegalAccessException if this {@code Field} object
171.376 - * is enforcing Java language access control and the underlying
171.377 - * field is inaccessible.
171.378 - * @exception IllegalArgumentException if the specified object is not
171.379 - * an instance of the class or interface declaring the
171.380 - * underlying field (or a subclass or implementor
171.381 - * thereof), or if the field value cannot be
171.382 - * converted to the type {@code byte} by a
171.383 - * widening conversion.
171.384 - * @exception NullPointerException if the specified object is null
171.385 - * and the field is an instance field.
171.386 - * @exception ExceptionInInitializerError if the initialization provoked
171.387 - * by this method fails.
171.388 - * @see Field#get
171.389 - */
171.390 - public byte getByte(Object obj)
171.391 - throws IllegalArgumentException, IllegalAccessException
171.392 - {
171.393 - return getFieldAccessor(obj).getByte(obj);
171.394 - }
171.395 -
171.396 - /**
171.397 - * Gets the value of a static or instance field of type
171.398 - * {@code char} or of another primitive type convertible to
171.399 - * type {@code char} via a widening conversion.
171.400 - *
171.401 - * @param obj the object to extract the {@code char} value
171.402 - * from
171.403 - * @return the value of the field converted to type {@code char}
171.404 - *
171.405 - * @exception IllegalAccessException if this {@code Field} object
171.406 - * is enforcing Java language access control and the underlying
171.407 - * field is inaccessible.
171.408 - * @exception IllegalArgumentException if the specified object is not
171.409 - * an instance of the class or interface declaring the
171.410 - * underlying field (or a subclass or implementor
171.411 - * thereof), or if the field value cannot be
171.412 - * converted to the type {@code char} by a
171.413 - * widening conversion.
171.414 - * @exception NullPointerException if the specified object is null
171.415 - * and the field is an instance field.
171.416 - * @exception ExceptionInInitializerError if the initialization provoked
171.417 - * by this method fails.
171.418 - * @see Field#get
171.419 - */
171.420 - public char getChar(Object obj)
171.421 - throws IllegalArgumentException, IllegalAccessException
171.422 - {
171.423 - return getFieldAccessor(obj).getChar(obj);
171.424 - }
171.425 -
171.426 - /**
171.427 - * Gets the value of a static or instance field of type
171.428 - * {@code short} or of another primitive type convertible to
171.429 - * type {@code short} via a widening conversion.
171.430 - *
171.431 - * @param obj the object to extract the {@code short} value
171.432 - * from
171.433 - * @return the value of the field converted to type {@code short}
171.434 - *
171.435 - * @exception IllegalAccessException if this {@code Field} object
171.436 - * is enforcing Java language access control and the underlying
171.437 - * field is inaccessible.
171.438 - * @exception IllegalArgumentException if the specified object is not
171.439 - * an instance of the class or interface declaring the
171.440 - * underlying field (or a subclass or implementor
171.441 - * thereof), or if the field value cannot be
171.442 - * converted to the type {@code short} by a
171.443 - * widening conversion.
171.444 - * @exception NullPointerException if the specified object is null
171.445 - * and the field is an instance field.
171.446 - * @exception ExceptionInInitializerError if the initialization provoked
171.447 - * by this method fails.
171.448 - * @see Field#get
171.449 - */
171.450 - public short getShort(Object obj)
171.451 - throws IllegalArgumentException, IllegalAccessException
171.452 - {
171.453 - return getFieldAccessor(obj).getShort(obj);
171.454 - }
171.455 -
171.456 - /**
171.457 - * Gets the value of a static or instance field of type
171.458 - * {@code int} or of another primitive type convertible to
171.459 - * type {@code int} via a widening conversion.
171.460 - *
171.461 - * @param obj the object to extract the {@code int} value
171.462 - * from
171.463 - * @return the value of the field converted to type {@code int}
171.464 - *
171.465 - * @exception IllegalAccessException if this {@code Field} object
171.466 - * is enforcing Java language access control and the underlying
171.467 - * field is inaccessible.
171.468 - * @exception IllegalArgumentException if the specified object is not
171.469 - * an instance of the class or interface declaring the
171.470 - * underlying field (or a subclass or implementor
171.471 - * thereof), or if the field value cannot be
171.472 - * converted to the type {@code int} by a
171.473 - * widening conversion.
171.474 - * @exception NullPointerException if the specified object is null
171.475 - * and the field is an instance field.
171.476 - * @exception ExceptionInInitializerError if the initialization provoked
171.477 - * by this method fails.
171.478 - * @see Field#get
171.479 - */
171.480 - public int getInt(Object obj)
171.481 - throws IllegalArgumentException, IllegalAccessException
171.482 - {
171.483 - return getFieldAccessor(obj).getInt(obj);
171.484 - }
171.485 -
171.486 - /**
171.487 - * Gets the value of a static or instance field of type
171.488 - * {@code long} or of another primitive type convertible to
171.489 - * type {@code long} via a widening conversion.
171.490 - *
171.491 - * @param obj the object to extract the {@code long} value
171.492 - * from
171.493 - * @return the value of the field converted to type {@code long}
171.494 - *
171.495 - * @exception IllegalAccessException if this {@code Field} object
171.496 - * is enforcing Java language access control and the underlying
171.497 - * field is inaccessible.
171.498 - * @exception IllegalArgumentException if the specified object is not
171.499 - * an instance of the class or interface declaring the
171.500 - * underlying field (or a subclass or implementor
171.501 - * thereof), or if the field value cannot be
171.502 - * converted to the type {@code long} by a
171.503 - * widening conversion.
171.504 - * @exception NullPointerException if the specified object is null
171.505 - * and the field is an instance field.
171.506 - * @exception ExceptionInInitializerError if the initialization provoked
171.507 - * by this method fails.
171.508 - * @see Field#get
171.509 - */
171.510 - public long getLong(Object obj)
171.511 - throws IllegalArgumentException, IllegalAccessException
171.512 - {
171.513 - return getFieldAccessor(obj).getLong(obj);
171.514 - }
171.515 -
171.516 - /**
171.517 - * Gets the value of a static or instance field of type
171.518 - * {@code float} or of another primitive type convertible to
171.519 - * type {@code float} via a widening conversion.
171.520 - *
171.521 - * @param obj the object to extract the {@code float} value
171.522 - * from
171.523 - * @return the value of the field converted to type {@code float}
171.524 - *
171.525 - * @exception IllegalAccessException if this {@code Field} object
171.526 - * is enforcing Java language access control and the underlying
171.527 - * field is inaccessible.
171.528 - * @exception IllegalArgumentException if the specified object is not
171.529 - * an instance of the class or interface declaring the
171.530 - * underlying field (or a subclass or implementor
171.531 - * thereof), or if the field value cannot be
171.532 - * converted to the type {@code float} by a
171.533 - * widening conversion.
171.534 - * @exception NullPointerException if the specified object is null
171.535 - * and the field is an instance field.
171.536 - * @exception ExceptionInInitializerError if the initialization provoked
171.537 - * by this method fails.
171.538 - * @see Field#get
171.539 - */
171.540 - public float getFloat(Object obj)
171.541 - throws IllegalArgumentException, IllegalAccessException
171.542 - {
171.543 - return getFieldAccessor(obj).getFloat(obj);
171.544 - }
171.545 -
171.546 - /**
171.547 - * Gets the value of a static or instance field of type
171.548 - * {@code double} or of another primitive type convertible to
171.549 - * type {@code double} via a widening conversion.
171.550 - *
171.551 - * @param obj the object to extract the {@code double} value
171.552 - * from
171.553 - * @return the value of the field converted to type {@code double}
171.554 - *
171.555 - * @exception IllegalAccessException if this {@code Field} object
171.556 - * is enforcing Java language access control and the underlying
171.557 - * field is inaccessible.
171.558 - * @exception IllegalArgumentException if the specified object is not
171.559 - * an instance of the class or interface declaring the
171.560 - * underlying field (or a subclass or implementor
171.561 - * thereof), or if the field value cannot be
171.562 - * converted to the type {@code double} by a
171.563 - * widening conversion.
171.564 - * @exception NullPointerException if the specified object is null
171.565 - * and the field is an instance field.
171.566 - * @exception ExceptionInInitializerError if the initialization provoked
171.567 - * by this method fails.
171.568 - * @see Field#get
171.569 - */
171.570 - public double getDouble(Object obj)
171.571 - throws IllegalArgumentException, IllegalAccessException
171.572 - {
171.573 - return getFieldAccessor(obj).getDouble(obj);
171.574 - }
171.575 -
171.576 - /**
171.577 - * Sets the field represented by this {@code Field} object on the
171.578 - * specified object argument to the specified new value. The new
171.579 - * value is automatically unwrapped if the underlying field has a
171.580 - * primitive type.
171.581 - *
171.582 - * <p>The operation proceeds as follows:
171.583 - *
171.584 - * <p>If the underlying field is static, the {@code obj} argument is
171.585 - * ignored; it may be null.
171.586 - *
171.587 - * <p>Otherwise the underlying field is an instance field. If the
171.588 - * specified object argument is null, the method throws a
171.589 - * {@code NullPointerException}. If the specified object argument is not
171.590 - * an instance of the class or interface declaring the underlying
171.591 - * field, the method throws an {@code IllegalArgumentException}.
171.592 - *
171.593 - * <p>If this {@code Field} object is enforcing Java language access control, and
171.594 - * the underlying field is inaccessible, the method throws an
171.595 - * {@code IllegalAccessException}.
171.596 - *
171.597 - * <p>If the underlying field is final, the method throws an
171.598 - * {@code IllegalAccessException} unless {@code setAccessible(true)}
171.599 - * has succeeded for this {@code Field} object
171.600 - * and the field is non-static. Setting a final field in this way
171.601 - * is meaningful only during deserialization or reconstruction of
171.602 - * instances of classes with blank final fields, before they are
171.603 - * made available for access by other parts of a program. Use in
171.604 - * any other context may have unpredictable effects, including cases
171.605 - * in which other parts of a program continue to use the original
171.606 - * value of this field.
171.607 - *
171.608 - * <p>If the underlying field is of a primitive type, an unwrapping
171.609 - * conversion is attempted to convert the new value to a value of
171.610 - * a primitive type. If this attempt fails, the method throws an
171.611 - * {@code IllegalArgumentException}.
171.612 - *
171.613 - * <p>If, after possible unwrapping, the new value cannot be
171.614 - * converted to the type of the underlying field by an identity or
171.615 - * widening conversion, the method throws an
171.616 - * {@code IllegalArgumentException}.
171.617 - *
171.618 - * <p>If the underlying field is static, the class that declared the
171.619 - * field is initialized if it has not already been initialized.
171.620 - *
171.621 - * <p>The field is set to the possibly unwrapped and widened new value.
171.622 - *
171.623 - * <p>If the field is hidden in the type of {@code obj},
171.624 - * the field's value is set according to the preceding rules.
171.625 - *
171.626 - * @param obj the object whose field should be modified
171.627 - * @param value the new value for the field of {@code obj}
171.628 - * being modified
171.629 - *
171.630 - * @exception IllegalAccessException if this {@code Field} object
171.631 - * is enforcing Java language access control and the underlying
171.632 - * field is either inaccessible or final.
171.633 - * @exception IllegalArgumentException if the specified object is not an
171.634 - * instance of the class or interface declaring the underlying
171.635 - * field (or a subclass or implementor thereof),
171.636 - * or if an unwrapping conversion fails.
171.637 - * @exception NullPointerException if the specified object is null
171.638 - * and the field is an instance field.
171.639 - * @exception ExceptionInInitializerError if the initialization provoked
171.640 - * by this method fails.
171.641 - */
171.642 - public void set(Object obj, Object value)
171.643 - throws IllegalArgumentException, IllegalAccessException
171.644 - {
171.645 - getFieldAccessor(obj).set(obj, value);
171.646 - }
171.647 -
171.648 - /**
171.649 - * Sets the value of a field as a {@code boolean} on the specified object.
171.650 - * This method is equivalent to
171.651 - * {@code set(obj, zObj)},
171.652 - * where {@code zObj} is a {@code Boolean} object and
171.653 - * {@code zObj.booleanValue() == z}.
171.654 - *
171.655 - * @param obj the object whose field should be modified
171.656 - * @param z the new value for the field of {@code obj}
171.657 - * being modified
171.658 - *
171.659 - * @exception IllegalAccessException if this {@code Field} object
171.660 - * is enforcing Java language access control and the underlying
171.661 - * field is either inaccessible or final.
171.662 - * @exception IllegalArgumentException if the specified object is not an
171.663 - * instance of the class or interface declaring the underlying
171.664 - * field (or a subclass or implementor thereof),
171.665 - * or if an unwrapping conversion fails.
171.666 - * @exception NullPointerException if the specified object is null
171.667 - * and the field is an instance field.
171.668 - * @exception ExceptionInInitializerError if the initialization provoked
171.669 - * by this method fails.
171.670 - * @see Field#set
171.671 - */
171.672 - public void setBoolean(Object obj, boolean z)
171.673 - throws IllegalArgumentException, IllegalAccessException
171.674 - {
171.675 - getFieldAccessor(obj).setBoolean(obj, z);
171.676 - }
171.677 -
171.678 - /**
171.679 - * Sets the value of a field as a {@code byte} on the specified object.
171.680 - * This method is equivalent to
171.681 - * {@code set(obj, bObj)},
171.682 - * where {@code bObj} is a {@code Byte} object and
171.683 - * {@code bObj.byteValue() == b}.
171.684 - *
171.685 - * @param obj the object whose field should be modified
171.686 - * @param b the new value for the field of {@code obj}
171.687 - * being modified
171.688 - *
171.689 - * @exception IllegalAccessException if this {@code Field} object
171.690 - * is enforcing Java language access control and the underlying
171.691 - * field is either inaccessible or final.
171.692 - * @exception IllegalArgumentException if the specified object is not an
171.693 - * instance of the class or interface declaring the underlying
171.694 - * field (or a subclass or implementor thereof),
171.695 - * or if an unwrapping conversion fails.
171.696 - * @exception NullPointerException if the specified object is null
171.697 - * and the field is an instance field.
171.698 - * @exception ExceptionInInitializerError if the initialization provoked
171.699 - * by this method fails.
171.700 - * @see Field#set
171.701 - */
171.702 - public void setByte(Object obj, byte b)
171.703 - throws IllegalArgumentException, IllegalAccessException
171.704 - {
171.705 - getFieldAccessor(obj).setByte(obj, b);
171.706 - }
171.707 -
171.708 - /**
171.709 - * Sets the value of a field as a {@code char} on the specified object.
171.710 - * This method is equivalent to
171.711 - * {@code set(obj, cObj)},
171.712 - * where {@code cObj} is a {@code Character} object and
171.713 - * {@code cObj.charValue() == c}.
171.714 - *
171.715 - * @param obj the object whose field should be modified
171.716 - * @param c the new value for the field of {@code obj}
171.717 - * being modified
171.718 - *
171.719 - * @exception IllegalAccessException if this {@code Field} object
171.720 - * is enforcing Java language access control and the underlying
171.721 - * field is either inaccessible or final.
171.722 - * @exception IllegalArgumentException if the specified object is not an
171.723 - * instance of the class or interface declaring the underlying
171.724 - * field (or a subclass or implementor thereof),
171.725 - * or if an unwrapping conversion fails.
171.726 - * @exception NullPointerException if the specified object is null
171.727 - * and the field is an instance field.
171.728 - * @exception ExceptionInInitializerError if the initialization provoked
171.729 - * by this method fails.
171.730 - * @see Field#set
171.731 - */
171.732 - public void setChar(Object obj, char c)
171.733 - throws IllegalArgumentException, IllegalAccessException
171.734 - {
171.735 - getFieldAccessor(obj).setChar(obj, c);
171.736 - }
171.737 -
171.738 - /**
171.739 - * Sets the value of a field as a {@code short} on the specified object.
171.740 - * This method is equivalent to
171.741 - * {@code set(obj, sObj)},
171.742 - * where {@code sObj} is a {@code Short} object and
171.743 - * {@code sObj.shortValue() == s}.
171.744 - *
171.745 - * @param obj the object whose field should be modified
171.746 - * @param s the new value for the field of {@code obj}
171.747 - * being modified
171.748 - *
171.749 - * @exception IllegalAccessException if this {@code Field} object
171.750 - * is enforcing Java language access control and the underlying
171.751 - * field is either inaccessible or final.
171.752 - * @exception IllegalArgumentException if the specified object is not an
171.753 - * instance of the class or interface declaring the underlying
171.754 - * field (or a subclass or implementor thereof),
171.755 - * or if an unwrapping conversion fails.
171.756 - * @exception NullPointerException if the specified object is null
171.757 - * and the field is an instance field.
171.758 - * @exception ExceptionInInitializerError if the initialization provoked
171.759 - * by this method fails.
171.760 - * @see Field#set
171.761 - */
171.762 - public void setShort(Object obj, short s)
171.763 - throws IllegalArgumentException, IllegalAccessException
171.764 - {
171.765 - getFieldAccessor(obj).setShort(obj, s);
171.766 - }
171.767 -
171.768 - /**
171.769 - * Sets the value of a field as an {@code int} on the specified object.
171.770 - * This method is equivalent to
171.771 - * {@code set(obj, iObj)},
171.772 - * where {@code iObj} is a {@code Integer} object and
171.773 - * {@code iObj.intValue() == i}.
171.774 - *
171.775 - * @param obj the object whose field should be modified
171.776 - * @param i the new value for the field of {@code obj}
171.777 - * being modified
171.778 - *
171.779 - * @exception IllegalAccessException if this {@code Field} object
171.780 - * is enforcing Java language access control and the underlying
171.781 - * field is either inaccessible or final.
171.782 - * @exception IllegalArgumentException if the specified object is not an
171.783 - * instance of the class or interface declaring the underlying
171.784 - * field (or a subclass or implementor thereof),
171.785 - * or if an unwrapping conversion fails.
171.786 - * @exception NullPointerException if the specified object is null
171.787 - * and the field is an instance field.
171.788 - * @exception ExceptionInInitializerError if the initialization provoked
171.789 - * by this method fails.
171.790 - * @see Field#set
171.791 - */
171.792 - public void setInt(Object obj, int i)
171.793 - throws IllegalArgumentException, IllegalAccessException
171.794 - {
171.795 - getFieldAccessor(obj).setInt(obj, i);
171.796 - }
171.797 -
171.798 - /**
171.799 - * Sets the value of a field as a {@code long} on the specified object.
171.800 - * This method is equivalent to
171.801 - * {@code set(obj, lObj)},
171.802 - * where {@code lObj} is a {@code Long} object and
171.803 - * {@code lObj.longValue() == l}.
171.804 - *
171.805 - * @param obj the object whose field should be modified
171.806 - * @param l the new value for the field of {@code obj}
171.807 - * being modified
171.808 - *
171.809 - * @exception IllegalAccessException if this {@code Field} object
171.810 - * is enforcing Java language access control and the underlying
171.811 - * field is either inaccessible or final.
171.812 - * @exception IllegalArgumentException if the specified object is not an
171.813 - * instance of the class or interface declaring the underlying
171.814 - * field (or a subclass or implementor thereof),
171.815 - * or if an unwrapping conversion fails.
171.816 - * @exception NullPointerException if the specified object is null
171.817 - * and the field is an instance field.
171.818 - * @exception ExceptionInInitializerError if the initialization provoked
171.819 - * by this method fails.
171.820 - * @see Field#set
171.821 - */
171.822 - public void setLong(Object obj, long l)
171.823 - throws IllegalArgumentException, IllegalAccessException
171.824 - {
171.825 - getFieldAccessor(obj).setLong(obj, l);
171.826 - }
171.827 -
171.828 - /**
171.829 - * Sets the value of a field as a {@code float} on the specified object.
171.830 - * This method is equivalent to
171.831 - * {@code set(obj, fObj)},
171.832 - * where {@code fObj} is a {@code Float} object and
171.833 - * {@code fObj.floatValue() == f}.
171.834 - *
171.835 - * @param obj the object whose field should be modified
171.836 - * @param f the new value for the field of {@code obj}
171.837 - * being modified
171.838 - *
171.839 - * @exception IllegalAccessException if this {@code Field} object
171.840 - * is enforcing Java language access control and the underlying
171.841 - * field is either inaccessible or final.
171.842 - * @exception IllegalArgumentException if the specified object is not an
171.843 - * instance of the class or interface declaring the underlying
171.844 - * field (or a subclass or implementor thereof),
171.845 - * or if an unwrapping conversion fails.
171.846 - * @exception NullPointerException if the specified object is null
171.847 - * and the field is an instance field.
171.848 - * @exception ExceptionInInitializerError if the initialization provoked
171.849 - * by this method fails.
171.850 - * @see Field#set
171.851 - */
171.852 - public void setFloat(Object obj, float f)
171.853 - throws IllegalArgumentException, IllegalAccessException
171.854 - {
171.855 - getFieldAccessor(obj).setFloat(obj, f);
171.856 - }
171.857 -
171.858 - /**
171.859 - * Sets the value of a field as a {@code double} on the specified object.
171.860 - * This method is equivalent to
171.861 - * {@code set(obj, dObj)},
171.862 - * where {@code dObj} is a {@code Double} object and
171.863 - * {@code dObj.doubleValue() == d}.
171.864 - *
171.865 - * @param obj the object whose field should be modified
171.866 - * @param d the new value for the field of {@code obj}
171.867 - * being modified
171.868 - *
171.869 - * @exception IllegalAccessException if this {@code Field} object
171.870 - * is enforcing Java language access control and the underlying
171.871 - * field is either inaccessible or final.
171.872 - * @exception IllegalArgumentException if the specified object is not an
171.873 - * instance of the class or interface declaring the underlying
171.874 - * field (or a subclass or implementor thereof),
171.875 - * or if an unwrapping conversion fails.
171.876 - * @exception NullPointerException if the specified object is null
171.877 - * and the field is an instance field.
171.878 - * @exception ExceptionInInitializerError if the initialization provoked
171.879 - * by this method fails.
171.880 - * @see Field#set
171.881 - */
171.882 - public void setDouble(Object obj, double d)
171.883 - throws IllegalArgumentException, IllegalAccessException
171.884 - {
171.885 - getFieldAccessor(obj).setDouble(obj, d);
171.886 - }
171.887 -
171.888 - // Convenience routine which performs security checks
171.889 - private FieldAccessor getFieldAccessor(Object obj)
171.890 - throws IllegalAccessException
171.891 - {
171.892 - throw new SecurityException();
171.893 - }
171.894 -
171.895 - private static abstract class FieldAccessor {
171.896 - abstract void setShort(Object obj, short s);
171.897 - abstract void setInt(Object obj, int i);
171.898 - abstract void setChar(Object obj, char c);
171.899 - abstract void setByte(Object obj, byte b);
171.900 - abstract void setBoolean(Object obj, boolean z);
171.901 - abstract void set(Object obj, Object value);
171.902 - abstract double getDouble(Object obj);
171.903 - abstract void setLong(Object obj, long l);
171.904 - abstract void setFloat(Object obj, float f);
171.905 - abstract void setDouble(Object obj, double d);
171.906 - abstract long getLong(Object obj);
171.907 - abstract int getInt(Object obj);
171.908 - abstract short getShort(Object obj);
171.909 - abstract char getChar(Object obj);
171.910 - abstract byte getByte(Object obj);
171.911 - abstract boolean getBoolean(Object obj);
171.912 - abstract Object get(Object obj);
171.913 - abstract float getFloat(Object obj);
171.914 - }
171.915 -
171.916 - /*
171.917 - * Utility routine to paper over array type names
171.918 - */
171.919 - static String getTypeName(Class<?> type) {
171.920 - if (type.isArray()) {
171.921 - try {
171.922 - Class<?> cl = type;
171.923 - int dimensions = 0;
171.924 - while (cl.isArray()) {
171.925 - dimensions++;
171.926 - cl = cl.getComponentType();
171.927 - }
171.928 - StringBuffer sb = new StringBuffer();
171.929 - sb.append(cl.getName());
171.930 - for (int i = 0; i < dimensions; i++) {
171.931 - sb.append("[]");
171.932 - }
171.933 - return sb.toString();
171.934 - } catch (Throwable e) { /*FALLTHRU*/ }
171.935 - }
171.936 - return type.getName();
171.937 - }
171.938 -
171.939 - /**
171.940 - * @throws NullPointerException {@inheritDoc}
171.941 - * @since 1.5
171.942 - */
171.943 - public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
171.944 - if (annotationClass == null)
171.945 - throw new NullPointerException();
171.946 -
171.947 - throw new UnsupportedOperationException();
171.948 - }
171.949 -
171.950 - /**
171.951 - * @since 1.5
171.952 - */
171.953 - public Annotation[] getDeclaredAnnotations() {
171.954 - throw new UnsupportedOperationException();
171.955 - }
171.956 -}
172.1 --- a/emul/src/main/java/java/lang/reflect/GenericDeclaration.java Wed Jan 23 20:16:48 2013 +0100
172.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
172.3 @@ -1,49 +0,0 @@
172.4 -/*
172.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
172.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
172.7 - *
172.8 - * This code is free software; you can redistribute it and/or modify it
172.9 - * under the terms of the GNU General Public License version 2 only, as
172.10 - * published by the Free Software Foundation. Oracle designates this
172.11 - * particular file as subject to the "Classpath" exception as provided
172.12 - * by Oracle in the LICENSE file that accompanied this code.
172.13 - *
172.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
172.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
172.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
172.17 - * version 2 for more details (a copy is included in the LICENSE file that
172.18 - * accompanied this code).
172.19 - *
172.20 - * You should have received a copy of the GNU General Public License version
172.21 - * 2 along with this work; if not, write to the Free Software Foundation,
172.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
172.23 - *
172.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
172.25 - * or visit www.oracle.com if you need additional information or have any
172.26 - * questions.
172.27 - */
172.28 -
172.29 -package java.lang.reflect;
172.30 -
172.31 -/**
172.32 - * A common interface for all entities that declare type variables.
172.33 - *
172.34 - * @since 1.5
172.35 - */
172.36 -public interface GenericDeclaration {
172.37 - /**
172.38 - * Returns an array of {@code TypeVariable} objects that
172.39 - * represent the type variables declared by the generic
172.40 - * declaration represented by this {@code GenericDeclaration}
172.41 - * object, in declaration order. Returns an array of length 0 if
172.42 - * the underlying generic declaration declares no type variables.
172.43 - *
172.44 - * @return an array of {@code TypeVariable} objects that represent
172.45 - * the type variables declared by this generic declaration
172.46 - * @throws GenericSignatureFormatError if the generic
172.47 - * signature of this generic declaration does not conform to
172.48 - * the format specified in
172.49 - * <cite>The Java™ Virtual Machine Specification</cite>
172.50 - */
172.51 - public TypeVariable<?>[] getTypeParameters();
172.52 -}
173.1 --- a/emul/src/main/java/java/lang/reflect/InvocationTargetException.java Wed Jan 23 20:16:48 2013 +0100
173.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
173.3 @@ -1,111 +0,0 @@
173.4 -/*
173.5 - * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
173.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
173.7 - *
173.8 - * This code is free software; you can redistribute it and/or modify it
173.9 - * under the terms of the GNU General Public License version 2 only, as
173.10 - * published by the Free Software Foundation. Oracle designates this
173.11 - * particular file as subject to the "Classpath" exception as provided
173.12 - * by Oracle in the LICENSE file that accompanied this code.
173.13 - *
173.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
173.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
173.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
173.17 - * version 2 for more details (a copy is included in the LICENSE file that
173.18 - * accompanied this code).
173.19 - *
173.20 - * You should have received a copy of the GNU General Public License version
173.21 - * 2 along with this work; if not, write to the Free Software Foundation,
173.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
173.23 - *
173.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
173.25 - * or visit www.oracle.com if you need additional information or have any
173.26 - * questions.
173.27 - */
173.28 -
173.29 -package java.lang.reflect;
173.30 -
173.31 -/**
173.32 - * InvocationTargetException is a checked exception that wraps
173.33 - * an exception thrown by an invoked method or constructor.
173.34 - *
173.35 - * <p>As of release 1.4, this exception has been retrofitted to conform to
173.36 - * the general purpose exception-chaining mechanism. The "target exception"
173.37 - * that is provided at construction time and accessed via the
173.38 - * {@link #getTargetException()} method is now known as the <i>cause</i>,
173.39 - * and may be accessed via the {@link Throwable#getCause()} method,
173.40 - * as well as the aforementioned "legacy method."
173.41 - *
173.42 - * @see Method
173.43 - * @see Constructor
173.44 - */
173.45 -public class InvocationTargetException extends ReflectiveOperationException {
173.46 - /**
173.47 - * Use serialVersionUID from JDK 1.1.X for interoperability
173.48 - */
173.49 - private static final long serialVersionUID = 4085088731926701167L;
173.50 -
173.51 - /**
173.52 - * This field holds the target if the
173.53 - * InvocationTargetException(Throwable target) constructor was
173.54 - * used to instantiate the object
173.55 - *
173.56 - * @serial
173.57 - *
173.58 - */
173.59 - private Throwable target;
173.60 -
173.61 - /**
173.62 - * Constructs an {@code InvocationTargetException} with
173.63 - * {@code null} as the target exception.
173.64 - */
173.65 - protected InvocationTargetException() {
173.66 - super((Throwable)null); // Disallow initCause
173.67 - }
173.68 -
173.69 - /**
173.70 - * Constructs a InvocationTargetException with a target exception.
173.71 - *
173.72 - * @param target the target exception
173.73 - */
173.74 - public InvocationTargetException(Throwable target) {
173.75 - super((Throwable)null); // Disallow initCause
173.76 - this.target = target;
173.77 - }
173.78 -
173.79 - /**
173.80 - * Constructs a InvocationTargetException with a target exception
173.81 - * and a detail message.
173.82 - *
173.83 - * @param target the target exception
173.84 - * @param s the detail message
173.85 - */
173.86 - public InvocationTargetException(Throwable target, String s) {
173.87 - super(s, null); // Disallow initCause
173.88 - this.target = target;
173.89 - }
173.90 -
173.91 - /**
173.92 - * Get the thrown target exception.
173.93 - *
173.94 - * <p>This method predates the general-purpose exception chaining facility.
173.95 - * The {@link Throwable#getCause()} method is now the preferred means of
173.96 - * obtaining this information.
173.97 - *
173.98 - * @return the thrown target exception (cause of this exception).
173.99 - */
173.100 - public Throwable getTargetException() {
173.101 - return target;
173.102 - }
173.103 -
173.104 - /**
173.105 - * Returns the cause of this exception (the thrown target exception,
173.106 - * which may be {@code null}).
173.107 - *
173.108 - * @return the cause of this exception.
173.109 - * @since 1.4
173.110 - */
173.111 - public Throwable getCause() {
173.112 - return target;
173.113 - }
173.114 -}
174.1 --- a/emul/src/main/java/java/lang/reflect/Member.java Wed Jan 23 20:16:48 2013 +0100
174.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
174.3 @@ -1,93 +0,0 @@
174.4 -/*
174.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
174.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
174.7 - *
174.8 - * This code is free software; you can redistribute it and/or modify it
174.9 - * under the terms of the GNU General Public License version 2 only, as
174.10 - * published by the Free Software Foundation. Oracle designates this
174.11 - * particular file as subject to the "Classpath" exception as provided
174.12 - * by Oracle in the LICENSE file that accompanied this code.
174.13 - *
174.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
174.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
174.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
174.17 - * version 2 for more details (a copy is included in the LICENSE file that
174.18 - * accompanied this code).
174.19 - *
174.20 - * You should have received a copy of the GNU General Public License version
174.21 - * 2 along with this work; if not, write to the Free Software Foundation,
174.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
174.23 - *
174.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
174.25 - * or visit www.oracle.com if you need additional information or have any
174.26 - * questions.
174.27 - */
174.28 -
174.29 -package java.lang.reflect;
174.30 -
174.31 -/**
174.32 - * Member is an interface that reflects identifying information about
174.33 - * a single member (a field or a method) or a constructor.
174.34 - *
174.35 - * @see java.lang.Class
174.36 - * @see Field
174.37 - * @see Method
174.38 - * @see Constructor
174.39 - *
174.40 - * @author Nakul Saraiya
174.41 - */
174.42 -public
174.43 -interface Member {
174.44 -
174.45 - /**
174.46 - * Identifies the set of all public members of a class or interface,
174.47 - * including inherited members.
174.48 - * @see java.lang.SecurityManager#checkMemberAccess
174.49 - */
174.50 - public static final int PUBLIC = 0;
174.51 -
174.52 - /**
174.53 - * Identifies the set of declared members of a class or interface.
174.54 - * Inherited members are not included.
174.55 - * @see java.lang.SecurityManager#checkMemberAccess
174.56 - */
174.57 - public static final int DECLARED = 1;
174.58 -
174.59 - /**
174.60 - * Returns the Class object representing the class or interface
174.61 - * that declares the member or constructor represented by this Member.
174.62 - *
174.63 - * @return an object representing the declaring class of the
174.64 - * underlying member
174.65 - */
174.66 - public Class<?> getDeclaringClass();
174.67 -
174.68 - /**
174.69 - * Returns the simple name of the underlying member or constructor
174.70 - * represented by this Member.
174.71 - *
174.72 - * @return the simple name of the underlying member
174.73 - */
174.74 - public String getName();
174.75 -
174.76 - /**
174.77 - * Returns the Java language modifiers for the member or
174.78 - * constructor represented by this Member, as an integer. The
174.79 - * Modifier class should be used to decode the modifiers in
174.80 - * the integer.
174.81 - *
174.82 - * @return the Java language modifiers for the underlying member
174.83 - * @see Modifier
174.84 - */
174.85 - public int getModifiers();
174.86 -
174.87 - /**
174.88 - * Returns {@code true} if this member was introduced by
174.89 - * the compiler; returns {@code false} otherwise.
174.90 - *
174.91 - * @return true if and only if this member was introduced by
174.92 - * the compiler.
174.93 - * @since 1.5
174.94 - */
174.95 - public boolean isSynthetic();
174.96 -}
175.1 --- a/emul/src/main/java/java/lang/reflect/Method.java Wed Jan 23 20:16:48 2013 +0100
175.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
175.3 @@ -1,720 +0,0 @@
175.4 -/*
175.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
175.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
175.7 - *
175.8 - * This code is free software; you can redistribute it and/or modify it
175.9 - * under the terms of the GNU General Public License version 2 only, as
175.10 - * published by the Free Software Foundation. Oracle designates this
175.11 - * particular file as subject to the "Classpath" exception as provided
175.12 - * by Oracle in the LICENSE file that accompanied this code.
175.13 - *
175.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
175.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
175.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
175.17 - * version 2 for more details (a copy is included in the LICENSE file that
175.18 - * accompanied this code).
175.19 - *
175.20 - * You should have received a copy of the GNU General Public License version
175.21 - * 2 along with this work; if not, write to the Free Software Foundation,
175.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
175.23 - *
175.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
175.25 - * or visit www.oracle.com if you need additional information or have any
175.26 - * questions.
175.27 - */
175.28 -
175.29 -package java.lang.reflect;
175.30 -
175.31 -import java.lang.annotation.Annotation;
175.32 -import java.util.Enumeration;
175.33 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
175.34 -import org.apidesign.bck2brwsr.emul.AnnotationImpl;
175.35 -import org.apidesign.bck2brwsr.emul.MethodImpl;
175.36 -
175.37 -/**
175.38 - * A {@code Method} provides information about, and access to, a single method
175.39 - * on a class or interface. The reflected method may be a class method
175.40 - * or an instance method (including an abstract method).
175.41 - *
175.42 - * <p>A {@code Method} permits widening conversions to occur when matching the
175.43 - * actual parameters to invoke with the underlying method's formal
175.44 - * parameters, but it throws an {@code IllegalArgumentException} if a
175.45 - * narrowing conversion would occur.
175.46 - *
175.47 - * @see Member
175.48 - * @see java.lang.Class
175.49 - * @see java.lang.Class#getMethods()
175.50 - * @see java.lang.Class#getMethod(String, Class[])
175.51 - * @see java.lang.Class#getDeclaredMethods()
175.52 - * @see java.lang.Class#getDeclaredMethod(String, Class[])
175.53 - *
175.54 - * @author Kenneth Russell
175.55 - * @author Nakul Saraiya
175.56 - */
175.57 -public final
175.58 - class Method extends AccessibleObject implements GenericDeclaration,
175.59 - Member {
175.60 - private final Class<?> clazz;
175.61 - private final String name;
175.62 - private final Object data;
175.63 - private final String sig;
175.64 -
175.65 - // Generics infrastructure
175.66 -
175.67 - private String getGenericSignature() {return null;}
175.68 -
175.69 - /**
175.70 - * Package-private constructor used by ReflectAccess to enable
175.71 - * instantiation of these objects in Java code from the java.lang
175.72 - * package via sun.reflect.LangReflectAccess.
175.73 - */
175.74 - Method(Class<?> declaringClass, String name, Object data, String sig)
175.75 - {
175.76 - this.clazz = declaringClass;
175.77 - this.name = name;
175.78 - this.data = data;
175.79 - this.sig = sig;
175.80 - }
175.81 -
175.82 - /**
175.83 - * Package-private routine (exposed to java.lang.Class via
175.84 - * ReflectAccess) which returns a copy of this Method. The copy's
175.85 - * "root" field points to this Method.
175.86 - */
175.87 - Method copy() {
175.88 - return this;
175.89 - }
175.90 -
175.91 - /**
175.92 - * Returns the {@code Class} object representing the class or interface
175.93 - * that declares the method represented by this {@code Method} object.
175.94 - */
175.95 - public Class<?> getDeclaringClass() {
175.96 - return clazz;
175.97 - }
175.98 -
175.99 - /**
175.100 - * Returns the name of the method represented by this {@code Method}
175.101 - * object, as a {@code String}.
175.102 - */
175.103 - public String getName() {
175.104 - return name;
175.105 - }
175.106 -
175.107 - /**
175.108 - * Returns the Java language modifiers for the method represented
175.109 - * by this {@code Method} object, as an integer. The {@code Modifier} class should
175.110 - * be used to decode the modifiers.
175.111 - *
175.112 - * @see Modifier
175.113 - */
175.114 - public int getModifiers() {
175.115 - return getAccess(data);
175.116 - }
175.117 -
175.118 - @JavaScriptBody(args = "self", body = "return self.access;")
175.119 - private static native int getAccess(Object self);
175.120 -
175.121 - /**
175.122 - * Returns an array of {@code TypeVariable} objects that represent the
175.123 - * type variables declared by the generic declaration represented by this
175.124 - * {@code GenericDeclaration} object, in declaration order. Returns an
175.125 - * array of length 0 if the underlying generic declaration declares no type
175.126 - * variables.
175.127 - *
175.128 - * @return an array of {@code TypeVariable} objects that represent
175.129 - * the type variables declared by this generic declaration
175.130 - * @throws GenericSignatureFormatError if the generic
175.131 - * signature of this generic declaration does not conform to
175.132 - * the format specified in
175.133 - * <cite>The Java™ Virtual Machine Specification</cite>
175.134 - * @since 1.5
175.135 - */
175.136 - public TypeVariable<Method>[] getTypeParameters() {
175.137 - throw new UnsupportedOperationException();
175.138 - }
175.139 -
175.140 - /**
175.141 - * Returns a {@code Class} object that represents the formal return type
175.142 - * of the method represented by this {@code Method} object.
175.143 - *
175.144 - * @return the return type for the method this object represents
175.145 - */
175.146 - public Class<?> getReturnType() {
175.147 - return MethodImpl.signatureParser(sig).nextElement();
175.148 - }
175.149 -
175.150 - /**
175.151 - * Returns a {@code Type} object that represents the formal return
175.152 - * type of the method represented by this {@code Method} object.
175.153 - *
175.154 - * <p>If the return type is a parameterized type,
175.155 - * the {@code Type} object returned must accurately reflect
175.156 - * the actual type parameters used in the source code.
175.157 - *
175.158 - * <p>If the return type is a type variable or a parameterized type, it
175.159 - * is created. Otherwise, it is resolved.
175.160 - *
175.161 - * @return a {@code Type} object that represents the formal return
175.162 - * type of the underlying method
175.163 - * @throws GenericSignatureFormatError
175.164 - * if the generic method signature does not conform to the format
175.165 - * specified in
175.166 - * <cite>The Java™ Virtual Machine Specification</cite>
175.167 - * @throws TypeNotPresentException if the underlying method's
175.168 - * return type refers to a non-existent type declaration
175.169 - * @throws MalformedParameterizedTypeException if the
175.170 - * underlying method's return typed refers to a parameterized
175.171 - * type that cannot be instantiated for any reason
175.172 - * @since 1.5
175.173 - */
175.174 - public Type getGenericReturnType() {
175.175 - throw new UnsupportedOperationException();
175.176 - }
175.177 -
175.178 -
175.179 - /**
175.180 - * Returns an array of {@code Class} objects that represent the formal
175.181 - * parameter types, in declaration order, of the method
175.182 - * represented by this {@code Method} object. Returns an array of length
175.183 - * 0 if the underlying method takes no parameters.
175.184 - *
175.185 - * @return the parameter types for the method this object
175.186 - * represents
175.187 - */
175.188 - public Class<?>[] getParameterTypes() {
175.189 - Class[] arr = new Class[MethodImpl.signatureElements(sig) - 1];
175.190 - Enumeration<Class> en = MethodImpl.signatureParser(sig);
175.191 - en.nextElement(); // return type
175.192 - for (int i = 0; i < arr.length; i++) {
175.193 - arr[i] = en.nextElement();
175.194 - }
175.195 - return arr;
175.196 - }
175.197 -
175.198 - /**
175.199 - * Returns an array of {@code Type} objects that represent the formal
175.200 - * parameter types, in declaration order, of the method represented by
175.201 - * this {@code Method} object. Returns an array of length 0 if the
175.202 - * underlying method takes no parameters.
175.203 - *
175.204 - * <p>If a formal parameter type is a parameterized type,
175.205 - * the {@code Type} object returned for it must accurately reflect
175.206 - * the actual type parameters used in the source code.
175.207 - *
175.208 - * <p>If a formal parameter type is a type variable or a parameterized
175.209 - * type, it is created. Otherwise, it is resolved.
175.210 - *
175.211 - * @return an array of Types that represent the formal
175.212 - * parameter types of the underlying method, in declaration order
175.213 - * @throws GenericSignatureFormatError
175.214 - * if the generic method signature does not conform to the format
175.215 - * specified in
175.216 - * <cite>The Java™ Virtual Machine Specification</cite>
175.217 - * @throws TypeNotPresentException if any of the parameter
175.218 - * types of the underlying method refers to a non-existent type
175.219 - * declaration
175.220 - * @throws MalformedParameterizedTypeException if any of
175.221 - * the underlying method's parameter types refer to a parameterized
175.222 - * type that cannot be instantiated for any reason
175.223 - * @since 1.5
175.224 - */
175.225 - public Type[] getGenericParameterTypes() {
175.226 - throw new UnsupportedOperationException();
175.227 - }
175.228 -
175.229 -
175.230 - /**
175.231 - * Returns an array of {@code Class} objects that represent
175.232 - * the types of the exceptions declared to be thrown
175.233 - * by the underlying method
175.234 - * represented by this {@code Method} object. Returns an array of length
175.235 - * 0 if the method declares no exceptions in its {@code throws} clause.
175.236 - *
175.237 - * @return the exception types declared as being thrown by the
175.238 - * method this object represents
175.239 - */
175.240 - public Class<?>[] getExceptionTypes() {
175.241 - throw new UnsupportedOperationException();
175.242 - //return (Class<?>[]) exceptionTypes.clone();
175.243 - }
175.244 -
175.245 - /**
175.246 - * Returns an array of {@code Type} objects that represent the
175.247 - * exceptions declared to be thrown by this {@code Method} object.
175.248 - * Returns an array of length 0 if the underlying method declares
175.249 - * no exceptions in its {@code throws} clause.
175.250 - *
175.251 - * <p>If an exception type is a type variable or a parameterized
175.252 - * type, it is created. Otherwise, it is resolved.
175.253 - *
175.254 - * @return an array of Types that represent the exception types
175.255 - * thrown by the underlying method
175.256 - * @throws GenericSignatureFormatError
175.257 - * if the generic method signature does not conform to the format
175.258 - * specified in
175.259 - * <cite>The Java™ Virtual Machine Specification</cite>
175.260 - * @throws TypeNotPresentException if the underlying method's
175.261 - * {@code throws} clause refers to a non-existent type declaration
175.262 - * @throws MalformedParameterizedTypeException if
175.263 - * the underlying method's {@code throws} clause refers to a
175.264 - * parameterized type that cannot be instantiated for any reason
175.265 - * @since 1.5
175.266 - */
175.267 - public Type[] getGenericExceptionTypes() {
175.268 - throw new UnsupportedOperationException();
175.269 - }
175.270 -
175.271 - /**
175.272 - * Compares this {@code Method} against the specified object. Returns
175.273 - * true if the objects are the same. Two {@code Methods} are the same if
175.274 - * they were declared by the same class and have the same name
175.275 - * and formal parameter types and return type.
175.276 - */
175.277 - public boolean equals(Object obj) {
175.278 - if (obj != null && obj instanceof Method) {
175.279 - Method other = (Method)obj;
175.280 - return data == other.data;
175.281 - }
175.282 - return false;
175.283 - }
175.284 -
175.285 - /**
175.286 - * Returns a hashcode for this {@code Method}. The hashcode is computed
175.287 - * as the exclusive-or of the hashcodes for the underlying
175.288 - * method's declaring class name and the method's name.
175.289 - */
175.290 - public int hashCode() {
175.291 - return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
175.292 - }
175.293 -
175.294 - /**
175.295 - * Returns a string describing this {@code Method}. The string is
175.296 - * formatted as the method access modifiers, if any, followed by
175.297 - * the method return type, followed by a space, followed by the
175.298 - * class declaring the method, followed by a period, followed by
175.299 - * the method name, followed by a parenthesized, comma-separated
175.300 - * list of the method's formal parameter types. If the method
175.301 - * throws checked exceptions, the parameter list is followed by a
175.302 - * space, followed by the word throws followed by a
175.303 - * comma-separated list of the thrown exception types.
175.304 - * For example:
175.305 - * <pre>
175.306 - * public boolean java.lang.Object.equals(java.lang.Object)
175.307 - * </pre>
175.308 - *
175.309 - * <p>The access modifiers are placed in canonical order as
175.310 - * specified by "The Java Language Specification". This is
175.311 - * {@code public}, {@code protected} or {@code private} first,
175.312 - * and then other modifiers in the following order:
175.313 - * {@code abstract}, {@code static}, {@code final},
175.314 - * {@code synchronized}, {@code native}, {@code strictfp}.
175.315 - */
175.316 - public String toString() {
175.317 - try {
175.318 - StringBuilder sb = new StringBuilder();
175.319 - int mod = getModifiers() & Modifier.methodModifiers();
175.320 - if (mod != 0) {
175.321 - sb.append(Modifier.toString(mod)).append(' ');
175.322 - }
175.323 - sb.append(Field.getTypeName(getReturnType())).append(' ');
175.324 - sb.append(Field.getTypeName(getDeclaringClass())).append('.');
175.325 - sb.append(getName()).append('(');
175.326 - Class<?>[] params = getParameterTypes(); // avoid clone
175.327 - for (int j = 0; j < params.length; j++) {
175.328 - sb.append(Field.getTypeName(params[j]));
175.329 - if (j < (params.length - 1))
175.330 - sb.append(',');
175.331 - }
175.332 - sb.append(')');
175.333 - /*
175.334 - Class<?>[] exceptions = exceptionTypes; // avoid clone
175.335 - if (exceptions.length > 0) {
175.336 - sb.append(" throws ");
175.337 - for (int k = 0; k < exceptions.length; k++) {
175.338 - sb.append(exceptions[k].getName());
175.339 - if (k < (exceptions.length - 1))
175.340 - sb.append(',');
175.341 - }
175.342 - }
175.343 - */
175.344 - return sb.toString();
175.345 - } catch (Exception e) {
175.346 - return "<" + e + ">";
175.347 - }
175.348 - }
175.349 -
175.350 - /**
175.351 - * Returns a string describing this {@code Method}, including
175.352 - * type parameters. The string is formatted as the method access
175.353 - * modifiers, if any, followed by an angle-bracketed
175.354 - * comma-separated list of the method's type parameters, if any,
175.355 - * followed by the method's generic return type, followed by a
175.356 - * space, followed by the class declaring the method, followed by
175.357 - * a period, followed by the method name, followed by a
175.358 - * parenthesized, comma-separated list of the method's generic
175.359 - * formal parameter types.
175.360 - *
175.361 - * If this method was declared to take a variable number of
175.362 - * arguments, instead of denoting the last parameter as
175.363 - * "<tt><i>Type</i>[]</tt>", it is denoted as
175.364 - * "<tt><i>Type</i>...</tt>".
175.365 - *
175.366 - * A space is used to separate access modifiers from one another
175.367 - * and from the type parameters or return type. If there are no
175.368 - * type parameters, the type parameter list is elided; if the type
175.369 - * parameter list is present, a space separates the list from the
175.370 - * class name. If the method is declared to throw exceptions, the
175.371 - * parameter list is followed by a space, followed by the word
175.372 - * throws followed by a comma-separated list of the generic thrown
175.373 - * exception types. If there are no type parameters, the type
175.374 - * parameter list is elided.
175.375 - *
175.376 - * <p>The access modifiers are placed in canonical order as
175.377 - * specified by "The Java Language Specification". This is
175.378 - * {@code public}, {@code protected} or {@code private} first,
175.379 - * and then other modifiers in the following order:
175.380 - * {@code abstract}, {@code static}, {@code final},
175.381 - * {@code synchronized}, {@code native}, {@code strictfp}.
175.382 - *
175.383 - * @return a string describing this {@code Method},
175.384 - * include type parameters
175.385 - *
175.386 - * @since 1.5
175.387 - */
175.388 - public String toGenericString() {
175.389 - try {
175.390 - StringBuilder sb = new StringBuilder();
175.391 - int mod = getModifiers() & Modifier.methodModifiers();
175.392 - if (mod != 0) {
175.393 - sb.append(Modifier.toString(mod)).append(' ');
175.394 - }
175.395 - TypeVariable<?>[] typeparms = getTypeParameters();
175.396 - if (typeparms.length > 0) {
175.397 - boolean first = true;
175.398 - sb.append('<');
175.399 - for(TypeVariable<?> typeparm: typeparms) {
175.400 - if (!first)
175.401 - sb.append(',');
175.402 - // Class objects can't occur here; no need to test
175.403 - // and call Class.getName().
175.404 - sb.append(typeparm.toString());
175.405 - first = false;
175.406 - }
175.407 - sb.append("> ");
175.408 - }
175.409 -
175.410 - Type genRetType = getGenericReturnType();
175.411 - sb.append( ((genRetType instanceof Class<?>)?
175.412 - Field.getTypeName((Class<?>)genRetType):genRetType.toString()))
175.413 - .append(' ');
175.414 -
175.415 - sb.append(Field.getTypeName(getDeclaringClass())).append('.');
175.416 - sb.append(getName()).append('(');
175.417 - Type[] params = getGenericParameterTypes();
175.418 - for (int j = 0; j < params.length; j++) {
175.419 - String param = (params[j] instanceof Class)?
175.420 - Field.getTypeName((Class)params[j]):
175.421 - (params[j].toString());
175.422 - if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
175.423 - param = param.replaceFirst("\\[\\]$", "...");
175.424 - sb.append(param);
175.425 - if (j < (params.length - 1))
175.426 - sb.append(',');
175.427 - }
175.428 - sb.append(')');
175.429 - Type[] exceptions = getGenericExceptionTypes();
175.430 - if (exceptions.length > 0) {
175.431 - sb.append(" throws ");
175.432 - for (int k = 0; k < exceptions.length; k++) {
175.433 - sb.append((exceptions[k] instanceof Class)?
175.434 - ((Class)exceptions[k]).getName():
175.435 - exceptions[k].toString());
175.436 - if (k < (exceptions.length - 1))
175.437 - sb.append(',');
175.438 - }
175.439 - }
175.440 - return sb.toString();
175.441 - } catch (Exception e) {
175.442 - return "<" + e + ">";
175.443 - }
175.444 - }
175.445 -
175.446 - /**
175.447 - * Invokes the underlying method represented by this {@code Method}
175.448 - * object, on the specified object with the specified parameters.
175.449 - * Individual parameters are automatically unwrapped to match
175.450 - * primitive formal parameters, and both primitive and reference
175.451 - * parameters are subject to method invocation conversions as
175.452 - * necessary.
175.453 - *
175.454 - * <p>If the underlying method is static, then the specified {@code obj}
175.455 - * argument is ignored. It may be null.
175.456 - *
175.457 - * <p>If the number of formal parameters required by the underlying method is
175.458 - * 0, the supplied {@code args} array may be of length 0 or null.
175.459 - *
175.460 - * <p>If the underlying method is an instance method, it is invoked
175.461 - * using dynamic method lookup as documented in The Java Language
175.462 - * Specification, Second Edition, section 15.12.4.4; in particular,
175.463 - * overriding based on the runtime type of the target object will occur.
175.464 - *
175.465 - * <p>If the underlying method is static, the class that declared
175.466 - * the method is initialized if it has not already been initialized.
175.467 - *
175.468 - * <p>If the method completes normally, the value it returns is
175.469 - * returned to the caller of invoke; if the value has a primitive
175.470 - * type, it is first appropriately wrapped in an object. However,
175.471 - * if the value has the type of an array of a primitive type, the
175.472 - * elements of the array are <i>not</i> wrapped in objects; in
175.473 - * other words, an array of primitive type is returned. If the
175.474 - * underlying method return type is void, the invocation returns
175.475 - * null.
175.476 - *
175.477 - * @param obj the object the underlying method is invoked from
175.478 - * @param args the arguments used for the method call
175.479 - * @return the result of dispatching the method represented by
175.480 - * this object on {@code obj} with parameters
175.481 - * {@code args}
175.482 - *
175.483 - * @exception IllegalAccessException if this {@code Method} object
175.484 - * is enforcing Java language access control and the underlying
175.485 - * method is inaccessible.
175.486 - * @exception IllegalArgumentException if the method is an
175.487 - * instance method and the specified object argument
175.488 - * is not an instance of the class or interface
175.489 - * declaring the underlying method (or of a subclass
175.490 - * or implementor thereof); if the number of actual
175.491 - * and formal parameters differ; if an unwrapping
175.492 - * conversion for primitive arguments fails; or if,
175.493 - * after possible unwrapping, a parameter value
175.494 - * cannot be converted to the corresponding formal
175.495 - * parameter type by a method invocation conversion.
175.496 - * @exception InvocationTargetException if the underlying method
175.497 - * throws an exception.
175.498 - * @exception NullPointerException if the specified object is null
175.499 - * and the method is an instance method.
175.500 - * @exception ExceptionInInitializerError if the initialization
175.501 - * provoked by this method fails.
175.502 - */
175.503 - public Object invoke(Object obj, Object... args)
175.504 - throws IllegalAccessException, IllegalArgumentException,
175.505 - InvocationTargetException
175.506 - {
175.507 - final boolean isStatic = (getModifiers() & Modifier.STATIC) == 0;
175.508 - if (isStatic && obj == null) {
175.509 - throw new NullPointerException();
175.510 - }
175.511 - Class[] types = getParameterTypes();
175.512 - if (types.length != args.length) {
175.513 - throw new IllegalArgumentException("Types len " + types.length + " args: " + args.length);
175.514 - } else {
175.515 - args = args.clone();
175.516 - for (int i = 0; i < types.length; i++) {
175.517 - Class c = types[i];
175.518 - if (c.isPrimitive()) {
175.519 - args[i] = toPrimitive(c, args[i]);
175.520 - }
175.521 - }
175.522 - }
175.523 - Object res = invoke0(isStatic, this, obj, args);
175.524 - if (getReturnType().isPrimitive()) {
175.525 - res = fromPrimitive(getReturnType(), res);
175.526 - }
175.527 - return res;
175.528 - }
175.529 -
175.530 - @JavaScriptBody(args = { "st", "method", "self", "args" }, body =
175.531 - "var p;\n"
175.532 - + "if (st) {\n"
175.533 - + " p = new Array(1);\n"
175.534 - + " p[0] = self;\n"
175.535 - + " p = p.concat(args);\n"
175.536 - + "} else {\n"
175.537 - + " p = args;\n"
175.538 - + "}\n"
175.539 - + "return method.fld_data.apply(self, p);\n"
175.540 - )
175.541 - private static native Object invoke0(boolean isStatic, Method m, Object self, Object[] args);
175.542 -
175.543 - static Object fromPrimitive(Class<?> type, Object o) {
175.544 - if (type == Integer.TYPE) {
175.545 - return fromRaw(Integer.class, "valueOf__Ljava_lang_Integer_2I", o);
175.546 - }
175.547 - if (type == Long.TYPE) {
175.548 - return fromRaw(Long.class, "valueOf__Ljava_lang_Long_2J", o);
175.549 - }
175.550 - if (type == Double.TYPE) {
175.551 - return fromRaw(Double.class, "valueOf__Ljava_lang_Double_2D", o);
175.552 - }
175.553 - if (type == Float.TYPE) {
175.554 - return fromRaw(Float.class, "valueOf__Ljava_lang_Float_2F", o);
175.555 - }
175.556 - if (type == Byte.TYPE) {
175.557 - return fromRaw(Byte.class, "valueOf__Ljava_lang_Byte_2B", o);
175.558 - }
175.559 - if (type == Boolean.TYPE) {
175.560 - return fromRaw(Boolean.class, "valueOf__Ljava_lang_Boolean_2Z", o);
175.561 - }
175.562 - if (type == Short.TYPE) {
175.563 - return fromRaw(Short.class, "valueOf__Ljava_lang_Short_2S", o);
175.564 - }
175.565 - if (type == Character.TYPE) {
175.566 - return fromRaw(Character.class, "valueOf__Ljava_lang_Character_2C", o);
175.567 - }
175.568 - if (type.getName().equals("void")) {
175.569 - return null;
175.570 - }
175.571 - throw new IllegalStateException("Can't convert " + o);
175.572 - }
175.573 -
175.574 - @JavaScriptBody(args = { "cls", "m", "o" },
175.575 - body = "return cls.cnstr(false)[m](o);"
175.576 - )
175.577 - private static native Integer fromRaw(Class<?> cls, String m, Object o);
175.578 -
175.579 - private static Object toPrimitive(Class<?> type, Object o) {
175.580 - if (type == Integer.TYPE) {
175.581 - return toRaw("intValue__I", o);
175.582 - }
175.583 - if (type == Long.TYPE) {
175.584 - return toRaw("longValue__J", o);
175.585 - }
175.586 - if (type == Double.TYPE) {
175.587 - return toRaw("doubleValue__D", o);
175.588 - }
175.589 - if (type == Float.TYPE) {
175.590 - return toRaw("floatValue__F", o);
175.591 - }
175.592 - if (type == Byte.TYPE) {
175.593 - return toRaw("byteValue__B", o);
175.594 - }
175.595 - if (type == Boolean.TYPE) {
175.596 - return toRaw("booleanValue__Z", o);
175.597 - }
175.598 - if (type == Short.TYPE) {
175.599 - return toRaw("shortValue__S", o);
175.600 - }
175.601 - if (type == Character.TYPE) {
175.602 - return toRaw("charValue__C", o);
175.603 - }
175.604 - if (type.getName().equals("void")) {
175.605 - return o;
175.606 - }
175.607 - throw new IllegalStateException("Can't convert " + o);
175.608 - }
175.609 -
175.610 - @JavaScriptBody(args = { "m", "o" },
175.611 - body = "return o[m](o);"
175.612 - )
175.613 - private static native Object toRaw(String m, Object o);
175.614 -
175.615 - /**
175.616 - * Returns {@code true} if this method is a bridge
175.617 - * method; returns {@code false} otherwise.
175.618 - *
175.619 - * @return true if and only if this method is a bridge
175.620 - * method as defined by the Java Language Specification.
175.621 - * @since 1.5
175.622 - */
175.623 - public boolean isBridge() {
175.624 - return (getModifiers() & Modifier.BRIDGE) != 0;
175.625 - }
175.626 -
175.627 - /**
175.628 - * Returns {@code true} if this method was declared to take
175.629 - * a variable number of arguments; returns {@code false}
175.630 - * otherwise.
175.631 - *
175.632 - * @return {@code true} if an only if this method was declared to
175.633 - * take a variable number of arguments.
175.634 - * @since 1.5
175.635 - */
175.636 - public boolean isVarArgs() {
175.637 - return (getModifiers() & Modifier.VARARGS) != 0;
175.638 - }
175.639 -
175.640 - /**
175.641 - * Returns {@code true} if this method is a synthetic
175.642 - * method; returns {@code false} otherwise.
175.643 - *
175.644 - * @return true if and only if this method is a synthetic
175.645 - * method as defined by the Java Language Specification.
175.646 - * @since 1.5
175.647 - */
175.648 - public boolean isSynthetic() {
175.649 - return Modifier.isSynthetic(getModifiers());
175.650 - }
175.651 -
175.652 - @JavaScriptBody(args = { "ac" },
175.653 - body =
175.654 - "if (this.fld_data.anno) {"
175.655 - + " return this.fld_data.anno['L' + ac.jvmName + ';'];"
175.656 - + "} else return null;"
175.657 - )
175.658 - private Object getAnnotationData(Class<?> annotationClass) {
175.659 - throw new UnsupportedOperationException();
175.660 - }
175.661 -
175.662 - /**
175.663 - * @throws NullPointerException {@inheritDoc}
175.664 - * @since 1.5
175.665 - */
175.666 - public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
175.667 - Object data = getAnnotationData(annotationClass);
175.668 - return data == null ? null : AnnotationImpl.create(annotationClass, data);
175.669 - }
175.670 -
175.671 - /**
175.672 - * @since 1.5
175.673 - */
175.674 - public Annotation[] getDeclaredAnnotations() {
175.675 - throw new UnsupportedOperationException();
175.676 - }
175.677 -
175.678 - /**
175.679 - * Returns the default value for the annotation member represented by
175.680 - * this {@code Method} instance. If the member is of a primitive type,
175.681 - * an instance of the corresponding wrapper type is returned. Returns
175.682 - * null if no default is associated with the member, or if the method
175.683 - * instance does not represent a declared member of an annotation type.
175.684 - *
175.685 - * @return the default value for the annotation member represented
175.686 - * by this {@code Method} instance.
175.687 - * @throws TypeNotPresentException if the annotation is of type
175.688 - * {@link Class} and no definition can be found for the
175.689 - * default class value.
175.690 - * @since 1.5
175.691 - */
175.692 - public Object getDefaultValue() {
175.693 - throw new UnsupportedOperationException();
175.694 - }
175.695 -
175.696 - /**
175.697 - * Returns an array of arrays that represent the annotations on the formal
175.698 - * parameters, in declaration order, of the method represented by
175.699 - * this {@code Method} object. (Returns an array of length zero if the
175.700 - * underlying method is parameterless. If the method has one or more
175.701 - * parameters, a nested array of length zero is returned for each parameter
175.702 - * with no annotations.) The annotation objects contained in the returned
175.703 - * arrays are serializable. The caller of this method is free to modify
175.704 - * the returned arrays; it will have no effect on the arrays returned to
175.705 - * other callers.
175.706 - *
175.707 - * @return an array of arrays that represent the annotations on the formal
175.708 - * parameters, in declaration order, of the method represented by this
175.709 - * Method object
175.710 - * @since 1.5
175.711 - */
175.712 - public Annotation[][] getParameterAnnotations() {
175.713 - throw new UnsupportedOperationException();
175.714 - }
175.715 -
175.716 - static {
175.717 - MethodImpl.INSTANCE = new MethodImpl() {
175.718 - protected Method create(Class<?> declaringClass, String name, Object data, String sig) {
175.719 - return new Method(declaringClass, name, data, sig);
175.720 - }
175.721 - };
175.722 - }
175.723 -}
176.1 --- a/emul/src/main/java/java/lang/reflect/Modifier.java Wed Jan 23 20:16:48 2013 +0100
176.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
176.3 @@ -1,437 +0,0 @@
176.4 -/*
176.5 - * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
176.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
176.7 - *
176.8 - * This code is free software; you can redistribute it and/or modify it
176.9 - * under the terms of the GNU General Public License version 2 only, as
176.10 - * published by the Free Software Foundation. Oracle designates this
176.11 - * particular file as subject to the "Classpath" exception as provided
176.12 - * by Oracle in the LICENSE file that accompanied this code.
176.13 - *
176.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
176.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
176.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
176.17 - * version 2 for more details (a copy is included in the LICENSE file that
176.18 - * accompanied this code).
176.19 - *
176.20 - * You should have received a copy of the GNU General Public License version
176.21 - * 2 along with this work; if not, write to the Free Software Foundation,
176.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
176.23 - *
176.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
176.25 - * or visit www.oracle.com if you need additional information or have any
176.26 - * questions.
176.27 - */
176.28 -
176.29 -package java.lang.reflect;
176.30 -
176.31 -/**
176.32 - * The Modifier class provides {@code static} methods and
176.33 - * constants to decode class and member access modifiers. The sets of
176.34 - * modifiers are represented as integers with distinct bit positions
176.35 - * representing different modifiers. The values for the constants
176.36 - * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
176.37 - * <cite>The Java™ Virtual Machine Specification</cite>.
176.38 - *
176.39 - * @see Class#getModifiers()
176.40 - * @see Member#getModifiers()
176.41 - *
176.42 - * @author Nakul Saraiya
176.43 - * @author Kenneth Russell
176.44 - */
176.45 -public
176.46 -class Modifier {
176.47 -
176.48 - /**
176.49 - * Return {@code true} if the integer argument includes the
176.50 - * {@code public} modifier, {@code false} otherwise.
176.51 - *
176.52 - * @param mod a set of modifiers
176.53 - * @return {@code true} if {@code mod} includes the
176.54 - * {@code public} modifier; {@code false} otherwise.
176.55 - */
176.56 - public static boolean isPublic(int mod) {
176.57 - return (mod & PUBLIC) != 0;
176.58 - }
176.59 -
176.60 - /**
176.61 - * Return {@code true} if the integer argument includes the
176.62 - * {@code private} modifier, {@code false} otherwise.
176.63 - *
176.64 - * @param mod a set of modifiers
176.65 - * @return {@code true} if {@code mod} includes the
176.66 - * {@code private} modifier; {@code false} otherwise.
176.67 - */
176.68 - public static boolean isPrivate(int mod) {
176.69 - return (mod & PRIVATE) != 0;
176.70 - }
176.71 -
176.72 - /**
176.73 - * Return {@code true} if the integer argument includes the
176.74 - * {@code protected} modifier, {@code false} otherwise.
176.75 - *
176.76 - * @param mod a set of modifiers
176.77 - * @return {@code true} if {@code mod} includes the
176.78 - * {@code protected} modifier; {@code false} otherwise.
176.79 - */
176.80 - public static boolean isProtected(int mod) {
176.81 - return (mod & PROTECTED) != 0;
176.82 - }
176.83 -
176.84 - /**
176.85 - * Return {@code true} if the integer argument includes the
176.86 - * {@code static} modifier, {@code false} otherwise.
176.87 - *
176.88 - * @param mod a set of modifiers
176.89 - * @return {@code true} if {@code mod} includes the
176.90 - * {@code static} modifier; {@code false} otherwise.
176.91 - */
176.92 - public static boolean isStatic(int mod) {
176.93 - return (mod & STATIC) != 0;
176.94 - }
176.95 -
176.96 - /**
176.97 - * Return {@code true} if the integer argument includes the
176.98 - * {@code final} modifier, {@code false} otherwise.
176.99 - *
176.100 - * @param mod a set of modifiers
176.101 - * @return {@code true} if {@code mod} includes the
176.102 - * {@code final} modifier; {@code false} otherwise.
176.103 - */
176.104 - public static boolean isFinal(int mod) {
176.105 - return (mod & FINAL) != 0;
176.106 - }
176.107 -
176.108 - /**
176.109 - * Return {@code true} if the integer argument includes the
176.110 - * {@code synchronized} modifier, {@code false} otherwise.
176.111 - *
176.112 - * @param mod a set of modifiers
176.113 - * @return {@code true} if {@code mod} includes the
176.114 - * {@code synchronized} modifier; {@code false} otherwise.
176.115 - */
176.116 - public static boolean isSynchronized(int mod) {
176.117 - return (mod & SYNCHRONIZED) != 0;
176.118 - }
176.119 -
176.120 - /**
176.121 - * Return {@code true} if the integer argument includes the
176.122 - * {@code volatile} modifier, {@code false} otherwise.
176.123 - *
176.124 - * @param mod a set of modifiers
176.125 - * @return {@code true} if {@code mod} includes the
176.126 - * {@code volatile} modifier; {@code false} otherwise.
176.127 - */
176.128 - public static boolean isVolatile(int mod) {
176.129 - return (mod & VOLATILE) != 0;
176.130 - }
176.131 -
176.132 - /**
176.133 - * Return {@code true} if the integer argument includes the
176.134 - * {@code transient} modifier, {@code false} otherwise.
176.135 - *
176.136 - * @param mod a set of modifiers
176.137 - * @return {@code true} if {@code mod} includes the
176.138 - * {@code transient} modifier; {@code false} otherwise.
176.139 - */
176.140 - public static boolean isTransient(int mod) {
176.141 - return (mod & TRANSIENT) != 0;
176.142 - }
176.143 -
176.144 - /**
176.145 - * Return {@code true} if the integer argument includes the
176.146 - * {@code native} modifier, {@code false} otherwise.
176.147 - *
176.148 - * @param mod a set of modifiers
176.149 - * @return {@code true} if {@code mod} includes the
176.150 - * {@code native} modifier; {@code false} otherwise.
176.151 - */
176.152 - public static boolean isNative(int mod) {
176.153 - return (mod & NATIVE) != 0;
176.154 - }
176.155 -
176.156 - /**
176.157 - * Return {@code true} if the integer argument includes the
176.158 - * {@code interface} modifier, {@code false} otherwise.
176.159 - *
176.160 - * @param mod a set of modifiers
176.161 - * @return {@code true} if {@code mod} includes the
176.162 - * {@code interface} modifier; {@code false} otherwise.
176.163 - */
176.164 - public static boolean isInterface(int mod) {
176.165 - return (mod & INTERFACE) != 0;
176.166 - }
176.167 -
176.168 - /**
176.169 - * Return {@code true} if the integer argument includes the
176.170 - * {@code abstract} modifier, {@code false} otherwise.
176.171 - *
176.172 - * @param mod a set of modifiers
176.173 - * @return {@code true} if {@code mod} includes the
176.174 - * {@code abstract} modifier; {@code false} otherwise.
176.175 - */
176.176 - public static boolean isAbstract(int mod) {
176.177 - return (mod & ABSTRACT) != 0;
176.178 - }
176.179 -
176.180 - /**
176.181 - * Return {@code true} if the integer argument includes the
176.182 - * {@code strictfp} modifier, {@code false} otherwise.
176.183 - *
176.184 - * @param mod a set of modifiers
176.185 - * @return {@code true} if {@code mod} includes the
176.186 - * {@code strictfp} modifier; {@code false} otherwise.
176.187 - */
176.188 - public static boolean isStrict(int mod) {
176.189 - return (mod & STRICT) != 0;
176.190 - }
176.191 -
176.192 - /**
176.193 - * Return a string describing the access modifier flags in
176.194 - * the specified modifier. For example:
176.195 - * <blockquote><pre>
176.196 - * public final synchronized strictfp
176.197 - * </pre></blockquote>
176.198 - * The modifier names are returned in an order consistent with the
176.199 - * suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of
176.200 - * <cite>The Java™ Language Specification</cite>.
176.201 - * The full modifier ordering used by this method is:
176.202 - * <blockquote> {@code
176.203 - * public protected private abstract static final transient
176.204 - * volatile synchronized native strictfp
176.205 - * interface } </blockquote>
176.206 - * The {@code interface} modifier discussed in this class is
176.207 - * not a true modifier in the Java language and it appears after
176.208 - * all other modifiers listed by this method. This method may
176.209 - * return a string of modifiers that are not valid modifiers of a
176.210 - * Java entity; in other words, no checking is done on the
176.211 - * possible validity of the combination of modifiers represented
176.212 - * by the input.
176.213 - *
176.214 - * Note that to perform such checking for a known kind of entity,
176.215 - * such as a constructor or method, first AND the argument of
176.216 - * {@code toString} with the appropriate mask from a method like
176.217 - * {@link #constructorModifiers} or {@link #methodModifiers}.
176.218 - *
176.219 - * @param mod a set of modifiers
176.220 - * @return a string representation of the set of modifiers
176.221 - * represented by {@code mod}
176.222 - */
176.223 - public static String toString(int mod) {
176.224 - StringBuffer sb = new StringBuffer();
176.225 - int len;
176.226 -
176.227 - if ((mod & PUBLIC) != 0) sb.append("public ");
176.228 - if ((mod & PROTECTED) != 0) sb.append("protected ");
176.229 - if ((mod & PRIVATE) != 0) sb.append("private ");
176.230 -
176.231 - /* Canonical order */
176.232 - if ((mod & ABSTRACT) != 0) sb.append("abstract ");
176.233 - if ((mod & STATIC) != 0) sb.append("static ");
176.234 - if ((mod & FINAL) != 0) sb.append("final ");
176.235 - if ((mod & TRANSIENT) != 0) sb.append("transient ");
176.236 - if ((mod & VOLATILE) != 0) sb.append("volatile ");
176.237 - if ((mod & SYNCHRONIZED) != 0) sb.append("synchronized ");
176.238 - if ((mod & NATIVE) != 0) sb.append("native ");
176.239 - if ((mod & STRICT) != 0) sb.append("strictfp ");
176.240 - if ((mod & INTERFACE) != 0) sb.append("interface ");
176.241 -
176.242 - if ((len = sb.length()) > 0) /* trim trailing space */
176.243 - return sb.toString().substring(0, len-1);
176.244 - return "";
176.245 - }
176.246 -
176.247 - /*
176.248 - * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
176.249 - * <cite>The Java™ Virtual Machine Specification</cite>
176.250 - */
176.251 -
176.252 - /**
176.253 - * The {@code int} value representing the {@code public}
176.254 - * modifier.
176.255 - */
176.256 - public static final int PUBLIC = 0x00000001;
176.257 -
176.258 - /**
176.259 - * The {@code int} value representing the {@code private}
176.260 - * modifier.
176.261 - */
176.262 - public static final int PRIVATE = 0x00000002;
176.263 -
176.264 - /**
176.265 - * The {@code int} value representing the {@code protected}
176.266 - * modifier.
176.267 - */
176.268 - public static final int PROTECTED = 0x00000004;
176.269 -
176.270 - /**
176.271 - * The {@code int} value representing the {@code static}
176.272 - * modifier.
176.273 - */
176.274 - public static final int STATIC = 0x00000008;
176.275 -
176.276 - /**
176.277 - * The {@code int} value representing the {@code final}
176.278 - * modifier.
176.279 - */
176.280 - public static final int FINAL = 0x00000010;
176.281 -
176.282 - /**
176.283 - * The {@code int} value representing the {@code synchronized}
176.284 - * modifier.
176.285 - */
176.286 - public static final int SYNCHRONIZED = 0x00000020;
176.287 -
176.288 - /**
176.289 - * The {@code int} value representing the {@code volatile}
176.290 - * modifier.
176.291 - */
176.292 - public static final int VOLATILE = 0x00000040;
176.293 -
176.294 - /**
176.295 - * The {@code int} value representing the {@code transient}
176.296 - * modifier.
176.297 - */
176.298 - public static final int TRANSIENT = 0x00000080;
176.299 -
176.300 - /**
176.301 - * The {@code int} value representing the {@code native}
176.302 - * modifier.
176.303 - */
176.304 - public static final int NATIVE = 0x00000100;
176.305 -
176.306 - /**
176.307 - * The {@code int} value representing the {@code interface}
176.308 - * modifier.
176.309 - */
176.310 - public static final int INTERFACE = 0x00000200;
176.311 -
176.312 - /**
176.313 - * The {@code int} value representing the {@code abstract}
176.314 - * modifier.
176.315 - */
176.316 - public static final int ABSTRACT = 0x00000400;
176.317 -
176.318 - /**
176.319 - * The {@code int} value representing the {@code strictfp}
176.320 - * modifier.
176.321 - */
176.322 - public static final int STRICT = 0x00000800;
176.323 -
176.324 - // Bits not (yet) exposed in the public API either because they
176.325 - // have different meanings for fields and methods and there is no
176.326 - // way to distinguish between the two in this class, or because
176.327 - // they are not Java programming language keywords
176.328 - static final int BRIDGE = 0x00000040;
176.329 - static final int VARARGS = 0x00000080;
176.330 - static final int SYNTHETIC = 0x00001000;
176.331 - static final int ANNOTATION= 0x00002000;
176.332 - static final int ENUM = 0x00004000;
176.333 - static boolean isSynthetic(int mod) {
176.334 - return (mod & SYNTHETIC) != 0;
176.335 - }
176.336 -
176.337 - /**
176.338 - * See JLSv3 section 8.1.1.
176.339 - */
176.340 - private static final int CLASS_MODIFIERS =
176.341 - Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
176.342 - Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
176.343 - Modifier.STRICT;
176.344 -
176.345 - /**
176.346 - * See JLSv3 section 9.1.1.
176.347 - */
176.348 - private static final int INTERFACE_MODIFIERS =
176.349 - Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
176.350 - Modifier.ABSTRACT | Modifier.STATIC | Modifier.STRICT;
176.351 -
176.352 -
176.353 - /**
176.354 - * See JLSv3 section 8.8.3.
176.355 - */
176.356 - private static final int CONSTRUCTOR_MODIFIERS =
176.357 - Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE;
176.358 -
176.359 - /**
176.360 - * See JLSv3 section 8.4.3.
176.361 - */
176.362 - private static final int METHOD_MODIFIERS =
176.363 - Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
176.364 - Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
176.365 - Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT;
176.366 -
176.367 - /**
176.368 - * See JLSv3 section 8.3.1.
176.369 - */
176.370 - private static final int FIELD_MODIFIERS =
176.371 - Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
176.372 - Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT |
176.373 - Modifier.VOLATILE;
176.374 -
176.375 - /**
176.376 - * Return an {@code int} value OR-ing together the source language
176.377 - * modifiers that can be applied to a class.
176.378 - * @return an {@code int} value OR-ing together the source language
176.379 - * modifiers that can be applied to a class.
176.380 - *
176.381 - * @jls 8.1.1 Class Modifiers
176.382 - * @since 1.7
176.383 - */
176.384 - public static int classModifiers() {
176.385 - return CLASS_MODIFIERS;
176.386 - }
176.387 -
176.388 - /**
176.389 - * Return an {@code int} value OR-ing together the source language
176.390 - * modifiers that can be applied to an interface.
176.391 - * @return an {@code int} value OR-ing together the source language
176.392 - * modifiers that can be applied to an inteface.
176.393 - *
176.394 - * @jls 9.1.1 Interface Modifiers
176.395 - * @since 1.7
176.396 - */
176.397 - public static int interfaceModifiers() {
176.398 - return INTERFACE_MODIFIERS;
176.399 - }
176.400 -
176.401 - /**
176.402 - * Return an {@code int} value OR-ing together the source language
176.403 - * modifiers that can be applied to a constructor.
176.404 - * @return an {@code int} value OR-ing together the source language
176.405 - * modifiers that can be applied to a constructor.
176.406 - *
176.407 - * @jls 8.8.3 Constructor Modifiers
176.408 - * @since 1.7
176.409 - */
176.410 - public static int constructorModifiers() {
176.411 - return CONSTRUCTOR_MODIFIERS;
176.412 - }
176.413 -
176.414 - /**
176.415 - * Return an {@code int} value OR-ing together the source language
176.416 - * modifiers that can be applied to a method.
176.417 - * @return an {@code int} value OR-ing together the source language
176.418 - * modifiers that can be applied to a method.
176.419 - *
176.420 - * @jls 8.4.3 Method Modifiers
176.421 - * @since 1.7
176.422 - */
176.423 - public static int methodModifiers() {
176.424 - return METHOD_MODIFIERS;
176.425 - }
176.426 -
176.427 -
176.428 - /**
176.429 - * Return an {@code int} value OR-ing together the source language
176.430 - * modifiers that can be applied to a field.
176.431 - * @return an {@code int} value OR-ing together the source language
176.432 - * modifiers that can be applied to a field.
176.433 - *
176.434 - * @jls 8.3.1 Field Modifiers
176.435 - * @since 1.7
176.436 - */
176.437 - public static int fieldModifiers() {
176.438 - return FIELD_MODIFIERS;
176.439 - }
176.440 -}
177.1 --- a/emul/src/main/java/java/lang/reflect/Type.java Wed Jan 23 20:16:48 2013 +0100
177.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
177.3 @@ -1,37 +0,0 @@
177.4 -/*
177.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
177.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
177.7 - *
177.8 - * This code is free software; you can redistribute it and/or modify it
177.9 - * under the terms of the GNU General Public License version 2 only, as
177.10 - * published by the Free Software Foundation. Oracle designates this
177.11 - * particular file as subject to the "Classpath" exception as provided
177.12 - * by Oracle in the LICENSE file that accompanied this code.
177.13 - *
177.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
177.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
177.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
177.17 - * version 2 for more details (a copy is included in the LICENSE file that
177.18 - * accompanied this code).
177.19 - *
177.20 - * You should have received a copy of the GNU General Public License version
177.21 - * 2 along with this work; if not, write to the Free Software Foundation,
177.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
177.23 - *
177.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
177.25 - * or visit www.oracle.com if you need additional information or have any
177.26 - * questions.
177.27 - */
177.28 -
177.29 -package java.lang.reflect;
177.30 -
177.31 -/**
177.32 - * Type is the common superinterface for all types in the Java
177.33 - * programming language. These include raw types, parameterized types,
177.34 - * array types, type variables and primitive types.
177.35 - *
177.36 - * @since 1.5
177.37 - */
177.38 -
177.39 -public interface Type {
177.40 -}
178.1 --- a/emul/src/main/java/java/lang/reflect/TypeVariable.java Wed Jan 23 20:16:48 2013 +0100
178.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
178.3 @@ -1,89 +0,0 @@
178.4 -/*
178.5 - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
178.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
178.7 - *
178.8 - * This code is free software; you can redistribute it and/or modify it
178.9 - * under the terms of the GNU General Public License version 2 only, as
178.10 - * published by the Free Software Foundation. Oracle designates this
178.11 - * particular file as subject to the "Classpath" exception as provided
178.12 - * by Oracle in the LICENSE file that accompanied this code.
178.13 - *
178.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
178.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
178.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
178.17 - * version 2 for more details (a copy is included in the LICENSE file that
178.18 - * accompanied this code).
178.19 - *
178.20 - * You should have received a copy of the GNU General Public License version
178.21 - * 2 along with this work; if not, write to the Free Software Foundation,
178.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
178.23 - *
178.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
178.25 - * or visit www.oracle.com if you need additional information or have any
178.26 - * questions.
178.27 - */
178.28 -
178.29 -package java.lang.reflect;
178.30 -
178.31 -/**
178.32 - * TypeVariable is the common superinterface for type variables of kinds.
178.33 - * A type variable is created the first time it is needed by a reflective
178.34 - * method, as specified in this package. If a type variable t is referenced
178.35 - * by a type (i.e, class, interface or annotation type) T, and T is declared
178.36 - * by the nth enclosing class of T (see JLS 8.1.2), then the creation of t
178.37 - * requires the resolution (see JVMS 5) of the ith enclosing class of T,
178.38 - * for i = 0 to n, inclusive. Creating a type variable must not cause the
178.39 - * creation of its bounds. Repeated creation of a type variable has no effect.
178.40 - *
178.41 - * <p>Multiple objects may be instantiated at run-time to
178.42 - * represent a given type variable. Even though a type variable is
178.43 - * created only once, this does not imply any requirement to cache
178.44 - * instances representing the type variable. However, all instances
178.45 - * representing a type variable must be equal() to each other.
178.46 - * As a consequence, users of type variables must not rely on the identity
178.47 - * of instances of classes implementing this interface.
178.48 - *
178.49 - * @param <D> the type of generic declaration that declared the
178.50 - * underlying type variable.
178.51 - *
178.52 - * @since 1.5
178.53 - */
178.54 -public interface TypeVariable<D extends GenericDeclaration> extends Type {
178.55 - /**
178.56 - * Returns an array of {@code Type} objects representing the
178.57 - * upper bound(s) of this type variable. Note that if no upper bound is
178.58 - * explicitly declared, the upper bound is {@code Object}.
178.59 - *
178.60 - * <p>For each upper bound B: <ul> <li>if B is a parameterized
178.61 - * type or a type variable, it is created, (see {@link
178.62 - * java.lang.reflect.ParameterizedType ParameterizedType} for the
178.63 - * details of the creation process for parameterized types).
178.64 - * <li>Otherwise, B is resolved. </ul>
178.65 - *
178.66 - * @throws TypeNotPresentException if any of the
178.67 - * bounds refers to a non-existent type declaration
178.68 - * @throws MalformedParameterizedTypeException if any of the
178.69 - * bounds refer to a parameterized type that cannot be instantiated
178.70 - * for any reason
178.71 - * @return an array of {@code Type}s representing the upper
178.72 - * bound(s) of this type variable
178.73 - */
178.74 - Type[] getBounds();
178.75 -
178.76 - /**
178.77 - * Returns the {@code GenericDeclaration} object representing the
178.78 - * generic declaration declared this type variable.
178.79 - *
178.80 - * @return the generic declaration declared for this type variable.
178.81 - *
178.82 - * @since 1.5
178.83 - */
178.84 - D getGenericDeclaration();
178.85 -
178.86 - /**
178.87 - * Returns the name of this type variable, as it occurs in the source code.
178.88 - *
178.89 - * @return the name of this type variable, as it appears in the source code
178.90 - */
178.91 - String getName();
178.92 -}
179.1 --- a/emul/src/main/java/java/lang/reflect/package-info.java Wed Jan 23 20:16:48 2013 +0100
179.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
179.3 @@ -1,49 +0,0 @@
179.4 -/*
179.5 - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
179.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
179.7 - *
179.8 - * This code is free software; you can redistribute it and/or modify it
179.9 - * under the terms of the GNU General Public License version 2 only, as
179.10 - * published by the Free Software Foundation. Oracle designates this
179.11 - * particular file as subject to the "Classpath" exception as provided
179.12 - * by Oracle in the LICENSE file that accompanied this code.
179.13 - *
179.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
179.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
179.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
179.17 - * version 2 for more details (a copy is included in the LICENSE file that
179.18 - * accompanied this code).
179.19 - *
179.20 - * You should have received a copy of the GNU General Public License version
179.21 - * 2 along with this work; if not, write to the Free Software Foundation,
179.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
179.23 - *
179.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
179.25 - * or visit www.oracle.com if you need additional information or have any
179.26 - * questions.
179.27 - */
179.28 -
179.29 -/**
179.30 - * Provides classes and interfaces for obtaining reflective
179.31 - * information about classes and objects. Reflection allows
179.32 - * programmatic access to information about the fields, methods and
179.33 - * constructors of loaded classes, and the use of reflected fields,
179.34 - * methods, and constructors to operate on their underlying
179.35 - * counterparts, within security restrictions.
179.36 - *
179.37 - * <p>{@code AccessibleObject} allows suppression of access checks if
179.38 - * the necessary {@code ReflectPermission} is available.
179.39 - *
179.40 - * <p>{@code Array} provides static methods to dynamically create and
179.41 - * access arrays.
179.42 - *
179.43 - * <p>Classes in this package, along with {@code java.lang.Class}
179.44 - * accommodate applications such as debuggers, interpreters, object
179.45 - * inspectors, class browsers, and services such as Object
179.46 - * Serialization and JavaBeans that need access to either the public
179.47 - * members of a target object (based on its runtime class) or the
179.48 - * members declared by a given class.
179.49 - *
179.50 - * @since JDK1.1
179.51 - */
179.52 -package java.lang.reflect;
180.1 --- a/emul/src/main/java/java/net/MalformedURLException.java Wed Jan 23 20:16:48 2013 +0100
180.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
180.3 @@ -1,56 +0,0 @@
180.4 -/*
180.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
180.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
180.7 - *
180.8 - * This code is free software; you can redistribute it and/or modify it
180.9 - * under the terms of the GNU General Public License version 2 only, as
180.10 - * published by the Free Software Foundation. Oracle designates this
180.11 - * particular file as subject to the "Classpath" exception as provided
180.12 - * by Oracle in the LICENSE file that accompanied this code.
180.13 - *
180.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
180.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
180.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
180.17 - * version 2 for more details (a copy is included in the LICENSE file that
180.18 - * accompanied this code).
180.19 - *
180.20 - * You should have received a copy of the GNU General Public License version
180.21 - * 2 along with this work; if not, write to the Free Software Foundation,
180.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
180.23 - *
180.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
180.25 - * or visit www.oracle.com if you need additional information or have any
180.26 - * questions.
180.27 - */
180.28 -
180.29 -package java.net;
180.30 -
180.31 -import java.io.IOException;
180.32 -
180.33 -/**
180.34 - * Thrown to indicate that a malformed URL has occurred. Either no
180.35 - * legal protocol could be found in a specification string or the
180.36 - * string could not be parsed.
180.37 - *
180.38 - * @author Arthur van Hoff
180.39 - * @since JDK1.0
180.40 - */
180.41 -public class MalformedURLException extends IOException {
180.42 - private static final long serialVersionUID = -182787522200415866L;
180.43 -
180.44 - /**
180.45 - * Constructs a <code>MalformedURLException</code> with no detail message.
180.46 - */
180.47 - public MalformedURLException() {
180.48 - }
180.49 -
180.50 - /**
180.51 - * Constructs a <code>MalformedURLException</code> with the
180.52 - * specified detail message.
180.53 - *
180.54 - * @param msg the detail message.
180.55 - */
180.56 - public MalformedURLException(String msg) {
180.57 - super(msg);
180.58 - }
180.59 -}
181.1 --- a/emul/src/main/java/java/net/URL.java Wed Jan 23 20:16:48 2013 +0100
181.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
181.3 @@ -1,1037 +0,0 @@
181.4 -/*
181.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
181.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
181.7 - *
181.8 - * This code is free software; you can redistribute it and/or modify it
181.9 - * under the terms of the GNU General Public License version 2 only, as
181.10 - * published by the Free Software Foundation. Oracle designates this
181.11 - * particular file as subject to the "Classpath" exception as provided
181.12 - * by Oracle in the LICENSE file that accompanied this code.
181.13 - *
181.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
181.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
181.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
181.17 - * version 2 for more details (a copy is included in the LICENSE file that
181.18 - * accompanied this code).
181.19 - *
181.20 - * You should have received a copy of the GNU General Public License version
181.21 - * 2 along with this work; if not, write to the Free Software Foundation,
181.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181.23 - *
181.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
181.25 - * or visit www.oracle.com if you need additional information or have any
181.26 - * questions.
181.27 - */
181.28 -
181.29 -package java.net;
181.30 -
181.31 -import java.io.IOException;
181.32 -import java.io.InputStream;
181.33 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
181.34 -
181.35 -/**
181.36 - * Class <code>URL</code> represents a Uniform Resource
181.37 - * Locator, a pointer to a "resource" on the World
181.38 - * Wide Web. A resource can be something as simple as a file or a
181.39 - * directory, or it can be a reference to a more complicated object,
181.40 - * such as a query to a database or to a search engine. More
181.41 - * information on the types of URLs and their formats can be found at:
181.42 - * <blockquote>
181.43 - * <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
181.44 - * <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
181.45 - * </blockquote>
181.46 - * <p>
181.47 - * In general, a URL can be broken into several parts. The previous
181.48 - * example of a URL indicates that the protocol to use is
181.49 - * <code>http</code> (HyperText Transfer Protocol) and that the
181.50 - * information resides on a host machine named
181.51 - * <code>www.socs.uts.edu.au</code>. The information on that host
181.52 - * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
181.53 - * meaning of this name on the host machine is both protocol
181.54 - * dependent and host dependent. The information normally resides in
181.55 - * a file, but it could be generated on the fly. This component of
181.56 - * the URL is called the <i>path</i> component.
181.57 - * <p>
181.58 - * A URL can optionally specify a "port", which is the
181.59 - * port number to which the TCP connection is made on the remote host
181.60 - * machine. If the port is not specified, the default port for
181.61 - * the protocol is used instead. For example, the default port for
181.62 - * <code>http</code> is <code>80</code>. An alternative port could be
181.63 - * specified as:
181.64 - * <blockquote><pre>
181.65 - * http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
181.66 - * </pre></blockquote>
181.67 - * <p>
181.68 - * The syntax of <code>URL</code> is defined by <a
181.69 - * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC 2396: Uniform
181.70 - * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
181.71 - * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC 2732: Format for
181.72 - * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
181.73 - * also supports scope_ids. The syntax and usage of scope_ids is described
181.74 - * <a href="Inet6Address.html#scoped">here</a>.
181.75 - * <p>
181.76 - * A URL may have appended to it a "fragment", also known
181.77 - * as a "ref" or a "reference". The fragment is indicated by the sharp
181.78 - * sign character "#" followed by more characters. For example,
181.79 - * <blockquote><pre>
181.80 - * http://java.sun.com/index.html#chapter1
181.81 - * </pre></blockquote>
181.82 - * <p>
181.83 - * This fragment is not technically part of the URL. Rather, it
181.84 - * indicates that after the specified resource is retrieved, the
181.85 - * application is specifically interested in that part of the
181.86 - * document that has the tag <code>chapter1</code> attached to it. The
181.87 - * meaning of a tag is resource specific.
181.88 - * <p>
181.89 - * An application can also specify a "relative URL",
181.90 - * which contains only enough information to reach the resource
181.91 - * relative to another URL. Relative URLs are frequently used within
181.92 - * HTML pages. For example, if the contents of the URL:
181.93 - * <blockquote><pre>
181.94 - * http://java.sun.com/index.html
181.95 - * </pre></blockquote>
181.96 - * contained within it the relative URL:
181.97 - * <blockquote><pre>
181.98 - * FAQ.html
181.99 - * </pre></blockquote>
181.100 - * it would be a shorthand for:
181.101 - * <blockquote><pre>
181.102 - * http://java.sun.com/FAQ.html
181.103 - * </pre></blockquote>
181.104 - * <p>
181.105 - * The relative URL need not specify all the components of a URL. If
181.106 - * the protocol, host name, or port number is missing, the value is
181.107 - * inherited from the fully specified URL. The file component must be
181.108 - * specified. The optional fragment is not inherited.
181.109 - * <p>
181.110 - * The URL class does not itself encode or decode any URL components
181.111 - * according to the escaping mechanism defined in RFC2396. It is the
181.112 - * responsibility of the caller to encode any fields, which need to be
181.113 - * escaped prior to calling URL, and also to decode any escaped fields,
181.114 - * that are returned from URL. Furthermore, because URL has no knowledge
181.115 - * of URL escaping, it does not recognise equivalence between the encoded
181.116 - * or decoded form of the same URL. For example, the two URLs:<br>
181.117 - * <pre> http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
181.118 - * would be considered not equal to each other.
181.119 - * <p>
181.120 - * Note, the {@link java.net.URI} class does perform escaping of its
181.121 - * component fields in certain circumstances. The recommended way
181.122 - * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
181.123 - * and to convert between these two classes using {@link #toURI()} and
181.124 - * {@link URI#toURL()}.
181.125 - * <p>
181.126 - * The {@link URLEncoder} and {@link URLDecoder} classes can also be
181.127 - * used, but only for HTML form encoding, which is not the same
181.128 - * as the encoding scheme defined in RFC2396.
181.129 - *
181.130 - * @author James Gosling
181.131 - * @since JDK1.0
181.132 - */
181.133 -public final class URL implements java.io.Serializable {
181.134 -
181.135 - static final long serialVersionUID = -7627629688361524110L;
181.136 -
181.137 - /**
181.138 - * The property which specifies the package prefix list to be scanned
181.139 - * for protocol handlers. The value of this property (if any) should
181.140 - * be a vertical bar delimited list of package names to search through
181.141 - * for a protocol handler to load. The policy of this class is that
181.142 - * all protocol handlers will be in a class called <protocolname>.Handler,
181.143 - * and each package in the list is examined in turn for a matching
181.144 - * handler. If none are found (or the property is not specified), the
181.145 - * default package prefix, sun.net.www.protocol, is used. The search
181.146 - * proceeds from the first package in the list to the last and stops
181.147 - * when a match is found.
181.148 - */
181.149 - private static final String protocolPathProp = "java.protocol.handler.pkgs";
181.150 -
181.151 - /**
181.152 - * The protocol to use (ftp, http, nntp, ... etc.) .
181.153 - * @serial
181.154 - */
181.155 - private String protocol;
181.156 -
181.157 - /**
181.158 - * The host name to connect to.
181.159 - * @serial
181.160 - */
181.161 - private String host;
181.162 -
181.163 - /**
181.164 - * The protocol port to connect to.
181.165 - * @serial
181.166 - */
181.167 - private int port = -1;
181.168 -
181.169 - /**
181.170 - * The specified file name on that host. <code>file</code> is
181.171 - * defined as <code>path[?query]</code>
181.172 - * @serial
181.173 - */
181.174 - private String file;
181.175 -
181.176 - /**
181.177 - * The query part of this URL.
181.178 - */
181.179 - private transient String query;
181.180 -
181.181 - /**
181.182 - * The authority part of this URL.
181.183 - * @serial
181.184 - */
181.185 - private String authority;
181.186 -
181.187 - /**
181.188 - * The path part of this URL.
181.189 - */
181.190 - private transient String path;
181.191 -
181.192 - /**
181.193 - * The userinfo part of this URL.
181.194 - */
181.195 - private transient String userInfo;
181.196 -
181.197 - /**
181.198 - * # reference.
181.199 - * @serial
181.200 - */
181.201 - private String ref;
181.202 -
181.203 - /**
181.204 - * The host's IP address, used in equals and hashCode.
181.205 - * Computed on demand. An uninitialized or unknown hostAddress is null.
181.206 - */
181.207 - transient Object hostAddress;
181.208 -
181.209 - /**
181.210 - * The URLStreamHandler for this URL.
181.211 - */
181.212 - transient URLStreamHandler handler;
181.213 -
181.214 - /* Our hash code.
181.215 - * @serial
181.216 - */
181.217 - private int hashCode = -1;
181.218 -
181.219 - /**
181.220 - * Creates a <code>URL</code> object from the specified
181.221 - * <code>protocol</code>, <code>host</code>, <code>port</code>
181.222 - * number, and <code>file</code>.<p>
181.223 - *
181.224 - * <code>host</code> can be expressed as a host name or a literal
181.225 - * IP address. If IPv6 literal address is used, it should be
181.226 - * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
181.227 - * specified by <a
181.228 - * href="http://www.ietf.org/rfc/rfc2732.txt">RFC 2732</a>;
181.229 - * However, the literal IPv6 address format defined in <a
181.230 - * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC 2373: IP
181.231 - * Version 6 Addressing Architecture</i></a> is also accepted.<p>
181.232 - *
181.233 - * Specifying a <code>port</code> number of <code>-1</code>
181.234 - * indicates that the URL should use the default port for the
181.235 - * protocol.<p>
181.236 - *
181.237 - * If this is the first URL object being created with the specified
181.238 - * protocol, a <i>stream protocol handler</i> object, an instance of
181.239 - * class <code>URLStreamHandler</code>, is created for that protocol:
181.240 - * <ol>
181.241 - * <li>If the application has previously set up an instance of
181.242 - * <code>URLStreamHandlerFactory</code> as the stream handler factory,
181.243 - * then the <code>createURLStreamHandler</code> method of that instance
181.244 - * is called with the protocol string as an argument to create the
181.245 - * stream protocol handler.
181.246 - * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
181.247 - * or if the factory's <code>createURLStreamHandler</code> method
181.248 - * returns <code>null</code>, then the constructor finds the
181.249 - * value of the system property:
181.250 - * <blockquote><pre>
181.251 - * java.protocol.handler.pkgs
181.252 - * </pre></blockquote>
181.253 - * If the value of that system property is not <code>null</code>,
181.254 - * it is interpreted as a list of packages separated by a vertical
181.255 - * slash character '<code>|</code>'. The constructor tries to load
181.256 - * the class named:
181.257 - * <blockquote><pre>
181.258 - * <<i>package</i>>.<<i>protocol</i>>.Handler
181.259 - * </pre></blockquote>
181.260 - * where <<i>package</i>> is replaced by the name of the package
181.261 - * and <<i>protocol</i>> is replaced by the name of the protocol.
181.262 - * If this class does not exist, or if the class exists but it is not
181.263 - * a subclass of <code>URLStreamHandler</code>, then the next package
181.264 - * in the list is tried.
181.265 - * <li>If the previous step fails to find a protocol handler, then the
181.266 - * constructor tries to load from a system default package.
181.267 - * <blockquote><pre>
181.268 - * <<i>system default package</i>>.<<i>protocol</i>>.Handler
181.269 - * </pre></blockquote>
181.270 - * If this class does not exist, or if the class exists but it is not a
181.271 - * subclass of <code>URLStreamHandler</code>, then a
181.272 - * <code>MalformedURLException</code> is thrown.
181.273 - * </ol>
181.274 - *
181.275 - * <p>Protocol handlers for the following protocols are guaranteed
181.276 - * to exist on the search path :-
181.277 - * <blockquote><pre>
181.278 - * http, https, ftp, file, and jar
181.279 - * </pre></blockquote>
181.280 - * Protocol handlers for additional protocols may also be
181.281 - * available.
181.282 - *
181.283 - * <p>No validation of the inputs is performed by this constructor.
181.284 - *
181.285 - * @param protocol the name of the protocol to use.
181.286 - * @param host the name of the host.
181.287 - * @param port the port number on the host.
181.288 - * @param file the file on the host
181.289 - * @exception MalformedURLException if an unknown protocol is specified.
181.290 - * @see java.lang.System#getProperty(java.lang.String)
181.291 - * @see java.net.URL#setURLStreamHandlerFactory(
181.292 - * java.net.URLStreamHandlerFactory)
181.293 - * @see java.net.URLStreamHandler
181.294 - * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
181.295 - * java.lang.String)
181.296 - */
181.297 - public URL(String protocol, String host, int port, String file)
181.298 - throws MalformedURLException
181.299 - {
181.300 - this(protocol, host, port, file, null);
181.301 - }
181.302 -
181.303 - /**
181.304 - * Creates a URL from the specified <code>protocol</code>
181.305 - * name, <code>host</code> name, and <code>file</code> name. The
181.306 - * default port for the specified protocol is used.
181.307 - * <p>
181.308 - * This method is equivalent to calling the four-argument
181.309 - * constructor with the arguments being <code>protocol</code>,
181.310 - * <code>host</code>, <code>-1</code>, and <code>file</code>.
181.311 - *
181.312 - * No validation of the inputs is performed by this constructor.
181.313 - *
181.314 - * @param protocol the name of the protocol to use.
181.315 - * @param host the name of the host.
181.316 - * @param file the file on the host.
181.317 - * @exception MalformedURLException if an unknown protocol is specified.
181.318 - * @see java.net.URL#URL(java.lang.String, java.lang.String,
181.319 - * int, java.lang.String)
181.320 - */
181.321 - public URL(String protocol, String host, String file)
181.322 - throws MalformedURLException {
181.323 - this(protocol, host, -1, file);
181.324 - }
181.325 -
181.326 - /**
181.327 - * Creates a <code>URL</code> object from the specified
181.328 - * <code>protocol</code>, <code>host</code>, <code>port</code>
181.329 - * number, <code>file</code>, and <code>handler</code>. Specifying
181.330 - * a <code>port</code> number of <code>-1</code> indicates that
181.331 - * the URL should use the default port for the protocol. Specifying
181.332 - * a <code>handler</code> of <code>null</code> indicates that the URL
181.333 - * should use a default stream handler for the protocol, as outlined
181.334 - * for:
181.335 - * java.net.URL#URL(java.lang.String, java.lang.String, int,
181.336 - * java.lang.String)
181.337 - *
181.338 - * <p>If the handler is not null and there is a security manager,
181.339 - * the security manager's <code>checkPermission</code>
181.340 - * method is called with a
181.341 - * <code>NetPermission("specifyStreamHandler")</code> permission.
181.342 - * This may result in a SecurityException.
181.343 - *
181.344 - * No validation of the inputs is performed by this constructor.
181.345 - *
181.346 - * @param protocol the name of the protocol to use.
181.347 - * @param host the name of the host.
181.348 - * @param port the port number on the host.
181.349 - * @param file the file on the host
181.350 - * @param handler the stream handler for the URL.
181.351 - * @exception MalformedURLException if an unknown protocol is specified.
181.352 - * @exception SecurityException
181.353 - * if a security manager exists and its
181.354 - * <code>checkPermission</code> method doesn't allow
181.355 - * specifying a stream handler explicitly.
181.356 - * @see java.lang.System#getProperty(java.lang.String)
181.357 - * @see java.net.URL#setURLStreamHandlerFactory(
181.358 - * java.net.URLStreamHandlerFactory)
181.359 - * @see java.net.URLStreamHandler
181.360 - * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
181.361 - * java.lang.String)
181.362 - * @see SecurityManager#checkPermission
181.363 - * @see java.net.NetPermission
181.364 - */
181.365 - public URL(String protocol, String host, int port, String file,
181.366 - URLStreamHandler handler) throws MalformedURLException {
181.367 - if (handler != null) {
181.368 - throw new SecurityException();
181.369 - }
181.370 -
181.371 - protocol = protocol.toLowerCase();
181.372 - this.protocol = protocol;
181.373 - if (host != null) {
181.374 -
181.375 - /**
181.376 - * if host is a literal IPv6 address,
181.377 - * we will make it conform to RFC 2732
181.378 - */
181.379 - if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
181.380 - host = "["+host+"]";
181.381 - }
181.382 - this.host = host;
181.383 -
181.384 - if (port < -1) {
181.385 - throw new MalformedURLException("Invalid port number :" +
181.386 - port);
181.387 - }
181.388 - this.port = port;
181.389 - authority = (port == -1) ? host : host + ":" + port;
181.390 - }
181.391 -
181.392 - Parts parts = new Parts(file);
181.393 - path = parts.getPath();
181.394 - query = parts.getQuery();
181.395 -
181.396 - if (query != null) {
181.397 - this.file = path + "?" + query;
181.398 - } else {
181.399 - this.file = path;
181.400 - }
181.401 - ref = parts.getRef();
181.402 -
181.403 - // Note: we don't do validation of the URL here. Too risky to change
181.404 - // right now, but worth considering for future reference. -br
181.405 - if (handler == null &&
181.406 - (handler = getURLStreamHandler(protocol)) == null) {
181.407 - throw new MalformedURLException("unknown protocol: " + protocol);
181.408 - }
181.409 - this.handler = handler;
181.410 - }
181.411 -
181.412 - /**
181.413 - * Creates a <code>URL</code> object from the <code>String</code>
181.414 - * representation.
181.415 - * <p>
181.416 - * This constructor is equivalent to a call to the two-argument
181.417 - * constructor with a <code>null</code> first argument.
181.418 - *
181.419 - * @param spec the <code>String</code> to parse as a URL.
181.420 - * @exception MalformedURLException if no protocol is specified, or an
181.421 - * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
181.422 - * @see java.net.URL#URL(java.net.URL, java.lang.String)
181.423 - */
181.424 - public URL(String spec) throws MalformedURLException {
181.425 - this(null, spec);
181.426 - }
181.427 -
181.428 - /**
181.429 - * Creates a URL by parsing the given spec within a specified context.
181.430 - *
181.431 - * The new URL is created from the given context URL and the spec
181.432 - * argument as described in
181.433 - * RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
181.434 - * <blockquote><pre>
181.435 - * <scheme>://<authority><path>?<query>#<fragment>
181.436 - * </pre></blockquote>
181.437 - * The reference is parsed into the scheme, authority, path, query and
181.438 - * fragment parts. If the path component is empty and the scheme,
181.439 - * authority, and query components are undefined, then the new URL is a
181.440 - * reference to the current document. Otherwise, the fragment and query
181.441 - * parts present in the spec are used in the new URL.
181.442 - * <p>
181.443 - * If the scheme component is defined in the given spec and does not match
181.444 - * the scheme of the context, then the new URL is created as an absolute
181.445 - * URL based on the spec alone. Otherwise the scheme component is inherited
181.446 - * from the context URL.
181.447 - * <p>
181.448 - * If the authority component is present in the spec then the spec is
181.449 - * treated as absolute and the spec authority and path will replace the
181.450 - * context authority and path. If the authority component is absent in the
181.451 - * spec then the authority of the new URL will be inherited from the
181.452 - * context.
181.453 - * <p>
181.454 - * If the spec's path component begins with a slash character
181.455 - * "/" then the
181.456 - * path is treated as absolute and the spec path replaces the context path.
181.457 - * <p>
181.458 - * Otherwise, the path is treated as a relative path and is appended to the
181.459 - * context path, as described in RFC2396. Also, in this case,
181.460 - * the path is canonicalized through the removal of directory
181.461 - * changes made by occurences of ".." and ".".
181.462 - * <p>
181.463 - * For a more detailed description of URL parsing, refer to RFC2396.
181.464 - *
181.465 - * @param context the context in which to parse the specification.
181.466 - * @param spec the <code>String</code> to parse as a URL.
181.467 - * @exception MalformedURLException if no protocol is specified, or an
181.468 - * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
181.469 - * @see java.net.URL#URL(java.lang.String, java.lang.String,
181.470 - * int, java.lang.String)
181.471 - * @see java.net.URLStreamHandler
181.472 - * @see java.net.URLStreamHandler#parseURL(java.net.URL,
181.473 - * java.lang.String, int, int)
181.474 - */
181.475 - public URL(URL context, String spec) throws MalformedURLException {
181.476 - this(context, spec, null);
181.477 - }
181.478 -
181.479 - /**
181.480 - * Creates a URL by parsing the given spec with the specified handler
181.481 - * within a specified context. If the handler is null, the parsing
181.482 - * occurs as with the two argument constructor.
181.483 - *
181.484 - * @param context the context in which to parse the specification.
181.485 - * @param spec the <code>String</code> to parse as a URL.
181.486 - * @param handler the stream handler for the URL.
181.487 - * @exception MalformedURLException if no protocol is specified, or an
181.488 - * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
181.489 - * @exception SecurityException
181.490 - * if a security manager exists and its
181.491 - * <code>checkPermission</code> method doesn't allow
181.492 - * specifying a stream handler.
181.493 - * @see java.net.URL#URL(java.lang.String, java.lang.String,
181.494 - * int, java.lang.String)
181.495 - * @see java.net.URLStreamHandler
181.496 - * @see java.net.URLStreamHandler#parseURL(java.net.URL,
181.497 - * java.lang.String, int, int)
181.498 - */
181.499 - public URL(URL context, String spec, URLStreamHandler handler)
181.500 - throws MalformedURLException
181.501 - {
181.502 - String original = spec;
181.503 - int i, limit, c;
181.504 - int start = 0;
181.505 - String newProtocol = null;
181.506 - boolean aRef=false;
181.507 - boolean isRelative = false;
181.508 -
181.509 - // Check for permission to specify a handler
181.510 - if (handler != null) {
181.511 - throw new SecurityException();
181.512 - }
181.513 -
181.514 - try {
181.515 - limit = spec.length();
181.516 - while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
181.517 - limit--; //eliminate trailing whitespace
181.518 - }
181.519 - while ((start < limit) && (spec.charAt(start) <= ' ')) {
181.520 - start++; // eliminate leading whitespace
181.521 - }
181.522 -
181.523 - if (spec.regionMatches(true, start, "url:", 0, 4)) {
181.524 - start += 4;
181.525 - }
181.526 - if (start < spec.length() && spec.charAt(start) == '#') {
181.527 - /* we're assuming this is a ref relative to the context URL.
181.528 - * This means protocols cannot start w/ '#', but we must parse
181.529 - * ref URL's like: "hello:there" w/ a ':' in them.
181.530 - */
181.531 - aRef=true;
181.532 - }
181.533 - for (i = start ; !aRef && (i < limit) &&
181.534 - ((c = spec.charAt(i)) != '/') ; i++) {
181.535 - if (c == ':') {
181.536 -
181.537 - String s = spec.substring(start, i).toLowerCase();
181.538 - if (isValidProtocol(s)) {
181.539 - newProtocol = s;
181.540 - start = i + 1;
181.541 - }
181.542 - break;
181.543 - }
181.544 - }
181.545 -
181.546 - // Only use our context if the protocols match.
181.547 - protocol = newProtocol;
181.548 - if ((context != null) && ((newProtocol == null) ||
181.549 - newProtocol.equalsIgnoreCase(context.protocol))) {
181.550 - // inherit the protocol handler from the context
181.551 - // if not specified to the constructor
181.552 - if (handler == null) {
181.553 - handler = context.handler;
181.554 - }
181.555 -
181.556 - // If the context is a hierarchical URL scheme and the spec
181.557 - // contains a matching scheme then maintain backwards
181.558 - // compatibility and treat it as if the spec didn't contain
181.559 - // the scheme; see 5.2.3 of RFC2396
181.560 - if (context.path != null && context.path.startsWith("/"))
181.561 - newProtocol = null;
181.562 -
181.563 - if (newProtocol == null) {
181.564 - protocol = context.protocol;
181.565 - authority = context.authority;
181.566 - userInfo = context.userInfo;
181.567 - host = context.host;
181.568 - port = context.port;
181.569 - file = context.file;
181.570 - path = context.path;
181.571 - isRelative = true;
181.572 - }
181.573 - }
181.574 -
181.575 - if (protocol == null) {
181.576 - throw new MalformedURLException("no protocol: "+original);
181.577 - }
181.578 -
181.579 - // Get the protocol handler if not specified or the protocol
181.580 - // of the context could not be used
181.581 - if (handler == null &&
181.582 - (handler = getURLStreamHandler(protocol)) == null) {
181.583 - throw new MalformedURLException("unknown protocol: "+protocol);
181.584 - }
181.585 - this.handler = handler;
181.586 -
181.587 - i = spec.indexOf('#', start);
181.588 - if (i >= 0) {
181.589 -//thrw(protocol + " hnd: " + handler.getClass().getName() + " i: " + i);
181.590 - ref = spec.substring(i + 1, limit);
181.591 - limit = i;
181.592 - }
181.593 -
181.594 - /*
181.595 - * Handle special case inheritance of query and fragment
181.596 - * implied by RFC2396 section 5.2.2.
181.597 - */
181.598 - if (isRelative && start == limit) {
181.599 - query = context.query;
181.600 - if (ref == null) {
181.601 - ref = context.ref;
181.602 - }
181.603 - }
181.604 -
181.605 - handler.parseURL(this, spec, start, limit);
181.606 -
181.607 - } catch(MalformedURLException e) {
181.608 - throw e;
181.609 - } catch(Exception e) {
181.610 - MalformedURLException exception = new MalformedURLException(e.getMessage());
181.611 - exception.initCause(e);
181.612 - throw exception;
181.613 - }
181.614 - }
181.615 -
181.616 - /*
181.617 - * Returns true if specified string is a valid protocol name.
181.618 - */
181.619 - private boolean isValidProtocol(String protocol) {
181.620 - int len = protocol.length();
181.621 - if (len < 1)
181.622 - return false;
181.623 - char c = protocol.charAt(0);
181.624 - if (!Character.isLetter(c))
181.625 - return false;
181.626 - for (int i = 1; i < len; i++) {
181.627 - c = protocol.charAt(i);
181.628 - if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
181.629 - c != '-') {
181.630 - return false;
181.631 - }
181.632 - }
181.633 - return true;
181.634 - }
181.635 -
181.636 - /**
181.637 - * Sets the fields of the URL. This is not a public method so that
181.638 - * only URLStreamHandlers can modify URL fields. URLs are
181.639 - * otherwise constant.
181.640 - *
181.641 - * @param protocol the name of the protocol to use
181.642 - * @param host the name of the host
181.643 - @param port the port number on the host
181.644 - * @param file the file on the host
181.645 - * @param ref the internal reference in the URL
181.646 - */
181.647 - protected void set(String protocol, String host,
181.648 - int port, String file, String ref) {
181.649 - synchronized (this) {
181.650 - this.protocol = protocol;
181.651 - this.host = host;
181.652 - authority = port == -1 ? host : host + ":" + port;
181.653 - this.port = port;
181.654 - this.file = file;
181.655 - this.ref = ref;
181.656 - /* This is very important. We must recompute this after the
181.657 - * URL has been changed. */
181.658 - hashCode = -1;
181.659 - hostAddress = null;
181.660 - int q = file.lastIndexOf('?');
181.661 - if (q != -1) {
181.662 - query = file.substring(q+1);
181.663 - path = file.substring(0, q);
181.664 - } else
181.665 - path = file;
181.666 - }
181.667 - }
181.668 -
181.669 - /**
181.670 - * Sets the specified 8 fields of the URL. This is not a public method so
181.671 - * that only URLStreamHandlers can modify URL fields. URLs are otherwise
181.672 - * constant.
181.673 - *
181.674 - * @param protocol the name of the protocol to use
181.675 - * @param host the name of the host
181.676 - * @param port the port number on the host
181.677 - * @param authority the authority part for the url
181.678 - * @param userInfo the username and password
181.679 - * @param path the file on the host
181.680 - * @param ref the internal reference in the URL
181.681 - * @param query the query part of this URL
181.682 - * @since 1.3
181.683 - */
181.684 - protected void set(String protocol, String host, int port,
181.685 - String authority, String userInfo, String path,
181.686 - String query, String ref) {
181.687 - synchronized (this) {
181.688 - this.protocol = protocol;
181.689 - this.host = host;
181.690 - this.port = port;
181.691 - this.file = query == null ? path : path + "?" + query;
181.692 - this.userInfo = userInfo;
181.693 - this.path = path;
181.694 - this.ref = ref;
181.695 - /* This is very important. We must recompute this after the
181.696 - * URL has been changed. */
181.697 - hashCode = -1;
181.698 - hostAddress = null;
181.699 - this.query = query;
181.700 - this.authority = authority;
181.701 - }
181.702 - }
181.703 -
181.704 - /**
181.705 - * Gets the query part of this <code>URL</code>.
181.706 - *
181.707 - * @return the query part of this <code>URL</code>,
181.708 - * or <CODE>null</CODE> if one does not exist
181.709 - * @since 1.3
181.710 - */
181.711 - public String getQuery() {
181.712 - return query;
181.713 - }
181.714 -
181.715 - /**
181.716 - * Gets the path part of this <code>URL</code>.
181.717 - *
181.718 - * @return the path part of this <code>URL</code>, or an
181.719 - * empty string if one does not exist
181.720 - * @since 1.3
181.721 - */
181.722 - public String getPath() {
181.723 - return path;
181.724 - }
181.725 -
181.726 - /**
181.727 - * Gets the userInfo part of this <code>URL</code>.
181.728 - *
181.729 - * @return the userInfo part of this <code>URL</code>, or
181.730 - * <CODE>null</CODE> if one does not exist
181.731 - * @since 1.3
181.732 - */
181.733 - public String getUserInfo() {
181.734 - return userInfo;
181.735 - }
181.736 -
181.737 - /**
181.738 - * Gets the authority part of this <code>URL</code>.
181.739 - *
181.740 - * @return the authority part of this <code>URL</code>
181.741 - * @since 1.3
181.742 - */
181.743 - public String getAuthority() {
181.744 - return authority;
181.745 - }
181.746 -
181.747 - /**
181.748 - * Gets the port number of this <code>URL</code>.
181.749 - *
181.750 - * @return the port number, or -1 if the port is not set
181.751 - */
181.752 - public int getPort() {
181.753 - return port;
181.754 - }
181.755 -
181.756 - /**
181.757 - * Gets the default port number of the protocol associated
181.758 - * with this <code>URL</code>. If the URL scheme or the URLStreamHandler
181.759 - * for the URL do not define a default port number,
181.760 - * then -1 is returned.
181.761 - *
181.762 - * @return the port number
181.763 - * @since 1.4
181.764 - */
181.765 - public int getDefaultPort() {
181.766 - return handler.getDefaultPort();
181.767 - }
181.768 -
181.769 - /**
181.770 - * Gets the protocol name of this <code>URL</code>.
181.771 - *
181.772 - * @return the protocol of this <code>URL</code>.
181.773 - */
181.774 - public String getProtocol() {
181.775 - return protocol;
181.776 - }
181.777 -
181.778 - /**
181.779 - * Gets the host name of this <code>URL</code>, if applicable.
181.780 - * The format of the host conforms to RFC 2732, i.e. for a
181.781 - * literal IPv6 address, this method will return the IPv6 address
181.782 - * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
181.783 - *
181.784 - * @return the host name of this <code>URL</code>.
181.785 - */
181.786 - public String getHost() {
181.787 - return host;
181.788 - }
181.789 -
181.790 - /**
181.791 - * Gets the file name of this <code>URL</code>.
181.792 - * The returned file portion will be
181.793 - * the same as <CODE>getPath()</CODE>, plus the concatenation of
181.794 - * the value of <CODE>getQuery()</CODE>, if any. If there is
181.795 - * no query portion, this method and <CODE>getPath()</CODE> will
181.796 - * return identical results.
181.797 - *
181.798 - * @return the file name of this <code>URL</code>,
181.799 - * or an empty string if one does not exist
181.800 - */
181.801 - public String getFile() {
181.802 - return file;
181.803 - }
181.804 -
181.805 - /**
181.806 - * Gets the anchor (also known as the "reference") of this
181.807 - * <code>URL</code>.
181.808 - *
181.809 - * @return the anchor (also known as the "reference") of this
181.810 - * <code>URL</code>, or <CODE>null</CODE> if one does not exist
181.811 - */
181.812 - public String getRef() {
181.813 - return ref;
181.814 - }
181.815 -
181.816 - /**
181.817 - * Compares this URL for equality with another object.<p>
181.818 - *
181.819 - * If the given object is not a URL then this method immediately returns
181.820 - * <code>false</code>.<p>
181.821 - *
181.822 - * Two URL objects are equal if they have the same protocol, reference
181.823 - * equivalent hosts, have the same port number on the host, and the same
181.824 - * file and fragment of the file.<p>
181.825 - *
181.826 - * Two hosts are considered equivalent if both host names can be resolved
181.827 - * into the same IP addresses; else if either host name can't be
181.828 - * resolved, the host names must be equal without regard to case; or both
181.829 - * host names equal to null.<p>
181.830 - *
181.831 - * Since hosts comparison requires name resolution, this operation is a
181.832 - * blocking operation. <p>
181.833 - *
181.834 - * Note: The defined behavior for <code>equals</code> is known to
181.835 - * be inconsistent with virtual hosting in HTTP.
181.836 - *
181.837 - * @param obj the URL to compare against.
181.838 - * @return <code>true</code> if the objects are the same;
181.839 - * <code>false</code> otherwise.
181.840 - */
181.841 - public boolean equals(Object obj) {
181.842 - if (!(obj instanceof URL))
181.843 - return false;
181.844 - URL u2 = (URL)obj;
181.845 -
181.846 - return handler.equals(this, u2);
181.847 - }
181.848 -
181.849 - /**
181.850 - * Creates an integer suitable for hash table indexing.<p>
181.851 - *
181.852 - * The hash code is based upon all the URL components relevant for URL
181.853 - * comparison. As such, this operation is a blocking operation.<p>
181.854 - *
181.855 - * @return a hash code for this <code>URL</code>.
181.856 - */
181.857 - public synchronized int hashCode() {
181.858 - if (hashCode != -1)
181.859 - return hashCode;
181.860 -
181.861 - hashCode = handler.hashCode(this);
181.862 - return hashCode;
181.863 - }
181.864 -
181.865 - /**
181.866 - * Compares two URLs, excluding the fragment component.<p>
181.867 - *
181.868 - * Returns <code>true</code> if this <code>URL</code> and the
181.869 - * <code>other</code> argument are equal without taking the
181.870 - * fragment component into consideration.
181.871 - *
181.872 - * @param other the <code>URL</code> to compare against.
181.873 - * @return <code>true</code> if they reference the same remote object;
181.874 - * <code>false</code> otherwise.
181.875 - */
181.876 - public boolean sameFile(URL other) {
181.877 - return handler.sameFile(this, other);
181.878 - }
181.879 -
181.880 - /**
181.881 - * Constructs a string representation of this <code>URL</code>. The
181.882 - * string is created by calling the <code>toExternalForm</code>
181.883 - * method of the stream protocol handler for this object.
181.884 - *
181.885 - * @return a string representation of this object.
181.886 - * @see java.net.URL#URL(java.lang.String, java.lang.String, int,
181.887 - * java.lang.String)
181.888 - * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
181.889 - */
181.890 - public String toString() {
181.891 - return toExternalForm();
181.892 - }
181.893 -
181.894 - /**
181.895 - * Constructs a string representation of this <code>URL</code>. The
181.896 - * string is created by calling the <code>toExternalForm</code>
181.897 - * method of the stream protocol handler for this object.
181.898 - *
181.899 - * @return a string representation of this object.
181.900 - * @see java.net.URL#URL(java.lang.String, java.lang.String,
181.901 - * int, java.lang.String)
181.902 - * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
181.903 - */
181.904 - public String toExternalForm() {
181.905 - return handler.toExternalForm(this);
181.906 - }
181.907 -
181.908 - /**
181.909 - * Returns a {@link java.net.URLConnection URLConnection} instance that
181.910 - * represents a connection to the remote object referred to by the
181.911 - * {@code URL}.
181.912 - *
181.913 - * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
181.914 - * created every time when invoking the
181.915 - * {@linkplain java.net.URLStreamHandler#openConnection(URL)
181.916 - * URLStreamHandler.openConnection(URL)} method of the protocol handler for
181.917 - * this URL.</P>
181.918 - *
181.919 - * <P>It should be noted that a URLConnection instance does not establish
181.920 - * the actual network connection on creation. This will happen only when
181.921 - * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
181.922 - *
181.923 - * <P>If for the URL's protocol (such as HTTP or JAR), there
181.924 - * exists a public, specialized URLConnection subclass belonging
181.925 - * to one of the following packages or one of their subpackages:
181.926 - * java.lang, java.io, java.util, java.net, the connection
181.927 - * returned will be of that subclass. For example, for HTTP an
181.928 - * HttpURLConnection will be returned, and for JAR a
181.929 - * JarURLConnection will be returned.</P>
181.930 - *
181.931 - * @return a {@link java.net.URLConnection URLConnection} linking
181.932 - * to the URL.
181.933 - * @exception IOException if an I/O exception occurs.
181.934 - * @see java.net.URL#URL(java.lang.String, java.lang.String,
181.935 - * int, java.lang.String)
181.936 - */
181.937 -// public URLConnection openConnection() throws java.io.IOException {
181.938 -// return handler.openConnection(this);
181.939 -// }
181.940 -
181.941 -
181.942 - /**
181.943 - * Opens a connection to this <code>URL</code> and returns an
181.944 - * <code>InputStream</code> for reading from that connection. This
181.945 - * method is a shorthand for:
181.946 - * <blockquote><pre>
181.947 - * openConnection().getInputStream()
181.948 - * </pre></blockquote>
181.949 - *
181.950 - * @return an input stream for reading from the URL connection.
181.951 - * @exception IOException if an I/O exception occurs.
181.952 - * @see java.net.URL#openConnection()
181.953 - * @see java.net.URLConnection#getInputStream()
181.954 - */
181.955 - public final InputStream openStream() throws java.io.IOException {
181.956 - throw new IOException();
181.957 -// return openConnection().getInputStream();
181.958 - }
181.959 -
181.960 - /**
181.961 - * Gets the contents of this URL. This method is a shorthand for:
181.962 - * <blockquote><pre>
181.963 - * openConnection().getContent()
181.964 - * </pre></blockquote>
181.965 - *
181.966 - * @return the contents of this URL.
181.967 - * @exception IOException if an I/O exception occurs.
181.968 - * @see java.net.URLConnection#getContent()
181.969 - */
181.970 - public final Object getContent() throws java.io.IOException {
181.971 - return loadText(toExternalForm());
181.972 - }
181.973 -
181.974 - @JavaScriptBody(args = "url", body = ""
181.975 - + "var request = new XMLHttpRequest();\n"
181.976 - + "request.open('GET', url, false);\n"
181.977 - + "request.send();\n"
181.978 - + "return request.responseText;\n"
181.979 - )
181.980 - private static native String loadText(String url) throws IOException;
181.981 -
181.982 - /**
181.983 - * Gets the contents of this URL. This method is a shorthand for:
181.984 - * <blockquote><pre>
181.985 - * openConnection().getContent(Class[])
181.986 - * </pre></blockquote>
181.987 - *
181.988 - * @param classes an array of Java types
181.989 - * @return the content object of this URL that is the first match of
181.990 - * the types specified in the classes array.
181.991 - * null if none of the requested types are supported.
181.992 - * @exception IOException if an I/O exception occurs.
181.993 - * @see java.net.URLConnection#getContent(Class[])
181.994 - * @since 1.3
181.995 - */
181.996 - public final Object getContent(Class[] classes)
181.997 - throws java.io.IOException {
181.998 - for (Class<?> c : classes) {
181.999 - if (c == String.class) {
181.1000 - return getContent();
181.1001 - }
181.1002 - }
181.1003 - return null;
181.1004 - }
181.1005 -
181.1006 - static URLStreamHandler getURLStreamHandler(String protocol) {
181.1007 - URLStreamHandler universal = new URLStreamHandler() {};
181.1008 - return universal;
181.1009 - }
181.1010 -
181.1011 -}
181.1012 -
181.1013 -class Parts {
181.1014 - String path, query, ref;
181.1015 -
181.1016 - Parts(String file) {
181.1017 - int ind = file.indexOf('#');
181.1018 - ref = ind < 0 ? null: file.substring(ind + 1);
181.1019 - file = ind < 0 ? file: file.substring(0, ind);
181.1020 - int q = file.lastIndexOf('?');
181.1021 - if (q != -1) {
181.1022 - query = file.substring(q+1);
181.1023 - path = file.substring(0, q);
181.1024 - } else {
181.1025 - path = file;
181.1026 - }
181.1027 - }
181.1028 -
181.1029 - String getPath() {
181.1030 - return path;
181.1031 - }
181.1032 -
181.1033 - String getQuery() {
181.1034 - return query;
181.1035 - }
181.1036 -
181.1037 - String getRef() {
181.1038 - return ref;
181.1039 - }
181.1040 -}
182.1 --- a/emul/src/main/java/java/net/URLStreamHandler.java Wed Jan 23 20:16:48 2013 +0100
182.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
182.3 @@ -1,568 +0,0 @@
182.4 -/*
182.5 - * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
182.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
182.7 - *
182.8 - * This code is free software; you can redistribute it and/or modify it
182.9 - * under the terms of the GNU General Public License version 2 only, as
182.10 - * published by the Free Software Foundation. Oracle designates this
182.11 - * particular file as subject to the "Classpath" exception as provided
182.12 - * by Oracle in the LICENSE file that accompanied this code.
182.13 - *
182.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
182.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
182.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
182.17 - * version 2 for more details (a copy is included in the LICENSE file that
182.18 - * accompanied this code).
182.19 - *
182.20 - * You should have received a copy of the GNU General Public License version
182.21 - * 2 along with this work; if not, write to the Free Software Foundation,
182.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
182.23 - *
182.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
182.25 - * or visit www.oracle.com if you need additional information or have any
182.26 - * questions.
182.27 - */
182.28 -
182.29 -package java.net;
182.30 -
182.31 -
182.32 -/**
182.33 - * The abstract class <code>URLStreamHandler</code> is the common
182.34 - * superclass for all stream protocol handlers. A stream protocol
182.35 - * handler knows how to make a connection for a particular protocol
182.36 - * type, such as <code>http</code>, <code>ftp</code>, or
182.37 - * <code>gopher</code>.
182.38 - * <p>
182.39 - * In most cases, an instance of a <code>URLStreamHandler</code>
182.40 - * subclass is not created directly by an application. Rather, the
182.41 - * first time a protocol name is encountered when constructing a
182.42 - * <code>URL</code>, the appropriate stream protocol handler is
182.43 - * automatically loaded.
182.44 - *
182.45 - * @author James Gosling
182.46 - * @see java.net.URL#URL(java.lang.String, java.lang.String, int, java.lang.String)
182.47 - * @since JDK1.0
182.48 - */
182.49 -public abstract class URLStreamHandler {
182.50 - /**
182.51 - * Opens a connection to the object referenced by the
182.52 - * <code>URL</code> argument.
182.53 - * This method should be overridden by a subclass.
182.54 - *
182.55 - * <p>If for the handler's protocol (such as HTTP or JAR), there
182.56 - * exists a public, specialized URLConnection subclass belonging
182.57 - * to one of the following packages or one of their subpackages:
182.58 - * java.lang, java.io, java.util, java.net, the connection
182.59 - * returned will be of that subclass. For example, for HTTP an
182.60 - * HttpURLConnection will be returned, and for JAR a
182.61 - * JarURLConnection will be returned.
182.62 - *
182.63 - * @param u the URL that this connects to.
182.64 - * @return a <code>URLConnection</code> object for the <code>URL</code>.
182.65 - * @exception IOException if an I/O error occurs while opening the
182.66 - * connection.
182.67 - */
182.68 -// abstract protected URLConnection openConnection(URL u) throws IOException;
182.69 -
182.70 - /**
182.71 - * Same as openConnection(URL), except that the connection will be
182.72 - * made through the specified proxy; Protocol handlers that do not
182.73 - * support proxying will ignore the proxy parameter and make a
182.74 - * normal connection.
182.75 - *
182.76 - * Calling this method preempts the system's default ProxySelector
182.77 - * settings.
182.78 - *
182.79 - * @param u the URL that this connects to.
182.80 - * @param p the proxy through which the connection will be made.
182.81 - * If direct connection is desired, Proxy.NO_PROXY
182.82 - * should be specified.
182.83 - * @return a <code>URLConnection</code> object for the <code>URL</code>.
182.84 - * @exception IOException if an I/O error occurs while opening the
182.85 - * connection.
182.86 - * @exception IllegalArgumentException if either u or p is null,
182.87 - * or p has the wrong type.
182.88 - * @exception UnsupportedOperationException if the subclass that
182.89 - * implements the protocol doesn't support this method.
182.90 - * @since 1.5
182.91 - */
182.92 -// protected URLConnection openConnection(URL u, Proxy p) throws IOException {
182.93 -// throw new UnsupportedOperationException("Method not implemented.");
182.94 -// }
182.95 -
182.96 - /**
182.97 - * Parses the string representation of a <code>URL</code> into a
182.98 - * <code>URL</code> object.
182.99 - * <p>
182.100 - * If there is any inherited context, then it has already been
182.101 - * copied into the <code>URL</code> argument.
182.102 - * <p>
182.103 - * The <code>parseURL</code> method of <code>URLStreamHandler</code>
182.104 - * parses the string representation as if it were an
182.105 - * <code>http</code> specification. Most URL protocol families have a
182.106 - * similar parsing. A stream protocol handler for a protocol that has
182.107 - * a different syntax must override this routine.
182.108 - *
182.109 - * @param u the <code>URL</code> to receive the result of parsing
182.110 - * the spec.
182.111 - * @param spec the <code>String</code> representing the URL that
182.112 - * must be parsed.
182.113 - * @param start the character index at which to begin parsing. This is
182.114 - * just past the '<code>:</code>' (if there is one) that
182.115 - * specifies the determination of the protocol name.
182.116 - * @param limit the character position to stop parsing at. This is the
182.117 - * end of the string or the position of the
182.118 - * "<code>#</code>" character, if present. All information
182.119 - * after the sharp sign indicates an anchor.
182.120 - */
182.121 - protected void parseURL(URL u, String spec, int start, int limit) {
182.122 - // These fields may receive context content if this was relative URL
182.123 - String protocol = u.getProtocol();
182.124 - String authority = u.getAuthority();
182.125 - String userInfo = u.getUserInfo();
182.126 - String host = u.getHost();
182.127 - int port = u.getPort();
182.128 - String path = u.getPath();
182.129 - String query = u.getQuery();
182.130 -
182.131 - // This field has already been parsed
182.132 - String ref = u.getRef();
182.133 -
182.134 - boolean isRelPath = false;
182.135 - boolean queryOnly = false;
182.136 -
182.137 -// FIX: should not assume query if opaque
182.138 - // Strip off the query part
182.139 - if (start < limit) {
182.140 - int queryStart = spec.indexOf('?');
182.141 - queryOnly = queryStart == start;
182.142 - if ((queryStart != -1) && (queryStart < limit)) {
182.143 - query = spec.substring(queryStart+1, limit);
182.144 - if (limit > queryStart)
182.145 - limit = queryStart;
182.146 - spec = spec.substring(0, queryStart);
182.147 - }
182.148 - }
182.149 -
182.150 - int i = 0;
182.151 - // Parse the authority part if any
182.152 - boolean isUNCName = (start <= limit - 4) &&
182.153 - (spec.charAt(start) == '/') &&
182.154 - (spec.charAt(start + 1) == '/') &&
182.155 - (spec.charAt(start + 2) == '/') &&
182.156 - (spec.charAt(start + 3) == '/');
182.157 - if (!isUNCName && (start <= limit - 2) && (spec.charAt(start) == '/') &&
182.158 - (spec.charAt(start + 1) == '/')) {
182.159 - start += 2;
182.160 - i = spec.indexOf('/', start);
182.161 - if (i < 0) {
182.162 - i = spec.indexOf('?', start);
182.163 - if (i < 0)
182.164 - i = limit;
182.165 - }
182.166 -
182.167 - host = authority = spec.substring(start, i);
182.168 -
182.169 - int ind = authority.indexOf('@');
182.170 - if (ind != -1) {
182.171 - userInfo = authority.substring(0, ind);
182.172 - host = authority.substring(ind+1);
182.173 - } else {
182.174 - userInfo = null;
182.175 - }
182.176 - if (host != null) {
182.177 - // If the host is surrounded by [ and ] then its an IPv6
182.178 - // literal address as specified in RFC2732
182.179 - if (host.length()>0 && (host.charAt(0) == '[')) {
182.180 - if ((ind = host.indexOf(']')) > 2) {
182.181 -
182.182 - String nhost = host ;
182.183 - host = nhost.substring(0,ind+1);
182.184 -// if (!IPAddressUtil.
182.185 -// isIPv6LiteralAddress(host.substring(1, ind))) {
182.186 -// throw new IllegalArgumentException(
182.187 -// "Invalid host: "+ host);
182.188 -// }
182.189 -
182.190 - port = -1 ;
182.191 - if (nhost.length() > ind+1) {
182.192 - if (nhost.charAt(ind+1) == ':') {
182.193 - ++ind ;
182.194 - // port can be null according to RFC2396
182.195 - if (nhost.length() > (ind + 1)) {
182.196 - port = Integer.parseInt(nhost.substring(ind+1));
182.197 - }
182.198 - } else {
182.199 - throw new IllegalArgumentException(
182.200 - "Invalid authority field: " + authority);
182.201 - }
182.202 - }
182.203 - } else {
182.204 - throw new IllegalArgumentException(
182.205 - "Invalid authority field: " + authority);
182.206 - }
182.207 - } else {
182.208 - ind = host.indexOf(':');
182.209 - port = -1;
182.210 - if (ind >= 0) {
182.211 - // port can be null according to RFC2396
182.212 - if (host.length() > (ind + 1)) {
182.213 - port = Integer.parseInt(host.substring(ind + 1));
182.214 - }
182.215 - host = host.substring(0, ind);
182.216 - }
182.217 - }
182.218 - } else {
182.219 - host = "";
182.220 - }
182.221 - if (port < -1)
182.222 - throw new IllegalArgumentException("Invalid port number :" +
182.223 - port);
182.224 - start = i;
182.225 - // If the authority is defined then the path is defined by the
182.226 - // spec only; See RFC 2396 Section 5.2.4.
182.227 - if (authority != null && authority.length() > 0)
182.228 - path = "";
182.229 - }
182.230 -
182.231 - if (host == null) {
182.232 - host = "";
182.233 - }
182.234 -
182.235 - // Parse the file path if any
182.236 - if (start < limit) {
182.237 - if (spec.charAt(start) == '/') {
182.238 - path = spec.substring(start, limit);
182.239 - } else if (path != null && path.length() > 0) {
182.240 - isRelPath = true;
182.241 - int ind = path.lastIndexOf('/');
182.242 - String seperator = "";
182.243 - if (ind == -1 && authority != null)
182.244 - seperator = "/";
182.245 - path = path.substring(0, ind + 1) + seperator +
182.246 - spec.substring(start, limit);
182.247 -
182.248 - } else {
182.249 - String seperator = (authority != null) ? "/" : "";
182.250 - path = seperator + spec.substring(start, limit);
182.251 - }
182.252 - } else if (queryOnly && path != null) {
182.253 - int ind = path.lastIndexOf('/');
182.254 - if (ind < 0)
182.255 - ind = 0;
182.256 - path = path.substring(0, ind) + "/";
182.257 - }
182.258 - if (path == null)
182.259 - path = "";
182.260 -
182.261 - if (isRelPath) {
182.262 - // Remove embedded /./
182.263 - while ((i = path.indexOf("/./")) >= 0) {
182.264 - path = path.substring(0, i) + path.substring(i + 2);
182.265 - }
182.266 - // Remove embedded /../ if possible
182.267 - i = 0;
182.268 - while ((i = path.indexOf("/../", i)) >= 0) {
182.269 - /*
182.270 - * A "/../" will cancel the previous segment and itself,
182.271 - * unless that segment is a "/../" itself
182.272 - * i.e. "/a/b/../c" becomes "/a/c"
182.273 - * but "/../../a" should stay unchanged
182.274 - */
182.275 - if (i > 0 && (limit = path.lastIndexOf('/', i - 1)) >= 0 &&
182.276 - (path.indexOf("/../", limit) != 0)) {
182.277 - path = path.substring(0, limit) + path.substring(i + 3);
182.278 - i = 0;
182.279 - } else {
182.280 - i = i + 3;
182.281 - }
182.282 - }
182.283 - // Remove trailing .. if possible
182.284 - while (path.endsWith("/..")) {
182.285 - i = path.indexOf("/..");
182.286 - if ((limit = path.lastIndexOf('/', i - 1)) >= 0) {
182.287 - path = path.substring(0, limit+1);
182.288 - } else {
182.289 - break;
182.290 - }
182.291 - }
182.292 - // Remove starting .
182.293 - if (path.startsWith("./") && path.length() > 2)
182.294 - path = path.substring(2);
182.295 -
182.296 - // Remove trailing .
182.297 - if (path.endsWith("/."))
182.298 - path = path.substring(0, path.length() -1);
182.299 - }
182.300 -
182.301 - setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
182.302 - }
182.303 -
182.304 - /**
182.305 - * Returns the default port for a URL parsed by this handler. This method
182.306 - * is meant to be overidden by handlers with default port numbers.
182.307 - * @return the default port for a <code>URL</code> parsed by this handler.
182.308 - * @since 1.3
182.309 - */
182.310 - protected int getDefaultPort() {
182.311 - return -1;
182.312 - }
182.313 -
182.314 - /**
182.315 - * Provides the default equals calculation. May be overidden by handlers
182.316 - * for other protocols that have different requirements for equals().
182.317 - * This method requires that none of its arguments is null. This is
182.318 - * guaranteed by the fact that it is only called by java.net.URL class.
182.319 - * @param u1 a URL object
182.320 - * @param u2 a URL object
182.321 - * @return <tt>true</tt> if the two urls are
182.322 - * considered equal, ie. they refer to the same
182.323 - * fragment in the same file.
182.324 - * @since 1.3
182.325 - */
182.326 - protected boolean equals(URL u1, URL u2) {
182.327 - String ref1 = u1.getRef();
182.328 - String ref2 = u2.getRef();
182.329 - return (ref1 == ref2 || (ref1 != null && ref1.equals(ref2))) &&
182.330 - sameFile(u1, u2);
182.331 - }
182.332 -
182.333 - /**
182.334 - * Provides the default hash calculation. May be overidden by handlers for
182.335 - * other protocols that have different requirements for hashCode
182.336 - * calculation.
182.337 - * @param u a URL object
182.338 - * @return an <tt>int</tt> suitable for hash table indexing
182.339 - * @since 1.3
182.340 - */
182.341 - protected int hashCode(URL u) {
182.342 - int h = 0;
182.343 -
182.344 - // Generate the protocol part.
182.345 - String protocol = u.getProtocol();
182.346 - if (protocol != null)
182.347 - h += protocol.hashCode();
182.348 -
182.349 - // Generate the host part.
182.350 - Object addr = getHostAddress(u);
182.351 - if (addr != null) {
182.352 - h += addr.hashCode();
182.353 - } else {
182.354 - String host = u.getHost();
182.355 - if (host != null)
182.356 - h += host.toLowerCase().hashCode();
182.357 - }
182.358 -
182.359 - // Generate the file part.
182.360 - String file = u.getFile();
182.361 - if (file != null)
182.362 - h += file.hashCode();
182.363 -
182.364 - // Generate the port part.
182.365 - if (u.getPort() == -1)
182.366 - h += getDefaultPort();
182.367 - else
182.368 - h += u.getPort();
182.369 -
182.370 - // Generate the ref part.
182.371 - String ref = u.getRef();
182.372 - if (ref != null)
182.373 - h += ref.hashCode();
182.374 -
182.375 - return h;
182.376 - }
182.377 -
182.378 - /**
182.379 - * Compare two urls to see whether they refer to the same file,
182.380 - * i.e., having the same protocol, host, port, and path.
182.381 - * This method requires that none of its arguments is null. This is
182.382 - * guaranteed by the fact that it is only called indirectly
182.383 - * by java.net.URL class.
182.384 - * @param u1 a URL object
182.385 - * @param u2 a URL object
182.386 - * @return true if u1 and u2 refer to the same file
182.387 - * @since 1.3
182.388 - */
182.389 - protected boolean sameFile(URL u1, URL u2) {
182.390 - // Compare the protocols.
182.391 - if (!((u1.getProtocol() == u2.getProtocol()) ||
182.392 - (u1.getProtocol() != null &&
182.393 - u1.getProtocol().equalsIgnoreCase(u2.getProtocol()))))
182.394 - return false;
182.395 -
182.396 - // Compare the files.
182.397 - if (!(u1.getFile() == u2.getFile() ||
182.398 - (u1.getFile() != null && u1.getFile().equals(u2.getFile()))))
182.399 - return false;
182.400 -
182.401 - // Compare the ports.
182.402 - int port1, port2;
182.403 - port1 = (u1.getPort() != -1) ? u1.getPort() : u1.handler.getDefaultPort();
182.404 - port2 = (u2.getPort() != -1) ? u2.getPort() : u2.handler.getDefaultPort();
182.405 - if (port1 != port2)
182.406 - return false;
182.407 -
182.408 - // Compare the hosts.
182.409 - if (!hostsEqual(u1, u2))
182.410 - return false;
182.411 -
182.412 - return true;
182.413 - }
182.414 -
182.415 - /**
182.416 - * Get the IP address of our host. An empty host field or a DNS failure
182.417 - * will result in a null return.
182.418 - *
182.419 - * @param u a URL object
182.420 - * @return an <code>InetAddress</code> representing the host
182.421 - * IP address.
182.422 - * @since 1.3
182.423 - */
182.424 - private synchronized Object getHostAddress(URL u) {
182.425 - return u.hostAddress;
182.426 - }
182.427 -
182.428 - /**
182.429 - * Compares the host components of two URLs.
182.430 - * @param u1 the URL of the first host to compare
182.431 - * @param u2 the URL of the second host to compare
182.432 - * @return <tt>true</tt> if and only if they
182.433 - * are equal, <tt>false</tt> otherwise.
182.434 - * @since 1.3
182.435 - */
182.436 - protected boolean hostsEqual(URL u1, URL u2) {
182.437 - Object a1 = getHostAddress(u1);
182.438 - Object a2 = getHostAddress(u2);
182.439 - // if we have internet address for both, compare them
182.440 - if (a1 != null && a2 != null) {
182.441 - return a1.equals(a2);
182.442 - // else, if both have host names, compare them
182.443 - } else if (u1.getHost() != null && u2.getHost() != null)
182.444 - return u1.getHost().equalsIgnoreCase(u2.getHost());
182.445 - else
182.446 - return u1.getHost() == null && u2.getHost() == null;
182.447 - }
182.448 -
182.449 - /**
182.450 - * Converts a <code>URL</code> of a specific protocol to a
182.451 - * <code>String</code>.
182.452 - *
182.453 - * @param u the URL.
182.454 - * @return a string representation of the <code>URL</code> argument.
182.455 - */
182.456 - protected String toExternalForm(URL u) {
182.457 -
182.458 - // pre-compute length of StringBuffer
182.459 - int len = u.getProtocol().length() + 1;
182.460 - if (u.getAuthority() != null && u.getAuthority().length() > 0)
182.461 - len += 2 + u.getAuthority().length();
182.462 - if (u.getPath() != null) {
182.463 - len += u.getPath().length();
182.464 - }
182.465 - if (u.getQuery() != null) {
182.466 - len += 1 + u.getQuery().length();
182.467 - }
182.468 - if (u.getRef() != null)
182.469 - len += 1 + u.getRef().length();
182.470 -
182.471 - StringBuffer result = new StringBuffer(len);
182.472 - result.append(u.getProtocol());
182.473 - result.append(":");
182.474 - if (u.getAuthority() != null && u.getAuthority().length() > 0) {
182.475 - result.append("//");
182.476 - result.append(u.getAuthority());
182.477 - }
182.478 - if (u.getPath() != null) {
182.479 - result.append(u.getPath());
182.480 - }
182.481 - if (u.getQuery() != null) {
182.482 - result.append('?');
182.483 - result.append(u.getQuery());
182.484 - }
182.485 - if (u.getRef() != null) {
182.486 - result.append("#");
182.487 - result.append(u.getRef());
182.488 - }
182.489 - return result.toString();
182.490 - }
182.491 -
182.492 - /**
182.493 - * Sets the fields of the <code>URL</code> argument to the indicated values.
182.494 - * Only classes derived from URLStreamHandler are supposed to be able
182.495 - * to call the set method on a URL.
182.496 - *
182.497 - * @param u the URL to modify.
182.498 - * @param protocol the protocol name.
182.499 - * @param host the remote host value for the URL.
182.500 - * @param port the port on the remote machine.
182.501 - * @param authority the authority part for the URL.
182.502 - * @param userInfo the userInfo part of the URL.
182.503 - * @param path the path component of the URL.
182.504 - * @param query the query part for the URL.
182.505 - * @param ref the reference.
182.506 - * @exception SecurityException if the protocol handler of the URL is
182.507 - * different from this one
182.508 - * @see java.net.URL#set(java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
182.509 - * @since 1.3
182.510 - */
182.511 - protected void setURL(URL u, String protocol, String host, int port,
182.512 - String authority, String userInfo, String path,
182.513 - String query, String ref) {
182.514 - if (this != u.handler) {
182.515 - throw new SecurityException("handler for url different from " +
182.516 - "this handler");
182.517 - }
182.518 - // ensure that no one can reset the protocol on a given URL.
182.519 - u.set(u.getProtocol(), host, port, authority, userInfo, path, query, ref);
182.520 - }
182.521 -
182.522 - /**
182.523 - * Sets the fields of the <code>URL</code> argument to the indicated values.
182.524 - * Only classes derived from URLStreamHandler are supposed to be able
182.525 - * to call the set method on a URL.
182.526 - *
182.527 - * @param u the URL to modify.
182.528 - * @param protocol the protocol name. This value is ignored since 1.2.
182.529 - * @param host the remote host value for the URL.
182.530 - * @param port the port on the remote machine.
182.531 - * @param file the file.
182.532 - * @param ref the reference.
182.533 - * @exception SecurityException if the protocol handler of the URL is
182.534 - * different from this one
182.535 - * @deprecated Use setURL(URL, String, String, int, String, String, String,
182.536 - * String);
182.537 - */
182.538 - @Deprecated
182.539 - protected void setURL(URL u, String protocol, String host, int port,
182.540 - String file, String ref) {
182.541 - /*
182.542 - * Only old URL handlers call this, so assume that the host
182.543 - * field might contain "user:passwd@host". Fix as necessary.
182.544 - */
182.545 - String authority = null;
182.546 - String userInfo = null;
182.547 - if (host != null && host.length() != 0) {
182.548 - authority = (port == -1) ? host : host + ":" + port;
182.549 - int at = host.lastIndexOf('@');
182.550 - if (at != -1) {
182.551 - userInfo = host.substring(0, at);
182.552 - host = host.substring(at+1);
182.553 - }
182.554 - }
182.555 -
182.556 - /*
182.557 - * Assume file might contain query part. Fix as necessary.
182.558 - */
182.559 - String path = null;
182.560 - String query = null;
182.561 - if (file != null) {
182.562 - int q = file.lastIndexOf('?');
182.563 - if (q != -1) {
182.564 - query = file.substring(q+1);
182.565 - path = file.substring(0, q);
182.566 - } else
182.567 - path = file;
182.568 - }
182.569 - setURL(u, protocol, host, port, authority, userInfo, path, query, ref);
182.570 - }
182.571 -}
183.1 --- a/emul/src/main/java/java/util/Comparator.java Wed Jan 23 20:16:48 2013 +0100
183.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
183.3 @@ -1,168 +0,0 @@
183.4 -/*
183.5 - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
183.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
183.7 - *
183.8 - * This code is free software; you can redistribute it and/or modify it
183.9 - * under the terms of the GNU General Public License version 2 only, as
183.10 - * published by the Free Software Foundation. Oracle designates this
183.11 - * particular file as subject to the "Classpath" exception as provided
183.12 - * by Oracle in the LICENSE file that accompanied this code.
183.13 - *
183.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
183.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
183.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
183.17 - * version 2 for more details (a copy is included in the LICENSE file that
183.18 - * accompanied this code).
183.19 - *
183.20 - * You should have received a copy of the GNU General Public License version
183.21 - * 2 along with this work; if not, write to the Free Software Foundation,
183.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
183.23 - *
183.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
183.25 - * or visit www.oracle.com if you need additional information or have any
183.26 - * questions.
183.27 - */
183.28 -
183.29 -package java.util;
183.30 -
183.31 -/**
183.32 - * A comparison function, which imposes a <i>total ordering</i> on some
183.33 - * collection of objects. Comparators can be passed to a sort method (such
183.34 - * as {@link Collections#sort(List,Comparator) Collections.sort} or {@link
183.35 - * Arrays#sort(Object[],Comparator) Arrays.sort}) to allow precise control
183.36 - * over the sort order. Comparators can also be used to control the order of
183.37 - * certain data structures (such as {@link SortedSet sorted sets} or {@link
183.38 - * SortedMap sorted maps}), or to provide an ordering for collections of
183.39 - * objects that don't have a {@link Comparable natural ordering}.<p>
183.40 - *
183.41 - * The ordering imposed by a comparator <tt>c</tt> on a set of elements
183.42 - * <tt>S</tt> is said to be <i>consistent with equals</i> if and only if
183.43 - * <tt>c.compare(e1, e2)==0</tt> has the same boolean value as
183.44 - * <tt>e1.equals(e2)</tt> for every <tt>e1</tt> and <tt>e2</tt> in
183.45 - * <tt>S</tt>.<p>
183.46 - *
183.47 - * Caution should be exercised when using a comparator capable of imposing an
183.48 - * ordering inconsistent with equals to order a sorted set (or sorted map).
183.49 - * Suppose a sorted set (or sorted map) with an explicit comparator <tt>c</tt>
183.50 - * is used with elements (or keys) drawn from a set <tt>S</tt>. If the
183.51 - * ordering imposed by <tt>c</tt> on <tt>S</tt> is inconsistent with equals,
183.52 - * the sorted set (or sorted map) will behave "strangely." In particular the
183.53 - * sorted set (or sorted map) will violate the general contract for set (or
183.54 - * map), which is defined in terms of <tt>equals</tt>.<p>
183.55 - *
183.56 - * For example, suppose one adds two elements {@code a} and {@code b} such that
183.57 - * {@code (a.equals(b) && c.compare(a, b) != 0)}
183.58 - * to an empty {@code TreeSet} with comparator {@code c}.
183.59 - * The second {@code add} operation will return
183.60 - * true (and the size of the tree set will increase) because {@code a} and
183.61 - * {@code b} are not equivalent from the tree set's perspective, even though
183.62 - * this is contrary to the specification of the
183.63 - * {@link Set#add Set.add} method.<p>
183.64 - *
183.65 - * Note: It is generally a good idea for comparators to also implement
183.66 - * <tt>java.io.Serializable</tt>, as they may be used as ordering methods in
183.67 - * serializable data structures (like {@link TreeSet}, {@link TreeMap}). In
183.68 - * order for the data structure to serialize successfully, the comparator (if
183.69 - * provided) must implement <tt>Serializable</tt>.<p>
183.70 - *
183.71 - * For the mathematically inclined, the <i>relation</i> that defines the
183.72 - * <i>imposed ordering</i> that a given comparator <tt>c</tt> imposes on a
183.73 - * given set of objects <tt>S</tt> is:<pre>
183.74 - * {(x, y) such that c.compare(x, y) <= 0}.
183.75 - * </pre> The <i>quotient</i> for this total order is:<pre>
183.76 - * {(x, y) such that c.compare(x, y) == 0}.
183.77 - * </pre>
183.78 - *
183.79 - * It follows immediately from the contract for <tt>compare</tt> that the
183.80 - * quotient is an <i>equivalence relation</i> on <tt>S</tt>, and that the
183.81 - * imposed ordering is a <i>total order</i> on <tt>S</tt>. When we say that
183.82 - * the ordering imposed by <tt>c</tt> on <tt>S</tt> is <i>consistent with
183.83 - * equals</i>, we mean that the quotient for the ordering is the equivalence
183.84 - * relation defined by the objects' {@link Object#equals(Object)
183.85 - * equals(Object)} method(s):<pre>
183.86 - * {(x, y) such that x.equals(y)}. </pre>
183.87 - *
183.88 - * <p>Unlike {@code Comparable}, a comparator may optionally permit
183.89 - * comparison of null arguments, while maintaining the requirements for
183.90 - * an equivalence relation.
183.91 - *
183.92 - * <p>This interface is a member of the
183.93 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
183.94 - * Java Collections Framework</a>.
183.95 - *
183.96 - * @param <T> the type of objects that may be compared by this comparator
183.97 - *
183.98 - * @author Josh Bloch
183.99 - * @author Neal Gafter
183.100 - * @see Comparable
183.101 - * @see java.io.Serializable
183.102 - * @since 1.2
183.103 - */
183.104 -
183.105 -public interface Comparator<T> {
183.106 - /**
183.107 - * Compares its two arguments for order. Returns a negative integer,
183.108 - * zero, or a positive integer as the first argument is less than, equal
183.109 - * to, or greater than the second.<p>
183.110 - *
183.111 - * In the foregoing description, the notation
183.112 - * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
183.113 - * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
183.114 - * <tt>0</tt>, or <tt>1</tt> according to whether the value of
183.115 - * <i>expression</i> is negative, zero or positive.<p>
183.116 - *
183.117 - * The implementor must ensure that <tt>sgn(compare(x, y)) ==
183.118 - * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
183.119 - * implies that <tt>compare(x, y)</tt> must throw an exception if and only
183.120 - * if <tt>compare(y, x)</tt> throws an exception.)<p>
183.121 - *
183.122 - * The implementor must also ensure that the relation is transitive:
183.123 - * <tt>((compare(x, y)>0) && (compare(y, z)>0))</tt> implies
183.124 - * <tt>compare(x, z)>0</tt>.<p>
183.125 - *
183.126 - * Finally, the implementor must ensure that <tt>compare(x, y)==0</tt>
183.127 - * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
183.128 - * <tt>z</tt>.<p>
183.129 - *
183.130 - * It is generally the case, but <i>not</i> strictly required that
183.131 - * <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking,
183.132 - * any comparator that violates this condition should clearly indicate
183.133 - * this fact. The recommended language is "Note: this comparator
183.134 - * imposes orderings that are inconsistent with equals."
183.135 - *
183.136 - * @param o1 the first object to be compared.
183.137 - * @param o2 the second object to be compared.
183.138 - * @return a negative integer, zero, or a positive integer as the
183.139 - * first argument is less than, equal to, or greater than the
183.140 - * second.
183.141 - * @throws NullPointerException if an argument is null and this
183.142 - * comparator does not permit null arguments
183.143 - * @throws ClassCastException if the arguments' types prevent them from
183.144 - * being compared by this comparator.
183.145 - */
183.146 - int compare(T o1, T o2);
183.147 -
183.148 - /**
183.149 - * Indicates whether some other object is "equal to" this
183.150 - * comparator. This method must obey the general contract of
183.151 - * {@link Object#equals(Object)}. Additionally, this method can return
183.152 - * <tt>true</tt> <i>only</i> if the specified object is also a comparator
183.153 - * and it imposes the same ordering as this comparator. Thus,
183.154 - * <code>comp1.equals(comp2)</code> implies that <tt>sgn(comp1.compare(o1,
183.155 - * o2))==sgn(comp2.compare(o1, o2))</tt> for every object reference
183.156 - * <tt>o1</tt> and <tt>o2</tt>.<p>
183.157 - *
183.158 - * Note that it is <i>always</i> safe <i>not</i> to override
183.159 - * <tt>Object.equals(Object)</tt>. However, overriding this method may,
183.160 - * in some cases, improve performance by allowing programs to determine
183.161 - * that two distinct comparators impose the same order.
183.162 - *
183.163 - * @param obj the reference object with which to compare.
183.164 - * @return <code>true</code> only if the specified object is also
183.165 - * a comparator and it imposes the same ordering as this
183.166 - * comparator.
183.167 - * @see Object#equals(Object)
183.168 - * @see Object#hashCode()
183.169 - */
183.170 - boolean equals(Object obj);
183.171 -}
184.1 --- a/emul/src/main/java/java/util/Enumeration.java Wed Jan 23 20:16:48 2013 +0100
184.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
184.3 @@ -1,79 +0,0 @@
184.4 -/*
184.5 - * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
184.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
184.7 - *
184.8 - * This code is free software; you can redistribute it and/or modify it
184.9 - * under the terms of the GNU General Public License version 2 only, as
184.10 - * published by the Free Software Foundation. Oracle designates this
184.11 - * particular file as subject to the "Classpath" exception as provided
184.12 - * by Oracle in the LICENSE file that accompanied this code.
184.13 - *
184.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
184.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
184.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
184.17 - * version 2 for more details (a copy is included in the LICENSE file that
184.18 - * accompanied this code).
184.19 - *
184.20 - * You should have received a copy of the GNU General Public License version
184.21 - * 2 along with this work; if not, write to the Free Software Foundation,
184.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
184.23 - *
184.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
184.25 - * or visit www.oracle.com if you need additional information or have any
184.26 - * questions.
184.27 - */
184.28 -
184.29 -package java.util;
184.30 -
184.31 -/**
184.32 - * An object that implements the Enumeration interface generates a
184.33 - * series of elements, one at a time. Successive calls to the
184.34 - * <code>nextElement</code> method return successive elements of the
184.35 - * series.
184.36 - * <p>
184.37 - * For example, to print all elements of a <tt>Vector<E></tt> <i>v</i>:
184.38 - * <pre>
184.39 - * for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
184.40 - * System.out.println(e.nextElement());</pre>
184.41 - * <p>
184.42 - * Methods are provided to enumerate through the elements of a
184.43 - * vector, the keys of a hashtable, and the values in a hashtable.
184.44 - * Enumerations are also used to specify the input streams to a
184.45 - * <code>SequenceInputStream</code>.
184.46 - * <p>
184.47 - * NOTE: The functionality of this interface is duplicated by the Iterator
184.48 - * interface. In addition, Iterator adds an optional remove operation, and
184.49 - * has shorter method names. New implementations should consider using
184.50 - * Iterator in preference to Enumeration.
184.51 - *
184.52 - * @see java.util.Iterator
184.53 - * @see java.io.SequenceInputStream
184.54 - * @see java.util.Enumeration#nextElement()
184.55 - * @see java.util.Hashtable
184.56 - * @see java.util.Hashtable#elements()
184.57 - * @see java.util.Hashtable#keys()
184.58 - * @see java.util.Vector
184.59 - * @see java.util.Vector#elements()
184.60 - *
184.61 - * @author Lee Boynton
184.62 - * @since JDK1.0
184.63 - */
184.64 -public interface Enumeration<E> {
184.65 - /**
184.66 - * Tests if this enumeration contains more elements.
184.67 - *
184.68 - * @return <code>true</code> if and only if this enumeration object
184.69 - * contains at least one more element to provide;
184.70 - * <code>false</code> otherwise.
184.71 - */
184.72 - boolean hasMoreElements();
184.73 -
184.74 - /**
184.75 - * Returns the next element of this enumeration if this enumeration
184.76 - * object has at least one more element to provide.
184.77 - *
184.78 - * @return the next element of this enumeration.
184.79 - * @exception NoSuchElementException if no more elements exist.
184.80 - */
184.81 - E nextElement();
184.82 -}
185.1 --- a/emul/src/main/java/java/util/NoSuchElementException.java Wed Jan 23 20:16:48 2013 +0100
185.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
185.3 @@ -1,60 +0,0 @@
185.4 -/*
185.5 - * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
185.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
185.7 - *
185.8 - * This code is free software; you can redistribute it and/or modify it
185.9 - * under the terms of the GNU General Public License version 2 only, as
185.10 - * published by the Free Software Foundation. Oracle designates this
185.11 - * particular file as subject to the "Classpath" exception as provided
185.12 - * by Oracle in the LICENSE file that accompanied this code.
185.13 - *
185.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
185.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
185.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
185.17 - * version 2 for more details (a copy is included in the LICENSE file that
185.18 - * accompanied this code).
185.19 - *
185.20 - * You should have received a copy of the GNU General Public License version
185.21 - * 2 along with this work; if not, write to the Free Software Foundation,
185.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
185.23 - *
185.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
185.25 - * or visit www.oracle.com if you need additional information or have any
185.26 - * questions.
185.27 - */
185.28 -
185.29 -package java.util;
185.30 -
185.31 -/**
185.32 - * Thrown by the <code>nextElement</code> method of an
185.33 - * <code>Enumeration</code> to indicate that there are no more
185.34 - * elements in the enumeration.
185.35 - *
185.36 - * @author unascribed
185.37 - * @see java.util.Enumeration
185.38 - * @see java.util.Enumeration#nextElement()
185.39 - * @since JDK1.0
185.40 - */
185.41 -public
185.42 -class NoSuchElementException extends RuntimeException {
185.43 - private static final long serialVersionUID = 6769829250639411880L;
185.44 -
185.45 - /**
185.46 - * Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
185.47 - * as its error message string.
185.48 - */
185.49 - public NoSuchElementException() {
185.50 - super();
185.51 - }
185.52 -
185.53 - /**
185.54 - * Constructs a <code>NoSuchElementException</code>, saving a reference
185.55 - * to the error message string <tt>s</tt> for later retrieval by the
185.56 - * <tt>getMessage</tt> method.
185.57 - *
185.58 - * @param s the detail message.
185.59 - */
185.60 - public NoSuchElementException(String s) {
185.61 - super(s);
185.62 - }
185.63 -}
186.1 --- a/emul/src/main/java/org/apidesign/bck2brwsr/emul/AnnotationImpl.java Wed Jan 23 20:16:48 2013 +0100
186.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
186.3 @@ -1,81 +0,0 @@
186.4 -/**
186.5 - * Back 2 Browser Bytecode Translator
186.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
186.7 - *
186.8 - * This program is free software: you can redistribute it and/or modify
186.9 - * it under the terms of the GNU General Public License as published by
186.10 - * the Free Software Foundation, version 2 of the License.
186.11 - *
186.12 - * This program is distributed in the hope that it will be useful,
186.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
186.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
186.15 - * GNU General Public License for more details.
186.16 - *
186.17 - * You should have received a copy of the GNU General Public License
186.18 - * along with this program. Look for COPYING file in the top folder.
186.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
186.20 - */
186.21 -package org.apidesign.bck2brwsr.emul;
186.22 -
186.23 -import java.lang.annotation.Annotation;
186.24 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
186.25 -
186.26 -/**
186.27 - *
186.28 - * @author Jaroslav Tulach <jtulach@netbeans.org>
186.29 - */
186.30 -public final class AnnotationImpl implements Annotation {
186.31 - public Class<? extends Annotation> annotationType() {
186.32 - return getClass();
186.33 - }
186.34 -
186.35 - @JavaScriptBody(args = { "a", "n", "values" }, body = ""
186.36 - + "function f(v, p) {\n"
186.37 - + " var val = v;\n"
186.38 - + " var prop = p;\n"
186.39 - + " return function() {\n"
186.40 - + " return val[prop];\n"
186.41 - + " };\n"
186.42 - + "}\n"
186.43 - + "var props = Object.getOwnPropertyNames(values);\n"
186.44 - + "for (var i = 0; i < props.length; i++) {\n"
186.45 - + " var p = props[i];\n"
186.46 - + " a[p] = new f(values, p);\n"
186.47 - + "}\n"
186.48 - + "a['$instOf_' + n] = true;\n"
186.49 - + "return a;"
186.50 - )
186.51 - private static <T extends Annotation> T create(AnnotationImpl a, String n, Object values) {
186.52 - return null;
186.53 - }
186.54 - public static <T extends Annotation> T create(Class<T> annoClass, Object values) {
186.55 - return create(new AnnotationImpl(), annoClass.getName().replace('.', '_'), values);
186.56 - }
186.57 -
186.58 - public static Annotation[] create(Object anno) {
186.59 - String[] names = findNames(anno);
186.60 - Annotation[] ret = new Annotation[names.length];
186.61 - for (int i = 0; i < names.length; i++) {
186.62 - String n = names[i].substring(1, names[i].length() - 1).replace('/', '_');
186.63 - ret[i] = create(new AnnotationImpl(), n, findData(anno, names[i]));
186.64 - }
186.65 - return ret;
186.66 - }
186.67 - @JavaScriptBody(args = "anno", body =
186.68 - "var arr = new Array();"
186.69 - + "var props = Object.getOwnPropertyNames(anno);\n"
186.70 - + "for (var i = 0; i < props.length; i++) {\n"
186.71 - + " var p = props[i];\n"
186.72 - + " arr.push(p);"
186.73 - + "}"
186.74 - + "return arr;"
186.75 - )
186.76 - private static String[] findNames(Object anno) {
186.77 - throw new UnsupportedOperationException();
186.78 - }
186.79 -
186.80 - @JavaScriptBody(args={ "anno", "p"}, body="return anno[p];")
186.81 - private static Object findData(Object anno, String p) {
186.82 - throw new UnsupportedOperationException();
186.83 - }
186.84 -}
187.1 --- a/emul/src/main/java/org/apidesign/bck2brwsr/emul/MethodImpl.java Wed Jan 23 20:16:48 2013 +0100
187.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
187.3 @@ -1,164 +0,0 @@
187.4 -/*
187.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
187.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
187.7 - *
187.8 - * This code is free software; you can redistribute it and/or modify it
187.9 - * under the terms of the GNU General Public License version 2 only, as
187.10 - * published by the Free Software Foundation. Oracle designates this
187.11 - * particular file as subject to the "Classpath" exception as provided
187.12 - * by Oracle in the LICENSE file that accompanied this code.
187.13 - *
187.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
187.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
187.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
187.17 - * version 2 for more details (a copy is included in the LICENSE file that
187.18 - * accompanied this code).
187.19 - *
187.20 - * You should have received a copy of the GNU General Public License version
187.21 - * 2 along with this work; if not, write to the Free Software Foundation,
187.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
187.23 - *
187.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
187.25 - * or visit www.oracle.com if you need additional information or have any
187.26 - * questions.
187.27 - */
187.28 -package org.apidesign.bck2brwsr.emul;
187.29 -
187.30 -import java.lang.reflect.Method;
187.31 -import java.util.Enumeration;
187.32 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
187.33 -
187.34 -/** Utilities to work on methods.
187.35 - *
187.36 - * @author Jaroslav Tulach <jtulach@netbeans.org>
187.37 - */
187.38 -public abstract class MethodImpl {
187.39 - public static MethodImpl INSTANCE;
187.40 - static {
187.41 - try {
187.42 - Class.forName(Method.class.getName());
187.43 - } catch (ClassNotFoundException ex) {
187.44 - throw new IllegalStateException(ex);
187.45 - }
187.46 - }
187.47 -
187.48 - protected abstract Method create(Class<?> declaringClass, String name, Object data, String sig);
187.49 -
187.50 -
187.51 - //
187.52 - // bck2brwsr implementation
187.53 - //
187.54 -
187.55 - @JavaScriptBody(args = {"clazz", "prefix"},
187.56 - body = ""
187.57 - + "var c = clazz.cnstr.prototype;"
187.58 - + "var arr = new Array();\n"
187.59 - + "for (m in c) {\n"
187.60 - + " if (m.indexOf(prefix) === 0) {\n"
187.61 - + " arr.push(m);\n"
187.62 - + " arr.push(c[m]);\n"
187.63 - + " }"
187.64 - + "}\n"
187.65 - + "return arr;")
187.66 - private static native Object[] findMethodData(
187.67 - Class<?> clazz, String prefix);
187.68 -
187.69 - public static Method findMethod(
187.70 - Class<?> clazz, String name, Class<?>... parameterTypes) {
187.71 - Object[] data = findMethodData(clazz, name + "__");
187.72 - BIG: for (int i = 0; i < data.length; i += 2) {
187.73 - String sig = ((String) data[0]).substring(name.length() + 2);
187.74 - Method tmp = INSTANCE.create(clazz, name, data[1], sig);
187.75 - Class<?>[] tmpParms = tmp.getParameterTypes();
187.76 - if (parameterTypes.length != tmpParms.length) {
187.77 - continue;
187.78 - }
187.79 - for (int j = 0; j < tmpParms.length; j++) {
187.80 - if (!parameterTypes[j].equals(tmpParms[j])) {
187.81 - continue BIG;
187.82 - }
187.83 - }
187.84 - return tmp;
187.85 - }
187.86 - return null;
187.87 - }
187.88 -
187.89 - public static Method[] findMethods(Class<?> clazz, int mask) {
187.90 - Object[] namesAndData = findMethodData(clazz, "");
187.91 - int cnt = 0;
187.92 - for (int i = 0; i < namesAndData.length; i += 2) {
187.93 - String sig = (String) namesAndData[i];
187.94 - Object data = namesAndData[i + 1];
187.95 - int middle = sig.indexOf("__");
187.96 - if (middle == -1) {
187.97 - continue;
187.98 - }
187.99 - String name = sig.substring(0, middle);
187.100 - sig = sig.substring(middle + 2);
187.101 - final Method m = INSTANCE.create(clazz, name, data, sig);
187.102 - if ((m.getModifiers() & mask) == 0) {
187.103 - continue;
187.104 - }
187.105 - namesAndData[cnt++] = m;
187.106 - }
187.107 - Method[] arr = new Method[cnt];
187.108 - for (int i = 0; i < cnt; i++) {
187.109 - arr[i] = (Method) namesAndData[i];
187.110 - }
187.111 - return arr;
187.112 - }
187.113 -
187.114 - public static int signatureElements(String sig) {
187.115 - Enumeration<Class> en = signatureParser(sig);
187.116 - int cnt = 0;
187.117 - while (en.hasMoreElements()) {
187.118 - en.nextElement();
187.119 - cnt++;
187.120 - }
187.121 - return cnt;
187.122 - }
187.123 -
187.124 - public static Enumeration<Class> signatureParser(final String sig) {
187.125 - class E implements Enumeration<Class> {
187.126 - int pos;
187.127 -
187.128 - public boolean hasMoreElements() {
187.129 - return pos < sig.length();
187.130 - }
187.131 -
187.132 - public Class nextElement() {
187.133 - switch (sig.charAt(pos++)) {
187.134 - case 'I':
187.135 - return Integer.TYPE;
187.136 - case 'J':
187.137 - return Long.TYPE;
187.138 - case 'D':
187.139 - return Double.TYPE;
187.140 - case 'F':
187.141 - return Float.TYPE;
187.142 - case 'B':
187.143 - return Byte.TYPE;
187.144 - case 'Z':
187.145 - return Boolean.TYPE;
187.146 - case 'S':
187.147 - return Short.TYPE;
187.148 - case 'V':
187.149 - return Void.TYPE;
187.150 - case 'C':
187.151 - return Character.TYPE;
187.152 - case 'L':
187.153 - try {
187.154 - int up = sig.indexOf("_2");
187.155 - String type = sig.substring(1, up);
187.156 - pos = up + 2;
187.157 - return Class.forName(type);
187.158 - } catch (ClassNotFoundException ex) {
187.159 - // should not happen
187.160 - }
187.161 - }
187.162 - throw new UnsupportedOperationException(sig + " at " + pos);
187.163 - }
187.164 - }
187.165 - return new E();
187.166 - }
187.167 -}
188.1 --- a/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_Number.js Wed Jan 23 20:16:48 2013 +0100
188.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
188.3 @@ -1,9 +0,0 @@
188.4 -// empty line needed here
188.5 -Number.prototype.add32 = function(x) { return (this + x) | 0; };
188.6 -Number.prototype.sub32 = function(x) { return (this - x) | 0; };
188.7 -Number.prototype.mul32 = function(x) {
188.8 - return (((this * (x >> 16)) << 16) + this * (x & 0xFFFF)) | 0;
188.9 -};
188.10 -
188.11 -Number.prototype.toInt8 = function() { return (this << 24) >> 24; };
188.12 -Number.prototype.toInt16 = function() { return (this << 16) >> 16; };
188.13 \ No newline at end of file
189.1 --- a/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js Wed Jan 23 20:16:48 2013 +0100
189.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
189.3 @@ -1,26 +0,0 @@
189.4 -// initialize methods on arrays and String constants
189.5 -vm.java_lang_reflect_Array(false);
189.6 -vm.java_lang_String(false);
189.7 -
189.8 -Array.prototype.at = function(indx, value) {
189.9 - if (indx < 0 || indx > this.length) {
189.10 - var e = vm.java_lang_ArrayIndexOutOfBoundsException(true);
189.11 - e.constructor.cons__VLjava_lang_String_2.call(e, indx.toString());
189.12 - throw e;
189.13 - }
189.14 - if (arguments.length === 2) {
189.15 - this[indx] = value;
189.16 - }
189.17 - return this[indx];
189.18 -};
189.19 -Array.prototype.getClass__Ljava_lang_Class_2 = function() {
189.20 - return vm.java_lang_Class(false).defineArray__Ljava_lang_Class_2Ljava_lang_String_2(this.jvmName);
189.21 -};
189.22 -Array.prototype.clone__Ljava_lang_Object_2 = function() {
189.23 - var s = this.length;
189.24 - var ret = new Array(s);
189.25 - for (var i = 0; i < s; i++) {
189.26 - ret[i] = this[i];
189.27 - }
189.28 - return ret;
189.29 -};
190.1 --- a/javap/pom.xml Wed Jan 23 20:16:48 2013 +0100
190.2 +++ b/javap/pom.xml Wed Jan 23 20:39:23 2013 +0100
190.3 @@ -34,7 +34,7 @@
190.4 <dependencies>
190.5 <dependency>
190.6 <groupId>org.apidesign.bck2brwsr</groupId>
190.7 - <artifactId>emul</artifactId>
190.8 + <artifactId>emul.mini</artifactId>
190.9 <version>0.3-SNAPSHOT</version>
190.10 </dependency>
190.11 </dependencies>
191.1 --- a/javaquery/api/pom.xml Wed Jan 23 20:16:48 2013 +0100
191.2 +++ b/javaquery/api/pom.xml Wed Jan 23 20:39:23 2013 +0100
191.3 @@ -52,7 +52,7 @@
191.4 </dependency>
191.5 <dependency>
191.6 <groupId>org.apidesign.bck2brwsr</groupId>
191.7 - <artifactId>emul</artifactId>
191.8 + <artifactId>emul.mini</artifactId>
191.9 <version>0.3-SNAPSHOT</version>
191.10 <type>jar</type>
191.11 <scope>runtime</scope>
192.1 --- a/javaquery/demo-calculator-dynamic/pom.xml Wed Jan 23 20:16:48 2013 +0100
192.2 +++ b/javaquery/demo-calculator-dynamic/pom.xml Wed Jan 23 20:39:23 2013 +0100
192.3 @@ -46,7 +46,7 @@
192.4 <dependencies>
192.5 <dependency>
192.6 <groupId>org.apidesign.bck2brwsr</groupId>
192.7 - <artifactId>emul</artifactId>
192.8 + <artifactId>emul.mini</artifactId>
192.9 <version>0.3-SNAPSHOT</version>
192.10 </dependency>
192.11 <dependency>
193.1 --- a/javaquery/demo-calculator/pom.xml Wed Jan 23 20:16:48 2013 +0100
193.2 +++ b/javaquery/demo-calculator/pom.xml Wed Jan 23 20:39:23 2013 +0100
193.3 @@ -61,7 +61,7 @@
193.4 <dependencies>
193.5 <dependency>
193.6 <groupId>org.apidesign.bck2brwsr</groupId>
193.7 - <artifactId>emul</artifactId>
193.8 + <artifactId>emul.mini</artifactId>
193.9 <version>0.3-SNAPSHOT</version>
193.10 </dependency>
193.11 <dependency>
194.1 --- a/mojo/pom.xml Wed Jan 23 20:16:48 2013 +0100
194.2 +++ b/mojo/pom.xml Wed Jan 23 20:39:23 2013 +0100
194.3 @@ -66,7 +66,7 @@
194.4 <version>0.3-SNAPSHOT</version>
194.5 <exclusions>
194.6 <exclusion>
194.7 - <artifactId>emul</artifactId>
194.8 + <artifactId>emul.mini</artifactId>
194.9 <groupId>org.apidesign.bck2brwsr</groupId>
194.10 </exclusion>
194.11 </exclusions>
195.1 --- a/mojo/src/main/resources/archetype-resources/pom.xml Wed Jan 23 20:16:48 2013 +0100
195.2 +++ b/mojo/src/main/resources/archetype-resources/pom.xml Wed Jan 23 20:39:23 2013 +0100
195.3 @@ -45,7 +45,7 @@
195.4 <dependencies>
195.5 <dependency>
195.6 <groupId>org.apidesign.bck2brwsr</groupId>
195.7 - <artifactId>emul</artifactId>
195.8 + <artifactId>emul.mini</artifactId>
195.9 <version>0.3-SNAPSHOT</version>
195.10 </dependency>
195.11 <dependency>
196.1 --- a/pom.xml Wed Jan 23 20:16:48 2013 +0100
196.2 +++ b/pom.xml Wed Jan 23 20:39:23 2013 +0100
196.3 @@ -115,4 +115,4 @@
196.4 <properties>
196.5 <license>COPYING</license>
196.6 </properties>
196.7 -</project>
196.8 +</project>
196.9 \ No newline at end of file
197.1 --- a/vm/pom.xml Wed Jan 23 20:16:48 2013 +0100
197.2 +++ b/vm/pom.xml Wed Jan 23 20:39:23 2013 +0100
197.3 @@ -90,7 +90,7 @@
197.4 </dependency>
197.5 <dependency>
197.6 <groupId>${project.groupId}</groupId>
197.7 - <artifactId>emul</artifactId>
197.8 + <artifactId>emul.mini</artifactId>
197.9 <version>0.3-SNAPSHOT</version>
197.10 <scope>test</scope>
197.11 </dependency>
198.1 --- a/vmtest/pom.xml Wed Jan 23 20:16:48 2013 +0100
198.2 +++ b/vmtest/pom.xml Wed Jan 23 20:39:23 2013 +0100
198.3 @@ -49,7 +49,7 @@
198.4 </dependency>
198.5 <dependency>
198.6 <groupId>${project.groupId}</groupId>
198.7 - <artifactId>emul</artifactId>
198.8 + <artifactId>emul.mini</artifactId>
198.9 <version>${project.version}</version>
198.10 <scope>test</scope>
198.11 </dependency>